(function($){$.widget("custom.lwss_4values",{options:{icon:"",cssColor:"",property:""},_create:function(){this.wrapper=this.element.addClass("lwss-4values-wrapper");this.inHouse=!1;this.shadow=$("<div>").addClass("lwss-4values-shadow").appendTo(this.wrapper);this.left=$("<div>").addClass("lwss-4values-left").appendTo(this.wrapper);this.right=$("<div>").addClass("lwss-4values-right").appendTo(this.wrapper);this.icon=$("<div>").addClass("lwss-4values-icon "+this.options.icon+" "+this.options.cssColor).appendTo(this.left);this.inputs=$("<div>").addClass("lwss-4values-inputs").appendTo(this.right);this.label=$("<div>").addClass("lwss-4values-label").html(this.options.property).appendTo(this.right);this.inputTable=[];for(var i=0;i<4;i++){var cssAttribute=this._getCssAttribute(i,this.options.property);var myInput=$("<input>").attr("type","text").addClass("lwss-4values-input lwss_value").data("order",i).data("css",cssAttribute).data("modified",!1).appendTo(this.inputs);this.inputTable.push(myInput)}
this._manageEvents()},_bind:function(fn,me){return function(){return fn.apply(me,arguments)}},_showShadow:function(){this.shadow.show()},_hideShadow:function(){this.shadow.hide()},_getCssAttribute:function(rank,property){var marpad=["top","right","bottom","left"];var rad=["top-left","top-right","bottom-right","bottom-left"];var prop=property.split("-");if(prop[1]=="radius"){return prop[0]+"-"+rad[rank]+"-"+prop[1]}else{return((prop[0]!="position")?prop[0]+"-":'')+marpad[rank]+((prop.length==2)?"-"+prop[1]:'')}},_getTheValue:function(sentValue,sens){if(sentValue==""){return""}
var text=sentValue.replace(/[0-9]/g,'');if(text=="auto"){return text}
var numeric=sentValue.replace(/\D/g,'');var validUnits=["em","rem","pt","mm","cm","%"];if(sens=="in"){return numeric+((validUnits.indexOf(text)!=-1)?text:'')}else{return numeric+((validUnits.indexOf(text)!=-1)?text:'px')}},_focusValue:function(event){var myInput=$(event.delegateTarget)
this.label.html(myInput.data("css"));myInput.val(this._getTheValue(myInput.val(),"in")).select()},_focusoutValue:function(event){var myInput=$(event.delegateTarget)
this.label.html(this.options.property);myInput.val(this._getTheValue(myInput.val(),"out")).trigger("change")},_changeValue:function(event){var myInput=$(event.delegateTarget)
var changedRank=myInput.data("order");var newValue=this._getTheValue(myInput.val(),"out");myInput.data("modified",(newValue!=''&&this.inHouse==!1)?!0:!1);myInput.val(newValue);if(newValue!=''&&this.inHouse==!1){this.inHouse=!0;for(var i=0;i<this.inputTable.length;i++){if(changedRank==0&&!this.inputTable[i].data("modified")){this.inputTable[i].val(newValue).trigger("change")}
if(changedRank==1&&!this.inputTable[i].data("modified")&&this.inputTable[i].data("order")==3){this.inputTable[i].val(newValue).trigger("change")}}
this.inHouse=!1}},_manageEvents:function(){var me=this;this.element.on('mouseenter',this._bind(this._showShadow,this));this.element.on('mouseleave',this._bind(this._hideShadow,this));this.element.on('focusin',function(){me.shadow.addClass("lwss-active")});this.element.on('focusout',function(){me.shadow.removeClass("lwss-active")});for(var i=0;i<this.inputTable.length;i++){this.inputTable[i].on('focus',this._bind(this._focusValue,this));this.inputTable[i].on('focusout',this._bind(this._focusoutValue,this));if(me.options.property!="position"){this.inputTable[i].on('change',this._bind(this._changeValue,this))}}}});$.widget("lws.lwss_select",{options:{icon:"",cssColor:"",property:"",values:[],},_create:function(){this.wrapper=this.element.addClass("lwss-select-wrapper");this.shadow=$("<div>").addClass("lwss-select-shadow").appendTo(this.wrapper);this.left=$("<div>").addClass("lwss-select-left").appendTo(this.wrapper);this.right=$("<div>").addClass("lwss-select-right").appendTo(this.wrapper);this.icon=$("<div>").addClass("lwss-select-icon "+this.options.icon+" "+this.options.cssColor).appendTo(this.left);this.input=$("<div>").addClass("lwss-select-input").appendTo(this.right);this.select=$("<select>").addClass("lwss-select-autocomplete lwss_value").data("css",this.options.property).appendTo(this.input);this.label=$("<div>").addClass("lwss-select-label").html(this.options.property).appendTo(this.right);var me=this;for(var i=0;i<this.options.values.length;i++){var myOption=$("<option>").val(this.options.values[i]).html(this.options.values[i]).appendTo(this.select)}
this.select.lws_autocomplete({"css":"lwss-select-autocomplete","cssColor":this.options.cssColor});this._manageEvents()},_bind:function(fn,me){return function(){return fn.apply(me,arguments)}},_showShadow:function(){this.shadow.show()},_hideShadow:function(){this.shadow.hide()},_manageEvents:function(){var me=this;this.element.on('mouseenter',this._bind(this._showShadow,this));this.element.on('mouseleave',this._bind(this._hideShadow,this));this.element.on('focusin',function(){me.shadow.addClass("lwss-active")});this.element.on('focusout',function(){me.shadow.removeClass("lwss-active")})}});$.widget("lws.lwss_size",{options:{icon:"",cssColor:"",property:""},_create:function(){this.wrapper=this.element.addClass("lwss-size-wrapper");this.shadow=$("<div>").addClass("lwss-size-shadow").appendTo(this.wrapper);this.left=$("<div>").addClass("lwss-size-left").appendTo(this.wrapper);this.right=$("<div>").addClass("lwss-size-right").appendTo(this.wrapper);this.icon=$("<div>").addClass("lwss-size-icon "+this.options.icon+" "+this.options.cssColor).appendTo(this.left);this.inputs=$("<div>").addClass("lwss-size-inputs").appendTo(this.right);this.label=$("<div>").addClass("lwss-size-label").html(this.options.property).appendTo(this.right);this.input=$("<input>").attr("type","text").addClass("lwss-size-input lwss_value").data("css",this.options.property).appendTo(this.inputs);this._manageEvents()},_bind:function(fn,me){return function(){return fn.apply(me,arguments)}},_showShadow:function(){this.shadow.show()},_hideShadow:function(){this.shadow.hide()},_getTheValue:function(sentValue,sens){if(sentValue.trim()==""){return""}
var text=sentValue.replace(/[0-9]/g,'');if(text=="auto"){return text}
var numeric=sentValue.replace(/\D/g,'');var validUnits=["em","rem","pt","mm","cm","%"];var vUnit=(validUnits.indexOf(text)!=-1)?text:'';if(sens=="in"){return numeric+((validUnits.indexOf(text)!=-1)?text:'')}else{return numeric+((validUnits.indexOf(text)!=-1)?text:'px')}},_focusValue:function(event){var myInput=$(event.delegateTarget)
myInput.val(this._getTheValue(myInput.val(),"in")).select()},_focusoutValue:function(event){var myInput=$(event.delegateTarget)
myInput.val(this._getTheValue(myInput.val(),"out")).trigger('change')},_manageEvents:function(){var me=this;this.element.on('mouseenter',this._bind(this._showShadow,this));this.element.on('mouseleave',this._bind(this._hideShadow,this));this.element.on('focusin',function(){me.shadow.addClass("lwss-active")});this.element.on('focusout',function(){me.shadow.removeClass("lwss-active")});this.input.on('focus',this._bind(this._focusValue,this));this.input.on('focusout',this._bind(this._focusoutValue,this))}});$.widget("lws.lwss_text_editor",{_create:function(){this.wrapper=this.element.addClass("lwss-content-wrapper");$("<div>",{'class':'lwss-content-expl ','html':'Enter the text you want, then click apply. html code allowed'}).appendTo(this.wrapper);this.input=$("<textarea>",{'class':'lwss-content-editor '}).appendTo(this.wrapper);this.applybtn=$("<div>",{'class':'lwss-content-apply ','html':'Apply'}).appendTo(this.wrapper);this._manageEvents()},_bind:function(fn,me){return function(){return fn.apply(me,arguments)}},setId:function(inputId){this.inputId=inputId;var stygen=this.element.closest('.lwss_editor');this.placeholderContainer=stygen.find("[data-id='"+this.inputId+"']");if(this.placeholderContainer.attr("placeholder")!=undefined){this.pholder=!0;this.content=this.placeholderContainer.attr("placeholder")}else{this.pholder=!1;this.contentContainer=this.placeholderContainer.find('.lwss_modify_content');this.content=this.contentContainer.html()}
this.outInput=stygen.find("input[name='"+this.inputId+"']");this.input.val(this.content)},_setValue:function(){var theValue=this.input.val();if(this.pholder){this.placeholderContainer.attr("placeholder",theValue)}else{this.contentContainer.html(theValue)}
this.outInput.val(theValue)},_manageEvents:function(){this.applybtn.on('click',this._bind(this._setValue,this))}})})(jQuery)