SiteOrigin CSS - Version 1.2.3

Version Description

  • 25 June 2018 =
  • Add preview iframe 'load' event listener in render function.
  • Reverted change to stylesheet hook.
Download this release

Release Info

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

Code changes from version 1.2.1 to 1.2.3

Files changed (5) hide show
  1. js/editor.js +4 -3
  2. js/editor.min.js +1 -1
  3. lang/so-css.pot +19 -19
  4. readme.txt +9 -2
  5. so-css.php +7 -5
js/editor.js CHANGED
@@ -511,7 +511,6 @@
511
  currentUri: null,
512
 
513
  events: {
514
- 'load #preview-iframe': 'initPreview',
515
  'mouseleave #preview-iframe': 'clearHighlight',
516
  'keydown #preview-navigator input[type="text"]': 'reloadPreview',
517
  },
@@ -548,7 +547,10 @@
548
  this.$( '#preview-navigator input' ).val( this.currentUri.toString() );
549
  this.currentUri.addQuery( 'so_css_preview', 1 );
550
 
551
- this.$( '#preview-iframe' ).attr( 'src', this.currentUri.toString() );
 
 
 
552
  },
553
 
554
  initPreview: function () {
@@ -1814,6 +1816,5 @@ jQuery( function ( $ ) {
1814
  } );
1815
 
1816
  window.socss.mainEditor = editor;
1817
- window.socss.revisionsList = revisionsList;
1818
  $( socss ).trigger( 'initialized' );
1819
  } );
511
  currentUri: null,
512
 
513
  events: {
 
514
  'mouseleave #preview-iframe': 'clearHighlight',
515
  'keydown #preview-navigator input[type="text"]': 'reloadPreview',
516
  },
547
  this.$( '#preview-navigator input' ).val( this.currentUri.toString() );
548
  this.currentUri.addQuery( 'so_css_preview', 1 );
549
 
550
+ this.$( '#preview-iframe' )
551
+ .attr( 'src', this.currentUri.toString() )
552
+ // 'load' event doesn't bubble so can't be used in the events hash
553
+ .on( 'load', this.initPreview.bind( this ) );
554
  },
555
 
556
  initPreview: function () {
1816
  } );
1817
 
1818
  window.socss.mainEditor = editor;
 
1819
  $( socss ).trigger( 'initialized' );
1820
  } );
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":"triggerEvent"},triggerEvent:function(t){t.preventDefault();var i=e(t.currentTarget);i.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",submit:"onSubmit"},initialize:function(e){this.listenTo(this.model,"change:selectedPost",this.getSelectedPostCss),this.getSelectedPostCss().then(function(){e.openVisualEditor&&this.showVisualEditor()}.bind(this))},getSelectedPostCss:function(){var t,i=this.model.get("selectedPost");return t=i&&!i.has("css")?i.fetch():(new e.Deferred).resolve(),t.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(){this.registerCodeMirrorAutocomplete();var t=this.$("textarea.css-editor");this.initValue=t.val();var s=this.initValue.match(/\n/gm),r=(s&&s.length,this.initValue);t.val(r),this.codeMirror=CodeMirror.fromTextArea(t.get(0),{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"}}),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)),this.setupCodeMirrorExtensions()},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){function i(e){for(var t in e)a&&0!==t.lastIndexOf(a,0)||p.push(t)}var s=t.getCursor(),r=t.getTokenAt(s),o=CodeMirror.innerMode(t.getMode(),r.state);if("css"===o.mode.name){if("keyword"===r.type&&0==="!important".indexOf(r.string))return{list:["!important"],from:CodeMirror.Pos(s.line,r.start),to:CodeMirror.Pos(s.line,r.end)};var n=r.start,l=s.ch,a=r.string.slice(0,l-n);/[^\w$_-]/.test(a)&&(a="",n=l=s.ch);var c=CodeMirror.resolveMode("text/css"),p=[],d=o.state.state;if("top"===d){for(var h=t.getLine(s.line).trim(),u=this.cssSelectors,v=0;v<u.length;v++)-1!==u[v].selector.indexOf(h)&&p.push(u[v].selector);if(p.length)return{list:p,from:CodeMirror.Pos(s.line,0),to:CodeMirror.Pos(s.line,l)}}else if("pseudo"===d||"variable-3"===r.type?i(e):"block"===d||"maybeprop"===d?i(c.propertyKeywords):"prop"===d||"parens"===d||"at"===d||"params"===d?(i(c.valueKeywords),i(c.colorKeywords)):"media"!==d&&"media_parens"!==d||(i(c.mediaTypes),i(c.mediaFeatures)),p.length)return{list:p,from:CodeMirror.Pos(s.line,n),to:CodeMirror.Pos(s.line,l)}}}.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),r=s.substring(0,i.end);this.preview.highlight(r)}else this.preview.clearHighlight()}.bind(this)),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=e(window).outerHeight();if(this.$el.hasClass("expanded"))this.$el.find(".CodeMirror-scroll").css("max-height",""),this.codeMirror.setSize("100%",t-this.$(".custom-css-toolbar").outerHeight());else{var i=e("#so-custom-css-form"),s=e("#wpadminbar").outerHeight(!0)+e("#siteorigin-custom-css").find("> h2").outerHeight(!0)+i.find("> .custom-css-toolbar").outerHeight(!0)+i.find("> p.description").outerHeight(!0)+i.find("> p.submit").outerHeight(!0)+parseFloat(e("#wpbody-content").css("padding-bottom"));this.$el.find(".CodeMirror-scroll").css("max-height",t-s),this.codeMirror.setSize("100%","auto")}},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:{"load #preview-iframe":"initPreview","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())},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),t.contents().find("a").each(function(){var t=e(this).attr("href");if(void 0===t)return!0;var i=-1===t.indexOf("?")?"?":"&";e(this).attr("href",t+i+"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.blur(),alert(t.data("invalid-uri")),t.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).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.view.properties=Backbone.View.extend({tabTemplate:t.template('<li data-section="<%- id %>"><span class="fa fa-<%- 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 .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 r=i.propertyControllers;for(var o in r){var n=(e(this.tabTemplate({id:o,icon:r[o].icon,title:r[o].title})).appendTo(this.$(".section-tabs")),e(this.sectionTemplate({id:o})).appendTo(this.$(".sections")));if(!t.isEmpty(r[o].controllers))for(var l=0;l<r[o].controllers.length;l++){var a,c=e(this.controllerTemplate({title:r[o].controllers[l].title})).appendTo(n.find("tbody")),p=r[o].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).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,r=!0,o=!1,n=0;n<s.length;n++)if(s[n].property===e){r=!1;var l=s[n];l.value!==i&&(l.value=i,o=!0),t.isEmpty(l.value)&&s.splice(s.indexOf(l));break}r&&!t.isEmpty(i)&&(s.push({property:e,value:i,type:"declaration"}),o=!0),o&&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)},isVisible:function(){return this.$el.is(":visible")},loadCSS:function(i,s){this.css=i,this.parsed=this.parser.parse(i,{silent:!0});for(var r=this.parsed.stylesheet.rules,o=this.$(".toolbar select").empty(),n=0;n<r.length;n++){var l=r[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&&o.append(e("<option>").html(c+": "+p.selectors.join(",")).attr("val",c+": "+p.selectors.join(",")).data("selector",p))}else o.append(e("<option>").html(l.selectors.join(",")).attr("val",l.selectors.join(",")).data("selector",l))}void 0===s&&(s=o.find("option").eq(0).attr("val")),t.isEmpty(s)||o.val(s).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.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(){this.$el.append(e(this.template({}))),this.field=this.$("select"),this.field.append(e('<option value=""></option>').html(""));for(var t in 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);e('<div class="select-tab" data-value=""><span class="fa fa-circle-o"></span></div>').appendTo(t);for(var i in this.args.option_icons)e('<div class="select-tab"></div>').appendTo(t).append(e('<span class="fa"></span>').addClass("fa-"+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="fa fa-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).change(),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=function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},i=this.units.map(t),s=new RegExp("([0-9\\.\\-]+)("+i.join("|")+")?","i"),r=s.exec(e);return null===r?{value:"",unit:""}:{value:r[1],unit:void 0===r[2]?"":r[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),r=0;r<this.units.length;r++){var o=e("<li></li>").html(this.units[r]).data("unit",this.units[r]);"px"===this.units[r]&&o.addClass("active"),i.append(o)}this.field.on("measurement_refresh",function(){var i=this.parseUnits(this.field.val());t.val(i.value);var r=""===i.unit?"px":i.unit;this.$el.data("unit",r),s.html(r);var o=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(i.value).appendTo("body"),n=o.width();n=Math.min(n,63),o.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="fa fa-minus"></span></div>').appendTo(n),a=e('<div class="inc-button socss-button"><span class="fa fa-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 r=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(i.val()+s).appendTo("body"),o=r.width();o=Math.min(o,63),r.remove(),this.$(".units").css("left",o+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.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="fa fa-minus"></span></div>').appendTo(t),s=e('<div class="inc-button socss-button"><span class="fa fa-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.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.$(".select-tab").each(function(i,r){for(var o=e(r).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];if(s.view.properties.controllers[a.type],!0){var c="";c="all"===o?a.args.propertyAll:a.args.property.replace("{dir}",o);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 r=this.$(".sides .side");r.hide(),r.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").click(function(t){t.preventDefault(),e("#so-custom-css-getting-started").slideUp(),e.get(e(this).attr("href"))}),window.socss.mainEditor=s,window.socss.revisionsList=revisionsList,e(t).trigger("initialized")});
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":"triggerEvent"},triggerEvent:function(t){t.preventDefault();var i=e(t.currentTarget);i.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",submit:"onSubmit"},initialize:function(e){this.listenTo(this.model,"change:selectedPost",this.getSelectedPostCss),this.getSelectedPostCss().then(function(){e.openVisualEditor&&this.showVisualEditor()}.bind(this))},getSelectedPostCss:function(){var t,i=this.model.get("selectedPost");return t=i&&!i.has("css")?i.fetch():(new e.Deferred).resolve(),t.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(){this.registerCodeMirrorAutocomplete();var t=this.$("textarea.css-editor");this.initValue=t.val();var s=this.initValue.match(/\n/gm),r=(s&&s.length,this.initValue);t.val(r),this.codeMirror=CodeMirror.fromTextArea(t.get(0),{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"}}),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)),this.setupCodeMirrorExtensions()},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){function i(e){for(var t in e)a&&0!==t.lastIndexOf(a,0)||p.push(t)}var s=t.getCursor(),r=t.getTokenAt(s),o=CodeMirror.innerMode(t.getMode(),r.state);if("css"===o.mode.name){if("keyword"===r.type&&0==="!important".indexOf(r.string))return{list:["!important"],from:CodeMirror.Pos(s.line,r.start),to:CodeMirror.Pos(s.line,r.end)};var n=r.start,l=s.ch,a=r.string.slice(0,l-n);/[^\w$_-]/.test(a)&&(a="",n=l=s.ch);var c=CodeMirror.resolveMode("text/css"),p=[],d=o.state.state;if("top"===d){for(var h=t.getLine(s.line).trim(),u=this.cssSelectors,v=0;v<u.length;v++)-1!==u[v].selector.indexOf(h)&&p.push(u[v].selector);if(p.length)return{list:p,from:CodeMirror.Pos(s.line,0),to:CodeMirror.Pos(s.line,l)}}else if("pseudo"===d||"variable-3"===r.type?i(e):"block"===d||"maybeprop"===d?i(c.propertyKeywords):"prop"===d||"parens"===d||"at"===d||"params"===d?(i(c.valueKeywords),i(c.colorKeywords)):"media"!==d&&"media_parens"!==d||(i(c.mediaTypes),i(c.mediaFeatures)),p.length)return{list:p,from:CodeMirror.Pos(s.line,n),to:CodeMirror.Pos(s.line,l)}}}.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),r=s.substring(0,i.end);this.preview.highlight(r)}else this.preview.clearHighlight()}.bind(this)),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=e(window).outerHeight();if(this.$el.hasClass("expanded"))this.$el.find(".CodeMirror-scroll").css("max-height",""),this.codeMirror.setSize("100%",t-this.$(".custom-css-toolbar").outerHeight());else{var i=e("#so-custom-css-form"),s=e("#wpadminbar").outerHeight(!0)+e("#siteorigin-custom-css").find("> h2").outerHeight(!0)+i.find("> .custom-css-toolbar").outerHeight(!0)+i.find("> p.description").outerHeight(!0)+i.find("> p.submit").outerHeight(!0)+parseFloat(e("#wpbody-content").css("padding-bottom"));this.$el.find(".CodeMirror-scroll").css("max-height",t-s),this.codeMirror.setSize("100%","auto")}},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),t.contents().find("a").each(function(){var t=e(this).attr("href");if(void 0===t)return!0;var i=-1===t.indexOf("?")?"?":"&";e(this).attr("href",t+i+"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.blur(),alert(t.data("invalid-uri")),t.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).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.view.properties=Backbone.View.extend({tabTemplate:t.template('<li data-section="<%- id %>"><span class="fa fa-<%- 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 .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 r=i.propertyControllers;for(var o in r){var n=(e(this.tabTemplate({id:o,icon:r[o].icon,title:r[o].title})).appendTo(this.$(".section-tabs")),e(this.sectionTemplate({id:o})).appendTo(this.$(".sections")));if(!t.isEmpty(r[o].controllers))for(var l=0;l<r[o].controllers.length;l++){var a,c=e(this.controllerTemplate({title:r[o].controllers[l].title})).appendTo(n.find("tbody")),p=r[o].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).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,r=!0,o=!1,n=0;n<s.length;n++)if(s[n].property===e){r=!1;var l=s[n];l.value!==i&&(l.value=i,o=!0),t.isEmpty(l.value)&&s.splice(s.indexOf(l));break}r&&!t.isEmpty(i)&&(s.push({property:e,value:i,type:"declaration"}),o=!0),o&&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)},isVisible:function(){return this.$el.is(":visible")},loadCSS:function(i,s){this.css=i,this.parsed=this.parser.parse(i,{silent:!0});for(var r=this.parsed.stylesheet.rules,o=this.$(".toolbar select").empty(),n=0;n<r.length;n++){var l=r[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&&o.append(e("<option>").html(c+": "+p.selectors.join(",")).attr("val",c+": "+p.selectors.join(",")).data("selector",p))}else o.append(e("<option>").html(l.selectors.join(",")).attr("val",l.selectors.join(",")).data("selector",l))}void 0===s&&(s=o.find("option").eq(0).attr("val")),t.isEmpty(s)||o.val(s).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.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(){this.$el.append(e(this.template({}))),this.field=this.$("select"),this.field.append(e('<option value=""></option>').html(""));for(var t in 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);e('<div class="select-tab" data-value=""><span class="fa fa-circle-o"></span></div>').appendTo(t);for(var i in this.args.option_icons)e('<div class="select-tab"></div>').appendTo(t).append(e('<span class="fa"></span>').addClass("fa-"+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="fa fa-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).change(),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=function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},i=this.units.map(t),s=new RegExp("([0-9\\.\\-]+)("+i.join("|")+")?","i"),r=s.exec(e);return null===r?{value:"",unit:""}:{value:r[1],unit:void 0===r[2]?"":r[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),r=0;r<this.units.length;r++){var o=e("<li></li>").html(this.units[r]).data("unit",this.units[r]);"px"===this.units[r]&&o.addClass("active"),i.append(o)}this.field.on("measurement_refresh",function(){var i=this.parseUnits(this.field.val());t.val(i.value);var r=""===i.unit?"px":i.unit;this.$el.data("unit",r),s.html(r);var o=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(i.value).appendTo("body"),n=o.width();n=Math.min(n,63),o.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="fa fa-minus"></span></div>').appendTo(n),a=e('<div class="inc-button socss-button"><span class="fa fa-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 r=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(i.val()+s).appendTo("body"),o=r.width();o=Math.min(o,63),r.remove(),this.$(".units").css("left",o+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.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="fa fa-minus"></span></div>').appendTo(t),s=e('<div class="inc-button socss-button"><span class="fa fa-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.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.$(".select-tab").each(function(i,r){for(var o=e(r).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];if(s.view.properties.controllers[a.type],!0){var c="";c="all"===o?a.args.propertyAll:a.args.property.replace("{dir}",o);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 r=this.$(".sides .side");r.hide(),r.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").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")});
lang/so-css.pot CHANGED
@@ -409,79 +409,79 @@ msgstr ""
409
  msgid "Z-Index"
410
  msgstr ""
411
 
412
- #: tmp/so-css.php:521, tmp/so-css.php:521, tmp/so-css.php:583
413
  msgid "Custom CSS"
414
  msgstr ""
415
 
416
- #: tmp/so-css.php:587
417
  msgid "SiteOrigin CSS adds any custom CSS you enter here into your site's header. "
418
  msgstr ""
419
 
420
- #: tmp/so-css.php:589
421
  msgid "These changes will persist across updates so it's best to make all your changes here. "
422
  msgstr ""
423
 
424
- #: tmp/so-css.php:767
425
  msgid "Unchanged"
426
  msgstr ""
427
 
428
- #: tmp/so-css.php:769
429
  msgid "Select"
430
  msgstr ""
431
 
432
- #: tmp/so-css.php:771
433
  msgid "Select Image"
434
  msgstr ""
435
 
436
- #: tmp/so-css.php:773
437
  msgid "Are you sure you want to leave without saving?"
438
  msgstr ""
439
 
440
- #: tmp/so-css.php:841
441
  msgid "CSS Editor"
442
  msgstr ""
443
 
444
- #: tmp/so-css.php:843
445
  msgid "Support"
446
  msgstr ""
447
 
448
- #: tmp/so-css.php:865
449
  msgid "SiteOrigin CSS"
450
  msgstr ""
451
 
452
- #: tmp/so-css.php:871
453
  msgid "Changes apply to %s and its child themes"
454
  msgstr ""
455
 
456
- #: tmp/so-css.php:873
457
  msgid "Save CSS"
458
  msgstr ""
459
 
460
- #: tmp/so-css.php:887
461
  msgid "Editing CSS for: %s"
462
  msgstr ""
463
 
464
- #: tmp/so-css.php:897
465
  msgid "Changes apply to the %s %s when the current theme is %s or its child themes"
466
  msgstr ""
467
 
468
- #: tmp/so-css.php:911
469
  msgid "Save %s CSS"
470
  msgstr ""
471
 
472
- #: tmp/so-css.php:937
473
  msgid "Revert to this revision"
474
  msgstr ""
475
 
476
- #: tmp/so-css.php:1155
477
  msgid "%d chars"
478
  msgstr ""
479
 
480
- #: tmp/so-css.php:1155
481
  msgid "Latest"
482
  msgstr ""
483
 
484
- #: tmp/so-css.php:1167
485
  msgid "No revisions yet."
486
  msgstr ""
487
 
409
  msgid "Z-Index"
410
  msgstr ""
411
 
412
+ #: tmp/so-css.php:525, tmp/so-css.php:525, tmp/so-css.php:587
413
  msgid "Custom CSS"
414
  msgstr ""
415
 
416
+ #: tmp/so-css.php:591
417
  msgid "SiteOrigin CSS adds any custom CSS you enter here into your site's header. "
418
  msgstr ""
419
 
420
+ #: tmp/so-css.php:593
421
  msgid "These changes will persist across updates so it's best to make all your changes here. "
422
  msgstr ""
423
 
424
+ #: tmp/so-css.php:771
425
  msgid "Unchanged"
426
  msgstr ""
427
 
428
+ #: tmp/so-css.php:773
429
  msgid "Select"
430
  msgstr ""
431
 
432
+ #: tmp/so-css.php:775
433
  msgid "Select Image"
434
  msgstr ""
435
 
436
+ #: tmp/so-css.php:777
437
  msgid "Are you sure you want to leave without saving?"
438
  msgstr ""
439
 
440
+ #: tmp/so-css.php:845
441
  msgid "CSS Editor"
442
  msgstr ""
443
 
444
+ #: tmp/so-css.php:847
445
  msgid "Support"
446
  msgstr ""
447
 
448
+ #: tmp/so-css.php:869
449
  msgid "SiteOrigin CSS"
450
  msgstr ""
451
 
452
+ #: tmp/so-css.php:875
453
  msgid "Changes apply to %s and its child themes"
454
  msgstr ""
455
 
456
+ #: tmp/so-css.php:877
457
  msgid "Save CSS"
458
  msgstr ""
459
 
460
+ #: tmp/so-css.php:891
461
  msgid "Editing CSS for: %s"
462
  msgstr ""
463
 
464
+ #: tmp/so-css.php:901
465
  msgid "Changes apply to the %s %s when the current theme is %s or its child themes"
466
  msgstr ""
467
 
468
+ #: tmp/so-css.php:915
469
  msgid "Save %s CSS"
470
  msgstr ""
471
 
472
+ #: tmp/so-css.php:941
473
  msgid "Revert to this revision"
474
  msgstr ""
475
 
476
+ #: tmp/so-css.php:1159
477
  msgid "%d chars"
478
  msgstr ""
479
 
480
+ #: tmp/so-css.php:1159
481
  msgid "Latest"
482
  msgstr ""
483
 
484
+ #: tmp/so-css.php:1171
485
  msgid "No revisions yet."
486
  msgstr ""
487
 
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Tags: css, design, edit, customize
3
  Requires at least: 3.9
4
  Tested up to: 4.9
5
- Stable tag: 1.2.1
6
- Build time: 2018-06-15T09:33:41+02:00
7
  License: GPLv2 or later
8
  Contributors: gpriday
9
  Donate link: https://siteorigin.com/downloads/contribution/
@@ -65,6 +65,13 @@ We offer free support on the [SiteOrigin support forums](https://siteorigin.com/
65
 
66
  == Changelog ==
67
 
 
 
 
 
 
 
 
68
  = 1.2.1 - 15 June 2018 =
69
  * Removed `.min` suffix from new stylesheets for CodeMirror plugins.
70
 
2
  Tags: css, design, edit, customize
3
  Requires at least: 3.9
4
  Tested up to: 4.9
5
+ Stable tag: 1.2.3
6
+ Build time: 2018-06-25T09:47:44+02:00
7
  License: GPLv2 or later
8
  Contributors: gpriday
9
  Donate link: https://siteorigin.com/downloads/contribution/
65
 
66
  == Changelog ==
67
 
68
+ = 1.2.3 - 25 June 2018 =
69
+ * Add preview iframe 'load' event listener in `render` function.
70
+ * Reverted change to stylesheet hook.
71
+
72
+ = 1.2.2 - 16 June 2018 =
73
+ * Removed reference to non-existent view.
74
+
75
  = 1.2.1 - 15 June 2018 =
76
  * Removed `.min` suffix from new stylesheets for CodeMirror plugins.
77
 
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.2.1
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.2.1' );
18
  define( 'SOCSS_JS_SUFFIX', '.min' );
19
 
20
  /**
@@ -30,7 +30,9 @@ class SiteOrigin_CSS {
30
 
31
  // Main header actions
32
  add_action( 'plugins_loaded', array( $this, 'set_plugin_textdomain' ) );
33
- add_action( 'wp_head', array( $this, 'action_wp_head' ), 20 );
 
 
34
 
35
  // All the admin actions
36
  add_action( 'admin_menu', array( $this, 'action_admin_menu' ) );
@@ -204,9 +206,9 @@ class SiteOrigin_CSS {
204
  }
205
 
206
  /**
207
- * Display the custom CSS in the header.
208
  */
209
- function action_wp_head() {
210
 
211
  $this->enqueue_custom_css( $this->theme );
212
 
2
  /*
3
  Plugin Name: SiteOrigin CSS
4
  Description: An advanced CSS editor from SiteOrigin.
5
+ Version: 1.2.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.2.3' );
18
  define( 'SOCSS_JS_SUFFIX', '.min' );
19
 
20
  /**
30
 
31
  // Main header actions
32
  add_action( 'plugins_loaded', array( $this, 'set_plugin_textdomain' ) );
33
+
34
+ // Priority 20 is necessary to ensure our CSS takes precedence.
35
+ add_action( 'wp_head', array( $this, 'enqueue_css' ), 20 );
36
 
37
  // All the admin actions
38
  add_action( 'admin_menu', array( $this, 'action_admin_menu' ) );
206
  }
207
 
208
  /**
209
+ * Enqueue or print inline CSS.
210
  */
211
+ function enqueue_css() {
212
 
213
  $this->enqueue_custom_css( $this->theme );
214