",options:{disabled:!1,create:null},_createWidget:function(t,s){s=e(s||this.defaultElement||this)[0],this.element=e(s),this.uuid=i++,this.eventNamespace="."+this.widgetName+this.uuid,this.options=e.widget.extend({},this.options,this._getCreateOptions(),t),this.bindings=e(),this.hoverable=e(),this.focusable=e(),s!==this&&(e.data(s,this.widgetFullName,this),this._on(!0,this.element,{remove:function(e){e.target===s&&this.destroy()}}),this.document=e(s.style?s.ownerDocument:s.document||s),this.window=e(this.document[0].defaultView||this.document[0].parentWindow)),this._create(),this._trigger("create",null,this._getCreateEventData()),this._init()},_getCreateOptions:e.noop,_getCreateEventData:e.noop,_create:e.noop,_init:e.noop,destroy:function(){this._destroy(),this.element.unbind(this.eventNamespace).removeData(this.widgetName).removeData(this.widgetFullName).removeData(e.camelCase(this.widgetFullName)),this.widget().unbind(this.eventNamespace).removeAttr("aria-disabled").removeClass(this.widgetFullName+"-disabled "+"ui-state-disabled"),this.bindings.unbind(this.eventNamespace),this.hoverable.removeClass("ui-state-hover"),this.focusable.removeClass("ui-state-focus")},_destroy:e.noop,widget:function(){return this.element},option:function(i,s){var n,a,r,o=i;if(0===arguments.length)return e.widget.extend({},this.options);if("string"==typeof i)if(o={},n=i.split("."),i=n.shift(),n.length){for(a=o[i]=e.widget.extend({},this.options[i]),r=0;n.length-1>r;r++)a[n[r]]=a[n[r]]||{},a=a[n[r]];if(i=n.pop(),s===t)return a[i]===t?null:a[i];a[i]=s}else{if(s===t)return this.options[i]===t?null:this.options[i];o[i]=s}return this._setOptions(o),this},_setOptions:function(e){var t;for(t in e)this._setOption(t,e[t]);return this},_setOption:function(e,t){return this.options[e]=t,"disabled"===e&&(this.widget().toggleClass(this.widgetFullName+"-disabled ui-state-disabled",!!t).attr("aria-disabled",t),this.hoverable.removeClass("ui-state-hover"),this.focusable.removeClass("ui-state-focus")),this},enable:function(){return this._setOption("disabled",!1)},disable:function(){return this._setOption("disabled",!0)},_on:function(i,s,n){var a,r=this;"boolean"!=typeof i&&(n=s,s=i,i=!1),n?(s=a=e(s),this.bindings=this.bindings.add(s)):(n=s,s=this.element,a=this.widget()),e.each(n,function(n,o){function h(){return i||r.options.disabled!==!0&&!e(this).hasClass("ui-state-disabled")?("string"==typeof o?r[o]:o).apply(r,arguments):t}"string"!=typeof o&&(h.guid=o.guid=o.guid||h.guid||e.guid++);var l=n.match(/^(\w+)\s*(.*)$/),u=l[1]+r.eventNamespace,c=l[2];c?a.delegate(c,u,h):s.bind(u,h)})},_off:function(e,t){t=(t||"").split(" ").join(this.eventNamespace+" ")+this.eventNamespace,e.unbind(t).undelegate(t)},_delay:function(e,t){function i(){return("string"==typeof e?s[e]:e).apply(s,arguments)}var s=this;return setTimeout(i,t||0)},_hoverable:function(t){this.hoverable=this.hoverable.add(t),this._on(t,{mouseenter:function(t){e(t.currentTarget).addClass("ui-state-hover")},mouseleave:function(t){e(t.currentTarget).removeClass("ui-state-hover")}})},_focusable:function(t){this.focusable=this.focusable.add(t),this._on(t,{focusin:function(t){e(t.currentTarget).addClass("ui-state-focus")},focusout:function(t){e(t.currentTarget).removeClass("ui-state-focus")}})},_trigger:function(t,i,s){var n,a,r=this.options[t];if(s=s||{},i=e.Event(i),i.type=(t===this.widgetEventPrefix?t:this.widgetEventPrefix+t).toLowerCase(),i.target=this.element[0],a=i.originalEvent)for(n in a)n in i||(i[n]=a[n]);return this.element.trigger(i,s),!(e.isFunction(r)&&r.apply(this.element[0],[i].concat(s))===!1||i.isDefaultPrevented())}},e.each({show:"fadeIn",hide:"fadeOut"},function(t,i){e.Widget.prototype["_"+t]=function(s,n,a){"string"==typeof n&&(n={effect:n});var r,o=n?n===!0||"number"==typeof n?i:n.effect||i:t;n=n||{},"number"==typeof n&&(n={duration:n}),r=!e.isEmptyObject(n),n.complete=a,n.delay&&s.delay(n.delay),r&&e.effects&&e.effects.effect[o]?s[t](n):o!==t&&s[o]?s[o](n.duration,n.easing,a):s.queue(function(i){e(this)[t](),a&&a.call(s[0]),i()})}})})(jQuery);
9 | /*! jQuery UI - v1.10.3 - 2013-05-03
10 | * http://jqueryui.com
11 | * Copyright 2013 jQuery Foundation and other contributors; Licensed MIT */
12 | (function(e){var t=!1;e(document).mouseup(function(){t=!1}),e.widget("ui.mouse",{version:"1.10.3",options:{cancel:"input,textarea,button,select,option",distance:1,delay:0},_mouseInit:function(){var t=this;this.element.bind("mousedown."+this.widgetName,function(e){return t._mouseDown(e)}).bind("click."+this.widgetName,function(i){return!0===e.data(i.target,t.widgetName+".preventClickEvent")?(e.removeData(i.target,t.widgetName+".preventClickEvent"),i.stopImmediatePropagation(),!1):undefined}),this.started=!1},_mouseDestroy:function(){this.element.unbind("."+this.widgetName),this._mouseMoveDelegate&&e(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate)},_mouseDown:function(i){if(!t){this._mouseStarted&&this._mouseUp(i),this._mouseDownEvent=i;var s=this,n=1===i.which,a="string"==typeof this.options.cancel&&i.target.nodeName?e(i.target).closest(this.options.cancel).length:!1;return n&&!a&&this._mouseCapture(i)?(this.mouseDelayMet=!this.options.delay,this.mouseDelayMet||(this._mouseDelayTimer=setTimeout(function(){s.mouseDelayMet=!0},this.options.delay)),this._mouseDistanceMet(i)&&this._mouseDelayMet(i)&&(this._mouseStarted=this._mouseStart(i)!==!1,!this._mouseStarted)?(i.preventDefault(),!0):(!0===e.data(i.target,this.widgetName+".preventClickEvent")&&e.removeData(i.target,this.widgetName+".preventClickEvent"),this._mouseMoveDelegate=function(e){return s._mouseMove(e)},this._mouseUpDelegate=function(e){return s._mouseUp(e)},e(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate),i.preventDefault(),t=!0,!0)):!0}},_mouseMove:function(t){return e.ui.ie&&(!document.documentMode||9>document.documentMode)&&!t.button?this._mouseUp(t):this._mouseStarted?(this._mouseDrag(t),t.preventDefault()):(this._mouseDistanceMet(t)&&this._mouseDelayMet(t)&&(this._mouseStarted=this._mouseStart(this._mouseDownEvent,t)!==!1,this._mouseStarted?this._mouseDrag(t):this._mouseUp(t)),!this._mouseStarted)},_mouseUp:function(t){return e(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate),this._mouseStarted&&(this._mouseStarted=!1,t.target===this._mouseDownEvent.target&&e.data(t.target,this.widgetName+".preventClickEvent",!0),this._mouseStop(t)),!1},_mouseDistanceMet:function(e){return Math.max(Math.abs(this._mouseDownEvent.pageX-e.pageX),Math.abs(this._mouseDownEvent.pageY-e.pageY))>=this.options.distance},_mouseDelayMet:function(){return this.mouseDelayMet},_mouseStart:function(){},_mouseDrag:function(){},_mouseStop:function(){},_mouseCapture:function(){return!0}})})(jQuery);
13 | /*! jQuery UI - v1.10.3 - 2013-05-03
14 | * http://jqueryui.com
15 | * Copyright 2013 jQuery Foundation and other contributors; Licensed MIT */
16 | (function(e){e.widget("ui.draggable",e.ui.mouse,{version:"1.10.3",widgetEventPrefix:"drag",options:{addClasses:!0,appendTo:"parent",axis:!1,connectToSortable:!1,containment:!1,cursor:"auto",cursorAt:!1,grid:!1,handle:!1,helper:"original",iframeFix:!1,opacity:!1,refreshPositions:!1,revert:!1,revertDuration:500,scope:"default",scroll:!0,scrollSensitivity:20,scrollSpeed:20,snap:!1,snapMode:"both",snapTolerance:20,stack:!1,zIndex:!1,drag:null,start:null,stop:null},_create:function(){"original"!==this.options.helper||/^(?:r|a|f)/.test(this.element.css("position"))||(this.element[0].style.position="relative"),this.options.addClasses&&this.element.addClass("ui-draggable"),this.options.disabled&&this.element.addClass("ui-draggable-disabled"),this._mouseInit()},_destroy:function(){this.element.removeClass("ui-draggable ui-draggable-dragging ui-draggable-disabled"),this._mouseDestroy()},_mouseCapture:function(t){var i=this.options;return this.helper||i.disabled||e(t.target).closest(".ui-resizable-handle").length>0?!1:(this.handle=this._getHandle(t),this.handle?(e(i.iframeFix===!0?"iframe":i.iframeFix).each(function(){e("
").css({width:this.offsetWidth+"px",height:this.offsetHeight+"px",position:"absolute",opacity:"0.001",zIndex:1e3}).css(e(this).offset()).appendTo("body")}),!0):!1)},_mouseStart:function(t){var i=this.options;return this.helper=this._createHelper(t),this.helper.addClass("ui-draggable-dragging"),this._cacheHelperProportions(),e.ui.ddmanager&&(e.ui.ddmanager.current=this),this._cacheMargins(),this.cssPosition=this.helper.css("position"),this.scrollParent=this.helper.scrollParent(),this.offsetParent=this.helper.offsetParent(),this.offsetParentCssPosition=this.offsetParent.css("position"),this.offset=this.positionAbs=this.element.offset(),this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left},this.offset.scroll=!1,e.extend(this.offset,{click:{left:t.pageX-this.offset.left,top:t.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()}),this.originalPosition=this.position=this._generatePosition(t),this.originalPageX=t.pageX,this.originalPageY=t.pageY,i.cursorAt&&this._adjustOffsetFromHelper(i.cursorAt),this._setContainment(),this._trigger("start",t)===!1?(this._clear(),!1):(this._cacheHelperProportions(),e.ui.ddmanager&&!i.dropBehaviour&&e.ui.ddmanager.prepareOffsets(this,t),this._mouseDrag(t,!0),e.ui.ddmanager&&e.ui.ddmanager.dragStart(this,t),!0)},_mouseDrag:function(t,i){if("fixed"===this.offsetParentCssPosition&&(this.offset.parent=this._getParentOffset()),this.position=this._generatePosition(t),this.positionAbs=this._convertPositionTo("absolute"),!i){var s=this._uiHash();if(this._trigger("drag",t,s)===!1)return this._mouseUp({}),!1;this.position=s.position}return this.options.axis&&"y"===this.options.axis||(this.helper[0].style.left=this.position.left+"px"),this.options.axis&&"x"===this.options.axis||(this.helper[0].style.top=this.position.top+"px"),e.ui.ddmanager&&e.ui.ddmanager.drag(this,t),!1},_mouseStop:function(t){var i=this,s=!1;return e.ui.ddmanager&&!this.options.dropBehaviour&&(s=e.ui.ddmanager.drop(this,t)),this.dropped&&(s=this.dropped,this.dropped=!1),"original"!==this.options.helper||e.contains(this.element[0].ownerDocument,this.element[0])?("invalid"===this.options.revert&&!s||"valid"===this.options.revert&&s||this.options.revert===!0||e.isFunction(this.options.revert)&&this.options.revert.call(this.element,s)?e(this.helper).animate(this.originalPosition,parseInt(this.options.revertDuration,10),function(){i._trigger("stop",t)!==!1&&i._clear()}):this._trigger("stop",t)!==!1&&this._clear(),!1):!1},_mouseUp:function(t){return e("div.ui-draggable-iframeFix").each(function(){this.parentNode.removeChild(this)}),e.ui.ddmanager&&e.ui.ddmanager.dragStop(this,t),e.ui.mouse.prototype._mouseUp.call(this,t)},cancel:function(){return this.helper.is(".ui-draggable-dragging")?this._mouseUp({}):this._clear(),this},_getHandle:function(t){return this.options.handle?!!e(t.target).closest(this.element.find(this.options.handle)).length:!0},_createHelper:function(t){var i=this.options,s=e.isFunction(i.helper)?e(i.helper.apply(this.element[0],[t])):"clone"===i.helper?this.element.clone().removeAttr("id"):this.element;return s.parents("body").length||s.appendTo("parent"===i.appendTo?this.element[0].parentNode:i.appendTo),s[0]===this.element[0]||/(fixed|absolute)/.test(s.css("position"))||s.css("position","absolute"),s},_adjustOffsetFromHelper:function(t){"string"==typeof t&&(t=t.split(" ")),e.isArray(t)&&(t={left:+t[0],top:+t[1]||0}),"left"in t&&(this.offset.click.left=t.left+this.margins.left),"right"in t&&(this.offset.click.left=this.helperProportions.width-t.right+this.margins.left),"top"in t&&(this.offset.click.top=t.top+this.margins.top),"bottom"in t&&(this.offset.click.top=this.helperProportions.height-t.bottom+this.margins.top)},_getParentOffset:function(){var t=this.offsetParent.offset();return"absolute"===this.cssPosition&&this.scrollParent[0]!==document&&e.contains(this.scrollParent[0],this.offsetParent[0])&&(t.left+=this.scrollParent.scrollLeft(),t.top+=this.scrollParent.scrollTop()),(this.offsetParent[0]===document.body||this.offsetParent[0].tagName&&"html"===this.offsetParent[0].tagName.toLowerCase()&&e.ui.ie)&&(t={top:0,left:0}),{top:t.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:t.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if("relative"===this.cssPosition){var e=this.element.position();return{top:e.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:e.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}}return{top:0,left:0}},_cacheMargins:function(){this.margins={left:parseInt(this.element.css("marginLeft"),10)||0,top:parseInt(this.element.css("marginTop"),10)||0,right:parseInt(this.element.css("marginRight"),10)||0,bottom:parseInt(this.element.css("marginBottom"),10)||0}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var t,i,s,n=this.options;return n.containment?"window"===n.containment?(this.containment=[e(window).scrollLeft()-this.offset.relative.left-this.offset.parent.left,e(window).scrollTop()-this.offset.relative.top-this.offset.parent.top,e(window).scrollLeft()+e(window).width()-this.helperProportions.width-this.margins.left,e(window).scrollTop()+(e(window).height()||document.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top],undefined):"document"===n.containment?(this.containment=[0,0,e(document).width()-this.helperProportions.width-this.margins.left,(e(document).height()||document.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top],undefined):n.containment.constructor===Array?(this.containment=n.containment,undefined):("parent"===n.containment&&(n.containment=this.helper[0].parentNode),i=e(n.containment),s=i[0],s&&(t="hidden"!==i.css("overflow"),this.containment=[(parseInt(i.css("borderLeftWidth"),10)||0)+(parseInt(i.css("paddingLeft"),10)||0),(parseInt(i.css("borderTopWidth"),10)||0)+(parseInt(i.css("paddingTop"),10)||0),(t?Math.max(s.scrollWidth,s.offsetWidth):s.offsetWidth)-(parseInt(i.css("borderRightWidth"),10)||0)-(parseInt(i.css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left-this.margins.right,(t?Math.max(s.scrollHeight,s.offsetHeight):s.offsetHeight)-(parseInt(i.css("borderBottomWidth"),10)||0)-(parseInt(i.css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top-this.margins.bottom],this.relative_container=i),undefined):(this.containment=null,undefined)},_convertPositionTo:function(t,i){i||(i=this.position);var s="absolute"===t?1:-1,n="absolute"!==this.cssPosition||this.scrollParent[0]!==document&&e.contains(this.scrollParent[0],this.offsetParent[0])?this.scrollParent:this.offsetParent;return this.offset.scroll||(this.offset.scroll={top:n.scrollTop(),left:n.scrollLeft()}),{top:i.top+this.offset.relative.top*s+this.offset.parent.top*s-("fixed"===this.cssPosition?-this.scrollParent.scrollTop():this.offset.scroll.top)*s,left:i.left+this.offset.relative.left*s+this.offset.parent.left*s-("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():this.offset.scroll.left)*s}},_generatePosition:function(t){var i,s,n,a,o=this.options,r="absolute"!==this.cssPosition||this.scrollParent[0]!==document&&e.contains(this.scrollParent[0],this.offsetParent[0])?this.scrollParent:this.offsetParent,h=t.pageX,l=t.pageY;return this.offset.scroll||(this.offset.scroll={top:r.scrollTop(),left:r.scrollLeft()}),this.originalPosition&&(this.containment&&(this.relative_container?(s=this.relative_container.offset(),i=[this.containment[0]+s.left,this.containment[1]+s.top,this.containment[2]+s.left,this.containment[3]+s.top]):i=this.containment,t.pageX-this.offset.click.left
i[2]&&(h=i[2]+this.offset.click.left),t.pageY-this.offset.click.top>i[3]&&(l=i[3]+this.offset.click.top)),o.grid&&(n=o.grid[1]?this.originalPageY+Math.round((l-this.originalPageY)/o.grid[1])*o.grid[1]:this.originalPageY,l=i?n-this.offset.click.top>=i[1]||n-this.offset.click.top>i[3]?n:n-this.offset.click.top>=i[1]?n-o.grid[1]:n+o.grid[1]:n,a=o.grid[0]?this.originalPageX+Math.round((h-this.originalPageX)/o.grid[0])*o.grid[0]:this.originalPageX,h=i?a-this.offset.click.left>=i[0]||a-this.offset.click.left>i[2]?a:a-this.offset.click.left>=i[0]?a-o.grid[0]:a+o.grid[0]:a)),{top:l-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+("fixed"===this.cssPosition?-this.scrollParent.scrollTop():this.offset.scroll.top),left:h-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():this.offset.scroll.left)}},_clear:function(){this.helper.removeClass("ui-draggable-dragging"),this.helper[0]===this.element[0]||this.cancelHelperRemoval||this.helper.remove(),this.helper=null,this.cancelHelperRemoval=!1},_trigger:function(t,i,s){return s=s||this._uiHash(),e.ui.plugin.call(this,t,[i,s]),"drag"===t&&(this.positionAbs=this._convertPositionTo("absolute")),e.Widget.prototype._trigger.call(this,t,i,s)},plugins:{},_uiHash:function(){return{helper:this.helper,position:this.position,originalPosition:this.originalPosition,offset:this.positionAbs}}}),e.ui.plugin.add("draggable","connectToSortable",{start:function(t,i){var s=e(this).data("ui-draggable"),n=s.options,a=e.extend({},i,{item:s.element});s.sortables=[],e(n.connectToSortable).each(function(){var i=e.data(this,"ui-sortable");i&&!i.options.disabled&&(s.sortables.push({instance:i,shouldRevert:i.options.revert}),i.refreshPositions(),i._trigger("activate",t,a))})},stop:function(t,i){var s=e(this).data("ui-draggable"),n=e.extend({},i,{item:s.element});e.each(s.sortables,function(){this.instance.isOver?(this.instance.isOver=0,s.cancelHelperRemoval=!0,this.instance.cancelHelperRemoval=!1,this.shouldRevert&&(this.instance.options.revert=this.shouldRevert),this.instance._mouseStop(t),this.instance.options.helper=this.instance.options._helper,"original"===s.options.helper&&this.instance.currentItem.css({top:"auto",left:"auto"})):(this.instance.cancelHelperRemoval=!1,this.instance._trigger("deactivate",t,n))})},drag:function(t,i){var s=e(this).data("ui-draggable"),n=this;e.each(s.sortables,function(){var a=!1,o=this;this.instance.positionAbs=s.positionAbs,this.instance.helperProportions=s.helperProportions,this.instance.offset.click=s.offset.click,this.instance._intersectsWith(this.instance.containerCache)&&(a=!0,e.each(s.sortables,function(){return this.instance.positionAbs=s.positionAbs,this.instance.helperProportions=s.helperProportions,this.instance.offset.click=s.offset.click,this!==o&&this.instance._intersectsWith(this.instance.containerCache)&&e.contains(o.instance.element[0],this.instance.element[0])&&(a=!1),a})),a?(this.instance.isOver||(this.instance.isOver=1,this.instance.currentItem=e(n).clone().removeAttr("id").appendTo(this.instance.element).data("ui-sortable-item",!0),this.instance.options._helper=this.instance.options.helper,this.instance.options.helper=function(){return i.helper[0]},t.target=this.instance.currentItem[0],this.instance._mouseCapture(t,!0),this.instance._mouseStart(t,!0,!0),this.instance.offset.click.top=s.offset.click.top,this.instance.offset.click.left=s.offset.click.left,this.instance.offset.parent.left-=s.offset.parent.left-this.instance.offset.parent.left,this.instance.offset.parent.top-=s.offset.parent.top-this.instance.offset.parent.top,s._trigger("toSortable",t),s.dropped=this.instance.element,s.currentItem=s.element,this.instance.fromOutside=s),this.instance.currentItem&&this.instance._mouseDrag(t)):this.instance.isOver&&(this.instance.isOver=0,this.instance.cancelHelperRemoval=!0,this.instance.options.revert=!1,this.instance._trigger("out",t,this.instance._uiHash(this.instance)),this.instance._mouseStop(t,!0),this.instance.options.helper=this.instance.options._helper,this.instance.currentItem.remove(),this.instance.placeholder&&this.instance.placeholder.remove(),s._trigger("fromSortable",t),s.dropped=!1)})}}),e.ui.plugin.add("draggable","cursor",{start:function(){var t=e("body"),i=e(this).data("ui-draggable").options;t.css("cursor")&&(i._cursor=t.css("cursor")),t.css("cursor",i.cursor)},stop:function(){var t=e(this).data("ui-draggable").options;t._cursor&&e("body").css("cursor",t._cursor)}}),e.ui.plugin.add("draggable","opacity",{start:function(t,i){var s=e(i.helper),n=e(this).data("ui-draggable").options;s.css("opacity")&&(n._opacity=s.css("opacity")),s.css("opacity",n.opacity)},stop:function(t,i){var s=e(this).data("ui-draggable").options;s._opacity&&e(i.helper).css("opacity",s._opacity)}}),e.ui.plugin.add("draggable","scroll",{start:function(){var t=e(this).data("ui-draggable");t.scrollParent[0]!==document&&"HTML"!==t.scrollParent[0].tagName&&(t.overflowOffset=t.scrollParent.offset())},drag:function(t){var i=e(this).data("ui-draggable"),s=i.options,n=!1;i.scrollParent[0]!==document&&"HTML"!==i.scrollParent[0].tagName?(s.axis&&"x"===s.axis||(i.overflowOffset.top+i.scrollParent[0].offsetHeight-t.pageY=0;c--)r=p.snapElements[c].left,h=r+p.snapElements[c].width,l=p.snapElements[c].top,u=l+p.snapElements[c].height,r-m>v||g>h+m||l-m>y||b>u+m||!e.contains(p.snapElements[c].item.ownerDocument,p.snapElements[c].item)?(p.snapElements[c].snapping&&p.options.snap.release&&p.options.snap.release.call(p.element,t,e.extend(p._uiHash(),{snapItem:p.snapElements[c].item})),p.snapElements[c].snapping=!1):("inner"!==f.snapMode&&(s=m>=Math.abs(l-y),n=m>=Math.abs(u-b),a=m>=Math.abs(r-v),o=m>=Math.abs(h-g),s&&(i.position.top=p._convertPositionTo("relative",{top:l-p.helperProportions.height,left:0}).top-p.margins.top),n&&(i.position.top=p._convertPositionTo("relative",{top:u,left:0}).top-p.margins.top),a&&(i.position.left=p._convertPositionTo("relative",{top:0,left:r-p.helperProportions.width}).left-p.margins.left),o&&(i.position.left=p._convertPositionTo("relative",{top:0,left:h}).left-p.margins.left)),d=s||n||a||o,"outer"!==f.snapMode&&(s=m>=Math.abs(l-b),n=m>=Math.abs(u-y),a=m>=Math.abs(r-g),o=m>=Math.abs(h-v),s&&(i.position.top=p._convertPositionTo("relative",{top:l,left:0}).top-p.margins.top),n&&(i.position.top=p._convertPositionTo("relative",{top:u-p.helperProportions.height,left:0}).top-p.margins.top),a&&(i.position.left=p._convertPositionTo("relative",{top:0,left:r}).left-p.margins.left),o&&(i.position.left=p._convertPositionTo("relative",{top:0,left:h-p.helperProportions.width}).left-p.margins.left)),!p.snapElements[c].snapping&&(s||n||a||o||d)&&p.options.snap.snap&&p.options.snap.snap.call(p.element,t,e.extend(p._uiHash(),{snapItem:p.snapElements[c].item})),p.snapElements[c].snapping=s||n||a||o||d)}}),e.ui.plugin.add("draggable","stack",{start:function(){var t,i=this.data("ui-draggable").options,s=e.makeArray(e(i.stack)).sort(function(t,i){return(parseInt(e(t).css("zIndex"),10)||0)-(parseInt(e(i).css("zIndex"),10)||0)});s.length&&(t=parseInt(e(s[0]).css("zIndex"),10)||0,e(s).each(function(i){e(this).css("zIndex",t+i)}),this.css("zIndex",t+s.length))}}),e.ui.plugin.add("draggable","zIndex",{start:function(t,i){var s=e(i.helper),n=e(this).data("ui-draggable").options;s.css("zIndex")&&(n._zIndex=s.css("zIndex")),s.css("zIndex",n.zIndex)},stop:function(t,i){var s=e(this).data("ui-draggable").options;s._zIndex&&e(i.helper).css("zIndex",s._zIndex)}})})(jQuery);
17 | /*! jQuery UI - v1.10.3 - 2013-05-03
18 | * http://jqueryui.com
19 | * Copyright 2013 jQuery Foundation and other contributors; Licensed MIT */
20 | (function(e){function t(e){return parseInt(e,10)||0}function i(e){return!isNaN(parseInt(e,10))}e.widget("ui.resizable",e.ui.mouse,{version:"1.10.3",widgetEventPrefix:"resize",options:{alsoResize:!1,animate:!1,animateDuration:"slow",animateEasing:"swing",aspectRatio:!1,autoHide:!1,containment:!1,ghost:!1,grid:!1,handles:"e,s,se",helper:!1,maxHeight:null,maxWidth:null,minHeight:10,minWidth:10,zIndex:90,resize:null,start:null,stop:null},_create:function(){var t,i,s,n,a,o=this,r=this.options;if(this.element.addClass("ui-resizable"),e.extend(this,{_aspectRatio:!!r.aspectRatio,aspectRatio:r.aspectRatio,originalElement:this.element,_proportionallyResizeElements:[],_helper:r.helper||r.ghost||r.animate?r.helper||"ui-resizable-helper":null}),this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)&&(this.element.wrap(e("").css({position:this.element.css("position"),width:this.element.outerWidth(),height:this.element.outerHeight(),top:this.element.css("top"),left:this.element.css("left")})),this.element=this.element.parent().data("ui-resizable",this.element.data("ui-resizable")),this.elementIsWrapper=!0,this.element.css({marginLeft:this.originalElement.css("marginLeft"),marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom")}),this.originalElement.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0}),this.originalResizeStyle=this.originalElement.css("resize"),this.originalElement.css("resize","none"),this._proportionallyResizeElements.push(this.originalElement.css({position:"static",zoom:1,display:"block"})),this.originalElement.css({margin:this.originalElement.css("margin")}),this._proportionallyResize()),this.handles=r.handles||(e(".ui-resizable-handle",this.element).length?{n:".ui-resizable-n",e:".ui-resizable-e",s:".ui-resizable-s",w:".ui-resizable-w",se:".ui-resizable-se",sw:".ui-resizable-sw",ne:".ui-resizable-ne",nw:".ui-resizable-nw"}:"e,s,se"),this.handles.constructor===String)for("all"===this.handles&&(this.handles="n,e,s,w,se,sw,ne,nw"),t=this.handles.split(","),this.handles={},i=0;t.length>i;i++)s=e.trim(t[i]),a="ui-resizable-"+s,n=e(""),n.css({zIndex:r.zIndex}),"se"===s&&n.addClass("ui-icon ui-icon-gripsmall-diagonal-se"),this.handles[s]=".ui-resizable-"+s,this.element.append(n);this._renderAxis=function(t){var i,s,n,a;t=t||this.element;for(i in this.handles)this.handles[i].constructor===String&&(this.handles[i]=e(this.handles[i],this.element).show()),this.elementIsWrapper&&this.originalElement[0].nodeName.match(/textarea|input|select|button/i)&&(s=e(this.handles[i],this.element),a=/sw|ne|nw|se|n|s/.test(i)?s.outerHeight():s.outerWidth(),n=["padding",/ne|nw|n/.test(i)?"Top":/se|sw|s/.test(i)?"Bottom":/^e$/.test(i)?"Right":"Left"].join(""),t.css(n,a),this._proportionallyResize()),e(this.handles[i]).length},this._renderAxis(this.element),this._handles=e(".ui-resizable-handle",this.element).disableSelection(),this._handles.mouseover(function(){o.resizing||(this.className&&(n=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i)),o.axis=n&&n[1]?n[1]:"se")}),r.autoHide&&(this._handles.hide(),e(this.element).addClass("ui-resizable-autohide").mouseenter(function(){r.disabled||(e(this).removeClass("ui-resizable-autohide"),o._handles.show())}).mouseleave(function(){r.disabled||o.resizing||(e(this).addClass("ui-resizable-autohide"),o._handles.hide())})),this._mouseInit()},_destroy:function(){this._mouseDestroy();var t,i=function(t){e(t).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing").removeData("resizable").removeData("ui-resizable").unbind(".resizable").find(".ui-resizable-handle").remove()};return this.elementIsWrapper&&(i(this.element),t=this.element,this.originalElement.css({position:t.css("position"),width:t.outerWidth(),height:t.outerHeight(),top:t.css("top"),left:t.css("left")}).insertAfter(t),t.remove()),this.originalElement.css("resize",this.originalResizeStyle),i(this.originalElement),this},_mouseCapture:function(t){var i,s,n=!1;for(i in this.handles)s=e(this.handles[i])[0],(s===t.target||e.contains(s,t.target))&&(n=!0);return!this.options.disabled&&n},_mouseStart:function(i){var s,n,a,o=this.options,r=this.element.position(),h=this.element;return this.resizing=!0,/absolute/.test(h.css("position"))?h.css({position:"absolute",top:h.css("top"),left:h.css("left")}):h.is(".ui-draggable")&&h.css({position:"absolute",top:r.top,left:r.left}),this._renderProxy(),s=t(this.helper.css("left")),n=t(this.helper.css("top")),o.containment&&(s+=e(o.containment).scrollLeft()||0,n+=e(o.containment).scrollTop()||0),this.offset=this.helper.offset(),this.position={left:s,top:n},this.size=this._helper?{width:h.outerWidth(),height:h.outerHeight()}:{width:h.width(),height:h.height()},this.originalSize=this._helper?{width:h.outerWidth(),height:h.outerHeight()}:{width:h.width(),height:h.height()},this.originalPosition={left:s,top:n},this.sizeDiff={width:h.outerWidth()-h.width(),height:h.outerHeight()-h.height()},this.originalMousePosition={left:i.pageX,top:i.pageY},this.aspectRatio="number"==typeof o.aspectRatio?o.aspectRatio:this.originalSize.width/this.originalSize.height||1,a=e(".ui-resizable-"+this.axis).css("cursor"),e("body").css("cursor","auto"===a?this.axis+"-resize":a),h.addClass("ui-resizable-resizing"),this._propagate("start",i),!0},_mouseDrag:function(t){var i,s=this.helper,n={},a=this.originalMousePosition,o=this.axis,r=this.position.top,h=this.position.left,l=this.size.width,u=this.size.height,c=t.pageX-a.left||0,d=t.pageY-a.top||0,p=this._change[o];return p?(i=p.apply(this,[t,c,d]),this._updateVirtualBoundaries(t.shiftKey),(this._aspectRatio||t.shiftKey)&&(i=this._updateRatio(i,t)),i=this._respectSize(i,t),this._updateCache(i),this._propagate("resize",t),this.position.top!==r&&(n.top=this.position.top+"px"),this.position.left!==h&&(n.left=this.position.left+"px"),this.size.width!==l&&(n.width=this.size.width+"px"),this.size.height!==u&&(n.height=this.size.height+"px"),s.css(n),!this._helper&&this._proportionallyResizeElements.length&&this._proportionallyResize(),e.isEmptyObject(n)||this._trigger("resize",t,this.ui()),!1):!1},_mouseStop:function(t){this.resizing=!1;var i,s,n,a,o,r,h,l=this.options,u=this;return this._helper&&(i=this._proportionallyResizeElements,s=i.length&&/textarea/i.test(i[0].nodeName),n=s&&e.ui.hasScroll(i[0],"left")?0:u.sizeDiff.height,a=s?0:u.sizeDiff.width,o={width:u.helper.width()-a,height:u.helper.height()-n},r=parseInt(u.element.css("left"),10)+(u.position.left-u.originalPosition.left)||null,h=parseInt(u.element.css("top"),10)+(u.position.top-u.originalPosition.top)||null,l.animate||this.element.css(e.extend(o,{top:h,left:r})),u.helper.height(u.size.height),u.helper.width(u.size.width),this._helper&&!l.animate&&this._proportionallyResize()),e("body").css("cursor","auto"),this.element.removeClass("ui-resizable-resizing"),this._propagate("stop",t),this._helper&&this.helper.remove(),!1},_updateVirtualBoundaries:function(e){var t,s,n,a,o,r=this.options;o={minWidth:i(r.minWidth)?r.minWidth:0,maxWidth:i(r.maxWidth)?r.maxWidth:1/0,minHeight:i(r.minHeight)?r.minHeight:0,maxHeight:i(r.maxHeight)?r.maxHeight:1/0},(this._aspectRatio||e)&&(t=o.minHeight*this.aspectRatio,n=o.minWidth/this.aspectRatio,s=o.maxHeight*this.aspectRatio,a=o.maxWidth/this.aspectRatio,t>o.minWidth&&(o.minWidth=t),n>o.minHeight&&(o.minHeight=n),o.maxWidth>s&&(o.maxWidth=s),o.maxHeight>a&&(o.maxHeight=a)),this._vBoundaries=o},_updateCache:function(e){this.offset=this.helper.offset(),i(e.left)&&(this.position.left=e.left),i(e.top)&&(this.position.top=e.top),i(e.height)&&(this.size.height=e.height),i(e.width)&&(this.size.width=e.width)},_updateRatio:function(e){var t=this.position,s=this.size,n=this.axis;return i(e.height)?e.width=e.height*this.aspectRatio:i(e.width)&&(e.height=e.width/this.aspectRatio),"sw"===n&&(e.left=t.left+(s.width-e.width),e.top=null),"nw"===n&&(e.top=t.top+(s.height-e.height),e.left=t.left+(s.width-e.width)),e},_respectSize:function(e){var t=this._vBoundaries,s=this.axis,n=i(e.width)&&t.maxWidth&&t.maxWidthe.width,r=i(e.height)&&t.minHeight&&t.minHeight>e.height,h=this.originalPosition.left+this.originalSize.width,l=this.position.top+this.size.height,u=/sw|nw|w/.test(s),c=/nw|ne|n/.test(s);return o&&(e.width=t.minWidth),r&&(e.height=t.minHeight),n&&(e.width=t.maxWidth),a&&(e.height=t.maxHeight),o&&u&&(e.left=h-t.minWidth),n&&u&&(e.left=h-t.maxWidth),r&&c&&(e.top=l-t.minHeight),a&&c&&(e.top=l-t.maxHeight),e.width||e.height||e.left||!e.top?e.width||e.height||e.top||!e.left||(e.left=null):e.top=null,e},_proportionallyResize:function(){if(this._proportionallyResizeElements.length){var e,t,i,s,n,a=this.helper||this.element;for(e=0;this._proportionallyResizeElements.length>e;e++){if(n=this._proportionallyResizeElements[e],!this.borderDif)for(this.borderDif=[],i=[n.css("borderTopWidth"),n.css("borderRightWidth"),n.css("borderBottomWidth"),n.css("borderLeftWidth")],s=[n.css("paddingTop"),n.css("paddingRight"),n.css("paddingBottom"),n.css("paddingLeft")],t=0;i.length>t;t++)this.borderDif[t]=(parseInt(i[t],10)||0)+(parseInt(s[t],10)||0);n.css({height:a.height()-this.borderDif[0]-this.borderDif[2]||0,width:a.width()-this.borderDif[1]-this.borderDif[3]||0})}}},_renderProxy:function(){var t=this.element,i=this.options;this.elementOffset=t.offset(),this._helper?(this.helper=this.helper||e(""),this.helper.addClass(this._helper).css({width:this.element.outerWidth()-1,height:this.element.outerHeight()-1,position:"absolute",left:this.elementOffset.left+"px",top:this.elementOffset.top+"px",zIndex:++i.zIndex}),this.helper.appendTo("body").disableSelection()):this.helper=this.element},_change:{e:function(e,t){return{width:this.originalSize.width+t}},w:function(e,t){var i=this.originalSize,s=this.originalPosition;return{left:s.left+t,width:i.width-t}},n:function(e,t,i){var s=this.originalSize,n=this.originalPosition;return{top:n.top+i,height:s.height-i}},s:function(e,t,i){return{height:this.originalSize.height+i}},se:function(t,i,s){return e.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[t,i,s]))},sw:function(t,i,s){return e.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[t,i,s]))},ne:function(t,i,s){return e.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[t,i,s]))},nw:function(t,i,s){return e.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[t,i,s]))}},_propagate:function(t,i){e.ui.plugin.call(this,t,[i,this.ui()]),"resize"!==t&&this._trigger(t,i,this.ui())},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}}),e.ui.plugin.add("resizable","animate",{stop:function(t){var i=e(this).data("ui-resizable"),s=i.options,n=i._proportionallyResizeElements,a=n.length&&/textarea/i.test(n[0].nodeName),o=a&&e.ui.hasScroll(n[0],"left")?0:i.sizeDiff.height,r=a?0:i.sizeDiff.width,h={width:i.size.width-r,height:i.size.height-o},l=parseInt(i.element.css("left"),10)+(i.position.left-i.originalPosition.left)||null,u=parseInt(i.element.css("top"),10)+(i.position.top-i.originalPosition.top)||null;i.element.animate(e.extend(h,u&&l?{top:u,left:l}:{}),{duration:s.animateDuration,easing:s.animateEasing,step:function(){var s={width:parseInt(i.element.css("width"),10),height:parseInt(i.element.css("height"),10),top:parseInt(i.element.css("top"),10),left:parseInt(i.element.css("left"),10)};n&&n.length&&e(n[0]).css({width:s.width,height:s.height}),i._updateCache(s),i._propagate("resize",t)}})}}),e.ui.plugin.add("resizable","containment",{start:function(){var i,s,n,a,o,r,h,l=e(this).data("ui-resizable"),u=l.options,c=l.element,d=u.containment,p=d instanceof e?d.get(0):/parent/.test(d)?c.parent().get(0):d;p&&(l.containerElement=e(p),/document/.test(d)||d===document?(l.containerOffset={left:0,top:0},l.containerPosition={left:0,top:0},l.parentData={element:e(document),left:0,top:0,width:e(document).width(),height:e(document).height()||document.body.parentNode.scrollHeight}):(i=e(p),s=[],e(["Top","Right","Left","Bottom"]).each(function(e,n){s[e]=t(i.css("padding"+n))}),l.containerOffset=i.offset(),l.containerPosition=i.position(),l.containerSize={height:i.innerHeight()-s[3],width:i.innerWidth()-s[1]},n=l.containerOffset,a=l.containerSize.height,o=l.containerSize.width,r=e.ui.hasScroll(p,"left")?p.scrollWidth:o,h=e.ui.hasScroll(p)?p.scrollHeight:a,l.parentData={element:p,left:n.left,top:n.top,width:r,height:h}))},resize:function(t){var i,s,n,a,o=e(this).data("ui-resizable"),r=o.options,h=o.containerOffset,l=o.position,u=o._aspectRatio||t.shiftKey,c={top:0,left:0},d=o.containerElement;d[0]!==document&&/static/.test(d.css("position"))&&(c=h),l.left<(o._helper?h.left:0)&&(o.size.width=o.size.width+(o._helper?o.position.left-h.left:o.position.left-c.left),u&&(o.size.height=o.size.width/o.aspectRatio),o.position.left=r.helper?h.left:0),l.top<(o._helper?h.top:0)&&(o.size.height=o.size.height+(o._helper?o.position.top-h.top:o.position.top),u&&(o.size.width=o.size.height*o.aspectRatio),o.position.top=o._helper?h.top:0),o.offset.left=o.parentData.left+o.position.left,o.offset.top=o.parentData.top+o.position.top,i=Math.abs((o._helper?o.offset.left-c.left:o.offset.left-c.left)+o.sizeDiff.width),s=Math.abs((o._helper?o.offset.top-c.top:o.offset.top-h.top)+o.sizeDiff.height),n=o.containerElement.get(0)===o.element.parent().get(0),a=/relative|absolute/.test(o.containerElement.css("position")),n&&a&&(i-=o.parentData.left),i+o.size.width>=o.parentData.width&&(o.size.width=o.parentData.width-i,u&&(o.size.height=o.size.width/o.aspectRatio)),s+o.size.height>=o.parentData.height&&(o.size.height=o.parentData.height-s,u&&(o.size.width=o.size.height*o.aspectRatio))},stop:function(){var t=e(this).data("ui-resizable"),i=t.options,s=t.containerOffset,n=t.containerPosition,a=t.containerElement,o=e(t.helper),r=o.offset(),h=o.outerWidth()-t.sizeDiff.width,l=o.outerHeight()-t.sizeDiff.height;t._helper&&!i.animate&&/relative/.test(a.css("position"))&&e(this).css({left:r.left-n.left-s.left,width:h,height:l}),t._helper&&!i.animate&&/static/.test(a.css("position"))&&e(this).css({left:r.left-n.left-s.left,width:h,height:l})}}),e.ui.plugin.add("resizable","alsoResize",{start:function(){var t=e(this).data("ui-resizable"),i=t.options,s=function(t){e(t).each(function(){var t=e(this);t.data("ui-resizable-alsoresize",{width:parseInt(t.width(),10),height:parseInt(t.height(),10),left:parseInt(t.css("left"),10),top:parseInt(t.css("top"),10)})})};"object"!=typeof i.alsoResize||i.alsoResize.parentNode?s(i.alsoResize):i.alsoResize.length?(i.alsoResize=i.alsoResize[0],s(i.alsoResize)):e.each(i.alsoResize,function(e){s(e)})},resize:function(t,i){var s=e(this).data("ui-resizable"),n=s.options,a=s.originalSize,o=s.originalPosition,r={height:s.size.height-a.height||0,width:s.size.width-a.width||0,top:s.position.top-o.top||0,left:s.position.left-o.left||0},h=function(t,s){e(t).each(function(){var t=e(this),n=e(this).data("ui-resizable-alsoresize"),a={},o=s&&s.length?s:t.parents(i.originalElement[0]).length?["width","height"]:["width","height","top","left"];e.each(o,function(e,t){var i=(n[t]||0)+(r[t]||0);i&&i>=0&&(a[t]=i||null)}),t.css(a)})};"object"!=typeof n.alsoResize||n.alsoResize.nodeType?h(n.alsoResize):e.each(n.alsoResize,function(e,t){h(e,t)})},stop:function(){e(this).removeData("resizable-alsoresize")}}),e.ui.plugin.add("resizable","ghost",{start:function(){var t=e(this).data("ui-resizable"),i=t.options,s=t.size;t.ghost=t.originalElement.clone(),t.ghost.css({opacity:.25,display:"block",position:"relative",height:s.height,width:s.width,margin:0,left:0,top:0}).addClass("ui-resizable-ghost").addClass("string"==typeof i.ghost?i.ghost:""),t.ghost.appendTo(t.helper)},resize:function(){var t=e(this).data("ui-resizable");t.ghost&&t.ghost.css({position:"relative",height:t.size.height,width:t.size.width})},stop:function(){var t=e(this).data("ui-resizable");t.ghost&&t.helper&&t.helper.get(0).removeChild(t.ghost.get(0))}}),e.ui.plugin.add("resizable","grid",{resize:function(){var t=e(this).data("ui-resizable"),i=t.options,s=t.size,n=t.originalSize,a=t.originalPosition,o=t.axis,r="number"==typeof i.grid?[i.grid,i.grid]:i.grid,h=r[0]||1,l=r[1]||1,u=Math.round((s.width-n.width)/h)*h,c=Math.round((s.height-n.height)/l)*l,d=n.width+u,p=n.height+c,f=i.maxWidth&&d>i.maxWidth,m=i.maxHeight&&p>i.maxHeight,g=i.minWidth&&i.minWidth>d,v=i.minHeight&&i.minHeight>p;i.grid=r,g&&(d+=h),v&&(p+=l),f&&(d-=h),m&&(p-=l),/^(se|s|e)$/.test(o)?(t.size.width=d,t.size.height=p):/^(ne)$/.test(o)?(t.size.width=d,t.size.height=p,t.position.top=a.top-c):/^(sw)$/.test(o)?(t.size.width=d,t.size.height=p,t.position.left=a.left-u):(t.size.width=d,t.size.height=p,t.position.top=a.top-c,t.position.left=a.left-u)}})})(jQuery);
--------------------------------------------------------------------------------
/tests/samples/labeled001.js:
--------------------------------------------------------------------------------
1 | Outer:
2 | for (i = 1; i <= 10; i++) {
3 | document.write ("
");
4 | document.write ("i: " + i);
5 | document.write (" j: ");
6 |
7 | Inner:
8 | for (j = 21; j <= 30; j++) {
9 | if (j == 24)
10 | {
11 | continue Inner;
12 | }
13 | document.write (j + " ");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/tests/samples/let001.js:
--------------------------------------------------------------------------------
1 | var l = 10;
2 | {
3 | let l = 2;
4 | // At this point, l = 2.
5 | }
6 | // At this point, l = 10.
7 |
8 | // Additional ways to declare a variable using let.
9 | let index;
10 | let name = "Thomas Jefferson";
11 | let answer = 42, counter, numpages = 10;
12 | let myarray = new Array();
13 |
--------------------------------------------------------------------------------
/tests/samples/misc001.js:
--------------------------------------------------------------------------------
1 | var testObj = {};
2 | testObj[":"] = undefined; // Breaks
3 | testObj["::"] = undefined; // Breaks
4 | testObj["a:"] = undefined; // Breaks
5 | testObj["."] = undefined; // OK
6 | testObj["{"] = undefined; // OK
7 | testObj["}"] = undefined; // OK
8 | testObj["["] = undefined; // Breaks
9 | testObj["]"] = undefined; // Breaks
10 | testObj["("] = undefined; // OK
11 | testObj[")"] = undefined; // OK
12 | testObj["="] = undefined; // Breaks
13 | testObj["-"] = undefined; // OK
14 | testObj["+"] = undefined; // OK
15 | testObj["*"] = undefined; // OK
16 | testObj["/"] = undefined; // OK
17 | testObj["\\"] = undefined; // Breaks
18 | testObj["%"] = undefined; // OK
19 | testObj["<"] = undefined; // Breaks
20 | testObj[">"] = undefined; // Breaks
21 | testObj["!"] = undefined; // OK
22 | testObj["?"] = undefined; // Breaks
23 | testObj[","] = undefined; // OK
24 | testObj["@"] = undefined; // Breaks
25 | testObj["#"] = undefined; // OK
26 | testObj["&"] = undefined; // OK
27 | testObj["|"] = undefined; // OK
28 | testObj["~"] = undefined; // OK
29 | testObj["`"] = undefined; // Breaks
30 | testObj["."] = undefined; // OK
31 |
--------------------------------------------------------------------------------
/tests/samples/misc002.js:
--------------------------------------------------------------------------------
1 | var dateFormatters = {
2 | s : function(d) { return d.getSeconds() },
3 | ss : function(d) { return zeroPad(d.getSeconds()) },
4 | m : function(d) { return d.getMinutes() },
5 | mm : function(d) { return zeroPad(d.getMinutes()) },
6 | h : function(d) { return d.getHours() % 12 || 12 },
7 | hh : function(d) { return zeroPad(d.getHours() % 12 || 12) },
8 | H : function(d) { return d.getHours() },
9 | HH : function(d) { return zeroPad(d.getHours()) },
10 | d : function(d) { return d.getDate() },
11 | dd : function(d) { return zeroPad(d.getDate()) },
12 | ddd : function(d,o) { return o.dayNamesShort[d.getDay()] },
13 | dddd: function(d,o) { return o.dayNames[d.getDay()] },
14 | M : function(d) { return d.getMonth() + 1 },
15 | MM : function(d) { return zeroPad(d.getMonth() + 1) },
16 | MMM : function(d,o) { return o.monthNamesShort[d.getMonth()] },
17 | MMMM: function(d,o) { return o.monthNames[d.getMonth()] },
18 | yy : function(d) { return (d.getFullYear()+'').substring(2) },
19 | yyyy: function(d) { return d.getFullYear() },
20 | t : function(d) { return d.getHours() < 12 ? 'a' : 'p' },
21 | tt : function(d) { return d.getHours() < 12 ? 'am' : 'pm' },
22 | T : function(d) { return d.getHours() < 12 ? 'A' : 'P' },
23 | TT : function(d) { return d.getHours() < 12 ? 'AM' : 'PM' },
24 | u : function(d) { return formatDate(d, "yyyy-MM-dd'T'HH:mm:ss'Z'") },
25 | S : function(d) {
26 | var date = d.getDate();
27 | if (date > 10 && date < 20) {
28 | return 'th';
29 | }
30 | return ['st', 'nd', 'rd'][date%10-1] || 'th';
31 | },
32 | w : function(d, o) { // local
33 | return o.weekNumberCalculation(d);
34 | },
35 | W : function(d) { // ISO
36 | return iso8601Week(d);
37 | }
38 | };
39 |
--------------------------------------------------------------------------------
/tests/samples/misc003.js:
--------------------------------------------------------------------------------
1 | var child_process = require('child_process');
2 | var fs = require('fs');
3 | var optimist = require('optimist');
4 | var phantom = require('phantom');
5 |
6 | var argv = optimist
7 | .usage('Usage: depict URL OUT_FILE [OPTIONS]')
8 | .options('h', {
9 | alias: 'help',
10 | describe: 'Display help',
11 | default: false
12 | })
13 | .options('s', {
14 | alias: 'selector',
15 | describe: 'CSS selector',
16 | default: 'body'
17 | })
18 | .options('c', {
19 | alias: 'css',
20 | describe: 'CSS file to include in rendering',
21 | default: false
22 | })
23 | .options('H', {
24 | alias: 'hide-selector',
25 | describe: 'Hide attributes of this selector before rendering.',
26 | default: false
27 | })
28 | .options('w', {
29 | alias: 'browser-width',
30 | describe: 'Specify the desired browser width.',
31 | default: 1440
32 | })
33 | .options('d', {
34 | alias: 'delay',
35 | describe: 'Specify a delay time, in milliseconds.',
36 | default: 1000
37 | })
38 | .check(function(argv) {
39 | if (argv._.length !== 2) throw new Error('URL and OUT_FILE must be given.');
40 | })
41 | .argv;
42 |
43 | if (argv.h || argv.help) return optimist.showHelp();
44 |
45 | // Append 'http://' if protocol not specified
46 | var url = argv._[0];
47 | if (!url.match(/^\w+:\/\//)) {
48 | url = 'http://' + url;
49 | }
50 |
51 | var selector = argv.s || argv.selector;
52 | var out_file = argv._[1];
53 |
54 | var css_file = argv.c || argv.css;
55 | var css_text = '';
56 | if (css_file) {
57 | css_text = fs.readFileSync(css_file, 'utf8');
58 | }
59 |
60 | var hide_selector = argv.H || argv["hide-selector"];
61 | if (hide_selector) {
62 | css_text += "\n\n " + hide_selector + " { display: none; }\n";
63 | }
64 |
65 | var viewport_width = argv.w || argv['browser-width'];
66 | var delay_time = argv.d || argv['delay'];
67 |
68 | function depict(url, out_file, selector, css_text) {
69 | // phantomjs heavily relies on callback functions
70 |
71 | var page;
72 | var ph;
73 |
74 | console.log('\nRequesting', url);
75 |
76 | phantom.create(createPage)
77 |
78 | function createPage(_ph) {
79 | ph = _ph;
80 | ph.createPage(openPage);
81 | }
82 |
83 | function openPage(_page) {
84 | page = _page;
85 | page.set('onError', function() { return; });
86 | page.onConsoleMessage = function (msg) { console.log(msg); };
87 | page.open(url, prepForRender);
88 | page.set('viewportSize', {width: viewport_width, height: 900}); // The height isn't taken into account here but phantomjs requires an object with both a width and a height.
89 | }
90 |
91 | function prepForRender(status) {
92 | page.evaluate(runInPhantomBrowser, renderImage, selector, css_text);
93 | }
94 |
95 | function runInPhantomBrowser(selector, css_text) {
96 | if (css_text) {
97 | var style = document.createElement('style');
98 | style.appendChild(document.createTextNode(css_text));
99 | document.head.appendChild(style);
100 | }
101 |
102 | var element = document.querySelector(selector);
103 | return element.getBoundingClientRect();
104 | }
105 |
106 | function renderImage(rect) {
107 | setTimeout(function(){
108 | page.set('clipRect', rect);
109 | page.render(out_file, cleanup);
110 | }, delay_time)
111 | }
112 |
113 | function cleanup() {
114 | console.log('Saved imaged to', out_file);
115 | ph.exit();
116 | }
117 | }
118 |
119 | depict(url, out_file, selector, css_text);
120 |
--------------------------------------------------------------------------------
/tests/samples/misc004.js:
--------------------------------------------------------------------------------
1 | Ee.addDays = l, Ee.cloneDate = d, Ee.parseDate = p, Ee.parseISO8601 = m, Ee.parseTime = y, Ee.formatDate = w, Ee.formatDates = b;
2 | var ke = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"],
3 | He = 864e5,
4 | Fe = 36e5,
5 | Re = 6e4;
6 |
--------------------------------------------------------------------------------
/tests/samples/misc005.js:
--------------------------------------------------------------------------------
1 | gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() {
2 | if (gapi.iframes && gapi.iframes.getContext) {
3 | gapi.iframes.getContext().openChild({
4 | url: 'https://www.blogger.com/navbar.g?targetBlogID\0754325487278375417853\46blogName\75spirello\46publishMode\75PUBLISH_MODE_BLOGSPOT\46navbarType\75LIGHT\46layoutType\75LAYOUTS\46searchRoot\75http://spirelloskrimskramserier.blogspot.com/search\46blogLocale\75no\46v\0752\46homepageUrl\75http://spirelloskrimskramserier.blogspot.com/\46vt\0751357383140196484672',
5 | where: document.getElementById("navbar-iframe-container"),
6 | id: "navbar-iframe"
7 | });
8 | }
9 | });
10 |
--------------------------------------------------------------------------------
/tests/samples/misc006.js:
--------------------------------------------------------------------------------
1 | (function(){(function(){function e(a){this.t={};this.tick=function(a,c,b){var d=void 0!=b?b:(new Date).getTime();this.t[a]=[d,c];if(void 0==b)try{window.console.timeStamp("CSI/"+a)}catch(e){}};this.tick("start",null,a)}var a;window.performance&&(a=window.performance.timing);var f=a?new e(a.responseStart):new e;window.jstiming={Timer:e,load:f};if(a){var c=a.navigationStart,d=a.responseStart;0=c&&(window.jstiming.srt=d-c)}if(a){var b=window.jstiming.load;0=c&&(b.tick("_wtsrt",void 0,c),b.tick("wtsrt_",
2 | "_wtsrt",d),b.tick("tbsd_","wtsrt_"))}try{a=null,window.chrome&&window.chrome.csi&&(a=Math.floor(window.chrome.csi().pageT),b&&0");
7 | document.write ("Error Code: ");
8 | document.write (e.number & 0xFFFF);
9 | document.write ("
");
10 | document.write ("Error Name: " + e.name);
11 | }
12 |
--------------------------------------------------------------------------------
/tests/samples/trycatch002.js:
--------------------------------------------------------------------------------
1 | try {
2 | document.write("Outer try running...
");
3 |
4 | try {
5 | document.write("Nested try running...
");
6 | throw new Error(301, "an error");
7 | }
8 | catch (e) {
9 | document.write ("Nested catch caught " + e.message + "
");
10 | throw e;
11 | }
12 | finally {
13 | document.write ("Nested finally is running...
");
14 | }
15 | }
16 | catch (e) {
17 | document.write ("Outer catch caught " + e.message + "
");
18 | }
19 | finally {
20 | document.write ("Outer finally running");
21 | }
22 |
--------------------------------------------------------------------------------
/tests/samples/var001.js:
--------------------------------------------------------------------------------
1 | var index;
2 | var name = "Thomas Jefferson";
3 | var answer = 42, counter, numpages = 10;
4 | var myarray = new Array();
5 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/complextypes-array001.js:
--------------------------------------------------------------------------------
1 | var myArray = new Array(0, 2, 4);
2 | var myOtherArray = new Array();
3 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/complextypes-array002.js:
--------------------------------------------------------------------------------
1 | var myArray = [0, 2, 4];
2 | var myOtherArray = [];
3 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/complextypes-array003.js:
--------------------------------------------------------------------------------
1 | myArray[2] = "Hello";
2 | var text = myArray[2];
3 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/complextypes-object001.js:
--------------------------------------------------------------------------------
1 | var myObject = new Object();
2 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/complextypes-object002.js:
--------------------------------------------------------------------------------
1 | var myObject = {};
2 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/functions-expr-anonymous.js:
--------------------------------------------------------------------------------
1 | var square = function(number) {return number * number};
2 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/functions-expr-names.js:
--------------------------------------------------------------------------------
1 | var factorial = function fac(n) {return n<2 ? 1 : n*fac(n-1)};
2 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/functions001.js:
--------------------------------------------------------------------------------
1 | function hello() {
2 | alert("Hello, World!");
3 | }
4 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/functions002.js:
--------------------------------------------------------------------------------
1 | var hello = function() {
2 | alert("Hello, World!");
3 | };
4 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/functions003.js:
--------------------------------------------------------------------------------
1 | var hello = new Function(
2 | 'alert("Hello, World!");'
3 | );
4 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/functions004.js:
--------------------------------------------------------------------------------
1 | function hello(who) {
2 | alert("Hello, " + who + "!");
3 | }
4 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/functions005.js:
--------------------------------------------------------------------------------
1 | var hello = function(who) {
2 | alert("Hello, " + who + "!");
3 | };
4 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/functions006.js:
--------------------------------------------------------------------------------
1 | var hello = new Function('who',
2 | 'alert("Hello, " + who + "!");'
3 | );
4 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/primitivetypes-boolean.js:
--------------------------------------------------------------------------------
1 | var mayday = false;
2 | var birthday = true;
3 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/primitivetypes-numeric.js:
--------------------------------------------------------------------------------
1 | var sal = 20;
2 | var pal = 12.1;
3 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/primitivetypes-string.js:
--------------------------------------------------------------------------------
1 | var myName = "Some Name";
2 | var myChar = 'f';
3 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/variable001.js:
--------------------------------------------------------------------------------
1 | var c;
2 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/variable002.js:
--------------------------------------------------------------------------------
1 | var c = 0;
2 |
--------------------------------------------------------------------------------
/tests/samples/wikibooks/variable003.js:
--------------------------------------------------------------------------------
1 | c = 1;
2 |
--------------------------------------------------------------------------------
/tests/samples/with001.js:
--------------------------------------------------------------------------------
1 | with (Math){
2 | x = cos(3 * PI) + sin (LN10)
3 | y = tan(14 * E)
4 | }
5 |
--------------------------------------------------------------------------------
/tests/test_json.py:
--------------------------------------------------------------------------------
1 | import js2xml
2 | import js2xml.jsonlike
3 |
4 |
5 | def test_json():
6 | jscode_snippets = [
7 | (
8 | r"""
9 | var arr1 = ["a","b","c"];
10 | var arr2 = ["d","e","f"];
11 | """,
12 | [["a", "b", "c"], ["d", "e", "f"]],
13 | ),
14 | (
15 | r"""
16 | var arr1 = ["a", null, "c"];
17 | var arr2 = [null, "e", null];
18 | """,
19 | [["a", None, "c"], [None, "e", None]],
20 | ),
21 | (
22 | r"""
23 | var arr1 = ["a", undefined, "c"];
24 | var arr2 = [undefined, "e", null];
25 | """,
26 | [["a", "undefined", "c"], ["undefined", "e", None]],
27 | ),
28 | (
29 | r"""
30 | var i = -3.14;
31 | """,
32 | [],
33 | ),
34 | (
35 | r"""
36 | money = {
37 | 'quarters': 20
38 | };
39 | """,
40 | [{"quarters": 20}],
41 | ),
42 | (
43 | r"""
44 | money = {
45 | quarters: 20
46 | };
47 | """,
48 | [{"quarters": 20}],
49 | ),
50 | (
51 | r"""
52 | currency = 'USD',
53 | money = {
54 | "value": 20,
55 | "currency": currency
56 | };
57 | """,
58 | [{"currency": "currency", "value": 20}],
59 | ),
60 | (
61 | r"""
62 | t = {a: "3", "b": 3, "3": 3.0};
63 | """,
64 | [{"3": 3.0, "a": "3", "b": 3}],
65 | ),
66 | (
67 | r"""
68 | money = {
69 | 'quarters': 10,
70 | 'addQuarters': function(amount) {
71 | this.quarters += amount;
72 | }
73 | };
74 | money.addQuarters(10);
75 | """,
76 | [],
77 | ),
78 | (
79 | r"""
80 | var money = {
81 | 'quarters': 10,
82 | 'something': [1,2,3,4],
83 | 'somethingelse': {'nested': [5,6,7,8]},
84 | 'addQuarters': function(amount) {
85 | this.quarters += amount;
86 | }
87 | };
88 | money.addQuarters(10);
89 | """,
90 | [[1, 2, 3, 4], {"nested": [5, 6, 7, 8]}],
91 | ),
92 | (
93 | r"""
94 | var store = {
95 | 'apples': 10,
96 | 'carrots': [1,2,3,4],
97 | 'chicken': {'eggs': [5,6,7,8]}
98 | };
99 | """,
100 | [{"apples": 10, "carrots": [1, 2, 3, 4], "chicken": {"eggs": [5, 6, 7, 8]}}],
101 | ),
102 | (
103 | r"""
104 | var store1 = {
105 | 'apples': 10,
106 | 'carrots': [1,2,3,4],
107 | 'chicken': {'eggs': [5,6,7,8]}
108 | };
109 | var store2 = {
110 | 'tomatoes': 20,
111 | 'potatoes': [9, false, 7, 6],
112 | 'spinach': {'cans': [true, 2]}
113 | };
114 | """,
115 | [
116 | {"apples": 10, "carrots": [1, 2, 3, 4], "chicken": {"eggs": [5, 6, 7, 8]}},
117 | {"potatoes": [9, False, 7, 6], "spinach": {"cans": [True, 2]}, "tomatoes": 20},
118 | ],
119 | ),
120 | ]
121 | for snippet, expected in jscode_snippets:
122 | jsxml = js2xml.parse(snippet)
123 | assert js2xml.jsonlike.getall(jsxml) == expected
124 |
125 |
126 | def test_findall():
127 | jscode_snippets = [
128 | (
129 | r"""
130 | var arr1 = ["a","b","c"];
131 | var arr2 = ["d","e","f"];
132 | """,
133 | "//array",
134 | [["a", "b", "c"], ["d", "e", "f"]],
135 | ),
136 | (
137 | r"""
138 | var arr1 = {"a": "b", "c": "d"};
139 | var arr2 = {"e": 1, "f": 2};
140 | """,
141 | "//object",
142 | [{"a": "b", "c": "d"}, {"e": 1, "f": 2}],
143 | ),
144 | ]
145 |
146 | for snippet, xp, expected in jscode_snippets:
147 | js = js2xml.parse(snippet)
148 | results = []
149 | for r in js.xpath(xp):
150 | results.extend(js2xml.jsonlike.findall(r))
151 | assert [js2xml.jsonlike.make_dict(r) for r in results] == expected
152 |
153 |
154 | def test_getall_complex():
155 | jscode_snippets = [
156 | (
157 | r"""
158 | var needleParam = needleParam || {};
159 | needleParam.chatGroup = "test";
160 | needleParam.productId = "6341292";
161 | needleParam.productPrice = "EUR 138.53".replace("$","n_").replace(/,/g,"");
162 | //Begin Needle (fan-sourcing platform) snippet
163 | jQuery(document).ready(function(){
164 |
165 | var e = document.createElement("script"); e.type = "text/javascript";
166 | e.async = true;
167 | e.src = document.location.protocol +
168 |
169 | "//overstock.needle.com/needle_service.js?1"; document.body.appendChild(e);
170 |
171 | });
172 | // End Needle snippet
173 | """,
174 | [{}],
175 | ),
176 | ]
177 |
178 | for snippet, expected in jscode_snippets:
179 | jsxml = js2xml.parse(snippet)
180 | assert js2xml.jsonlike.getall(jsxml) == expected
181 |
--------------------------------------------------------------------------------
/tests/test_parse.py:
--------------------------------------------------------------------------------
1 | import pytest
2 |
3 | import js2xml
4 |
5 |
6 | def test_parse():
7 | jscode_snippets = [
8 | r"""
9 | var i = 0;
10 | """,
11 | r"""
12 | document.write("\n");
13 | """,
14 | r"""
15 | var t1 = "nested \"quote\".";
16 | var t2 = 'nested \'quote\'.';
17 | var t3 = 'nested \"quote\".';
18 | var t2 = "nested \'quote\'.";
19 | """,
20 | ]
21 |
22 | for snippet in jscode_snippets:
23 | assert js2xml.parse(snippet) is not None
24 |
25 |
26 | def test_parse_exception():
27 | jscode_snippets = [
28 | r"""
29 | var i = ';
30 | """,
31 | r"""
32 | {
33 | .document.write;
34 | }
35 | """,
36 | r"""
37 | var t = "nested "quote"."d;
38 | """,
39 | r"""
40 | t = -;
41 | """,
42 | ]
43 |
44 | for snippet in jscode_snippets:
45 | with pytest.raises(SyntaxError):
46 | js2xml.parse(snippet)
47 |
48 |
49 | def test_parse_string():
50 | jscode_snippets = [
51 | (
52 | r"""
53 | var h = 'test';
54 | var i = "test";
55 | var j = "";
56 | var k = '""';
57 | var l = '"';
58 | var m = '';
59 | var n = "''";
60 | var o = "'";
61 | """,
62 | ["test", "test", "", '""', '"', "", "''", "'"],
63 | ),
64 | (
65 | r"""
66 | var i = 'test\'s output';
67 | """,
68 | [r"test's output"],
69 | ),
70 | (
71 | r"""
72 | var i = 'test\
73 | multiline';
74 | """,
75 | [r"test multiline"],
76 | ),
77 | (
78 | r"""
79 | var i = 'test\
80 | long \
81 | multiline';
82 | """,
83 | [r"test long multiline"],
84 | ),
85 | (
86 | r"""
87 | var i = ["\"", '\''];
88 | var j = "test\'s output";
89 | var k = "test\\'s output";
90 | var l = "nested \"quotes\".";
91 | """,
92 | ['"', "'", r"test's output", r"test\'s output", r'nested "quotes".'],
93 | ),
94 | (
95 | r"""
96 | var i = 'https://www.blogger.com/navbar.g?targetBlogID\0754325487278375417853\46blogName\75spirello\46publishMode\75PUBLISH_MODE_BLOGSPOT\46navbarType\75LIGHT\46layoutType\75LAYOUTS\46searchRoot\75http://spirelloskrimskramserier.blogspot.com/search\46blogLocale\75no\46v\0752\46homepageUrl\75http://spirelloskrimskramserier.blogspot.com/\46vt\0751357383140196484672';
97 | """,
98 | [
99 | r"https://www.blogger.com/navbar.g?targetBlogID=4325487278375417853&blogName=spirello&publishMode=PUBLISH_MODE_BLOGSPOT&navbarType=LIGHT&layoutType=LAYOUTS&searchRoot=http://spirelloskrimskramserier.blogspot.com/search&blogLocale=no&v=2&homepageUrl=http://spirelloskrimskramserier.blogspot.com/&vt=1357383140196484672"
100 | ],
101 | ),
102 | (
103 | r"""
104 | var i = "foo \
105 | bar";
106 | var j = "foo \
107 | bar";
108 | """,
109 | [r"foo bar", "foo bar"],
110 | ),
111 | (
112 | # testing Unicode literals
113 | b"""
114 | var x = "\\u00A9 Netscape Communications 1";
115 | """,
116 | [u"\u00a9 Netscape Communications 1"],
117 | ),
118 | (
119 | # testing Unicode characters
120 | u"""
121 | var x = "\u00A9 Netscape Communications 2";
122 | """.encode(
123 | "utf8"
124 | ),
125 | [u"\u00a9 Netscape Communications 2"],
126 | ),
127 | # a real example
128 | (
129 | r"""
130 | var needleParam = needleParam || {};
131 | needleParam.chatGroup = "test";
132 | needleParam.productId = "6341292";
133 | needleParam.productPrice = "EUR 138.53".replace("$","n_").replace(/,/g,"");
134 | //Begin Needle (fan-sourcing platform) snippet
135 | jQuery(document).ready(function(){
136 |
137 | var e = document.createElement("script"); e.type = "text/javascript";
138 | e.async = true;
139 | e.src = document.location.protocol +
140 |
141 | "//overstock.needle.com/needle_service.js?1"; document.body.appendChild(e);
142 |
143 | });
144 | // End Needle snippet
145 | """,
146 | [
147 | "test",
148 | "6341292",
149 | "EUR 138.53",
150 | "$",
151 | "n_",
152 | "",
153 | "script",
154 | "text/javascript",
155 | "//overstock.needle.com/needle_service.js?1",
156 | ],
157 | ),
158 | # test replacing some control characters
159 | (
160 | r"""
161 | var name = "\u13e9\u0352\u0362\u044f\u2778\u00b3\u1d43\u034e\u034e\u0442\u035b\u13b7\u0362\u033b\u1d51A\u0362\u13de\u0001\u0001\u277c00b";
162 | """,
163 | [
164 | u"\u13e9\u0352\u0362\u044f\u2778\xb3\u1d43\u034e\u034e\u0442\u035b\u13b7\u0362\u033b\u1d51A\u0362\u13de\ufffd\ufffd\u277c00b"
165 | ],
166 | ),
167 | # surrogate pairs
168 | (r'''var name = "\ud835\udebd"''', [u"\U0001d6bd"]),
169 | ]
170 |
171 | for snippet, expected in jscode_snippets:
172 | jsxml = js2xml.parse(snippet)
173 | result = jsxml.xpath("//string/text()")
174 | assert result == expected
175 |
176 |
177 | def test_parse_url():
178 | jscode_snippets = [
179 | (
180 | r"""
181 | var i = 'http://www.example.com';
182 | """,
183 | [r"http://www.example.com"],
184 | ),
185 | (
186 | r"""
187 | var i = 'http:\/\/www.example.com';
188 | """,
189 | [r"http://www.example.com"],
190 | ),
191 | ]
192 |
193 | for snippet, expected in jscode_snippets:
194 | jsxml = js2xml.parse(snippet)
195 | result = jsxml.xpath("//string/text()")
196 | assert result == expected
197 |
198 |
199 | def test_parse_number():
200 | jscode_snippets = [
201 | (
202 | r"""
203 | var i = 3;
204 | """,
205 | [r"3"],
206 | ),
207 | (
208 | r"""
209 | var i = -3.14;
210 | """,
211 | [r"-3.14"],
212 | ),
213 | ]
214 |
215 | for snippet, expected in jscode_snippets:
216 | jsxml = js2xml.parse(snippet)
217 | result = jsxml.xpath("//number/@value")
218 | assert result == expected
219 |
220 |
221 | def test_parse_undefined():
222 | jscode_snippets = [
223 | (
224 | r"""
225 | myArray = [0,1,,,4,5];
226 | """,
227 | 2,
228 | ),
229 | (
230 | r"""
231 | myArray = [,1,,,4,];
232 | """,
233 | 3, # and not 4
234 | ),
235 | (
236 | r"""
237 | myArray = [,1,,,4,,,];
238 | """,
239 | 5,
240 | ),
241 | ]
242 |
243 | for snippet, expected in jscode_snippets:
244 | jsxml = js2xml.parse(snippet)
245 | result = jsxml.xpath("count(//array/undefined)")
246 | assert result == expected
247 |
248 |
249 | def test_parse_encoding():
250 |
251 | jscode_snippets = [
252 | (
253 | u"""
254 | var test = "Daniel Gra\xf1a";
255 | """,
256 | None,
257 | [u"Daniel Gra\xf1a"],
258 | ),
259 | (
260 | u"""
261 | var test = "Daniel Gra\xf1a";
262 | """.encode(
263 | "latin1"
264 | ),
265 | "latin1",
266 | [u"Daniel Gra\xf1a"],
267 | ),
268 | ]
269 |
270 | for snippet, encoding, expected in jscode_snippets:
271 | jsxml = js2xml.parse(snippet, encoding=encoding)
272 | result = jsxml.xpath("//string/text()")
273 | assert result == expected
274 |
275 |
276 | def test_keywords_as_object_keys():
277 | # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords
278 | keywords = [
279 | "abstract",
280 | "arguments",
281 | "await",
282 | "boolean",
283 | "break",
284 | "byte",
285 | "catch",
286 | "char",
287 | "class",
288 | "const",
289 | "continue",
290 | "debugger",
291 | "default",
292 | "delete",
293 | "do",
294 | "double",
295 | "else",
296 | "enum",
297 | "eval",
298 | "export",
299 | "extends",
300 | "false",
301 | "final",
302 | "finally",
303 | "float",
304 | "for",
305 | "function",
306 | "goto",
307 | "if",
308 | "implements",
309 | "import",
310 | "in",
311 | "instanceof",
312 | "int",
313 | "interface",
314 | "let",
315 | "long",
316 | "native",
317 | "new",
318 | "null",
319 | "package",
320 | "private",
321 | "protected",
322 | "public",
323 | "return",
324 | "short",
325 | "static",
326 | "super",
327 | "switch",
328 | "synchronized",
329 | "this",
330 | "throw",
331 | "throws",
332 | "transient",
333 | "true",
334 | "try",
335 | "typeof",
336 | "var",
337 | "void",
338 | "volatile",
339 | "while",
340 | "with",
341 | "yield",
342 | ]
343 | for keyword in keywords:
344 | jsxml = js2xml.parse("x={{{}: 0}}".format(keyword))
345 | xpath = "//property[@name='{}']".format(keyword)
346 | matches = len(jsxml.xpath(xpath))
347 | assert matches == 1
348 |
--------------------------------------------------------------------------------
/tests/test_syntax.py:
--------------------------------------------------------------------------------
1 | import js2xml
2 |
3 |
4 | def test_syntax():
5 | jscode_snippets = [
6 | # strings
7 | r"""
8 | "test";
9 | """,
10 | r"""
11 | "test\
12 | multiline";
13 | """,
14 | # numbers
15 | "3.14;",
16 | "-12;",
17 | "3.45e2;",
18 | "0377;",
19 | "0xFF;"
20 | # arrays
21 | "[]",
22 | "[1,2]",
23 | "[1,,2]",
24 | "[1,,2,,3,]",
25 | "['a', 'b','c']",
26 | "[a, 'b', c]",
27 | # objects
28 | "o = {};",
29 | "o = {a: 1};",
30 | "o = {a: 1, b: 2};",
31 | "o = {'c': 1, 'd': 2};",
32 | 'o = {"c": 1, "d": 2};',
33 | 'o = {"c": 1, d: "e"};',
34 | "e = {foo: 5, bar: 6, baz: ['Baz', 'Content']};",
35 | "e = {1: a, 2: b};",
36 | # other primitive data types
37 | "null;",
38 | "undefined;",
39 | "true;",
40 | "false;",
41 | # variables
42 | r"""
43 | var i;
44 | """,
45 | r"""
46 | var i,j,k;
47 | """,
48 | r"""
49 | var i = 0;
50 | """,
51 | r"""
52 | var i = "test";
53 | """,
54 | r"""var z = 'foxes', r = 'birds';""",
55 | r"""
56 | var i, j, k = 0;
57 | """,
58 | r"""
59 | var i=1, j, k = 2;
60 | """,
61 | r"""
62 | var i = obj.prop;
63 | """,
64 | r"""var testObj = {};""",
65 | r"""var testObj = [];""",
66 | # assignements
67 | r"""
68 | i = b;
69 | """,
70 | r"""
71 | i.a = "b";
72 | """,
73 | r"""
74 | i["a"] = "b";
75 | """,
76 | r"""
77 | i[a] = "b";
78 | """,
79 | # control structures
80 | r"""
81 | if (condition) {
82 | result = expression;
83 | };""",
84 | r"""
85 | if (condition) {
86 | result = expression;
87 | } else {
88 | result = alternative;
89 | };""",
90 | r"""
91 | if (exprA == exprB) {
92 | result = expression;
93 | } else if (expr2) {
94 | result = alternative1;
95 | } else {
96 | result = alternative2;
97 | };""",
98 | "result = condition ? expression : alternative;",
99 | # switch
100 | r"""
101 | switch (expr) {
102 | case SOMEVALUE:
103 | //statements;
104 | break;
105 | case ANOTHERVALUE:
106 | //statements;
107 | break;
108 | default:
109 | //statements;
110 | break;
111 | }
112 | """
113 | # for loop
114 | r"""
115 | for (var i = 0; i < 5; i++) {
116 | a = i;
117 | }
118 | """,
119 | r"""
120 | for (var i = 0; i < 5; i++) {
121 | a = i
122 | }
123 | """,
124 | r"""
125 | for (var key in array) {
126 | continue;
127 | }
128 | """,
129 | r"""
130 | for (;;) {
131 | break;
132 | }
133 | """,
134 | r"""
135 | for (; i < len; i++) {
136 | text += cars[i] + "
";
137 | }
138 | """,
139 | r"""
140 | for (var i = 0, len = cars.length, text = ""; i < len; i++) {
141 | text += cars[i] + "
";
142 | }
143 | """,
144 | """
145 | for (; i < len; ) {
146 | text += cars[i] + "
";
147 | i++;
148 | }
149 | """,
150 | # while loop
151 | """
152 | while (a");
274 | document.write ("Error Code: ");
275 | document.write (e.number & 0xFFFF);
276 | document.write ("
");
277 | document.write ("Error Name: " + e.name);
278 | }
279 | """,
280 | """
281 | try {
282 | document.write("Outer try running...
");
283 |
284 | try {
285 | document.write("Nested try running...
");
286 | throw new Error(301, "an error");
287 | }
288 | catch (e) {
289 | document.write ("Nested catch caught " + e.message + "
");
290 | throw e;
291 | }
292 | finally {
293 | document.write ("Nested finally is running...
");
294 | }
295 | }
296 | catch (e) {
297 | document.write ("Outer catch caught " + e.message + "
");
298 | }
299 | finally {
300 | document.write ("Outer finally running");
301 | }
302 | """,
303 | """
304 | new Map
305 | """,
306 | ]
307 |
308 | for snippet in jscode_snippets:
309 | assert js2xml.parse(snippet) is not None
310 |
--------------------------------------------------------------------------------
/tests/test_utils_objects.py:
--------------------------------------------------------------------------------
1 | import js2xml
2 | from js2xml.utils.objects import findall, getall, make
3 |
4 |
5 | def test_json():
6 | jscode_snippets = [
7 | (
8 | r"""
9 | var arr1 = ["a","b","c"];
10 | var arr2 = ["d","e","f"];
11 | """,
12 | [["a", "b", "c"], ["d", "e", "f"]],
13 | ),
14 | (
15 | r"""
16 | var arr1 = ["a", null, "c"];
17 | var arr2 = [null, "e", null];
18 | """,
19 | [["a", None, "c"], [None, "e", None]],
20 | ),
21 | (
22 | r"""
23 | var arr1 = ["a", undefined, "c"];
24 | var arr2 = [undefined, "e", null];
25 | """,
26 | [["a", "undefined", "c"], ["undefined", "e", None]],
27 | ),
28 | (
29 | r"""
30 | var i = -3.14;
31 | """,
32 | [],
33 | ),
34 | (
35 | r"""
36 | money = {
37 | 'quarters': 20
38 | };
39 | """,
40 | [{"quarters": 20}],
41 | ),
42 | (
43 | r"""
44 | money = {
45 | quarters: 20
46 | };
47 | """,
48 | [{"quarters": 20}],
49 | ),
50 | (
51 | r"""
52 | currency = 'USD',
53 | money = {
54 | "value": 20,
55 | "currency": currency
56 | };
57 | """,
58 | [{"currency": "currency", "value": 20}],
59 | ),
60 | (
61 | r"""
62 | t = {a: "3", "b": 3, "3": 3.0};
63 | """,
64 | [{"3": 3.0, "a": "3", "b": 3}],
65 | ),
66 | (
67 | r"""
68 | money = {
69 | 'quarters': 10,
70 | 'addQuarters': function(amount) {
71 | this.quarters += amount;
72 | }
73 | };
74 | money.addQuarters(10);
75 | """,
76 | [],
77 | ),
78 | (
79 | r"""
80 | var money = {
81 | 'quarters': 10,
82 | 'something': [1,2,3,4],
83 | 'somethingelse': {'nested': [5,6,7,8]},
84 | 'addQuarters': function(amount) {
85 | this.quarters += amount;
86 | }
87 | };
88 | money.addQuarters(10);
89 | """,
90 | [[1, 2, 3, 4], {"nested": [5, 6, 7, 8]}],
91 | ),
92 | (
93 | r"""
94 | var store = {
95 | 'apples': 10,
96 | 'carrots': [1,2,3,4],
97 | 'chicken': {'eggs': [5,6,7,8]}
98 | };
99 | """,
100 | [{"apples": 10, "carrots": [1, 2, 3, 4], "chicken": {"eggs": [5, 6, 7, 8]}}],
101 | ),
102 | (
103 | r"""
104 | var store1 = {
105 | 'apples': 10,
106 | 'carrots': [1,2,3,4],
107 | 'chicken': {'eggs': [5,6,7,8]}
108 | };
109 | var store2 = {
110 | 'tomatoes': 20,
111 | 'potatoes': [9, false, 7, 6],
112 | 'spinach': {'cans': [true, 2]}
113 | };
114 | """,
115 | [
116 | {"apples": 10, "carrots": [1, 2, 3, 4], "chicken": {"eggs": [5, 6, 7, 8]}},
117 | {"potatoes": [9, False, 7, 6], "spinach": {"cans": [True, 2]}, "tomatoes": 20},
118 | ],
119 | ),
120 | ]
121 | for snippet, expected in jscode_snippets:
122 | jsxml = js2xml.parse(snippet)
123 | assert getall(jsxml, types=[dict, list]) == expected
124 |
125 |
126 | def test_findall():
127 | jscode_snippets = [
128 | (
129 | r"""
130 | var arr1 = ["a","b","c"];
131 | var arr2 = ["d","e","f"];
132 | """,
133 | "//array",
134 | [dict, list],
135 | [["a", "b", "c"], ["d", "e", "f"]],
136 | ),
137 | (
138 | r"""
139 | var arr1 = {"a": "b", "c": "d"};
140 | var arr2 = {"e": 1, "f": 2};
141 | """,
142 | "//object",
143 | [dict, list],
144 | [{"a": "b", "c": "d"}, {"e": 1, "f": 2}],
145 | ),
146 | ]
147 |
148 | for snippet, xp, types, expected in jscode_snippets:
149 | js = js2xml.parse(snippet)
150 | results = []
151 | for r in js.xpath(xp):
152 | results.extend(findall(r, types=types))
153 | assert [make(r) for r in results] == expected
154 |
155 |
156 | def test_getall_complex():
157 | jscode_snippets = [
158 | (
159 | r"""
160 | var needleParam = needleParam || {};
161 | needleParam.chatGroup = "test";
162 | needleParam.productId = "6341292";
163 | needleParam.productPrice = "EUR 138.53".replace("$","n_").replace(/,/g,"");
164 | //Begin Needle (fan-sourcing platform) snippet
165 | jQuery(document).ready(function(){
166 |
167 | var e = document.createElement("script"); e.type = "text/javascript";
168 | e.async = true;
169 | e.src = document.location.protocol +
170 |
171 | "//overstock.needle.com/needle_service.js?1"; document.body.appendChild(e);
172 |
173 | });
174 | // End Needle snippet
175 | """,
176 | [dict, list],
177 | [{}],
178 | ),
179 | (
180 | r"""
181 | var needleParam = needleParam || {};
182 | needleParam.chatGroup = "test";
183 | needleParam.productId = "6341292";
184 | needleParam.productPrice = "EUR 138.53".replace("$","n_").replace(/,/g,"");
185 | //Begin Needle (fan-sourcing platform) snippet
186 | jQuery(document).ready(function(){
187 |
188 | var e = document.createElement("script"); e.type = "text/javascript";
189 | e.async = true;
190 | e.src = document.location.protocol +
191 |
192 | "//overstock.needle.com/needle_service.js?1"; document.body.appendChild(e);
193 |
194 | });
195 | // End Needle snippet
196 | """,
197 | [str],
198 | [
199 | "test",
200 | "6341292",
201 | "EUR 138.53",
202 | "$",
203 | "n_",
204 | "",
205 | "script",
206 | "text/javascript",
207 | "//overstock.needle.com/needle_service.js?1",
208 | ],
209 | ),
210 | (
211 | r"""
212 | var needleParam = needleParam || {};
213 | needleParam.chatGroup = "test";
214 | needleParam.productId = "6341292";
215 | needleParam.productPrice = "EUR 138.53".replace("$","n_").replace(/,/g,"");
216 | //Begin Needle (fan-sourcing platform) snippet
217 | jQuery(document).ready(function(){
218 |
219 | var e = document.createElement("script"); e.type = "text/javascript";
220 | e.async = true;
221 | e.src = document.location.protocol +
222 |
223 | "//overstock.needle.com/needle_service.js?1"; document.body.appendChild(e);
224 |
225 | });
226 | // End Needle snippet
227 | """,
228 | [bool],
229 | [True],
230 | ),
231 | ]
232 |
233 | for snippet, types, expected in jscode_snippets:
234 | jsxml = js2xml.parse(snippet)
235 | assert getall(jsxml, types=types) == expected
236 |
--------------------------------------------------------------------------------
/tests/test_utils_vars.py:
--------------------------------------------------------------------------------
1 | from js2xml import parse
2 | from js2xml.utils.vars import get_vars
3 |
4 |
5 | def test_vars():
6 | jscode_snippets = [
7 | (
8 | r"""
9 | var arr1 = ["a","b","c"];
10 | var arr2 = ["d","e","f"];
11 | """,
12 | {"arr1": ["a", "b", "c"], "arr2": ["d", "e", "f"]},
13 | ),
14 | (
15 | r"""
16 | var arr1 = ["a", null, "c"];
17 | var arr2 = [null, "e", null];
18 | """,
19 | {"arr1": ["a", None, "c"], "arr2": [None, "e", None]},
20 | ),
21 | (
22 | r"""
23 | var arr1 = ["a", undefined, "c"];
24 | var arr2 = [undefined, "e", null];
25 | """,
26 | {"arr1": ["a", "undefined", "c"], "arr2": ["undefined", "e", None]},
27 | ),
28 | (
29 | r"""
30 | var i = -3.14;
31 | """,
32 | {"i": -3.14},
33 | ),
34 | (
35 | r"""
36 | money = {
37 | 'quarters': 20
38 | };
39 | """,
40 | {"money": {"quarters": 20}},
41 | ),
42 | (
43 | r"""
44 | money = {
45 | quarters: 20
46 | };
47 | """,
48 | {"money": {"quarters": 20}},
49 | ),
50 | (
51 | r"""
52 | currency = 'USD';
53 | money = {
54 | "value": 20,
55 | "currency": currency
56 | };
57 | """,
58 | {"currency": "USD", "money": {"currency": "currency", "value": 20}},
59 | ),
60 | (
61 | r"""
62 | t = {a: "3", "b": 3, "3": 3.0};
63 | """,
64 | {"t": {"3": 3.0, "a": "3", "b": 3}},
65 | ),
66 | (
67 | r"""
68 | money = {
69 | 'quarters': 10,
70 | 'addQuarters': function(amount) {
71 | this.quarters += amount;
72 | }
73 | };
74 | money.addQuarters(10);
75 | """,
76 | {"money": {"quarters": 10, "addQuarters": None}},
77 | ),
78 | (
79 | r"""
80 | var money = {
81 | 'quarters': 10,
82 | 'something': [1,2,3,4],
83 | 'somethingelse': {'nested': [5,6,7,8]},
84 | 'addQuarters': function(amount) {
85 | this.quarters += amount;
86 | }
87 | };
88 | money.addQuarters(10);
89 | """,
90 | {
91 | "money": {
92 | "quarters": 10,
93 | "addQuarters": None,
94 | "something": [1, 2, 3, 4],
95 | "somethingelse": {"nested": [5, 6, 7, 8]},
96 | }
97 | },
98 | ),
99 | (
100 | r"""
101 | var store = {
102 | 'apples': 10,
103 | 'carrots': [1,2,3,4],
104 | 'chicken': {'eggs': [5,6,7,8]}
105 | };
106 | """,
107 | {"store": {"apples": 10, "carrots": [1, 2, 3, 4], "chicken": {"eggs": [5, 6, 7, 8]}}},
108 | ),
109 | (
110 | r"""
111 | var store1 = {
112 | 'apples': 10,
113 | 'carrots': [1,2,3,4],
114 | 'chicken': {'eggs': [5,6,7,8]}
115 | };
116 | var store2 = {
117 | 'tomatoes': 20,
118 | 'potatoes': [9, false, 7, 6],
119 | 'spinach': {'cans': [true, 2]}
120 | };
121 | """,
122 | {
123 | "store1": {
124 | "apples": 10,
125 | "carrots": [1, 2, 3, 4],
126 | "chicken": {"eggs": [5, 6, 7, 8]},
127 | },
128 | "store2": {
129 | "potatoes": [9, False, 7, 6],
130 | "spinach": {"cans": [True, 2]},
131 | "tomatoes": 20,
132 | },
133 | },
134 | ),
135 | ]
136 | for snippet, expected in jscode_snippets:
137 | tree = parse(snippet)
138 | assert get_vars(tree) == expected, (snippet, expected)
139 |
--------------------------------------------------------------------------------
/tox.ini:
--------------------------------------------------------------------------------
1 | [tox]
2 | envlist = black,flake8,py
3 |
4 | [testenv]
5 | basepython = python3
6 | deps =
7 | pytest-cov>=2.8
8 | pytest>=5.4
9 | commands =
10 | pytest --cov=js2xml \
11 | --cov-report=term-missing --cov-report=html --cov-report=xml \
12 | --verbose {posargs: js2xml tests}
13 |
14 | [testenv:black]
15 | basepython = python3
16 | deps =
17 | black==21.6b0
18 | commands =
19 | black --check {posargs: js2xml setup.py tests}
20 |
21 | [testenv:flake8]
22 | basepython = python3
23 | deps =
24 | flake8==3.9.2
25 | commands =
26 | flake8 {posargs: js2xml setup.py tests}
27 |
--------------------------------------------------------------------------------