Comparing version 1.2.14 to 1.2.15
@@ -58,3 +58,3 @@ "use strict"; | ||
this.INIT_HEIGHT = height ? height : 300; | ||
this.DEFAULT_BOX_CLASS = "dragbox"; | ||
this.DEFAULT_BOX_THEME = "dragbox-gray"; | ||
this.DEFAULT_DRAGGABLE = true; | ||
@@ -81,3 +81,3 @@ this.DEFAULT_STICKINESS_TYPE = "magnetized"; | ||
this._overflow = "hidden"; | ||
this._boxClass = this.DEFAULT_BOX_CLASS; | ||
this._boxClass = this.DEFAULT_BOX_THEME; | ||
this._width = this.INIT_WIDTH; | ||
@@ -109,3 +109,3 @@ this._height = this.INIT_HEIGHT; | ||
// html for creation | ||
this.boxHTML = '<div id="' + this.boxId + '" class="' + this._boxClass + '" style="opacity:0.0;" draggable="false">' + '<div class="col-xs-12 dragbox-container"><div class="col-xs-12 dragbox-title"><center><h3>Dragbox</h3></center></div>' + '<div class="col-xs-12 dragbox-content"></div><div class="col-xs-12 dragbox-footer"></div></div>' + '</div>'; | ||
this.boxHTML = '<div id="' + this.boxId + '" class="dragbox ' + this._boxClass + '" style="opacity:0.0;" draggable="false">' + '<div class="col-xs-12 dragbox-container"><div class="col-xs-12 dragbox-title"><center><h3>Dragbox</h3></center></div>' + '<div class="col-xs-12 dragbox-content"></div><div class="col-xs-12 dragbox-footer"></div></div>' + '</div>'; | ||
@@ -465,6 +465,6 @@ $(document.body).append(this.boxHTML); | ||
// if there is more than one class in the string take the first one | ||
var spacePos = newClass.indexOf(" "); | ||
if (spacePos != -1) { | ||
newClass = newClass.substr(0, spacePos); | ||
} | ||
// var spacePos = newClass.indexOf(" "); | ||
// if (spacePos != -1) { | ||
// newClass = newClass.substr(0, spacePos); | ||
// } | ||
@@ -471,0 +471,0 @@ // remove the old class from the boxElement and add the new class |
@@ -39,3 +39,3 @@ /** | ||
this.INIT_HEIGHT = (height) ? height : 300; | ||
this.DEFAULT_BOX_CLASS = "dragbox"; | ||
this.DEFAULT_BOX_THEME = "dragbox-gray"; | ||
this.DEFAULT_DRAGGABLE = true; | ||
@@ -62,3 +62,3 @@ this.DEFAULT_STICKINESS_TYPE = "magnetized"; | ||
this._overflow = "hidden"; | ||
this._boxClass = this.DEFAULT_BOX_CLASS; | ||
this._boxClass = this.DEFAULT_BOX_THEME; | ||
this._width = this.INIT_WIDTH; | ||
@@ -90,3 +90,3 @@ this._height = this.INIT_HEIGHT; | ||
// html for creation | ||
this.boxHTML = '<div id="' + this.boxId + '" class="' + this._boxClass + '" style="opacity:0.0;" draggable="false">' + | ||
this.boxHTML = '<div id="' + this.boxId + '" class="dragbox ' + this._boxClass + '" style="opacity:0.0;" draggable="false">' + | ||
'<div class="col-xs-12 dragbox-container"><div class="col-xs-12 dragbox-title"><center><h3>Dragbox</h3></center></div>' + | ||
@@ -385,6 +385,6 @@ '<div class="col-xs-12 dragbox-content"></div><div class="col-xs-12 dragbox-footer"></div></div>' + | ||
// if there is more than one class in the string take the first one | ||
var spacePos = newClass.indexOf(" "); | ||
if (spacePos != -1) { | ||
newClass = newClass.substr(0, spacePos); | ||
} | ||
// var spacePos = newClass.indexOf(" "); | ||
// if (spacePos != -1) { | ||
// newClass = newClass.substr(0, spacePos); | ||
// } | ||
@@ -391,0 +391,0 @@ // remove the old class from the boxElement and add the new class |
@@ -1,1 +0,1 @@ | ||
"use strict";function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function mandatory(){var t=arguments.length<=0||void 0===arguments[0]?"":arguments[0];throw new Error("Missing parameter "+t)}function findAllIndices(){for(var t=arguments.length<=0||void 0===arguments[0]?mandatory():arguments[0],e=arguments.length<=1||void 0===arguments[1]?mandatory():arguments[1],n=[],i=0;i<e.length;i++)e.substr(i,t.length)===t&&n.push(i);return n.length?n:-1}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},_createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),scripts=document.getElementsByTagName("script"),paramBoxFullpath=scripts[scripts.length-1].src,delimiterIndices=findAllIndices("/",paramBoxFullpath);paramBoxFullpath=paramBoxFullpath.substr(0,delimiterIndices[delimiterIndices.length-2]),document.addEventListener("DOMContentLoaded",function(t){var e=document.getElementsByTagName("head")[0],n=document.createElement("link");n.rel="stylesheet",n.type="text/css",n.href=paramBoxFullpath+"/dist/paramBox.css",e.appendChild(n)});var DragBox=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?null:arguments[0],n=arguments.length<=1||void 0===arguments[1]?null:arguments[1],i=arguments.length<=2||void 0===arguments[2]?null:arguments[2];_classCallCheck(this,t),this.MAX_BINDED_PROPERTIES=15,this.INIT_WIDTH=n?n:400,this.INIT_HEIGHT=i?i:300,this.DEFAULT_BOX_CLASS="dragbox",this.DEFAULT_DRAGGABLE=!0,this.DEFAULT_STICKINESS_TYPE="magnetized",this.boxId=null,this.boxElement=e,this.draggable=this.DEFAULT_DRAGGABLE,this.boxHTML=null,this.shouldStick=null,this.shouldMagnetize=null,this.isStickingX=null,this.isStickingY=null,this.stickiness=this.DEFAULT_STICKINESS_TYPE,this._beingDragged=!1,this._visibility="hidden",this._overflow="hidden",this._boxClass=this.DEFAULT_BOX_CLASS,this._width=this.INIT_WIDTH,this._height=this.INIT_HEIGHT,this.map=[],this.currentMousePos={x:-1,y:-1};var o=this;$(document).mousemove(function(t){o.currentMousePos.x=t.pageX,o.currentMousePos.y=t.pageY}),this.boxElement?this.boxId=$(this.boxElement).attr("id"):(this.boxId="dragbox"+($('div[id*="dragbox"]').length+1),this.boxHTML='<div id="'+this.boxId+'" class="'+this._boxClass+'" style="opacity:0.0;" draggable="false"><div class="col-xs-12 dragbox-container"><div class="col-xs-12 dragbox-title"><center><h3>Dragbox</h3></center></div><div class="col-xs-12 dragbox-content"></div><div class="col-xs-12 dragbox-footer"></div></div></div>',$(document.body).append(this.boxHTML),this.boxElement=$("#"+this.boxId)),this.boxClass=$(this.boxElement).attr("class"),this.width=this._width,this.height=this._height,this.overflow="hidden",$(document.body).keydown(function(t){o.keyfunction(t)}),$(document.body).keyup(function(t){o.keyfunction(t)}),$(this.boxElement).click(function(t){$(".dragbox").css("zIndex",10),$(o.boxElement).css("zIndex",100)}),$(this.boxElement).find(".dragbox-title").mousedown(function(t){o.startDrag(t)}),$(this.boxElement).find(".dragbox-title").mouseup(function(t){o.stopDrag(t)}),$(document).click(function(t){o.stopDrag(t)}),this.queryString=this.getQueryString()}return _createClass(t,[{key:"destroy",value:function(){var t=this;$(this.boxElement).animate({opacity:0},25,function(){$(t.boxElement).remove()})}},{key:"updateSize",value:function(){$(this.boxElement).width(this.width),$(this.boxElement).height(this.height);var t=this.height-$(this.boxElement).find(".dragbox-title").height()-$(this.boxElement).find(".dragbox-footer").height()-7,e=this;$(this.boxElement).animate({height:e.height,width:e.width},25,function(){}),$(this.boxElement).find(".dragbox-container").animate({height:e.height},25,function(){}),$(this.boxElement).find(".dragbox-content").animate({height:t},25,function(){})}},{key:"startDrag",value:function(t){if(t.preventDefault(),"true"==this.beingDragged)return void(this.beingDragged=!1);if(this.draggable){var e={x:t.clientX-$(this.boxElement).offset().left,y:t.clientY-$(this.boxElement).offset().top};return this.beingDragged=!0,this.loopDrag(e),!1}}},{key:"stopDrag",value:function(){this.beingDragged=!1}},{key:"loopDrag",value:function(t){if(this.beingDragged===!0){var e=this.currentMousePos.x-t.x,n=this.currentMousePos.y-t.y,i={offsetLeft:e,offsetTop:n,offsetWidth:$(this.boxElement).width(),offsetHeigth:$(this.boxElement).height()},o=ParamBox.stayInWindow(i),r=o.x,s=o.y;this.shouldStick&&(o.stickyX!=-2&&2!=o.stickyX||(this.isStickingX=!0),this.isStickingX&&0!==o.stickyX&&(r=o.leftSticky),0===o.stickyX&&(this.isStickingX=!1),o.stickyY!=-2&&2!=o.stickyY||(this.isStickingY=!0),this.isStickingY&&0!==o.stickyY&&(s=o.topSticky),0===o.stickyY&&(this.isStickingY=!1)),this.shouldMagnetize&&(r=o.leftSticky,s=o.topSticky);var a=this;return $(this.boxElement).animate({left:r,top:s},25,function(){a.loopDrag(t)}),!1}}},{key:"keyfunction",value:function(t){console.log("keyEvent dragbox method")}},{key:"toggle",value:function(){"hidden"==this.visibility?this.visibility="visible":this.visibility="hidden"}},{key:"show",value:function(){this.visibility="visible"}},{key:"hide",value:function(){this.visibility="hidden"}},{key:"append",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?".dragbox-content":arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.boxElement&&(null!==n&&(t='<div class="'+n+'" >'+t+"</div>"),"container"!=e?this.boxElement.find(e).append(t):this.boxElement.append(t))}},{key:"html",value:function(){var t=arguments.length<=0||void 0===arguments[0]?".dragbox-content":arguments[0],e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(this.boxElement){var n="container"!=t?this.boxElement.find(t):this.boxElement;if(null===e)return n.html();n.html(e)}}},{key:"getQueryString",value:function(){for(var t={},e=window.location.search.substring(1),n=e.split("&"),i=0;i<n.length;i++){var o=n[i].split("=");if("undefined"==typeof t[o[0]])t[o[0]]=decodeURIComponent(o[1]);else if("string"==typeof t[o[0]]){var r=[t[o[0]],decodeURIComponent(o[1])];t[o[0]]=r}else t[o[0]].push(decodeURIComponent(o[1]))}return t}},{key:"width",set:function(t){this._width=t,this.updateSize()},get:function(){return this._width}},{key:"height",set:function(t){this._height=t,this.updateSize()},get:function(){return this._height}},{key:"beingDragged",set:function(t){this._beingDragged=t,$(this.boxElement).attr("beingDragged",t)},get:function(){return this._beingDragged}},{key:"boxClass",set:function(t){if(this.boxElement){if("string"!=typeof t)throw new Error("newClass must be a string");var e=t.indexOf(" ");e!=-1&&(t=t.substr(0,e)),this.boxElement.removeClass(this.boxClass).addClass(t),this._boxClass=t}},get:function(){if(this.boxElement)return this._boxClass}},{key:"visibility",set:function(t){this._visibility=t,"visible"==t?$(this.boxElement).animate({opacity:1},150):$(this.boxElement).animate({opacity:0},150)},get:function(){return this._visibility}},{key:"overflow",set:function(t){this._overflow=t,$(this.boxElement).find(".dragbox-content").css("overflow-y",t)},get:function(){return this._overflow}},{key:"stickiness",get:function(){return this._stickiness},set:function(t){switch(t){case"none":this.shouldMagnetize=!1,this.shouldStick=!1,console.log("Parambox: stickiness set to none");break;case"glue":this.shouldStick=!0,this.shouldMagnetize=!1,console.log("stickiness set to glue");break;case"magnetized":this.shouldStick=!1,this.shouldMagnetize=!0,console.log("stickiness set to magnetized");break;default:throw new Error("this sticky type does not exist. Types are : none, glue, or magnetized.")}this._stickiness=t}},{key:"title",get:function(){this.boxElement&&$(this.boxElement).find(".dragbox-title").html()},set:function(t){this.boxElement&&($(this.boxElement).find(".dragbox-title").html(t),this.updateSize())}},{key:"content",set:function(t){this.boxElement&&(this.contentDiv.html(t),this.updateSize())},get:function(){if(this.boxElement)return this.contentDiv.html()}},{key:"contentDiv",get:function(){if(this.boxElement)return $(this.boxElement).find(".dragbox-content")}}],[{key:"stayInWindow",value:function(t){if("undefined"==typeof t)throw new Error("element is undefined");var e=.15,n=t.offsetLeft,i=t.offsetLeft+t.offsetWidth,o=t.offsetTop,r=t.offsetTop+t.offsetHeigth,s=window.innerWidth-t.offsetWidth,a=window.innerHeight-t.offsetHeigth;return{x:n<0?0:i>window.innerWidth?s:n,y:o<0?0:r>window.innerHeight?a:o,stickyX:n<=0?-2:n<=e*t.offsetWidth?-1:i>=window.innerWidth?2:i>=window.innerWidth-e*t.offsetWidth?1:0,stickyY:o<=0?-2:o<=e*t.offsetHeigth?-1:r>=window.innerHeight?2:r>=window.innerHeight-e*t.offsetHeigth?1:0,leftSticky:n<=0?0:n<=e*t.offsetWidth?0:i>=window.innerWidth?window.innerWidth-t.offsetWidth:i>=window.innerWidth-e*t.offsetWidth?window.innerWidth-t.offsetWidth:n,topSticky:o<=0?0:o<=e*t.offsetHeigth?0:r>=window.innerHeight?window.innerHeight-t.offsetHeigth:r>=window.innerHeight-e*t.offsetHeigth?window.innerHeight-t.offsetHeigth:o}}},{key:"getCoordinateInWindow",value:function(t){var e=t.offsetLeft,n=t.offsetLeft+t.offsetWidth,i=t.offsetTop,o=t.offsetTop+t.offsetHeigth,r=window.innerWidth-t.offsetWidth,s=window.innerHeight-t.offsetHeigth;return{left:e,right:n,top:i,bottom:o,maxLeft:r,maxTop:s}}},{key:"stickiness",get:function(){}},{key:"title",get:function(){}}]),t}(),SmartModal=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?"across":arguments[0],n=arguments.length<=1||void 0===arguments[1]?null:arguments[1],i=arguments.length<=2||void 0===arguments[2]?"closebutton":arguments[2],o=arguments.length<=3||void 0===arguments[3]?null:arguments[3];_classCallCheck(this,e);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,o));if(r.DEFAULT_BUTTON_ROW_HTML='<div class="col-xs-12 dragbox-row smartmodal-buttonrow"></div>',r.DEFAULT_BUTTON_HTML={closebutton:'<button type="button" class="btn btn-secondary dragbox-button smartmodal-closebutton">Close</button>',nextbutton:'<button type="button" class="btn btn-secondary dragbox-button smartmodal-nextbutton">Next</button>',blankbutton:'<button type="button" class="btn btn-secondary dragbox-button smartmodal-blankbutton"></button>',sendbutton:'<button type="button" class="btn btn-secondary dragbox-button smartmodal-sendbutton">Send</button>'},r.DEFAULT_FORMAT_TYPES={centralSmall:[.2,.4,.3],centralLarge:[.2,.7,.6],across:[.3,1,.4],overlay:[.1,.8,.8]},r.callback=n,r.draggable=!1,r.formatType=t,r.buttonRowHtml=r.DEFAULT_BUTTON_ROW_HTML,!(i in r.DEFAULT_BUTTON_HTML))throw new Error("buttonType invalid");r.buttonType=i,r.rows=[],r.title="<center><h5>Smart Modal</h5></center>",r.append(r.buttonRowHtml,".dragbox-footer"),r.append(r.DEFAULT_BUTTON_HTML[r.buttonType],".smartmodal-buttonrow"),r.button=$(r.boxElement).find(".smartmodal-"+r.buttonType),r.callAfterConstructor();var s=r;return $(window).resize(function(){s.updatePosition()}),$(r.button).click(function(){s.callThenDestroy()}),r}return _inherits(e,t),_createClass(e,[{key:"callAfterConstructor",value:function(){this.updatePosition(),this.updateSize(),this.show()}},{key:"callThenDestroy",value:function(){this.callback&&this.callback(),this.destroy()}},{key:"updatePosition",value:function(){var t=window.innerHeight,e=window.innerWidth,n=this.DEFAULT_FORMAT_TYPES[this.formatType],i=n[0]*t,o=e*(1-n[1])/2,r=e*n[1],s=t*n[2];return this.width=r,this.height=s,$(this.boxElement).animate({left:o,top:i},25,function(){}),!1}}]),e}(DragBox),ParamBox=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0];_classCallCheck(this,e);var n=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,t));n.DEFAULT_ROW_HTML='<div class="col-md-12 dragbox-row paramboxtmprow"></div>',n.PARAMBOX_EMPTY_ROW_HTML='<div class="col-md-12 dragbox-row parambox-empty"><center>No parameters binded.</center></div>',n.DEFAULT_BUTTON_ROW_HTML='<div class="col-xs-12 dragbox-row parambox-buttonrow"></div>',n.DEFAULT_BUTTON_HTML={savebutton:'<button type="button" class="btn btn-secondary btn-block dragbox-button parambox-savebutton">Save</button>',importbutton:'<button type="button" class="btn btn-secondary btn-block dragbox-button parambox-importbutton">Import</button>',reloadbutton:'<button type="button" class="btn btn-secondary btn-block dragbox-button parambox-reloadbutton">Reload</button>'},n.append(n.DEFAULT_BUTTON_ROW_HTML,".dragbox-footer"),n.append(n.DEFAULT_BUTTON_HTML.savebutton,".parambox-buttonrow","col-xs-4"),n.append(n.DEFAULT_BUTTON_HTML.importbutton,".parambox-buttonrow","col-xs-4"),n.append(n.DEFAULT_BUTTON_HTML.reloadbutton,".parambox-buttonrow","col-xs-4");var i=n;return n.boxElement[0].getElementsByClassName("parambox-savebutton")[0].addEventListener("click",function(t){i.save(t)}),n.boxElement[0].getElementsByClassName("parambox-importbutton")[0].addEventListener("click",function(t){i.import(t)}),n.boxElement[0].getElementsByClassName("parambox-reloadbutton")[0].addEventListener("click",function(t){i.reloadAndImport(t)}),n.rowHtml=n.DEFAULT_ROW_HTML,n.rows=[],n.title='<h5><i class="fa fa-cog fa-1x"></i> Parameter Box</h5>',n.overflow="scroll","undefined"==typeof window.paramPrefixIncrement?window.paramPrefixIncrement=0:window.paramPrefixIncrement+=1,n.prefix="paramBox"+window.paramPrefixIncrement,n.updateSize(),n.refreshView(),n}return _inherits(e,t),_createClass(e,[{key:"bind",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];if("undefined"==typeof t)throw new Error("object is undefined");var i=null;e.constructor!==Array&&(e=[e]);for(var o=0;o<e.length;o++){i=this.getDescendantProp(t,e[o]);var r=i[0],s=i[1],a=e[o].replace(".","_"),l=this.newRowInDom(),h=null,d=null;if("undefined"!=typeof this.queryString[a]&&(d=this.queryString[a]),null!==n&&"undefined"!=typeof n[e[o]]){var u=n[e[o]];if(null!==d){if(u.indexOf(d)===-1)throw new Error("ParamBox.bind: cannot set initial value to query string value of "+d+" because it is not in the constraints array.");r[s]=r[s].constructor(d)}var h=new BindedField(r,s,l,"selector",u,e[o])}if(!h)if(null!==d&&(r[s]=r[s].constructor(d)),r[s].constructor===Boolean)var h=new BindedField(r,s,l,"selector",["TRUE","FALSE"],e[o]);else var h=new BindedField(r,s,l,"input",null,e[o]);this.rows.push(this.getBindedRow(l,h))}this.refreshView()}},{key:"unbind",value:function(t,e){for(var n=0;n<this.rows.length;n++){var i=this.rows[n].bindedField;i.object===t&&i.property==e&&(this.rows.splice(n,1),i.delete())}this.refreshView()}},{key:"newRowInDom",value:function(){var t=null;return $(this.boxElement).find(".dragbox-content").append(this.rowHtml),t=this.boxElement.find(".paramboxtmprow"),$(t).removeClass("paramboxtmprow"),t}},{key:"getBindedRow",value:function(t,e){return{rowDom:t,bindedField:e}}},{key:"refreshView",value:function(){this.rows.length?this.boxElement[0].getElementsByClassName("parambox-buttonrow")[0].style.visibility="visible":this.boxElement[0].getElementsByClassName("parambox-buttonrow")[0].style.visibility="hidden";var t=80+75*this.rows.length;t>600&&(t=600),this.height=t}},{key:"keyfunction",value:function(t){this.map[t.keyCode]="keydown"==t.type,this.map[16]&&this.map[80]&&(this.map[80]=!1,this.toggle(),t.preventDefault())}},{key:"getSummaryArray",value:function(){for(var t=[],e=0;e<this.rows.length;e++){var n=this.rows[e].bindedField;t.push({property:n.property,value:n.value,hierarchy:n.hierarchy,exportName:n.exportName})}return t}},{key:"import",value:function(t){var e=prompt("Enter a JSON string:"),n=null;try{n=JSON.parse(e)}catch(t){console.error("ParamBox.import: Invalid JSON string - Parsing error:",t)}if(null!==n){n.constructor!==Array&&console.error("ParamBox.import: Invalid JSON string - the parent object needs to be of the same structure as the summaryArray");for(var i=0;i<n.length;i++)"undefined"==typeof n[i].property&&console.error("ParamBox.import: importedJSON["+i+"].property is undefined. Invalid JSON string - the parent object needs to be of the same structure as the summaryArray."),"undefined"==typeof n[i].value&&console.error("ParamBox.import: importedJSON["+i+"].value is undefined. Invalid JSON string - the parent object needs to be of the same structure as the summaryArray."),this.setProperty(n[i].property,n[i].value)}}},{key:"save",value:function(t){var e=this.getSummaryArray(),n=JSON.stringify(e,null,2),i=30+70*e.length;i>500&&(i=500),window.open("data:application/json;"+(window.btoa?"base64,"+btoa(n):n),"ParamBox.save","width=400,height="+i)}},{key:"reloadAndImport",value:function(t){for(var e=this.getSummaryArray(),n="",i=0;i<e.length;i++)""!==n&&(n+="&"),n+=e[i].exportName+"="+encodeURIComponent(e[i].value);var o=window.location.href,r=o.indexOf("?");r!==-1&&(o=o.substring(0,r)),o+="?"+n,window.location.href=o}},{key:"getDescendantProp",value:function(t,e){for(var n=e.split("."),i=null,o=null;n.length;){if(i=t,o=n.shift(),"undefined"==typeof t[o])throw new Error("object property "+o+" is undefined");t=t[o]}var r=t;return[i,o,r]}},{key:"setProperty",value:function(t,e){if(t.constructor!==String)throw new Error("ParamBox.setProperty: property needs to be a string.");for(var n=!1,i=0;i<this.rows.length;i++)this.rows[i].bindedField.property===t&&(this.rows[i].bindedField.value=e,n=!0);n===!1&&console.warn("ParamBox.setProperty: did not find property "+t)}}]),e}(DragBox),SmartChart=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?mandatory():arguments[0],n=arguments.length<=1||void 0===arguments[1]?null:arguments[1],i=arguments.length<=2||void 0===arguments[2]?null:arguments[2];if(_classCallCheck(this,e),"undefined"==typeof Chart)throw new Error("SmartChart.constructor: Chart.js is not loaded.");if(t.constructor!==Object)throw new Error("SmartChart.constructor: options needs to be an object (chart.js chart options)");var o=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,"overlay",n,"closebutton",i));o.chartOptions=$.extend(!0,{},t),o.title="<center><h5>Smart Chart</h5></center>";var r="chart-canvas"+($("canvas").length+1);o.content='<canvas id="'+r+'" class="chart-canvas"></canvas>',o.canvas=document.getElementById(r),"undefined"!=typeof t.options.title.text&&(t.options.title.display=!1,o.title="<center><h5>"+t.options.title.text+"</h5></center>");try{Chart.defaults.global.responsive=!0,Chart.defaults.global.maintainAspectRatio=!1,o.chart=new Chart(o.canvas,t)}catch(t){throw new Error("SmartChart.constructor: could not build the chart. Error: "+t)}o.canvas.style.background="white",o.boxClass="dragbox-white-boxshadow",o.DEFAULT_BUTTON_ROW_HTML='<div class="col-xs-12 dragbox-row smartchart-buttonrow"><div class="col-xs-10"></div></div>',o.DEFAULT_BUTTON_HTML={closebutton:'<button type="button" class="btn btn-secondary dragbox-button smartchart-closebutton">Close</button>',savebutton:'<button type="button" class="btn btn-secondary dragbox-button smartchart-savebutton">Save</button>'},o.html(".dragbox-footer",o.DEFAULT_BUTTON_ROW_HTML),o.append(o.DEFAULT_BUTTON_HTML.savebutton,".smartchart-buttonrow","col-xs-1 centered"),o.append(o.DEFAULT_BUTTON_HTML.closebutton,".smartchart-buttonrow","col-xs-1 centered"),o.closeButton=o.button=$(o.boxElement).find(".smartchart-closebutton"),o.saveButton=$(o.boxElement).find(".smartchart-savebutton"),s=o,$(o.closeButton).click(function(t){s.callThenDestroy()}),$(o.saveButton).click(function(t){s.save(t)}),o.updatePosition(),o.updateSize();var s=o;return setTimeout(function(){s.chart.resize(),s.show()},250),o}return _inherits(e,t),_createClass(e,[{key:"callAfterConstructor",value:function(){}},{key:"callThenDestroy",value:function(){this.callback&&this.callback(),"undefined"!=typeof this.chart&&"undefined"!=typeof Chart&&this.chart.constructor===Chart&&this.chart.destroy(),this.destroy()}},{key:"save",value:function(t){var e=JSON.stringify(this.chartOptions,null,2),n=150+150*this.chartOptions.data.datasets.length;n>500&&(n=500),window.open("data:application/json;"+(window.btoa?"base64,"+btoa(e):e),"SmartChart.save","width=400,height="+n)}}]),e}(SmartModal),BindedProperty=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?null:arguments[0],n=arguments.length<=1||void 0===arguments[1]?null:arguments[1],i=arguments.length<=2||void 0===arguments[2]?null:arguments[2];_classCallCheck(this,t),this.HANDLED_VARIABLE_TYPES=["number","string","boolean"],this.property=n,this.object=e,this.propagate=!1,this.type=null,this.hierarchy=null!==i?i.replace(".","_"):n,this.exportName=this.hierarchy.replace(".","_"),this.object||(this.object=window),null!==n&&this.bind(e,n)}return _createClass(t,[{key:"bind",value:function(t,e){var n=_typeof(this.object[this.property]);if("undefined"===n)throw new Error("Parambox: The variable '"+e+"' you are trying to bind is undefined - either this object or the property is not defined");if(this.HANDLED_VARIABLE_TYPES.indexOf(n)==-1)throw new Error("The variable you are trying to bind is of a non-handled type (string, number or boolean");this.property=e,this.object=t,this.type=this.object[this.property].constructor}},{key:"convertToType",value:function(t){if(this.type){if(this.type===Boolean)switch(String(t).toUpperCase()){case"0":return!1;case"1":return!0;case"FALSE":return!1;case"TRUE":return!0}return this.type(t)}throw new Error("You are trying to convert a value to a the type of the binded property but the object has no property binded to it (or no type)")}},{key:"value",set:function(t){if("undefined"==typeof this.object[this.property])throw new Error("The variable you are trying to bind is undefined - either this object or the property is incorrect");this.object[this.property]=this.convertToType(t)},get:function(){if("undefined"==typeof this.object[this.property])throw new Error("The variable you are trying to bind is undefined - either this object or the property is incorrect");return this.object[this.property]}}]),t}(),BindedField=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?mandatory("object"):arguments[0],n=arguments.length<=1||void 0===arguments[1]?mandatory("property"):arguments[1],i=arguments.length<=2||void 0===arguments[2]?null:arguments[2],o=arguments.length<=3||void 0===arguments[3]?"input":arguments[3],r=arguments.length<=4||void 0===arguments[4]?null:arguments[4],s=arguments.length<=5||void 0===arguments[5]?null:arguments[5];_classCallCheck(this,e);var a=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,t,n,s));switch(a.VALID_FIELD_TYPE=["input","selector","slider"],a.field=null,a.fieldType=o,a.fieldHTML=null,a.allowedValues=r,a.tempClass="binded-"+("undefined"==typeof t?"undefined":_typeof(t))+n,a.parent=i,a.fieldType){case"input":a.fieldHTML='<fieldset class="form-group"><label>'+n+'</label><input type="text" class="form-control '+a.tempClass+'" data-binded="'+n+'"></fieldset>';break;case"selector":if(!r)throw new Error("fieldType selector needs at least one allowedValues");a.fieldHTML='<fieldset class="form-group"><label>'+n+'</label><select class="form-control '+a.tempClass+'" data-binded="'+n+'">';for(var l=0;l<a.allowedValues.length;l++)a.fieldHTML=a.fieldHTML+'<option value="'+a.allowedValues[l]+'">'+a.allowedValues[l]+"</option>";a.fieldHTML=a.fieldHTML+"</select></fieldset>";break;case"slider":break;default:throw new Error("fieldType is invalid : input, selector and slider are the only valid type for now")}return i&&a.placeInParent(),a}return _inherits(e,t),_createClass(e,[{key:"placeInParent",value:function(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0];t&&(this.parent=t),$(this.parent).append(this.fieldHTML),this.field=$("."+this.tempClass),this.field.removeClass(this.tempClass),this.allowedValues&&this.allowedValues.constructor===Array?this.allowedValues.indexOf(this.value)!==-1?this.field.val(this.value):this.field.val(this.allowedValues[0]):this.field.val(this.value);var e=this;this.field.change(function(t){e.update("field")}),this.field.keydown(function(t){switch(t.keyCode){case 13:e.update("field")}})}},{key:"delete",value:function(){this.field.parent().remove(),this.property=null,this.object=null}},{key:"update",value:function(){var t=arguments.length<=0||void 0===arguments[0]?"field":arguments[0];"field"==t?(this.value=$(this.field).val(),$(this.field).get(0).blur()):$(this.field).val().toUpperCase()!=String(this.value).toUpperCase()&&$(this.field).val(this.value)}},{key:"value",set:function(t){if("undefined"==typeof this.object[this.property])throw new Error("The variable you are trying to bind is undefined - either this object or the property is incorrect");this.object[this.property]=this.convertToType(t),this.update("setter")},get:function(){if("undefined"==typeof this.object[this.property])throw new Error("The variable you are trying to bind is undefined - either this object or the property is incorrect");return this.object[this.property]}}]),e}(BindedProperty); | ||
"use strict";function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function mandatory(){var t=arguments.length<=0||void 0===arguments[0]?"":arguments[0];throw new Error("Missing parameter "+t)}function findAllIndices(){for(var t=arguments.length<=0||void 0===arguments[0]?mandatory():arguments[0],e=arguments.length<=1||void 0===arguments[1]?mandatory():arguments[1],n=[],i=0;i<e.length;i++)e.substr(i,t.length)===t&&n.push(i);return n.length?n:-1}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},_createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),scripts=document.getElementsByTagName("script"),paramBoxFullpath=scripts[scripts.length-1].src,delimiterIndices=findAllIndices("/",paramBoxFullpath);paramBoxFullpath=paramBoxFullpath.substr(0,delimiterIndices[delimiterIndices.length-2]),document.addEventListener("DOMContentLoaded",function(t){var e=document.getElementsByTagName("head")[0],n=document.createElement("link");n.rel="stylesheet",n.type="text/css",n.href=paramBoxFullpath+"/dist/paramBox.css",e.appendChild(n)});var DragBox=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?null:arguments[0],n=arguments.length<=1||void 0===arguments[1]?null:arguments[1],i=arguments.length<=2||void 0===arguments[2]?null:arguments[2];_classCallCheck(this,t),this.MAX_BINDED_PROPERTIES=15,this.INIT_WIDTH=n?n:400,this.INIT_HEIGHT=i?i:300,this.DEFAULT_BOX_THEME="dragbox-gray",this.DEFAULT_DRAGGABLE=!0,this.DEFAULT_STICKINESS_TYPE="magnetized",this.boxId=null,this.boxElement=e,this.draggable=this.DEFAULT_DRAGGABLE,this.boxHTML=null,this.shouldStick=null,this.shouldMagnetize=null,this.isStickingX=null,this.isStickingY=null,this.stickiness=this.DEFAULT_STICKINESS_TYPE,this._beingDragged=!1,this._visibility="hidden",this._overflow="hidden",this._boxClass=this.DEFAULT_BOX_THEME,this._width=this.INIT_WIDTH,this._height=this.INIT_HEIGHT,this.map=[],this.currentMousePos={x:-1,y:-1};var o=this;$(document).mousemove(function(t){o.currentMousePos.x=t.pageX,o.currentMousePos.y=t.pageY}),this.boxElement?this.boxId=$(this.boxElement).attr("id"):(this.boxId="dragbox"+($('div[id*="dragbox"]').length+1),this.boxHTML='<div id="'+this.boxId+'" class="dragbox '+this._boxClass+'" style="opacity:0.0;" draggable="false"><div class="col-xs-12 dragbox-container"><div class="col-xs-12 dragbox-title"><center><h3>Dragbox</h3></center></div><div class="col-xs-12 dragbox-content"></div><div class="col-xs-12 dragbox-footer"></div></div></div>',$(document.body).append(this.boxHTML),this.boxElement=$("#"+this.boxId)),this.boxClass=$(this.boxElement).attr("class"),this.width=this._width,this.height=this._height,this.overflow="hidden",$(document.body).keydown(function(t){o.keyfunction(t)}),$(document.body).keyup(function(t){o.keyfunction(t)}),$(this.boxElement).click(function(t){$(".dragbox").css("zIndex",10),$(o.boxElement).css("zIndex",100)}),$(this.boxElement).find(".dragbox-title").mousedown(function(t){o.startDrag(t)}),$(this.boxElement).find(".dragbox-title").mouseup(function(t){o.stopDrag(t)}),$(document).click(function(t){o.stopDrag(t)}),this.queryString=this.getQueryString()}return _createClass(t,[{key:"destroy",value:function(){var t=this;$(this.boxElement).animate({opacity:0},25,function(){$(t.boxElement).remove()})}},{key:"updateSize",value:function(){$(this.boxElement).width(this.width),$(this.boxElement).height(this.height);var t=this.height-$(this.boxElement).find(".dragbox-title").height()-$(this.boxElement).find(".dragbox-footer").height()-7,e=this;$(this.boxElement).animate({height:e.height,width:e.width},25,function(){}),$(this.boxElement).find(".dragbox-container").animate({height:e.height},25,function(){}),$(this.boxElement).find(".dragbox-content").animate({height:t},25,function(){})}},{key:"startDrag",value:function(t){if(t.preventDefault(),"true"==this.beingDragged)return void(this.beingDragged=!1);if(this.draggable){var e={x:t.clientX-$(this.boxElement).offset().left,y:t.clientY-$(this.boxElement).offset().top};return this.beingDragged=!0,this.loopDrag(e),!1}}},{key:"stopDrag",value:function(){this.beingDragged=!1}},{key:"loopDrag",value:function(t){if(this.beingDragged===!0){var e=this.currentMousePos.x-t.x,n=this.currentMousePos.y-t.y,i={offsetLeft:e,offsetTop:n,offsetWidth:$(this.boxElement).width(),offsetHeigth:$(this.boxElement).height()},o=ParamBox.stayInWindow(i),r=o.x,s=o.y;this.shouldStick&&(o.stickyX!=-2&&2!=o.stickyX||(this.isStickingX=!0),this.isStickingX&&0!==o.stickyX&&(r=o.leftSticky),0===o.stickyX&&(this.isStickingX=!1),o.stickyY!=-2&&2!=o.stickyY||(this.isStickingY=!0),this.isStickingY&&0!==o.stickyY&&(s=o.topSticky),0===o.stickyY&&(this.isStickingY=!1)),this.shouldMagnetize&&(r=o.leftSticky,s=o.topSticky);var a=this;return $(this.boxElement).animate({left:r,top:s},25,function(){a.loopDrag(t)}),!1}}},{key:"keyfunction",value:function(t){console.log("keyEvent dragbox method")}},{key:"toggle",value:function(){"hidden"==this.visibility?this.visibility="visible":this.visibility="hidden"}},{key:"show",value:function(){this.visibility="visible"}},{key:"hide",value:function(){this.visibility="hidden"}},{key:"append",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?".dragbox-content":arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.boxElement&&(null!==n&&(t='<div class="'+n+'" >'+t+"</div>"),"container"!=e?this.boxElement.find(e).append(t):this.boxElement.append(t))}},{key:"html",value:function(){var t=arguments.length<=0||void 0===arguments[0]?".dragbox-content":arguments[0],e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(this.boxElement){var n="container"!=t?this.boxElement.find(t):this.boxElement;if(null===e)return n.html();n.html(e)}}},{key:"getQueryString",value:function(){for(var t={},e=window.location.search.substring(1),n=e.split("&"),i=0;i<n.length;i++){var o=n[i].split("=");if("undefined"==typeof t[o[0]])t[o[0]]=decodeURIComponent(o[1]);else if("string"==typeof t[o[0]]){var r=[t[o[0]],decodeURIComponent(o[1])];t[o[0]]=r}else t[o[0]].push(decodeURIComponent(o[1]))}return t}},{key:"width",set:function(t){this._width=t,this.updateSize()},get:function(){return this._width}},{key:"height",set:function(t){this._height=t,this.updateSize()},get:function(){return this._height}},{key:"beingDragged",set:function(t){this._beingDragged=t,$(this.boxElement).attr("beingDragged",t)},get:function(){return this._beingDragged}},{key:"boxClass",set:function(t){if(this.boxElement){if("string"!=typeof t)throw new Error("newClass must be a string");this.boxElement.removeClass(this.boxClass).addClass(t),this._boxClass=t}},get:function(){if(this.boxElement)return this._boxClass}},{key:"visibility",set:function(t){this._visibility=t,"visible"==t?$(this.boxElement).animate({opacity:1},150):$(this.boxElement).animate({opacity:0},150)},get:function(){return this._visibility}},{key:"overflow",set:function(t){this._overflow=t,$(this.boxElement).find(".dragbox-content").css("overflow-y",t)},get:function(){return this._overflow}},{key:"stickiness",get:function(){return this._stickiness},set:function(t){switch(t){case"none":this.shouldMagnetize=!1,this.shouldStick=!1,console.log("Parambox: stickiness set to none");break;case"glue":this.shouldStick=!0,this.shouldMagnetize=!1,console.log("stickiness set to glue");break;case"magnetized":this.shouldStick=!1,this.shouldMagnetize=!0,console.log("stickiness set to magnetized");break;default:throw new Error("this sticky type does not exist. Types are : none, glue, or magnetized.")}this._stickiness=t}},{key:"title",get:function(){this.boxElement&&$(this.boxElement).find(".dragbox-title").html()},set:function(t){this.boxElement&&($(this.boxElement).find(".dragbox-title").html(t),this.updateSize())}},{key:"content",set:function(t){this.boxElement&&(this.contentDiv.html(t),this.updateSize())},get:function(){if(this.boxElement)return this.contentDiv.html()}},{key:"contentDiv",get:function(){if(this.boxElement)return $(this.boxElement).find(".dragbox-content")}}],[{key:"stayInWindow",value:function(t){if("undefined"==typeof t)throw new Error("element is undefined");var e=.15,n=t.offsetLeft,i=t.offsetLeft+t.offsetWidth,o=t.offsetTop,r=t.offsetTop+t.offsetHeigth,s=window.innerWidth-t.offsetWidth,a=window.innerHeight-t.offsetHeigth;return{x:n<0?0:i>window.innerWidth?s:n,y:o<0?0:r>window.innerHeight?a:o,stickyX:n<=0?-2:n<=e*t.offsetWidth?-1:i>=window.innerWidth?2:i>=window.innerWidth-e*t.offsetWidth?1:0,stickyY:o<=0?-2:o<=e*t.offsetHeigth?-1:r>=window.innerHeight?2:r>=window.innerHeight-e*t.offsetHeigth?1:0,leftSticky:n<=0?0:n<=e*t.offsetWidth?0:i>=window.innerWidth?window.innerWidth-t.offsetWidth:i>=window.innerWidth-e*t.offsetWidth?window.innerWidth-t.offsetWidth:n,topSticky:o<=0?0:o<=e*t.offsetHeigth?0:r>=window.innerHeight?window.innerHeight-t.offsetHeigth:r>=window.innerHeight-e*t.offsetHeigth?window.innerHeight-t.offsetHeigth:o}}},{key:"getCoordinateInWindow",value:function(t){var e=t.offsetLeft,n=t.offsetLeft+t.offsetWidth,i=t.offsetTop,o=t.offsetTop+t.offsetHeigth,r=window.innerWidth-t.offsetWidth,s=window.innerHeight-t.offsetHeigth;return{left:e,right:n,top:i,bottom:o,maxLeft:r,maxTop:s}}},{key:"stickiness",get:function(){}},{key:"title",get:function(){}}]),t}(),SmartModal=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?"across":arguments[0],n=arguments.length<=1||void 0===arguments[1]?null:arguments[1],i=arguments.length<=2||void 0===arguments[2]?"closebutton":arguments[2],o=arguments.length<=3||void 0===arguments[3]?null:arguments[3];_classCallCheck(this,e);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,o));if(r.DEFAULT_BUTTON_ROW_HTML='<div class="col-xs-12 dragbox-row smartmodal-buttonrow"></div>',r.DEFAULT_BUTTON_HTML={closebutton:'<button type="button" class="btn btn-secondary dragbox-button smartmodal-closebutton">Close</button>',nextbutton:'<button type="button" class="btn btn-secondary dragbox-button smartmodal-nextbutton">Next</button>',blankbutton:'<button type="button" class="btn btn-secondary dragbox-button smartmodal-blankbutton"></button>',sendbutton:'<button type="button" class="btn btn-secondary dragbox-button smartmodal-sendbutton">Send</button>'},r.DEFAULT_FORMAT_TYPES={centralSmall:[.2,.4,.3],centralLarge:[.2,.7,.6],across:[.3,1,.4],overlay:[.1,.8,.8]},r.callback=n,r.draggable=!1,r.formatType=t,r.buttonRowHtml=r.DEFAULT_BUTTON_ROW_HTML,!(i in r.DEFAULT_BUTTON_HTML))throw new Error("buttonType invalid");r.buttonType=i,r.rows=[],r.title="<center><h5>Smart Modal</h5></center>",r.append(r.buttonRowHtml,".dragbox-footer"),r.append(r.DEFAULT_BUTTON_HTML[r.buttonType],".smartmodal-buttonrow"),r.button=$(r.boxElement).find(".smartmodal-"+r.buttonType),r.callAfterConstructor();var s=r;return $(window).resize(function(){s.updatePosition()}),$(r.button).click(function(){s.callThenDestroy()}),r}return _inherits(e,t),_createClass(e,[{key:"callAfterConstructor",value:function(){this.updatePosition(),this.updateSize(),this.show()}},{key:"callThenDestroy",value:function(){this.callback&&this.callback(),this.destroy()}},{key:"updatePosition",value:function(){var t=window.innerHeight,e=window.innerWidth,n=this.DEFAULT_FORMAT_TYPES[this.formatType],i=n[0]*t,o=e*(1-n[1])/2,r=e*n[1],s=t*n[2];return this.width=r,this.height=s,$(this.boxElement).animate({left:o,top:i},25,function(){}),!1}}]),e}(DragBox),ParamBox=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0];_classCallCheck(this,e);var n=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,t));n.DEFAULT_ROW_HTML='<div class="col-md-12 dragbox-row paramboxtmprow"></div>',n.PARAMBOX_EMPTY_ROW_HTML='<div class="col-md-12 dragbox-row parambox-empty"><center>No parameters binded.</center></div>',n.DEFAULT_BUTTON_ROW_HTML='<div class="col-xs-12 dragbox-row parambox-buttonrow"></div>',n.DEFAULT_BUTTON_HTML={savebutton:'<button type="button" class="btn btn-secondary btn-block dragbox-button parambox-savebutton">Save</button>',importbutton:'<button type="button" class="btn btn-secondary btn-block dragbox-button parambox-importbutton">Import</button>',reloadbutton:'<button type="button" class="btn btn-secondary btn-block dragbox-button parambox-reloadbutton">Reload</button>'},n.append(n.DEFAULT_BUTTON_ROW_HTML,".dragbox-footer"),n.append(n.DEFAULT_BUTTON_HTML.savebutton,".parambox-buttonrow","col-xs-4"),n.append(n.DEFAULT_BUTTON_HTML.importbutton,".parambox-buttonrow","col-xs-4"),n.append(n.DEFAULT_BUTTON_HTML.reloadbutton,".parambox-buttonrow","col-xs-4");var i=n;return n.boxElement[0].getElementsByClassName("parambox-savebutton")[0].addEventListener("click",function(t){i.save(t)}),n.boxElement[0].getElementsByClassName("parambox-importbutton")[0].addEventListener("click",function(t){i.import(t)}),n.boxElement[0].getElementsByClassName("parambox-reloadbutton")[0].addEventListener("click",function(t){i.reloadAndImport(t)}),n.rowHtml=n.DEFAULT_ROW_HTML,n.rows=[],n.title='<h5><i class="fa fa-cog fa-1x"></i> Parameter Box</h5>',n.overflow="scroll","undefined"==typeof window.paramPrefixIncrement?window.paramPrefixIncrement=0:window.paramPrefixIncrement+=1,n.prefix="paramBox"+window.paramPrefixIncrement,n.updateSize(),n.refreshView(),n}return _inherits(e,t),_createClass(e,[{key:"bind",value:function(t,e){var n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];if("undefined"==typeof t)throw new Error("object is undefined");var i=null;e.constructor!==Array&&(e=[e]);for(var o=0;o<e.length;o++){i=this.getDescendantProp(t,e[o]);var r=i[0],s=i[1],a=e[o].replace(".","_"),l=this.newRowInDom(),h=null,d=null;if("undefined"!=typeof this.queryString[a]&&(d=this.queryString[a]),null!==n&&"undefined"!=typeof n[e[o]]){var u=n[e[o]];if(null!==d){if(u.indexOf(d)===-1)throw new Error("ParamBox.bind: cannot set initial value to query string value of "+d+" because it is not in the constraints array.");r[s]=r[s].constructor(d)}var h=new BindedField(r,s,l,"selector",u,e[o])}if(!h)if(null!==d&&(r[s]=r[s].constructor(d)),r[s].constructor===Boolean)var h=new BindedField(r,s,l,"selector",["TRUE","FALSE"],e[o]);else var h=new BindedField(r,s,l,"input",null,e[o]);this.rows.push(this.getBindedRow(l,h))}this.refreshView()}},{key:"unbind",value:function(t,e){for(var n=0;n<this.rows.length;n++){var i=this.rows[n].bindedField;i.object===t&&i.property==e&&(this.rows.splice(n,1),i.delete())}this.refreshView()}},{key:"newRowInDom",value:function(){var t=null;return $(this.boxElement).find(".dragbox-content").append(this.rowHtml),t=this.boxElement.find(".paramboxtmprow"),$(t).removeClass("paramboxtmprow"),t}},{key:"getBindedRow",value:function(t,e){return{rowDom:t,bindedField:e}}},{key:"refreshView",value:function(){this.rows.length?this.boxElement[0].getElementsByClassName("parambox-buttonrow")[0].style.visibility="visible":this.boxElement[0].getElementsByClassName("parambox-buttonrow")[0].style.visibility="hidden";var t=80+75*this.rows.length;t>600&&(t=600),this.height=t}},{key:"keyfunction",value:function(t){this.map[t.keyCode]="keydown"==t.type,this.map[16]&&this.map[80]&&(this.map[80]=!1,this.toggle(),t.preventDefault())}},{key:"getSummaryArray",value:function(){for(var t=[],e=0;e<this.rows.length;e++){var n=this.rows[e].bindedField;t.push({property:n.property,value:n.value,hierarchy:n.hierarchy,exportName:n.exportName})}return t}},{key:"import",value:function(t){var e=prompt("Enter a JSON string:"),n=null;try{n=JSON.parse(e)}catch(t){console.error("ParamBox.import: Invalid JSON string - Parsing error:",t)}if(null!==n){n.constructor!==Array&&console.error("ParamBox.import: Invalid JSON string - the parent object needs to be of the same structure as the summaryArray");for(var i=0;i<n.length;i++)"undefined"==typeof n[i].property&&console.error("ParamBox.import: importedJSON["+i+"].property is undefined. Invalid JSON string - the parent object needs to be of the same structure as the summaryArray."),"undefined"==typeof n[i].value&&console.error("ParamBox.import: importedJSON["+i+"].value is undefined. Invalid JSON string - the parent object needs to be of the same structure as the summaryArray."),this.setProperty(n[i].property,n[i].value)}}},{key:"save",value:function(t){var e=this.getSummaryArray(),n=JSON.stringify(e,null,2),i=30+70*e.length;i>500&&(i=500),window.open("data:application/json;"+(window.btoa?"base64,"+btoa(n):n),"ParamBox.save","width=400,height="+i)}},{key:"reloadAndImport",value:function(t){for(var e=this.getSummaryArray(),n="",i=0;i<e.length;i++)""!==n&&(n+="&"),n+=e[i].exportName+"="+encodeURIComponent(e[i].value);var o=window.location.href,r=o.indexOf("?");r!==-1&&(o=o.substring(0,r)),o+="?"+n,window.location.href=o}},{key:"getDescendantProp",value:function(t,e){for(var n=e.split("."),i=null,o=null;n.length;){if(i=t,o=n.shift(),"undefined"==typeof t[o])throw new Error("object property "+o+" is undefined");t=t[o]}var r=t;return[i,o,r]}},{key:"setProperty",value:function(t,e){if(t.constructor!==String)throw new Error("ParamBox.setProperty: property needs to be a string.");for(var n=!1,i=0;i<this.rows.length;i++)this.rows[i].bindedField.property===t&&(this.rows[i].bindedField.value=e,n=!0);n===!1&&console.warn("ParamBox.setProperty: did not find property "+t)}}]),e}(DragBox),SmartChart=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?mandatory():arguments[0],n=arguments.length<=1||void 0===arguments[1]?null:arguments[1],i=arguments.length<=2||void 0===arguments[2]?null:arguments[2];if(_classCallCheck(this,e),"undefined"==typeof Chart)throw new Error("SmartChart.constructor: Chart.js is not loaded.");if(t.constructor!==Object)throw new Error("SmartChart.constructor: options needs to be an object (chart.js chart options)");var o=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,"overlay",n,"closebutton",i));o.chartOptions=$.extend(!0,{},t),o.title="<center><h5>Smart Chart</h5></center>";var r="chart-canvas"+($("canvas").length+1);o.content='<canvas id="'+r+'" class="chart-canvas"></canvas>',o.canvas=document.getElementById(r),"undefined"!=typeof t.options.title.text&&(t.options.title.display=!1,o.title="<center><h5>"+t.options.title.text+"</h5></center>");try{Chart.defaults.global.responsive=!0,Chart.defaults.global.maintainAspectRatio=!1,o.chart=new Chart(o.canvas,t)}catch(t){throw new Error("SmartChart.constructor: could not build the chart. Error: "+t)}o.canvas.style.background="white",o.boxClass="dragbox-white-boxshadow",o.DEFAULT_BUTTON_ROW_HTML='<div class="col-xs-12 dragbox-row smartchart-buttonrow"><div class="col-xs-10"></div></div>',o.DEFAULT_BUTTON_HTML={closebutton:'<button type="button" class="btn btn-secondary dragbox-button smartchart-closebutton">Close</button>',savebutton:'<button type="button" class="btn btn-secondary dragbox-button smartchart-savebutton">Save</button>'},o.html(".dragbox-footer",o.DEFAULT_BUTTON_ROW_HTML),o.append(o.DEFAULT_BUTTON_HTML.savebutton,".smartchart-buttonrow","col-xs-1 centered"),o.append(o.DEFAULT_BUTTON_HTML.closebutton,".smartchart-buttonrow","col-xs-1 centered"),o.closeButton=o.button=$(o.boxElement).find(".smartchart-closebutton"),o.saveButton=$(o.boxElement).find(".smartchart-savebutton"),s=o,$(o.closeButton).click(function(t){s.callThenDestroy()}),$(o.saveButton).click(function(t){s.save(t)}),o.updatePosition(),o.updateSize();var s=o;return setTimeout(function(){s.chart.resize(),s.show()},250),o}return _inherits(e,t),_createClass(e,[{key:"callAfterConstructor",value:function(){}},{key:"callThenDestroy",value:function(){this.callback&&this.callback(),"undefined"!=typeof this.chart&&"undefined"!=typeof Chart&&this.chart.constructor===Chart&&this.chart.destroy(),this.destroy()}},{key:"save",value:function(t){var e=JSON.stringify(this.chartOptions,null,2),n=150+150*this.chartOptions.data.datasets.length;n>500&&(n=500),window.open("data:application/json;"+(window.btoa?"base64,"+btoa(e):e),"SmartChart.save","width=400,height="+n)}}]),e}(SmartModal),BindedProperty=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?null:arguments[0],n=arguments.length<=1||void 0===arguments[1]?null:arguments[1],i=arguments.length<=2||void 0===arguments[2]?null:arguments[2];_classCallCheck(this,t),this.HANDLED_VARIABLE_TYPES=["number","string","boolean"],this.property=n,this.object=e,this.propagate=!1,this.type=null,this.hierarchy=null!==i?i.replace(".","_"):n,this.exportName=this.hierarchy.replace(".","_"),this.object||(this.object=window),null!==n&&this.bind(e,n)}return _createClass(t,[{key:"bind",value:function(t,e){var n=_typeof(this.object[this.property]);if("undefined"===n)throw new Error("Parambox: The variable '"+e+"' you are trying to bind is undefined - either this object or the property is not defined");if(this.HANDLED_VARIABLE_TYPES.indexOf(n)==-1)throw new Error("The variable you are trying to bind is of a non-handled type (string, number or boolean");this.property=e,this.object=t,this.type=this.object[this.property].constructor}},{key:"convertToType",value:function(t){if(this.type){if(this.type===Boolean)switch(String(t).toUpperCase()){case"0":return!1;case"1":return!0;case"FALSE":return!1;case"TRUE":return!0}return this.type(t)}throw new Error("You are trying to convert a value to a the type of the binded property but the object has no property binded to it (or no type)")}},{key:"value",set:function(t){if("undefined"==typeof this.object[this.property])throw new Error("The variable you are trying to bind is undefined - either this object or the property is incorrect");this.object[this.property]=this.convertToType(t)},get:function(){if("undefined"==typeof this.object[this.property])throw new Error("The variable you are trying to bind is undefined - either this object or the property is incorrect");return this.object[this.property]}}]),t}(),BindedField=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?mandatory("object"):arguments[0],n=arguments.length<=1||void 0===arguments[1]?mandatory("property"):arguments[1],i=arguments.length<=2||void 0===arguments[2]?null:arguments[2],o=arguments.length<=3||void 0===arguments[3]?"input":arguments[3],r=arguments.length<=4||void 0===arguments[4]?null:arguments[4],s=arguments.length<=5||void 0===arguments[5]?null:arguments[5];_classCallCheck(this,e);var a=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,t,n,s));switch(a.VALID_FIELD_TYPE=["input","selector","slider"],a.field=null,a.fieldType=o,a.fieldHTML=null,a.allowedValues=r,a.tempClass="binded-"+("undefined"==typeof t?"undefined":_typeof(t))+n,a.parent=i,a.fieldType){case"input":a.fieldHTML='<fieldset class="form-group"><label>'+n+'</label><input type="text" class="form-control '+a.tempClass+'" data-binded="'+n+'"></fieldset>';break;case"selector":if(!r)throw new Error("fieldType selector needs at least one allowedValues");a.fieldHTML='<fieldset class="form-group"><label>'+n+'</label><select class="form-control '+a.tempClass+'" data-binded="'+n+'">';for(var l=0;l<a.allowedValues.length;l++)a.fieldHTML=a.fieldHTML+'<option value="'+a.allowedValues[l]+'">'+a.allowedValues[l]+"</option>";a.fieldHTML=a.fieldHTML+"</select></fieldset>";break;case"slider":break;default:throw new Error("fieldType is invalid : input, selector and slider are the only valid type for now")}return i&&a.placeInParent(),a}return _inherits(e,t),_createClass(e,[{key:"placeInParent",value:function(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0];t&&(this.parent=t),$(this.parent).append(this.fieldHTML),this.field=$("."+this.tempClass),this.field.removeClass(this.tempClass),this.allowedValues&&this.allowedValues.constructor===Array?this.allowedValues.indexOf(this.value)!==-1?this.field.val(this.value):this.field.val(this.allowedValues[0]):this.field.val(this.value);var e=this;this.field.change(function(t){e.update("field")}),this.field.keydown(function(t){switch(t.keyCode){case 13:e.update("field")}})}},{key:"delete",value:function(){this.field.parent().remove(),this.property=null,this.object=null}},{key:"update",value:function(){var t=arguments.length<=0||void 0===arguments[0]?"field":arguments[0];"field"==t?(this.value=$(this.field).val(),$(this.field).get(0).blur()):$(this.field).val().toUpperCase()!=String(this.value).toUpperCase()&&$(this.field).val(this.value)}},{key:"value",set:function(t){if("undefined"==typeof this.object[this.property])throw new Error("The variable you are trying to bind is undefined - either this object or the property is incorrect");this.object[this.property]=this.convertToType(t),this.update("setter")},get:function(){if("undefined"==typeof this.object[this.property])throw new Error("The variable you are trying to bind is undefined - either this object or the property is incorrect");return this.object[this.property]}}]),e}(BindedProperty); |
{ | ||
"name": "parambox", | ||
"version": "1.2.14", | ||
"version": "1.2.15", | ||
"description": "Too much parameters to handle ? paramBox is a collection of smart plug and play tools to facilitate the design of javascript projects such as games and cognitive tasks. ParamBox is one of the helper class and allows to modify key variable on the fly without having to modify the code or reload the page.", | ||
@@ -5,0 +5,0 @@ "main": "lib/paramBox-transpiled-0.2.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1010506