SiteOrigin CSS - Version 1.4.3

Version Description

  • 29 November 2021 =
  • Restored editor scrollbar.
  • Added a fixed editor height.
Download this release

Release Info

Developer SiteOrigin
Plugin Icon 128x128 SiteOrigin CSS
Version 1.4.3
Comparing to
See all releases

Code changes from version 1.4.2 to 1.4.3

Files changed (7) hide show
  1. css/admin.css +15 -0
  2. js/editor.js +4 -3
  3. js/editor.min.js +1 -1
  4. lang/so-css.pot +2 -2
  5. readme.txt +6 -2
  6. so-css.php +2 -2
  7. tpl/page.php +6 -2
css/admin.css CHANGED
@@ -206,7 +206,10 @@
206
  height: auto;
207
  }
208
  #so-custom-css-form .custom-css-container .CodeMirror-scroll {
 
209
  min-height: 300px;
 
 
210
  }
211
  #so-custom-css-form .custom-css-container .CodeMirror-lines {
212
  padding: 8px 0 8px 0;
@@ -223,6 +226,18 @@
223
  border-left: 1px solid #ddd;
224
  margin-left: 16px;
225
  }
 
 
 
 
 
 
 
 
 
 
 
 
226
  #so-custom-css-form .decoration {
227
  display: none;
228
  }
206
  height: auto;
207
  }
208
  #so-custom-css-form .custom-css-container .CodeMirror-scroll {
209
+ margin: 0;
210
  min-height: 300px;
211
+ overflow-x: hidden !important;
212
+ padding: 0;
213
  }
214
  #so-custom-css-form .custom-css-container .CodeMirror-lines {
215
  padding: 8px 0 8px 0;
226
  border-left: 1px solid #ddd;
227
  margin-left: 16px;
228
  }
229
+ #so-custom-css-form .so-css-footer {
230
+ align-items: center;
231
+ display: flex;
232
+ justify-content: space-between;
233
+ margin-top: 10px;
234
+ }
235
+ @media (max-width: 800px) {
236
+ #so-custom-css-form .so-css-footer {
237
+ align-items: start;
238
+ flex-direction: column-reverse;
239
+ }
240
+ }
241
  #so-custom-css-form .decoration {
242
  display: none;
243
  }
js/editor.js CHANGED
@@ -382,6 +382,7 @@
382
  this.$el.find( '.CodeMirror-scroll' ).css( 'max-height', '' );
383
  areaHeight = windowHeight - this.$( '.custom-css-toolbar' ).outerHeight();
384
  this.codeMirror.setSize( '100%', areaHeight );
 
385
  }
386
  else {
387
  // Attempt to calculate approximate space available for editor when not expanded.
@@ -389,7 +390,7 @@
389
  var otherEltsHeight = $( '#wpadminbar' ).outerHeight( true ) +
390
  $( '#siteorigin-custom-css' ).find( '> h2' ).outerHeight( true ) +
391
  $form.find( '> .custom-css-toolbar' ).outerHeight( true ) +
392
- $form.find( '> p.description' ).outerHeight( true ) +
393
  parseFloat( $( '#wpbody-content' ).css( 'padding-bottom' ) );
394
 
395
  areaHeight = windowHeight - otherEltsHeight;
@@ -398,10 +399,10 @@
398
  areaHeight = 300;
399
  }
400
 
401
- this.$el.find( '.CodeMirror-scroll' ).css( 'min-height', areaHeight + 'px' );
402
  this.codeMirror.setSize( '100%', 'auto' );
 
403
  }
404
- this.$el.find( '.CodeMirror-code' ).css( 'min-height', areaHeight + 'px' );
405
  },
406
 
407
  /**
382
  this.$el.find( '.CodeMirror-scroll' ).css( 'max-height', '' );
383
  areaHeight = windowHeight - this.$( '.custom-css-toolbar' ).outerHeight();
384
  this.codeMirror.setSize( '100%', areaHeight );
385
+ this.$el.find( '.CodeMirror-scroll' ).css( 'height', '100%' );
386
  }
387
  else {
388
  // Attempt to calculate approximate space available for editor when not expanded.
390
  var otherEltsHeight = $( '#wpadminbar' ).outerHeight( true ) +
391
  $( '#siteorigin-custom-css' ).find( '> h2' ).outerHeight( true ) +
392
  $form.find( '> .custom-css-toolbar' ).outerHeight( true ) +
393
+ $form.find( '> .so-css-footer' ).outerHeight( true ) +
394
  parseFloat( $( '#wpbody-content' ).css( 'padding-bottom' ) );
395
 
396
  areaHeight = windowHeight - otherEltsHeight;
399
  areaHeight = 300;
400
  }
401
 
 
402
  this.codeMirror.setSize( '100%', 'auto' );
403
+ this.$el.find( '.CodeMirror-scroll' ).css( 'height', areaHeight + 'px' );
404
  }
405
+ this.$el.find( '.CodeMirror-code' ).css( 'height', areaHeight + 'px' );
406
  },
407
 
408
  /**
js/editor.min.js CHANGED
@@ -1 +1 @@
1
- !function(e,t,i){var s={model:{},collection:{},view:{},fn:{}};window.socss=s,s.model.CustomCssModel=Backbone.Model.extend({defaults:{postId:null,postTitle:null,css:null},urlRoot:i.postCssUrlRoot,url:function(){return this.urlRoot+"&postId="+this.get("postId")}}),s.model.CustomCssCollection=Backbone.Collection.extend({model:s.model.CustomCssModel,modelId:function(e){return e.postId}}),s.model.CSSEditorModel=Backbone.Model.extend({defaults:{customCssPosts:null}}),s.view.toolbar=Backbone.View.extend({button:t.template('<li><a href="#<%= action %>" class="toolbar-button socss-button"><%= text %></a></li>'),events:{"click .socss-button:not(.save)":"triggerEvent"},triggerEvent:function(t){t.preventDefault();var i=e(t.currentTarget);i.trigger("blur");var s=i.attr("href").replace("#","");this.$el.trigger("click_"+s)},addButton:function(t,i){return e(this.button({text:t,action:i})).appendTo(this.$(".toolbar-function-buttons .toolbar-buttons"))}}),s.view.editor=Backbone.View.extend({codeMirror:null,snippets:null,toolbar:null,visualProperties:null,inspector:null,cssSelectors:[],initValue:null,events:{"click_expand .custom-css-toolbar":"toggleExpand","click_visual .custom-css-toolbar":"showVisualEditor","click .socss-button.save":"save",submit:"onSubmit"},initialize:function(e){this.listenTo(this.model,"change:selectedPost",this.getSelectedPostCss),this.getSelectedPostCss().then(function(){e.openVisualEditor&&this.showVisualEditor()}.bind(this))},save:function(){s.save(this)},getSelectedPostCss:function(){var t=this.model.get("selectedPost");return(t&&!t.has("css")?t.fetch():(new e.Deferred).resolve()).then(this.render.bind(this))},render:function(){var t=this.model.get("selectedPost");return t&&!t.has("css")?this:(this.codeMirror||this.setupEditor(),this.toolbar||(this.toolbar=new s.view.toolbar({el:this.$(".custom-css-toolbar"),model:this.model}),this.toolbar.render()),this.visualProperties||(this.visualProperties=new s.view.properties({editor:this,el:e("#so-custom-css-properties")}),this.visualProperties.render()),this.preview||(this.preview=new s.view.preview({editor:this,model:this.model,el:this.$(".custom-css-preview"),initURL:i.homeURL}),this.preview.render()),t&&(this.codeMirror.setValue(t.get("css")),this.codeMirror.clearHistory()),this)},setupEditor:function(){var s=this.$("textarea.css-editor");this.initValue=s.val();var o=this.initValue.match(/\n/gm),r=(o&&o.length,this.initValue);s.val(r);var n={tabSize:2,lineNumbers:!0,mode:"css",theme:"neat",inputStyle:"contenteditable",gutters:["CodeMirror-lint-markers"],lint:!0,search:!0,dialog:!0,annotateScrollbar:!0,extraKeys:{"Ctrl-F":"findPersistent","Alt-G":"jumpToLine"}};void 0!==wp.codeEditor?(n=t.extend(wp.codeEditor.defaultSettings.codemirror,n),this.codeMirror=wp.codeEditor.initialize(s.get(0),n).codemirror):(this.registerCodeMirrorAutocomplete(),this.codeMirror=CodeMirror.fromTextArea(s.get(0),n),this.setupCodeMirrorExtensions()),this.codeMirror.on("change",function(e,t){var i=this.model.get("selectedPost");i&&i.get("css")!==e.getValue().trim()&&i.set("css",e.getValue().trim())}.bind(this)),e(window).on("beforeunload",function(){if(this.codeMirror.getValue().trim()!==this.initValue)return i.loc.leave}.bind(this)),this.$el.find(".custom-css-container").css("overflow","visible"),this.scaleEditor(),e(window).on("resize",function(){this.scaleEditor()}.bind(this))},onSubmit:function(){this.initValue=this.codeMirror.getValue().trim()},registerCodeMirrorAutocomplete:function(){var e={link:1,visited:1,active:1,hover:1,focus:1,"first-letter":1,"first-line":1,"first-child":1,before:1,after:1,lang:1};CodeMirror.registerHelper("hint","css",function(t){var i=t.getCursor(),s=t.getTokenAt(i),o=CodeMirror.innerMode(t.getMode(),s.state);if("css"===o.mode.name){if("keyword"===s.type&&0==="!important".indexOf(s.string))return{list:["!important"],from:CodeMirror.Pos(i.line,s.start),to:CodeMirror.Pos(i.line,s.end)};var r=s.start,n=i.ch,l=s.string.slice(0,n-r);/[^\w$_-]/.test(l)&&(l="",r=n=i.ch);var a=CodeMirror.resolveMode("text/css"),c=[],p=o.state.state;if("top"===p){for(var d=t.getLine(i.line).trim(),h=this.cssSelectors,u=0;u<h.length;u++)-1!==h[u].selector.indexOf(d)&&c.push(h[u].selector);if(c.length)return{list:c,from:CodeMirror.Pos(i.line,0),to:CodeMirror.Pos(i.line,n)}}else if("pseudo"===p||"variable-3"===s.type?v(e):"block"===p||"maybeprop"===p?v(a.propertyKeywords):"prop"===p||"parens"===p||"at"===p||"params"===p?(v(a.valueKeywords),v(a.colorKeywords)):"media"!==p&&"media_parens"!==p||(v(a.mediaTypes),v(a.mediaFeatures)),c.length)return{list:c,from:CodeMirror.Pos(i.line,r),to:CodeMirror.Pos(i.line,n)}}function v(e){for(var t in e)l&&0!==t.lastIndexOf(l,0)||c.push(t)}}.bind(this))},setupCodeMirrorExtensions:function(){this.codeMirror.on("cursorActivity",function(e){var t=e.getCursor(),i=e.getTokenAt(t);CodeMirror.innerMode(e.getMode(),i.state);if("qualifier"===i.type||"tag"===i.type||"builtin"===i.type){var s=e.getLine(t.line).substring(0,i.end);this.preview.highlight(s)}else this.preview.clearHighlight()}.bind(this)),"function"==typeof CodeMirror.showHint&&this.codeMirror.on("keyup",(function(e,t){(t.keyCode>=65&&t.keyCode<=90||189===t.keyCode&&!t.shiftKey||190===t.keyCode&&!t.shiftKey||51===t.keyCode&&t.shiftKey||189===t.keyCode&&t.shiftKey)&&e.showHint({completeSingle:!1})}))},scaleEditor:function(){var t,i=e(window).outerHeight();if(this.$el.hasClass("expanded"))this.$el.find(".CodeMirror-scroll").css("max-height",""),t=i-this.$(".custom-css-toolbar").outerHeight(),this.codeMirror.setSize("100%",t);else{var s=e("#so-custom-css-form");(t=i-(e("#wpadminbar").outerHeight(!0)+e("#siteorigin-custom-css").find("> h2").outerHeight(!0)+s.find("> .custom-css-toolbar").outerHeight(!0)+s.find("> p.description").outerHeight(!0)+parseFloat(e("#wpbody-content").css("padding-bottom"))))<300&&(t=300),this.$el.find(".CodeMirror-scroll").css("min-height",t+"px"),this.codeMirror.setSize("100%","auto")}this.$el.find(".CodeMirror-code").css("min-height",t+"px")},isExpanded:function(){return this.$el.hasClass("expanded")},toggleExpand:function(){this.$el.toggleClass("expanded"),this.scaleEditor()},setExpand:function(e){e?this.$el.addClass("expanded"):this.$el.removeClass("expanded"),this.scaleEditor()},showVisualEditor:function(){this.visualProperties.loadCSS(this.codeMirror.getValue().trim()),this.visualProperties.show()},setSnippets:function(e){t.isEmpty(e)||(this.snippets=new s.view.snippets({snippets:e}),this.snippets.editor=this,this.snippets.render(),this.toolbar.addButton("Snippets","snippets"),this.toolbar.on("click_snippets",function(){this.snippets.show()}.bind(this)))},addCode:function(e){var t=this.codeMirror,i="";i=1===t.doc.lineCount()&&0===t.doc.getLine(t.doc.lastLine()).length?"":0===t.doc.getLine(t.doc.lastLine()).length?"\n":"\n\n",t.doc.setCursor(t.doc.lastLine(),t.doc.getLine(t.doc.lastLine()).length),t.doc.replaceSelection(i+e)},addEmptySelector:function(e){this.addCode(e+" {\n \n}")},setInspector:function(e){this.inspector=e,this.cssSelectors=e.pageSelectors,e.on("click_selector",function(e){this.visualProperties.isVisible()?this.visualProperties.addSelector(e):this.addEmptySelector(e)}.bind(this)),e.on("click_property",function(e){this.visualProperties.isVisible()||this.codeMirror.replaceSelection(e+";\n ")}.bind(this)),e.on("set_active_element",function(e,t){this.visualProperties.isVisible()&&t.length&&this.visualProperties.addSelector(t[0].selector)}.bind(this))}}),s.view.preview=Backbone.View.extend({template:t.template(e("#template-preview-window").html()),editor:null,originalUri:null,currentUri:null,events:{"mouseleave #preview-iframe":"clearHighlight",'keydown #preview-navigator input[type="text"]':"reloadPreview"},initialize:function(e){this.editor=e.editor,this.listenTo(this.model,"change:selectedPost",this.render.bind(this)),this.originalUri=new URI(e.initURL),this.currentUri=new URI(e.initURL),this.editor.codeMirror.on("change",function(e,t){this.updatePreviewCss()}.bind(this))},render:function(){var e=this.model.get("selectedPost");if(e&&!e.has("postUrl"))return e.fetch().then(this.render.bind(this)),this;this.$el.html(this.template()),e&&(this.currentUri=new URI(e.get("postUrl"))),this.currentUri.removeQuery("so_css_preview",1),this.$("#preview-navigator input").val(this.currentUri.toString()),this.currentUri.addQuery("so_css_preview",1),this.$("#preview-iframe").attr("src",this.currentUri.toString()).on("load",this.initPreview.bind(this))},initPreview:function(){var t=this.$("#preview-iframe");this.currentUri=new URI(t.contents().get(0).location.href),this.currentUri.removeQuery("so_css_preview"),this.$("#preview-navigator input").val(this.currentUri.toString()),this.currentUri.addQuery("so_css_preview",1);var i=t.contents().find(".single-product").length;t.contents().find("a").each((function(){var t=e(this),s=t.attr("href");if(void 0===s||i&&t.parents(".wc-tabs").length)return!0;var o=-1===s.indexOf("?")?"?":"&";t.attr("href",s+o+"so_css_preview=1")})),this.updatePreviewCss()},reloadPreview:function(e){var t=this.$('#preview-navigator input[type="text"]');if(13===e.keyCode){e.preventDefault();var i=new URI(t.val());this.originalUri.host()!==i.host()||this.originalUri.protocol()!==i.protocol()?(t.trigger("blur"),alert(t.data("invalid-uri")),t.trigger("focus")):(i.addQuery("so_css_preview",1),this.$("#preview-iframe").attr("src",i.toString()))}},updatePreviewCss:function(){var e=this.$("#preview-iframe");if(0!==e.length){var t=e.contents().find("head");0===t.find("style.siteorigin-custom-css").length&&t.append('<style class="siteorigin-custom-css" type="text/css"></style>');var i=t.find("style.siteorigin-custom-css"),s=this.editor.codeMirror.getValue().trim();i.html(s)}},highlight:function(e){try{this.editor.inspector.hl.highlight(e)}catch(e){console.log("No inspector to highlight with")}},clearHighlight:function(){try{this.editor.inspector.hl.clear()}catch(e){console.log("No inspector to highlight with")}}}),s.view.snippets=Backbone.View.extend({template:t.template(e("#template-snippet-browser").html()),snippet:t.template('<li class="snippet"><%- name %></li>'),className:"css-editor-snippet-browser",snippets:null,editor:null,events:{"click .close":"hide","click .buttons .insert-snippet":"insertSnippet","click .snippet":"clickSnippet"},currentSnippet:null,initialize:function(e){this.snippets=e.snippets},render:function(){this.$el.html(this.template());for(var t=0;t<this.snippets.length;t++)e(this.snippet({name:this.snippets[t].Name})).data({description:this.snippets[t].Description,css:this.snippets[t].css}).appendTo(this.$("ul.snippets"));return this.$(".snippets li.snippet").eq(0).trigger("click"),this.attach(),this},clickSnippet:function(t){t.preventDefault();var i=e(t.currentTarget);this.$(".snippets li.snippet").removeClass("active"),e(this).addClass("active"),this.viewSnippet({name:i.html(),description:i.data("description"),css:i.data("css")})},viewSnippet:function(e){var t=this.$(".main .snippet-view");t.find(".snippet-title").html(e.name),t.find(".snippet-description").html(e.description),t.find(".snippet-code").html(e.css),this.currentSnippet=e},insertSnippet:function(){var e=this.editor.codeMirror,t=this.currentSnippet.css,i="";i=1===e.doc.lineCount()&&0===e.doc.getLine(e.doc.lastLine()).length?"":0===e.doc.getLine(e.doc.lastLine()).length?"\n":"\n\n",e.doc.setCursor(e.doc.lastLine(),e.doc.getLine(e.doc.lastLine()).length),e.doc.replaceSelection(i+t),this.hide()},attach:function(){this.$el.appendTo("body")},show:function(){this.$el.show()},hide:function(){this.$el.hide()}}),s.save=function(t){let s=e("#siteorigin-custom-css .save");var o;s.hasClass("button-primary-disabled")||(s.addClass("button-primary-disabled"),void 0!==t.editor?(o=t.editor.codeMirror.getValue().trim(),t.updateMainEditor(!0)):o=t.codeMirror.getValue().trim(),e.post(i.ajaxurl,{action:"socss_save_css",css:o},null,"html").done((function(t){t.length&&e(".custom-revisions-list").html(t)})).fail((function(e){alert(e.responseText)})).always((function(){s.removeClass("button-primary-disabled")})))},s.view.properties=Backbone.View.extend({tabTemplate:t.template('<li data-section="<%- id %>"><span class="so-css-icon so-css-icon-<%- icon %>"></span> <%- title %></li>'),sectionTemplate:t.template('<div class="section" data-section="<%- id %>"><table class="fields-table"><tbody></tbody></table></div>'),controllerTemplate:t.template('<tr><th scope="row"><%- title %></th><td></td></tr>'),propertyControllers:[],editor:null,css:"",parsed:{},activeSelector:"",editorExpandedBefore:!1,events:{"click .close":"hide","click .save":"save","click .section-tabs li":"onTabClick","change .toolbar select":"onToolbarSelectChange"},initialize:function(e){this.parser=window.css,this.editor=e.editor},render:function(){this.$(".section-tabs").empty(),this.$(".sections").empty(),this.$(".toolbar select").off(),this.propertyControllers=[];var o=i.propertyControllers;for(var r in o){e(this.tabTemplate({id:r,icon:o[r].icon,title:o[r].title})).appendTo(this.$(".section-tabs"));var n=e(this.sectionTemplate({id:r})).appendTo(this.$(".sections"));if(!t.isEmpty(o[r].controllers))for(var l=0;l<o[r].controllers.length;l++){var a,c=e(this.controllerTemplate({title:o[r].controllers[l].title})).appendTo(n.find("tbody")),p=o[r].controllers[l];a=void 0===s.view.properties.controllers[p.type]?new s.view.propertyController({el:c.find("td"),propertiesView:this,args:void 0===p.args?{}:p.args}):new s.view.properties.controllers[p.type]({el:c.find("td"),propertiesView:this,args:void 0===p.args?{}:p.args}),this.propertyControllers.push(a),a.render()}}this.$(".section-tabs li").eq(0).trigger("click")},onTabClick:function(t){var i=e(t.currentTarget),s=this.$('.sections .section[data-section="'+i.data("section")+'"]');this.$(".sections .section").not(s).hide().removeClass("active"),s.show().addClass("active"),this.$(".section-tabs li").not(i).removeClass("active"),i.addClass("active")},onToolbarSelectChange:function(t){this.setActiveSelector(e(t.currentTarget).find(":selected").data("selector"))},setRuleValue:function(e,i){if(void 0!==this.activeSelector&&void 0!==this.activeSelector.declarations){for(var s=this.activeSelector.declarations,o=!0,r=!1,n=0;n<s.length;n++)if(s[n].property===e){o=!1;var l=s[n];l.value!==i&&(l.value=i,r=!0),t.isEmpty(l.value)&&s.splice(s.indexOf(l));break}o&&!t.isEmpty(i)&&(s.push({property:e,value:i,type:"declaration"}),r=!0),r&&this.updateMainEditor(!1)}},addImport:function(e){var i=t.filter(this.parsed.stylesheet.rules,(function(e){return"import"===e.type}));t.any(i,(function(t){return t.import===e.import}))||(this.parsed.stylesheet.rules.unshift(e),this.updateMainEditor(!1))},findImport:function(e){return t.find(this.parsed.stylesheet.rules,(function(t){return"import"===t.type&&t.import.indexOf(e)>-1}))},updateImport:function(e,t){var i=this.findImport(e);i.import!==t.import&&(i.import=t.import,this.updateMainEditor(!1))},removeImport:function(e){var i=t.findIndex(this.parsed.stylesheet.rules,(function(t){return"import"===t.type&&t.import.indexOf(e)>-1}));i>-1&&this.parsed.stylesheet.rules.splice(i,1)},getRuleValue:function(e){if(void 0===this.activeSelector||void 0===this.activeSelector.declarations)return"";for(var t=this.activeSelector.declarations,i=0;i<t.length;i++)if(t[i].property===e)return t[i].value;return""},updateMainEditor:function(e){this.editor.codeMirror.setValue(this.parser.stringify(this.parsed))},show:function(){this.editorExpandedBefore=this.editor.isExpanded(),this.editor.setExpand(!0),this.$el.show().animate({left:0},"fast")},hide:function(){this.editor.setExpand(this.editorExpandedBefore),this.$el.animate({left:-338},"fast",(function(){e(this).hide()})),this.updateMainEditor(!0)},save:function(){s.save(this)},isVisible:function(){return this.$el.is(":visible")},loadCSS:function(i,s){this.css=i,this.parsed=this.parser.parse(i,{silent:!0});for(var o=this.parsed.stylesheet.rules,r=this.$(".toolbar select").empty(),n=0;n<o.length;n++){var l=o[n];if(t.contains(["rule","media"],l.type))if("media"===l.type)for(var a=0;a<l.rules.length;a++){var c="@media "+l.media,p=l.rules[a];"rule"==p.type&&r.append(e("<option>").html(c+": "+p.selectors.join(",")).attr("val",c+": "+p.selectors.join(",")).data("selector",p))}else r.append(e("<option>").html(l.selectors.join(",")).attr("val",l.selectors.join(",")).data("selector",l))}void 0===s&&(s=r.find("option").eq(0).attr("val")),t.isEmpty(s)||r.val(s).trigger("change")},setActiveSelector:function(e){this.activeSelector=e;for(var t=0;t<this.propertyControllers.length;t++)this.propertyControllers[t].refreshFromRule()},addSelector:function(e){var t=this.$(".toolbar select");t.val(e),t.val()===e?t.trigger("change"):(this.editor.addEmptySelector(e),this.loadCSS(this.editor.codeMirror.getValue().trim(),e)),t.addClass("highlighted"),setTimeout((function(){t.removeClass("highlighted")}),2e3)}}),s.view.propertyController=Backbone.View.extend({template:t.template('<input type="text" value="" class="socss-property-controller-input"/>'),activeRule:null,args:null,propertiesView:null,events:{"change .socss-property-controller-input":"onChange","keyup input.socss-property-controller-input":"onChange"},initialize:function(e){this.args=e.args,this.propertiesView=e.propertiesView,this.events=t.extend(s.view.propertyController.prototype.events,this.events),this.delegateEvents(this.events),this.on("set_value",this.updateRule,this),this.on("change",this.updateRule,this)},render:function(){this.$el.append(e(this.template({}))),this.field=this.$("input.socss-property-controller-input")},onChange:function(){this.trigger("change",this.field.val())},updateRule:function(){this.propertiesView.setRuleValue(this.args.property,this.getValue())},refreshFromRule:function(){var e=this.propertiesView.getRuleValue(this.args.property);this.setValue(e,{silent:!0})},getValue:function(){return this.field.val()},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.val(e),i.silent||this.trigger("set_value",e)},reset:function(e){e=t.extend({silent:!1},e),this.setValue("",e)}}),s.view.properties.controllers={},s.view.properties.controllers.color=s.view.propertyController.extend({render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.field.minicolors({})},onChange:function(){this.trigger("change",this.field.minicolors("value"))},getValue:function(){return this.field.minicolors("value").trim()},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.minicolors("value",e),i.silent||this.trigger("set_value",e)}}),s.view.properties.controllers.select=s.view.propertyController.extend({template:t.template('<select class="socss-property-controller-input"></select>'),events:{"click .select-tab":"onSelect"},render:function(){for(var t in this.$el.append(e(this.template({}))),this.field=this.$("select"),this.field.append(e('<option value=""></option>').html("")),this.args.options)this.field.append(e("<option></option>").attr("value",t).html(this.args.options[t]));void 0!==this.args.option_icons&&this.setupVisualSelect()},setupVisualSelect:function(){this.field.hide();var t=e('<div class="select-tabs"></div>').appendTo(this.$el);for(var i in e('<div class="select-tab" data-value=""><span class="so-css-icon so-css-icon-circle"></span></div>').appendTo(t),this.args.option_icons)e('<div class="select-tab"></div>').appendTo(t).append(e('<span class="so-css-icon"></span>').addClass("so-css-icon-"+this.args.option_icons[i])).attr("data-value",i);t.find(".select-tab").css("width",100/t.find(">div").length+"%")},onSelect:function(t){this.$(".select-tab").removeClass("active");var i=e(t.currentTarget);i.addClass("active"),this.field.val(i.data("value")).trigger("change")},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.val(e),this.$(".select-tabs .select-tab").removeClass("active").filter('[data-value="'+e+'"]').addClass("active"),i.silent||this.trigger("set_value",e)}}),s.view.properties.controllers.image=s.view.propertyController.extend({template:t.template('<input type="text" value="" /> <span class="select socss-button"><span class="so-css-icon so-css-icon-upload"></span></span>'),events:{"click .select":"openMedia"},render:function(){this.media=wp.media({title:i.loc.select_image,library:{type:"image"},button:{text:i.loc.select,close:!1}}),this.$el.append(e(this.template({select:i.loc.select}))),this.field=this.$el.find("input"),this.media.on("select",function(){var e=this.media.state().get("selection").first().attributes,t=this.args.value.replace("{{url}}",e.url);this.field.val(t).trigger("change"),this.trigger("set_value",t),this.media.close()}.bind(this))},openMedia:function(){this.media.open()}}),s.view.properties.controllers.measurement=s.view.propertyController.extend({wrapperClass:"socss-field-measurement",events:{"click .toggle-dropdown":"toggleUnitDropdown","click .dropdown li":"onSelectUnit","keydown .socss-field-input":"onInputKeyPress","keyup .socss-field-input":"onInputKeyUp"},render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.setupMeasurementField()},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.val(e).trigger("measurement_refresh"),i.silent||this.trigger("set_value",e)},units:["px","%","em","cm","mm","in","pt","pc","ex","ch","rem","vw","vh","vmin","vmax"],parseUnits:function(e){var t=this.units.map((function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")})),i=new RegExp("([0-9\\.\\-]+)("+t.join("|")+")?","i").exec(e);return null===i?{value:"",unit:""}:{value:i[1],unit:void 0===i[2]?"":i[2]}},setupMeasurementField:function(){this.field.hide(),this.$el.addClass(this.wrapperClass).data("unit","px");var t=e('<input type="text" class="socss-field-input"/>').appendTo(this.$el);e('<span class="toggle-dropdown dashicons dashicons-arrow-down"></span>').appendTo(this.$el);for(var i=e('<ul class="dropdown"></ul>').appendTo(this.$el),s=e('<span class="units"></span>').html("px").appendTo(this.$el),o=0;o<this.units.length;o++){var r=e("<li></li>").html(this.units[o]).data("unit",this.units[o]);"px"===this.units[o]&&r.addClass("active"),i.append(r)}this.field.on("measurement_refresh",function(){var i=this.parseUnits(this.field.val());t.val(i.value);var o=""===i.unit?"px":i.unit;this.$el.data("unit",o),s.html(o);var r=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(i.value).appendTo("body"),n=r.width();n=Math.min(n,63),r.remove(),s.css("left",n+12)}.bind(this));var n=e('<div class="socss-diw"></div>').appendTo(this.$el),l=e('<div class="dec-button socss-button"><span class="so-css-icon so-css-icon-minus"></span></div>').appendTo(n),a=e('<div class="inc-button socss-button"><span class="so-css-icon so-css-icon-plus"></span></div>').appendTo(n);this.setupStepButton(l),this.setupStepButton(a)},updateValue:function(){var e=this.$(".socss-field-input"),t=this.parseUnits(e.val());""!==t.unit&&t.unit!==this.$el.data("unit")&&(e.val(t.value),this.setUnit(t.unit)),""===t.value?this.field.val(""):this.field.val(t.value+this.$el.data("unit")),this.field.trigger("change")},setUnit:function(e){this.$(".units").html(e),this.$el.data("unit",e),this.$(".socss-field-input").trigger("keydown")},toggleUnitDropdown:function(){this.$(".dropdown").toggle()},onSelectUnit:function(t){this.toggleUnitDropdown(),this.setUnit(e(t.currentTarget).data("unit")),this.updateValue()},onInputKeyUp:function(e){this.onInputKeyPress(e),this.updateValue()},onInputKeyPress:function(t){var i=this.$(".socss-field-input"),s="";"keydown"===t.type&&(t.keyCode>=48&&t.keyCode<=57?s=String.fromCharCode(t.keyCode):189===t.keyCode?s="-":190===t.keyCode&&(s="."));var o=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(i.val()+s).appendTo("body"),r=o.width();r=Math.min(r,63),o.remove(),this.$(".units").css("left",r+12)},stepValue:function(e){var t=Number.parseInt(this.parseUnits(this.field.val()).value);Number.isNaN(t)&&(t=0);var i=t+e;this.$(".socss-field-input").val(i),this.updateValue(),this.field.trigger("measurement_refresh")},setupStepButton:function(e){var t,i,s=e.is(".dec-button")?-1:1;e.on("mousedown",function(){this.stepValue(s),i=setTimeout(function(){t=setInterval(function(){this.stepValue(s)}.bind(this),50)}.bind(this),500)}.bind(this)).on("mouseup mouseout",(function(){i&&(clearTimeout(i),i=null),t&&(clearInterval(t),t=null)}))}}),s.view.properties.controllers.number=s.view.propertyController.extend({initialize:function(e){s.view.propertyController.prototype.initialize.apply(this,arguments),this.args=t.extend({change:null,default:0,increment:1,decrement:-1,max:null,min:null},e.args)},render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.setupNumberField()},setupNumberField:function(){this.$el.addClass("socss-field-number");var t=e('<div class="socss-diw"></div>').appendTo(this.$el),i=e('<div class="dec-button socss-button"><span class="so-css-icon so-css-icon-minus"></span></div>').appendTo(t),s=e('<div class="inc-button socss-button"><span class="so-css-icon so-css-icon-plus"></span></div>').appendTo(t);return this.setupStepButton(i),this.setupStepButton(s),this},stepValue:function(e){var t=Number.parseFloat(this.field.val());Number.isNaN(t)&&(t=this.args.default);var i=t+e;i=Math.round(100*i)/100,null!==this.args.max&&(i=Math.min(this.args.max,i)),null!==this.args.min&&(i=Math.max(this.args.min,i)),this.field.val(i),this.field.trigger("change")},setupStepButton:function(e){var t,i,s=e.is(".dec-button")?this.args.decrement:this.args.increment;e.on("mousedown",function(){this.stepValue(s),i=setTimeout(function(){t=setInterval(function(){this.stepValue(s)}.bind(this),50)}.bind(this),500)}.bind(this)).on("mouseup mouseout",(function(){i&&(clearTimeout(i),i=null),t&&(clearInterval(t),t=null)}))}}),s.view.properties.controllers.sides=s.view.propertyController.extend({template:t.template(e("#template-sides-field").html().trim()),controllers:[],events:{"click .select-tab":"onTabClick"},render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.args.hasAll||(this.$(".select-tab").eq(0).remove(),this.$(".select-tab").css("width","25%")),this.args.isRadius?this.$('.select-tabs[data-type="box"]').remove():this.$('.select-tabs[data-type="radius"]').remove(),this.$(".select-tab").each(function(i,o){for(var r=e(o).data("direction"),n=e('<li class="side">').appendTo(this.$(".sides")).hide(),l=0;l<this.args.controllers.length;l++){var a=this.args.controllers[l];s.view.properties.controllers[a.type];var c="";c="all"===r?a.args.propertyAll:a.args.property.replace("{dir}",r);var p=t.extend({},a.args,{property:c}),d=new s.view.properties.controllers[a.type]({el:e("<div>").appendTo(n),propertiesView:this.propertiesView,args:p});d.render(),this.propertiesView.propertyControllers.push(d)}}.bind(this)),this.$(".select-tab").eq(0).click()},onTabClick:function(t){var i=this.$(".select-tab");i.removeClass("active");var s=e(t.currentTarget);s.addClass("active");var o=this.$(".sides .side");o.hide(),o.eq(i.index(s)).show()}}),s.view.properties.controllers.font_select=s.view.propertyController.extend({template:t.template(e("#template-webfont-teaser").html().trim())})}(jQuery,_,socssOptions),jQuery((function(e){var t=window.socss,i=new t.model.CSSEditorModel({customCssPosts:socssOptions.customCssPosts}),s=new t.view.editor({el:e("#so-custom-css-form").get(0),model:i,openVisualEditor:socssOptions.openVisualEditor});s.setSnippets(socssOptions.snippets),e("#so-custom-css-getting-started a.hide").on("click",(function(t){t.preventDefault(),e("#so-custom-css-getting-started").slideUp(),e.get(e(this).attr("href"))})),window.socss.mainEditor=s,e(t).trigger("initialized"),e('.button-primary[name="siteorigin_custom_css_save"]').on("click",(function(){e("#so-custom-css-form").trigger("submit")}))}));
1
+ !function(e,t,i){var s={model:{},collection:{},view:{},fn:{}};window.socss=s,s.model.CustomCssModel=Backbone.Model.extend({defaults:{postId:null,postTitle:null,css:null},urlRoot:i.postCssUrlRoot,url:function(){return this.urlRoot+"&postId="+this.get("postId")}}),s.model.CustomCssCollection=Backbone.Collection.extend({model:s.model.CustomCssModel,modelId:function(e){return e.postId}}),s.model.CSSEditorModel=Backbone.Model.extend({defaults:{customCssPosts:null}}),s.view.toolbar=Backbone.View.extend({button:t.template('<li><a href="#<%= action %>" class="toolbar-button socss-button"><%= text %></a></li>'),events:{"click .socss-button:not(.save)":"triggerEvent"},triggerEvent:function(t){t.preventDefault();var i=e(t.currentTarget);i.trigger("blur");var s=i.attr("href").replace("#","");this.$el.trigger("click_"+s)},addButton:function(t,i){return e(this.button({text:t,action:i})).appendTo(this.$(".toolbar-function-buttons .toolbar-buttons"))}}),s.view.editor=Backbone.View.extend({codeMirror:null,snippets:null,toolbar:null,visualProperties:null,inspector:null,cssSelectors:[],initValue:null,events:{"click_expand .custom-css-toolbar":"toggleExpand","click_visual .custom-css-toolbar":"showVisualEditor","click .socss-button.save":"save",submit:"onSubmit"},initialize:function(e){this.listenTo(this.model,"change:selectedPost",this.getSelectedPostCss),this.getSelectedPostCss().then(function(){e.openVisualEditor&&this.showVisualEditor()}.bind(this))},save:function(){s.save(this)},getSelectedPostCss:function(){var t=this.model.get("selectedPost");return(t&&!t.has("css")?t.fetch():(new e.Deferred).resolve()).then(this.render.bind(this))},render:function(){var t=this.model.get("selectedPost");return t&&!t.has("css")?this:(this.codeMirror||this.setupEditor(),this.toolbar||(this.toolbar=new s.view.toolbar({el:this.$(".custom-css-toolbar"),model:this.model}),this.toolbar.render()),this.visualProperties||(this.visualProperties=new s.view.properties({editor:this,el:e("#so-custom-css-properties")}),this.visualProperties.render()),this.preview||(this.preview=new s.view.preview({editor:this,model:this.model,el:this.$(".custom-css-preview"),initURL:i.homeURL}),this.preview.render()),t&&(this.codeMirror.setValue(t.get("css")),this.codeMirror.clearHistory()),this)},setupEditor:function(){var s=this.$("textarea.css-editor");this.initValue=s.val();var o=this.initValue.match(/\n/gm),r=(o&&o.length,this.initValue);s.val(r);var n={tabSize:2,lineNumbers:!0,mode:"css",theme:"neat",inputStyle:"contenteditable",gutters:["CodeMirror-lint-markers"],lint:!0,search:!0,dialog:!0,annotateScrollbar:!0,extraKeys:{"Ctrl-F":"findPersistent","Alt-G":"jumpToLine"}};void 0!==wp.codeEditor?(n=t.extend(wp.codeEditor.defaultSettings.codemirror,n),this.codeMirror=wp.codeEditor.initialize(s.get(0),n).codemirror):(this.registerCodeMirrorAutocomplete(),this.codeMirror=CodeMirror.fromTextArea(s.get(0),n),this.setupCodeMirrorExtensions()),this.codeMirror.on("change",function(e,t){var i=this.model.get("selectedPost");i&&i.get("css")!==e.getValue().trim()&&i.set("css",e.getValue().trim())}.bind(this)),e(window).on("beforeunload",function(){if(this.codeMirror.getValue().trim()!==this.initValue)return i.loc.leave}.bind(this)),this.$el.find(".custom-css-container").css("overflow","visible"),this.scaleEditor(),e(window).on("resize",function(){this.scaleEditor()}.bind(this))},onSubmit:function(){this.initValue=this.codeMirror.getValue().trim()},registerCodeMirrorAutocomplete:function(){var e={link:1,visited:1,active:1,hover:1,focus:1,"first-letter":1,"first-line":1,"first-child":1,before:1,after:1,lang:1};CodeMirror.registerHelper("hint","css",function(t){var i=t.getCursor(),s=t.getTokenAt(i),o=CodeMirror.innerMode(t.getMode(),s.state);if("css"===o.mode.name){if("keyword"===s.type&&0==="!important".indexOf(s.string))return{list:["!important"],from:CodeMirror.Pos(i.line,s.start),to:CodeMirror.Pos(i.line,s.end)};var r=s.start,n=i.ch,l=s.string.slice(0,n-r);/[^\w$_-]/.test(l)&&(l="",r=n=i.ch);var a=CodeMirror.resolveMode("text/css"),c=[],d=o.state.state;if("top"===d){for(var p=t.getLine(i.line).trim(),h=this.cssSelectors,u=0;u<h.length;u++)-1!==h[u].selector.indexOf(p)&&c.push(h[u].selector);if(c.length)return{list:c,from:CodeMirror.Pos(i.line,0),to:CodeMirror.Pos(i.line,n)}}else if("pseudo"===d||"variable-3"===s.type?v(e):"block"===d||"maybeprop"===d?v(a.propertyKeywords):"prop"===d||"parens"===d||"at"===d||"params"===d?(v(a.valueKeywords),v(a.colorKeywords)):"media"!==d&&"media_parens"!==d||(v(a.mediaTypes),v(a.mediaFeatures)),c.length)return{list:c,from:CodeMirror.Pos(i.line,r),to:CodeMirror.Pos(i.line,n)}}function v(e){for(var t in e)l&&0!==t.lastIndexOf(l,0)||c.push(t)}}.bind(this))},setupCodeMirrorExtensions:function(){this.codeMirror.on("cursorActivity",function(e){var t=e.getCursor(),i=e.getTokenAt(t);CodeMirror.innerMode(e.getMode(),i.state);if("qualifier"===i.type||"tag"===i.type||"builtin"===i.type){var s=e.getLine(t.line).substring(0,i.end);this.preview.highlight(s)}else this.preview.clearHighlight()}.bind(this)),"function"==typeof CodeMirror.showHint&&this.codeMirror.on("keyup",(function(e,t){(t.keyCode>=65&&t.keyCode<=90||189===t.keyCode&&!t.shiftKey||190===t.keyCode&&!t.shiftKey||51===t.keyCode&&t.shiftKey||189===t.keyCode&&t.shiftKey)&&e.showHint({completeSingle:!1})}))},scaleEditor:function(){var t,i=e(window).outerHeight();if(this.$el.hasClass("expanded"))this.$el.find(".CodeMirror-scroll").css("max-height",""),t=i-this.$(".custom-css-toolbar").outerHeight(),this.codeMirror.setSize("100%",t),this.$el.find(".CodeMirror-scroll").css("height","100%");else{var s=e("#so-custom-css-form");(t=i-(e("#wpadminbar").outerHeight(!0)+e("#siteorigin-custom-css").find("> h2").outerHeight(!0)+s.find("> .custom-css-toolbar").outerHeight(!0)+s.find("> .so-css-footer").outerHeight(!0)+parseFloat(e("#wpbody-content").css("padding-bottom"))))<300&&(t=300),this.codeMirror.setSize("100%","auto"),this.$el.find(".CodeMirror-scroll").css("height",t+"px")}this.$el.find(".CodeMirror-code").css("height",t+"px")},isExpanded:function(){return this.$el.hasClass("expanded")},toggleExpand:function(){this.$el.toggleClass("expanded"),this.scaleEditor()},setExpand:function(e){e?this.$el.addClass("expanded"):this.$el.removeClass("expanded"),this.scaleEditor()},showVisualEditor:function(){this.visualProperties.loadCSS(this.codeMirror.getValue().trim()),this.visualProperties.show()},setSnippets:function(e){t.isEmpty(e)||(this.snippets=new s.view.snippets({snippets:e}),this.snippets.editor=this,this.snippets.render(),this.toolbar.addButton("Snippets","snippets"),this.toolbar.on("click_snippets",function(){this.snippets.show()}.bind(this)))},addCode:function(e){var t=this.codeMirror,i="";i=1===t.doc.lineCount()&&0===t.doc.getLine(t.doc.lastLine()).length?"":0===t.doc.getLine(t.doc.lastLine()).length?"\n":"\n\n",t.doc.setCursor(t.doc.lastLine(),t.doc.getLine(t.doc.lastLine()).length),t.doc.replaceSelection(i+e)},addEmptySelector:function(e){this.addCode(e+" {\n \n}")},setInspector:function(e){this.inspector=e,this.cssSelectors=e.pageSelectors,e.on("click_selector",function(e){this.visualProperties.isVisible()?this.visualProperties.addSelector(e):this.addEmptySelector(e)}.bind(this)),e.on("click_property",function(e){this.visualProperties.isVisible()||this.codeMirror.replaceSelection(e+";\n ")}.bind(this)),e.on("set_active_element",function(e,t){this.visualProperties.isVisible()&&t.length&&this.visualProperties.addSelector(t[0].selector)}.bind(this))}}),s.view.preview=Backbone.View.extend({template:t.template(e("#template-preview-window").html()),editor:null,originalUri:null,currentUri:null,events:{"mouseleave #preview-iframe":"clearHighlight",'keydown #preview-navigator input[type="text"]':"reloadPreview"},initialize:function(e){this.editor=e.editor,this.listenTo(this.model,"change:selectedPost",this.render.bind(this)),this.originalUri=new URI(e.initURL),this.currentUri=new URI(e.initURL),this.editor.codeMirror.on("change",function(e,t){this.updatePreviewCss()}.bind(this))},render:function(){var e=this.model.get("selectedPost");if(e&&!e.has("postUrl"))return e.fetch().then(this.render.bind(this)),this;this.$el.html(this.template()),e&&(this.currentUri=new URI(e.get("postUrl"))),this.currentUri.removeQuery("so_css_preview",1),this.$("#preview-navigator input").val(this.currentUri.toString()),this.currentUri.addQuery("so_css_preview",1),this.$("#preview-iframe").attr("src",this.currentUri.toString()).on("load",this.initPreview.bind(this))},initPreview:function(){var t=this.$("#preview-iframe");this.currentUri=new URI(t.contents().get(0).location.href),this.currentUri.removeQuery("so_css_preview"),this.$("#preview-navigator input").val(this.currentUri.toString()),this.currentUri.addQuery("so_css_preview",1);var i=t.contents().find(".single-product").length;t.contents().find("a").each((function(){var t=e(this),s=t.attr("href");if(void 0===s||i&&t.parents(".wc-tabs").length)return!0;var o=-1===s.indexOf("?")?"?":"&";t.attr("href",s+o+"so_css_preview=1")})),this.updatePreviewCss()},reloadPreview:function(e){var t=this.$('#preview-navigator input[type="text"]');if(13===e.keyCode){e.preventDefault();var i=new URI(t.val());this.originalUri.host()!==i.host()||this.originalUri.protocol()!==i.protocol()?(t.trigger("blur"),alert(t.data("invalid-uri")),t.trigger("focus")):(i.addQuery("so_css_preview",1),this.$("#preview-iframe").attr("src",i.toString()))}},updatePreviewCss:function(){var e=this.$("#preview-iframe");if(0!==e.length){var t=e.contents().find("head");0===t.find("style.siteorigin-custom-css").length&&t.append('<style class="siteorigin-custom-css" type="text/css"></style>');var i=t.find("style.siteorigin-custom-css"),s=this.editor.codeMirror.getValue().trim();i.html(s)}},highlight:function(e){try{this.editor.inspector.hl.highlight(e)}catch(e){console.log("No inspector to highlight with")}},clearHighlight:function(){try{this.editor.inspector.hl.clear()}catch(e){console.log("No inspector to highlight with")}}}),s.view.snippets=Backbone.View.extend({template:t.template(e("#template-snippet-browser").html()),snippet:t.template('<li class="snippet"><%- name %></li>'),className:"css-editor-snippet-browser",snippets:null,editor:null,events:{"click .close":"hide","click .buttons .insert-snippet":"insertSnippet","click .snippet":"clickSnippet"},currentSnippet:null,initialize:function(e){this.snippets=e.snippets},render:function(){this.$el.html(this.template());for(var t=0;t<this.snippets.length;t++)e(this.snippet({name:this.snippets[t].Name})).data({description:this.snippets[t].Description,css:this.snippets[t].css}).appendTo(this.$("ul.snippets"));return this.$(".snippets li.snippet").eq(0).trigger("click"),this.attach(),this},clickSnippet:function(t){t.preventDefault();var i=e(t.currentTarget);this.$(".snippets li.snippet").removeClass("active"),e(this).addClass("active"),this.viewSnippet({name:i.html(),description:i.data("description"),css:i.data("css")})},viewSnippet:function(e){var t=this.$(".main .snippet-view");t.find(".snippet-title").html(e.name),t.find(".snippet-description").html(e.description),t.find(".snippet-code").html(e.css),this.currentSnippet=e},insertSnippet:function(){var e=this.editor.codeMirror,t=this.currentSnippet.css,i="";i=1===e.doc.lineCount()&&0===e.doc.getLine(e.doc.lastLine()).length?"":0===e.doc.getLine(e.doc.lastLine()).length?"\n":"\n\n",e.doc.setCursor(e.doc.lastLine(),e.doc.getLine(e.doc.lastLine()).length),e.doc.replaceSelection(i+t),this.hide()},attach:function(){this.$el.appendTo("body")},show:function(){this.$el.show()},hide:function(){this.$el.hide()}}),s.save=function(t){let s=e("#siteorigin-custom-css .save");var o;s.hasClass("button-primary-disabled")||(s.addClass("button-primary-disabled"),void 0!==t.editor?(o=t.editor.codeMirror.getValue().trim(),t.updateMainEditor(!0)):o=t.codeMirror.getValue().trim(),e.post(i.ajaxurl,{action:"socss_save_css",css:o},null,"html").done((function(t){t.length&&e(".custom-revisions-list").html(t)})).fail((function(e){alert(e.responseText)})).always((function(){s.removeClass("button-primary-disabled")})))},s.view.properties=Backbone.View.extend({tabTemplate:t.template('<li data-section="<%- id %>"><span class="so-css-icon so-css-icon-<%- icon %>"></span> <%- title %></li>'),sectionTemplate:t.template('<div class="section" data-section="<%- id %>"><table class="fields-table"><tbody></tbody></table></div>'),controllerTemplate:t.template('<tr><th scope="row"><%- title %></th><td></td></tr>'),propertyControllers:[],editor:null,css:"",parsed:{},activeSelector:"",editorExpandedBefore:!1,events:{"click .close":"hide","click .save":"save","click .section-tabs li":"onTabClick","change .toolbar select":"onToolbarSelectChange"},initialize:function(e){this.parser=window.css,this.editor=e.editor},render:function(){this.$(".section-tabs").empty(),this.$(".sections").empty(),this.$(".toolbar select").off(),this.propertyControllers=[];var o=i.propertyControllers;for(var r in o){e(this.tabTemplate({id:r,icon:o[r].icon,title:o[r].title})).appendTo(this.$(".section-tabs"));var n=e(this.sectionTemplate({id:r})).appendTo(this.$(".sections"));if(!t.isEmpty(o[r].controllers))for(var l=0;l<o[r].controllers.length;l++){var a,c=e(this.controllerTemplate({title:o[r].controllers[l].title})).appendTo(n.find("tbody")),d=o[r].controllers[l];a=void 0===s.view.properties.controllers[d.type]?new s.view.propertyController({el:c.find("td"),propertiesView:this,args:void 0===d.args?{}:d.args}):new s.view.properties.controllers[d.type]({el:c.find("td"),propertiesView:this,args:void 0===d.args?{}:d.args}),this.propertyControllers.push(a),a.render()}}this.$(".section-tabs li").eq(0).trigger("click")},onTabClick:function(t){var i=e(t.currentTarget),s=this.$('.sections .section[data-section="'+i.data("section")+'"]');this.$(".sections .section").not(s).hide().removeClass("active"),s.show().addClass("active"),this.$(".section-tabs li").not(i).removeClass("active"),i.addClass("active")},onToolbarSelectChange:function(t){this.setActiveSelector(e(t.currentTarget).find(":selected").data("selector"))},setRuleValue:function(e,i){if(void 0!==this.activeSelector&&void 0!==this.activeSelector.declarations){for(var s=this.activeSelector.declarations,o=!0,r=!1,n=0;n<s.length;n++)if(s[n].property===e){o=!1;var l=s[n];l.value!==i&&(l.value=i,r=!0),t.isEmpty(l.value)&&s.splice(s.indexOf(l));break}o&&!t.isEmpty(i)&&(s.push({property:e,value:i,type:"declaration"}),r=!0),r&&this.updateMainEditor(!1)}},addImport:function(e){var i=t.filter(this.parsed.stylesheet.rules,(function(e){return"import"===e.type}));t.any(i,(function(t){return t.import===e.import}))||(this.parsed.stylesheet.rules.unshift(e),this.updateMainEditor(!1))},findImport:function(e){return t.find(this.parsed.stylesheet.rules,(function(t){return"import"===t.type&&t.import.indexOf(e)>-1}))},updateImport:function(e,t){var i=this.findImport(e);i.import!==t.import&&(i.import=t.import,this.updateMainEditor(!1))},removeImport:function(e){var i=t.findIndex(this.parsed.stylesheet.rules,(function(t){return"import"===t.type&&t.import.indexOf(e)>-1}));i>-1&&this.parsed.stylesheet.rules.splice(i,1)},getRuleValue:function(e){if(void 0===this.activeSelector||void 0===this.activeSelector.declarations)return"";for(var t=this.activeSelector.declarations,i=0;i<t.length;i++)if(t[i].property===e)return t[i].value;return""},updateMainEditor:function(e){this.editor.codeMirror.setValue(this.parser.stringify(this.parsed))},show:function(){this.editorExpandedBefore=this.editor.isExpanded(),this.editor.setExpand(!0),this.$el.show().animate({left:0},"fast")},hide:function(){this.editor.setExpand(this.editorExpandedBefore),this.$el.animate({left:-338},"fast",(function(){e(this).hide()})),this.updateMainEditor(!0)},save:function(){s.save(this)},isVisible:function(){return this.$el.is(":visible")},loadCSS:function(i,s){this.css=i,this.parsed=this.parser.parse(i,{silent:!0});for(var o=this.parsed.stylesheet.rules,r=this.$(".toolbar select").empty(),n=0;n<o.length;n++){var l=o[n];if(t.contains(["rule","media"],l.type))if("media"===l.type)for(var a=0;a<l.rules.length;a++){var c="@media "+l.media,d=l.rules[a];"rule"==d.type&&r.append(e("<option>").html(c+": "+d.selectors.join(",")).attr("val",c+": "+d.selectors.join(",")).data("selector",d))}else r.append(e("<option>").html(l.selectors.join(",")).attr("val",l.selectors.join(",")).data("selector",l))}void 0===s&&(s=r.find("option").eq(0).attr("val")),t.isEmpty(s)||r.val(s).trigger("change")},setActiveSelector:function(e){this.activeSelector=e;for(var t=0;t<this.propertyControllers.length;t++)this.propertyControllers[t].refreshFromRule()},addSelector:function(e){var t=this.$(".toolbar select");t.val(e),t.val()===e?t.trigger("change"):(this.editor.addEmptySelector(e),this.loadCSS(this.editor.codeMirror.getValue().trim(),e)),t.addClass("highlighted"),setTimeout((function(){t.removeClass("highlighted")}),2e3)}}),s.view.propertyController=Backbone.View.extend({template:t.template('<input type="text" value="" class="socss-property-controller-input"/>'),activeRule:null,args:null,propertiesView:null,events:{"change .socss-property-controller-input":"onChange","keyup input.socss-property-controller-input":"onChange"},initialize:function(e){this.args=e.args,this.propertiesView=e.propertiesView,this.events=t.extend(s.view.propertyController.prototype.events,this.events),this.delegateEvents(this.events),this.on("set_value",this.updateRule,this),this.on("change",this.updateRule,this)},render:function(){this.$el.append(e(this.template({}))),this.field=this.$("input.socss-property-controller-input")},onChange:function(){this.trigger("change",this.field.val())},updateRule:function(){this.propertiesView.setRuleValue(this.args.property,this.getValue())},refreshFromRule:function(){var e=this.propertiesView.getRuleValue(this.args.property);this.setValue(e,{silent:!0})},getValue:function(){return this.field.val()},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.val(e),i.silent||this.trigger("set_value",e)},reset:function(e){e=t.extend({silent:!1},e),this.setValue("",e)}}),s.view.properties.controllers={},s.view.properties.controllers.color=s.view.propertyController.extend({render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.field.minicolors({})},onChange:function(){this.trigger("change",this.field.minicolors("value"))},getValue:function(){return this.field.minicolors("value").trim()},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.minicolors("value",e),i.silent||this.trigger("set_value",e)}}),s.view.properties.controllers.select=s.view.propertyController.extend({template:t.template('<select class="socss-property-controller-input"></select>'),events:{"click .select-tab":"onSelect"},render:function(){for(var t in this.$el.append(e(this.template({}))),this.field=this.$("select"),this.field.append(e('<option value=""></option>').html("")),this.args.options)this.field.append(e("<option></option>").attr("value",t).html(this.args.options[t]));void 0!==this.args.option_icons&&this.setupVisualSelect()},setupVisualSelect:function(){this.field.hide();var t=e('<div class="select-tabs"></div>').appendTo(this.$el);for(var i in e('<div class="select-tab" data-value=""><span class="so-css-icon so-css-icon-circle"></span></div>').appendTo(t),this.args.option_icons)e('<div class="select-tab"></div>').appendTo(t).append(e('<span class="so-css-icon"></span>').addClass("so-css-icon-"+this.args.option_icons[i])).attr("data-value",i);t.find(".select-tab").css("width",100/t.find(">div").length+"%")},onSelect:function(t){this.$(".select-tab").removeClass("active");var i=e(t.currentTarget);i.addClass("active"),this.field.val(i.data("value")).trigger("change")},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.val(e),this.$(".select-tabs .select-tab").removeClass("active").filter('[data-value="'+e+'"]').addClass("active"),i.silent||this.trigger("set_value",e)}}),s.view.properties.controllers.image=s.view.propertyController.extend({template:t.template('<input type="text" value="" /> <span class="select socss-button"><span class="so-css-icon so-css-icon-upload"></span></span>'),events:{"click .select":"openMedia"},render:function(){this.media=wp.media({title:i.loc.select_image,library:{type:"image"},button:{text:i.loc.select,close:!1}}),this.$el.append(e(this.template({select:i.loc.select}))),this.field=this.$el.find("input"),this.media.on("select",function(){var e=this.media.state().get("selection").first().attributes,t=this.args.value.replace("{{url}}",e.url);this.field.val(t).trigger("change"),this.trigger("set_value",t),this.media.close()}.bind(this))},openMedia:function(){this.media.open()}}),s.view.properties.controllers.measurement=s.view.propertyController.extend({wrapperClass:"socss-field-measurement",events:{"click .toggle-dropdown":"toggleUnitDropdown","click .dropdown li":"onSelectUnit","keydown .socss-field-input":"onInputKeyPress","keyup .socss-field-input":"onInputKeyUp"},render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.setupMeasurementField()},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.val(e).trigger("measurement_refresh"),i.silent||this.trigger("set_value",e)},units:["px","%","em","cm","mm","in","pt","pc","ex","ch","rem","vw","vh","vmin","vmax"],parseUnits:function(e){var t=this.units.map((function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")})),i=new RegExp("([0-9\\.\\-]+)("+t.join("|")+")?","i").exec(e);return null===i?{value:"",unit:""}:{value:i[1],unit:void 0===i[2]?"":i[2]}},setupMeasurementField:function(){this.field.hide(),this.$el.addClass(this.wrapperClass).data("unit","px");var t=e('<input type="text" class="socss-field-input"/>').appendTo(this.$el);e('<span class="toggle-dropdown dashicons dashicons-arrow-down"></span>').appendTo(this.$el);for(var i=e('<ul class="dropdown"></ul>').appendTo(this.$el),s=e('<span class="units"></span>').html("px").appendTo(this.$el),o=0;o<this.units.length;o++){var r=e("<li></li>").html(this.units[o]).data("unit",this.units[o]);"px"===this.units[o]&&r.addClass("active"),i.append(r)}this.field.on("measurement_refresh",function(){var i=this.parseUnits(this.field.val());t.val(i.value);var o=""===i.unit?"px":i.unit;this.$el.data("unit",o),s.html(o);var r=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(i.value).appendTo("body"),n=r.width();n=Math.min(n,63),r.remove(),s.css("left",n+12)}.bind(this));var n=e('<div class="socss-diw"></div>').appendTo(this.$el),l=e('<div class="dec-button socss-button"><span class="so-css-icon so-css-icon-minus"></span></div>').appendTo(n),a=e('<div class="inc-button socss-button"><span class="so-css-icon so-css-icon-plus"></span></div>').appendTo(n);this.setupStepButton(l),this.setupStepButton(a)},updateValue:function(){var e=this.$(".socss-field-input"),t=this.parseUnits(e.val());""!==t.unit&&t.unit!==this.$el.data("unit")&&(e.val(t.value),this.setUnit(t.unit)),""===t.value?this.field.val(""):this.field.val(t.value+this.$el.data("unit")),this.field.trigger("change")},setUnit:function(e){this.$(".units").html(e),this.$el.data("unit",e),this.$(".socss-field-input").trigger("keydown")},toggleUnitDropdown:function(){this.$(".dropdown").toggle()},onSelectUnit:function(t){this.toggleUnitDropdown(),this.setUnit(e(t.currentTarget).data("unit")),this.updateValue()},onInputKeyUp:function(e){this.onInputKeyPress(e),this.updateValue()},onInputKeyPress:function(t){var i=this.$(".socss-field-input"),s="";"keydown"===t.type&&(t.keyCode>=48&&t.keyCode<=57?s=String.fromCharCode(t.keyCode):189===t.keyCode?s="-":190===t.keyCode&&(s="."));var o=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(i.val()+s).appendTo("body"),r=o.width();r=Math.min(r,63),o.remove(),this.$(".units").css("left",r+12)},stepValue:function(e){var t=Number.parseInt(this.parseUnits(this.field.val()).value);Number.isNaN(t)&&(t=0);var i=t+e;this.$(".socss-field-input").val(i),this.updateValue(),this.field.trigger("measurement_refresh")},setupStepButton:function(e){var t,i,s=e.is(".dec-button")?-1:1;e.on("mousedown",function(){this.stepValue(s),i=setTimeout(function(){t=setInterval(function(){this.stepValue(s)}.bind(this),50)}.bind(this),500)}.bind(this)).on("mouseup mouseout",(function(){i&&(clearTimeout(i),i=null),t&&(clearInterval(t),t=null)}))}}),s.view.properties.controllers.number=s.view.propertyController.extend({initialize:function(e){s.view.propertyController.prototype.initialize.apply(this,arguments),this.args=t.extend({change:null,default:0,increment:1,decrement:-1,max:null,min:null},e.args)},render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.setupNumberField()},setupNumberField:function(){this.$el.addClass("socss-field-number");var t=e('<div class="socss-diw"></div>').appendTo(this.$el),i=e('<div class="dec-button socss-button"><span class="so-css-icon so-css-icon-minus"></span></div>').appendTo(t),s=e('<div class="inc-button socss-button"><span class="so-css-icon so-css-icon-plus"></span></div>').appendTo(t);return this.setupStepButton(i),this.setupStepButton(s),this},stepValue:function(e){var t=Number.parseFloat(this.field.val());Number.isNaN(t)&&(t=this.args.default);var i=t+e;i=Math.round(100*i)/100,null!==this.args.max&&(i=Math.min(this.args.max,i)),null!==this.args.min&&(i=Math.max(this.args.min,i)),this.field.val(i),this.field.trigger("change")},setupStepButton:function(e){var t,i,s=e.is(".dec-button")?this.args.decrement:this.args.increment;e.on("mousedown",function(){this.stepValue(s),i=setTimeout(function(){t=setInterval(function(){this.stepValue(s)}.bind(this),50)}.bind(this),500)}.bind(this)).on("mouseup mouseout",(function(){i&&(clearTimeout(i),i=null),t&&(clearInterval(t),t=null)}))}}),s.view.properties.controllers.sides=s.view.propertyController.extend({template:t.template(e("#template-sides-field").html().trim()),controllers:[],events:{"click .select-tab":"onTabClick"},render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.args.hasAll||(this.$(".select-tab").eq(0).remove(),this.$(".select-tab").css("width","25%")),this.args.isRadius?this.$('.select-tabs[data-type="box"]').remove():this.$('.select-tabs[data-type="radius"]').remove(),this.$(".select-tab").each(function(i,o){for(var r=e(o).data("direction"),n=e('<li class="side">').appendTo(this.$(".sides")).hide(),l=0;l<this.args.controllers.length;l++){var a=this.args.controllers[l];s.view.properties.controllers[a.type];var c="";c="all"===r?a.args.propertyAll:a.args.property.replace("{dir}",r);var d=t.extend({},a.args,{property:c}),p=new s.view.properties.controllers[a.type]({el:e("<div>").appendTo(n),propertiesView:this.propertiesView,args:d});p.render(),this.propertiesView.propertyControllers.push(p)}}.bind(this)),this.$(".select-tab").eq(0).click()},onTabClick:function(t){var i=this.$(".select-tab");i.removeClass("active");var s=e(t.currentTarget);s.addClass("active");var o=this.$(".sides .side");o.hide(),o.eq(i.index(s)).show()}}),s.view.properties.controllers.font_select=s.view.propertyController.extend({template:t.template(e("#template-webfont-teaser").html().trim())})}(jQuery,_,socssOptions),jQuery((function(e){var t=window.socss,i=new t.model.CSSEditorModel({customCssPosts:socssOptions.customCssPosts}),s=new t.view.editor({el:e("#so-custom-css-form").get(0),model:i,openVisualEditor:socssOptions.openVisualEditor});s.setSnippets(socssOptions.snippets),e("#so-custom-css-getting-started a.hide").on("click",(function(t){t.preventDefault(),e("#so-custom-css-getting-started").slideUp(),e.get(e(this).attr("href"))})),window.socss.mainEditor=s,e(t).trigger("initialized"),e('.button-primary[name="siteorigin_custom_css_save"]').on("click",(function(){e("#so-custom-css-form").trigger("submit")}))}));
lang/so-css.pot CHANGED
@@ -80,7 +80,7 @@ msgstr ""
80
  msgid "Changes apply to %s and its child themes"
81
  msgstr ""
82
 
83
- #: so-css.php:452, tpl/page.php:99, tpl/page.php:127
84
  msgid "Save CSS"
85
  msgstr ""
86
 
@@ -584,6 +584,6 @@ msgstr ""
584
  msgid "Open Visual Mode"
585
  msgstr ""
586
 
587
- #: tpl/page.php:124
588
  msgid "Close"
589
  msgstr ""
80
  msgid "Changes apply to %s and its child themes"
81
  msgstr ""
82
 
83
+ #: so-css.php:452, tpl/page.php:99, tpl/page.php:131
84
  msgid "Save CSS"
85
  msgstr ""
86
 
584
  msgid "Open Visual Mode"
585
  msgstr ""
586
 
587
+ #: tpl/page.php:128
588
  msgid "Close"
589
  msgstr ""
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Tags: css, visual css, css editor, design, customize
3
  Requires at least: 3.9
4
  Tested up to: 5.8
5
- Stable tag: 1.4.2
6
- Build time: 2021-11-08T20:49:29+02:00
7
  License: GPLv2 or later
8
  Contributors: gpriday, alexgso
9
  Donate link: https://siteorigin.com/downloads/premium/
@@ -71,6 +71,10 @@ SiteOrigin Premium includes access to our professional email support service, pe
71
 
72
  == Changelog ==
73
 
 
 
 
 
74
  = 1.4.2 - 08 November 2021 =
75
  * Fixed string translation functions.
76
 
2
  Tags: css, visual css, css editor, design, customize
3
  Requires at least: 3.9
4
  Tested up to: 5.8
5
+ Stable tag: 1.4.3
6
+ Build time: 2021-11-29T21:56:11+02:00
7
  License: GPLv2 or later
8
  Contributors: gpriday, alexgso
9
  Donate link: https://siteorigin.com/downloads/premium/
71
 
72
  == Changelog ==
73
 
74
+ = 1.4.3 - 29 November 2021 =
75
+ * Restored editor scrollbar.
76
+ * Added a fixed editor height.
77
+
78
  = 1.4.2 - 08 November 2021 =
79
  * Fixed string translation functions.
80
 
so-css.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: SiteOrigin CSS
4
  Description: An advanced CSS editor from SiteOrigin.
5
- Version: 1.4.2
6
  Author: SiteOrigin
7
  Author URI: https://siteorigin.com
8
  Plugin URI: https://siteorigin.com/css/
@@ -14,7 +14,7 @@ Text Domain: so-css
14
  // Handle the legacy CSS editor that came with SiteOrigin themes
15
  include plugin_dir_path( __FILE__ ) . 'inc/legacy.php';
16
 
17
- define( 'SOCSS_VERSION', '1.4.2' );
18
  define( 'SOCSS_JS_SUFFIX', '.min' );
19
 
20
  /**
2
  /*
3
  Plugin Name: SiteOrigin CSS
4
  Description: An advanced CSS editor from SiteOrigin.
5
+ Version: 1.4.3
6
  Author: SiteOrigin
7
  Author URI: https://siteorigin.com
8
  Plugin URI: https://siteorigin.com/css/
14
  // Handle the legacy CSS editor that came with SiteOrigin themes
15
  include plugin_dir_path( __FILE__ ) . 'inc/legacy.php';
16
 
17
+ define( 'SOCSS_VERSION', '1.4.3' );
18
  define( 'SOCSS_JS_SUFFIX', '.min' );
19
 
20
  /**
tpl/page.php CHANGED
@@ -44,7 +44,7 @@ if ( ! empty( $current_revision ) ) {
44
  <div class="postbox">
45
  <h3 class="hndle"><span><?php esc_html_e( 'Get The Full Experience', 'so-css' ); ?></span></h3>
46
  <div class="inside">
47
- <?php printf( esc_html__( '%sSiteOrigin Premium%s adds a <strong>Google Web Font</strong> selector to SiteOrigin CSS so you can easily change any font.', 'so-css' ) , '<a href="https://siteorigin.com/downloads/premium/?featured_addon=plugin/web-font-selector" target="_blank">', '</a>' ); ?>
48
  </div>
49
  </div>
50
  <?php endif; ?>
@@ -106,7 +106,11 @@ if ( ! empty( $current_revision ) ) {
106
  <textarea name="siteorigin_custom_css" id="custom-css-textarea" class="css-editor" rows="<?php echo max( 10, substr_count( $custom_css, "\n" ) + 1 ) ?>"><?php echo esc_textarea( $custom_css ) ?></textarea>
107
  <?php wp_nonce_field( 'custom_css', '_sononce' ) ?>
108
  </div>
109
- <p class="description"><?php esc_html_e( $editor_description ) ?></p>
 
 
 
 
110
 
111
  <div class="custom-css-preview">
112
 
44
  <div class="postbox">
45
  <h3 class="hndle"><span><?php esc_html_e( 'Get The Full Experience', 'so-css' ); ?></span></h3>
46
  <div class="inside">
47
+ <?php printf( wp_kses_post( __( '%sSiteOrigin Premium%s adds a <strong>Google Web Font</strong> selector to SiteOrigin CSS so you can easily change any font.', 'so-css' ) ), '<a href="https://siteorigin.com/downloads/premium/?featured_addon=plugin/web-font-selector" target="_blank">', '</a>' ); ?>
48
  </div>
49
  </div>
50
  <?php endif; ?>
106
  <textarea name="siteorigin_custom_css" id="custom-css-textarea" class="css-editor" rows="<?php echo max( 10, substr_count( $custom_css, "\n" ) + 1 ) ?>"><?php echo esc_textarea( $custom_css ) ?></textarea>
107
  <?php wp_nonce_field( 'custom_css', '_sononce' ) ?>
108
  </div>
109
+ <div class="so-css-footer">
110
+ <p class="description">
111
+ <?php esc_html_e( $editor_description ); ?>
112
+ </p>
113
+ </div>
114
 
115
  <div class="custom-css-preview">
116