Version Description
- 15 August 2016 =
- Fixed action link.
- Support for GlotPress.
- Removed unused code.
- Handling of @imports for future addons.
Download this release
Release Info
Developer | gpriday |
Plugin | SiteOrigin CSS |
Version | 1.0.8 |
Comparing to | |
See all releases |
Code changes from version 1.0.7 to 1.0.8
- inc/controller-config.php +2 -2
- js/css.js +4 -4
- js/css.min.js +1 -1
- js/editor.js +59 -2
- js/editor.min.js +1 -1
- readme.txt +8 -2
- so-css.php +17 -28
- tpl/page.php +16 -6
inc/controller-config.php
CHANGED
@@ -110,7 +110,7 @@ return array (
|
|
110 |
),
|
111 |
array(
|
112 |
'title' => __('Font Family', 'so-css'),
|
113 |
-
'type' => '
|
114 |
'args' => array(
|
115 |
'property' => 'font-family',
|
116 |
)
|
@@ -501,4 +501,4 @@ return array (
|
|
501 |
)
|
502 |
),
|
503 |
|
504 |
-
);
|
110 |
),
|
111 |
array(
|
112 |
'title' => __('Font Family', 'so-css'),
|
113 |
+
'type' => 'font_select',
|
114 |
'args' => array(
|
115 |
'property' => 'font-family',
|
116 |
)
|
501 |
)
|
502 |
),
|
503 |
|
504 |
+
);
|
js/css.js
CHANGED
@@ -240,7 +240,7 @@
|
|
240 |
}
|
241 |
|
242 |
}
|
243 |
-
if (found.length < 2) {
|
244 |
return found;
|
245 |
}
|
246 |
else {
|
@@ -279,8 +279,8 @@
|
|
279 |
}
|
280 |
|
281 |
var found = this.findBySelector(cssObjectArray, obj.selector); //found compressed
|
282 |
-
if ( found.length
|
283 |
-
compressed.
|
284 |
done[obj.selector] = true;
|
285 |
}
|
286 |
}
|
@@ -695,4 +695,4 @@
|
|
695 |
|
696 |
window.cssjs = fi;
|
697 |
|
698 |
-
})();
|
240 |
}
|
241 |
|
242 |
}
|
243 |
+
if (selector === '@imports' || found.length < 2) {
|
244 |
return found;
|
245 |
}
|
246 |
else {
|
279 |
}
|
280 |
|
281 |
var found = this.findBySelector(cssObjectArray, obj.selector); //found compressed
|
282 |
+
if ( found.length > 0 ) {
|
283 |
+
compressed = compressed.concat(found);
|
284 |
done[obj.selector] = true;
|
285 |
}
|
286 |
}
|
695 |
|
696 |
window.cssjs = fi;
|
697 |
|
698 |
+
})();
|
js/css.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
!function(e){"use strict";var t=function(){this.cssImportStatements=[],this.cssKeyframeStatements=[],this.cssRegex=new RegExp("([\\s\\S]*?){([\\s\\S]*?)}","gi"),this.cssMediaQueryRegex="((@media [\\s\\S]*?){([\\s\\S]*?}\\s*?)})",this.cssKeyframeRegex="((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})",this.combinedCSSRegex="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",this.cssCommentsRegex="(\\/\\*[\\s\\S]*?\\*\\/)",this.cssImportStatementRegex=new RegExp("@import .*?;","gi")};t.prototype.stripComments=function(e){var t=new RegExp(this.cssCommentsRegex,"gi");return e.replace(t,"")},t.prototype.parseCSS=function(e){if(void 0===e)return[];for(var t=[];;){var s=this.cssImportStatementRegex.exec(e);if(null===s)break;this.cssImportStatements.push(s[0]),t.push({selector:"@imports",type:"imports",styles:s[0]})}e=e.replace(this.cssImportStatementRegex,"");for(var r,i=new RegExp(this.cssKeyframeRegex,"gi");;){if(r=i.exec(e),null===r)break;t.push({selector:"@keyframes",type:"keyframes",styles:r[0]})}e=e.replace(i,"");for(var
|
1 |
+
!function(e){"use strict";var t=function(){this.cssImportStatements=[],this.cssKeyframeStatements=[],this.cssRegex=new RegExp("([\\s\\S]*?){([\\s\\S]*?)}","gi"),this.cssMediaQueryRegex="((@media [\\s\\S]*?){([\\s\\S]*?}\\s*?)})",this.cssKeyframeRegex="((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})",this.combinedCSSRegex="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",this.cssCommentsRegex="(\\/\\*[\\s\\S]*?\\*\\/)",this.cssImportStatementRegex=new RegExp("@import .*?;","gi")};t.prototype.stripComments=function(e){var t=new RegExp(this.cssCommentsRegex,"gi");return e.replace(t,"")},t.prototype.parseCSS=function(e){if(void 0===e)return[];for(var t=[];;){var s=this.cssImportStatementRegex.exec(e);if(null===s)break;this.cssImportStatements.push(s[0]),t.push({selector:"@imports",type:"imports",styles:s[0]})}e=e.replace(this.cssImportStatementRegex,"");for(var r,i=new RegExp(this.cssKeyframeRegex,"gi");;){if(r=i.exec(e),null===r)break;t.push({selector:"@keyframes",type:"keyframes",styles:r[0]})}e=e.replace(i,"");for(var o=new RegExp(this.combinedCSSRegex,"gi");;){if(r=o.exec(e),null===r)break;var n="";n=void 0===r[2]?r[5].split("\r\n").join("\n").trim():r[2].split("\r\n").join("\n").trim();var l=new RegExp(this.cssCommentsRegex,"gi"),p=l.exec(n);if(null!==p&&(n=n.replace(l,"").trim()),n=n.replace(/\n+/,"\n"),-1!==n.indexOf("@media")){var a={selector:n,type:"media",subStyles:this.parseCSS(r[3]+"\n}")};null!==p&&(a.comments=p[0]),t.push(a)}else{var c=this.parseRules(r[6]),u={selector:n,rules:c};"@font-face"===n&&(u.type="font-face"),null!==p&&(u.comments=p[0]),t.push(u)}}return t},t.prototype.parseRules=function(e){e=e.split("\r\n").join("\n");var t=[];e=e.split(";");for(var s=0;s<e.length;s++){var r=e[s];if(r=r.trim(),-1!==r.indexOf(":")){r=r.split(":");var i=r[0].trim(),o=r.slice(1).join(":").trim();t.push({directive:i,value:o})}else"base64,"===r.trim().substr(0,7)?t[t.length-1].value+=r.trim():r.length>0&&t.push({directive:"",value:r,defective:!0})}return t},t.prototype.findCorrespondingRule=function(e,t,s){void 0===s&&(s=!1);for(var r=!1,i=0;i<e.length&&(e[i].directive!=t||(r=e[i],s!==e[i].value));i++);return r},t.prototype.findBySelector=function(e,t,s){void 0===s&&(s=!1);for(var r=[],i=0;i<e.length;i++)s===!1?e[i].selector===t&&r.push(e[i]):-1!==e[i].selector.indexOf(t)&&r.push(e[i]);if("@imports"===t||r.length<2)return r;var o=r[0];for(i=1;i<r.length;i++)this.intelligentCSSPush([o],r[i]);return[o]},t.prototype.deleteBySelector=function(e,t){for(var s=[],r=0;r<e.length;r++)e[r].selector!==t&&s.push(e[r]);return s},t.prototype.compressCSS=function(e){for(var t=[],s={},r=0;r<e.length;r++){var i=e[r];if(s[i.selector]!==!0){var o=this.findBySelector(e,i.selector);o.length>0&&(t=t.concat(o),s[i.selector]=!0)}}return t},t.prototype.cssDiff=function(e,t){if(e.selector!==t.selector)return!1;if("media"===e.type||"media"===t.type)return!1;for(var s,r,i={selector:e.selector,rules:[]},o=0;o<e.rules.length;o++)s=e.rules[o],r=this.findCorrespondingRule(t.rules,s.directive,s.value),r===!1?i.rules.push(s):s.value!==r.value&&i.rules.push(s);for(var n=0;n<t.rules.length;n++)r=t.rules[n],s=this.findCorrespondingRule(e.rules,r.directive),s===!1&&(r.type="DELETED",i.rules.push(r));return 0===i.rules.length?!1:i},t.prototype.intelligentMerge=function(e,t,s){void 0===s&&(s=!1);for(var r=0;r<t.length;r++)this.intelligentCSSPush(e,t[r],s);for(r=0;r<e.length;r++){var i=e[r];"media"!==i.type&&"keyframes"!==i.type&&(i.rules=this.compactRules(i.rules))}},t.prototype.intelligentCSSPush=function(e,t,s){var r=(t.selector,!1);if(void 0===s&&(s=!1),s===!1){for(var i=0;i<e.length;i++)if(e[i].selector===t.selector){r=e[i];break}}else for(var o=e.length-1;o>-1;o--)if(e[o].selector===t.selector){r=e[o];break}if(r===!1)e.push(t);else if("media"!==t.type)for(var n=0;n<t.rules.length;n++){var l=t.rules[n],p=this.findCorrespondingRule(r.rules,l.directive);p===!1?r.rules.push(l):"DELETED"===l.type?p.type="DELETED":p.value=l.value}else r.subStyles=r.subStyles.concat(t.subStyles)},t.prototype.compactRules=function(e){for(var t=[],s=0;s<e.length;s++)"DELETED"!==e[s].type&&t.push(e[s]);return t},t.prototype.getCSSForEditor=function(e,t){void 0===t&&(t=0);var s="";void 0===e&&(e=this.css);for(var r=0;r<e.length;r++)"imports"===e[r].type&&(s+=e[r].styles+"\n\n");for(r=0;r<e.length;r++){var i=e[r];if(void 0!==i.selector){var o="";void 0!==i.comments&&(o=i.comments+"\n"),"media"===i.type?(s+=o+i.selector+"{\n",s+=this.getCSSForEditor(i.subStyles,t+1),s+="}\n\n"):"keyframes"!==i.type&&"imports"!==i.type&&(s+=this.getSpaces(t)+o+i.selector+" {\n",s+=this.getCSSOfRules(i.rules,t+1),s+=this.getSpaces(t)+"}\n\n")}}for(r=0;r<e.length;r++)"keyframes"===e[r].type&&(s+=e[r].styles+"\n\n");return s},t.prototype.getImports=function(e){for(var t=[],s=0;s<e.length;s++)"imports"===e[s].type&&t.push(e[s].styles);return t},t.prototype.getCSSOfRules=function(e,t){for(var s="",r=0;r<e.length;r++)void 0!==e[r]&&""!==e[r].value&&(s+=void 0===e[r].defective?this.getSpaces(t)+e[r].directive+": "+e[r].value+";\n":this.getSpaces(t)+e[r].value+";\n");return s||"\n"},t.prototype.getSpaces=function(e){for(var t="",s=0;2*e>s;s++)t+=" ";return t},t.prototype.applyNamespacing=function(e,t){var s=e,r="."+this.cssPreviewNamespace;void 0!==t&&(r=t),"string"==typeof e&&(s=this.parseCSS(e));for(var i=0;i<s.length;i++){var o=s[i];if(!(o.selector.indexOf("@font-face")>-1||o.selector.indexOf("keyframes")>-1||o.selector.indexOf("@import")>-1||o.selector.indexOf(".form-all")>-1||o.selector.indexOf("#stage")>-1))if("media"!==o.type){for(var n=o.selector.split(","),l=[],p=0;p<n.length;p++)-1===n[p].indexOf(".supernova")?l.push(r+" "+n[p]):l.push(n[p]);o.selector=l.join(",")}else o.subStyles=this.applyNamespacing(o.subStyles,t)}return s},t.prototype.clearNamespacing=function(e,t){void 0===t&&(t=!1);var s=e,r="."+this.cssPreviewNamespace;"string"==typeof e&&(s=this.parseCSS(e));for(var i=0;i<s.length;i++){var o=s[i];if("media"!==o.type){for(var n=o.selector.split(","),l=[],p=0;p<n.length;p++)l.push(n[p].split(r+" ").join(""));o.selector=l.join(",")}else o.subStyles=this.clearNamespacing(o.subStyles,!0)}return t===!1?this.getCSSForEditor(s):s},t.prototype.createStyleElement=function(e,t,s){if(void 0===s&&(s=!1),this.testMode===!1&&"nonamespace"!==s&&(t=this.applyNamespacing(t)),"string"!=typeof t&&(t=this.getCSSForEditor(t)),s===!0&&(t=this.getCSSForEditor(this.parseCSS(t))),this.testMode!==!1)return this.testMode("create style #"+e,t);var r=document.getElementById(e);r&&r.parentNode.removeChild(r);var i=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.id=e,o.type="text/css",i.appendChild(o),o.styleSheet&&!o.sheet?o.styleSheet.cssText=t:o.appendChild(document.createTextNode(t))},window.cssjs=t}();
|
js/editor.js
CHANGED
@@ -669,6 +669,12 @@
|
|
669 |
*/
|
670 |
render: function () {
|
671 |
var thisView = this;
|
|
|
|
|
|
|
|
|
|
|
|
|
672 |
|
673 |
var controllers = socssOptions.propertyControllers;
|
674 |
|
@@ -769,6 +775,50 @@
|
|
769 |
this.updateMainEditor( false );
|
770 |
},
|
771 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
772 |
/**
|
773 |
* Get the rule value for the active selector
|
774 |
* @param rule
|
@@ -852,7 +902,12 @@
|
|
852 |
var dropdown = this.$('.toolbar select').empty();
|
853 |
for (var i = 0; i < this.parsed.length; i++) {
|
854 |
var rule = this.parsed[i];
|
855 |
-
|
|
|
|
|
|
|
|
|
|
|
856 |
if( typeof rule.subStyles !== 'undefined' ) {
|
857 |
|
858 |
for (var j = 0; j < rule.subStyles.length; j++) {
|
@@ -879,7 +934,9 @@
|
|
879 |
if (typeof activeSelector === 'undefined') {
|
880 |
activeSelector = dropdown.find('option').eq(0).attr('val');
|
881 |
}
|
882 |
-
|
|
|
|
|
883 |
},
|
884 |
|
885 |
/**
|
669 |
*/
|
670 |
render: function () {
|
671 |
var thisView = this;
|
672 |
+
|
673 |
+
// Clean up for potential re-renders
|
674 |
+
this.$('.section-tabs').empty();
|
675 |
+
this.$('.sections').empty();
|
676 |
+
this.$('.toolbar select').off();
|
677 |
+
thisView.propertyControllers = [];
|
678 |
|
679 |
var controllers = socssOptions.propertyControllers;
|
680 |
|
775 |
this.updateMainEditor( false );
|
776 |
},
|
777 |
|
778 |
+
/**
|
779 |
+
* Adds the @import rule value if it doesn't already exist.
|
780 |
+
*
|
781 |
+
* @param atRule
|
782 |
+
* @param value
|
783 |
+
*/
|
784 |
+
addImport: function (value) {
|
785 |
+
|
786 |
+
// get @import rules
|
787 |
+
// check if any have the same value
|
788 |
+
// if not, then add the new @ rule
|
789 |
+
|
790 |
+
var importRules = _.filter( this.parsed, function ( selector ) {
|
791 |
+
return selector.selector.startsWith('@import');
|
792 |
+
} );
|
793 |
+
var exists = _.any( importRules, function ( rule ) {
|
794 |
+
return rule.styles === value;
|
795 |
+
} );
|
796 |
+
|
797 |
+
if ( !exists ) {
|
798 |
+
var newRule = {
|
799 |
+
selector: '@imports',
|
800 |
+
styles: value,
|
801 |
+
type: 'imports'
|
802 |
+
};
|
803 |
+
// Add it to the top! @import statements must precede other rule types.
|
804 |
+
this.parsed.unshift( newRule );
|
805 |
+
}
|
806 |
+
|
807 |
+
this.updateMainEditor( false );
|
808 |
+
},
|
809 |
+
|
810 |
+
/**
|
811 |
+
* Find @import which completely or partially contains the specified value.
|
812 |
+
*
|
813 |
+
* @param value
|
814 |
+
*/
|
815 |
+
findImport: function(value) {
|
816 |
+
|
817 |
+
return _.find( this.parsed, function ( selector ) {
|
818 |
+
return selector.selector.startsWith('@import') && selector.styles.indexOf(value) > -1;
|
819 |
+
} );
|
820 |
+
},
|
821 |
+
|
822 |
/**
|
823 |
* Get the rule value for the active selector
|
824 |
* @param rule
|
902 |
var dropdown = this.$('.toolbar select').empty();
|
903 |
for (var i = 0; i < this.parsed.length; i++) {
|
904 |
var rule = this.parsed[i];
|
905 |
+
|
906 |
+
// Exclude @imports statements
|
907 |
+
if(rule.type === 'imports') {
|
908 |
+
continue;
|
909 |
+
}
|
910 |
+
|
911 |
if( typeof rule.subStyles !== 'undefined' ) {
|
912 |
|
913 |
for (var j = 0; j < rule.subStyles.length; j++) {
|
934 |
if (typeof activeSelector === 'undefined') {
|
935 |
activeSelector = dropdown.find('option').eq(0).attr('val');
|
936 |
}
|
937 |
+
if(!_.isEmpty(activeSelector)) {
|
938 |
+
dropdown.val(activeSelector).change();
|
939 |
+
}
|
940 |
},
|
941 |
|
942 |
/**
|
js/editor.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
!function(e,t,i){var s={model:{},collection:{},view:{},fn:{}};window.socss=s,s.view.toolbar=Backbone.View.extend({button:t.template('<li><a href="#" class="toolbar-button socss-button"><%= text %></a></li>'),editor:null,initialize:function(t){this.editor=t.editor;var i=this;this.$(".editor-expand").click(function(t){t.preventDefault(),e(this).blur(),i.trigger("click_expand")}),this.$(".editor-visual").click(function(t){t.preventDefault(),e(this).blur(),i.trigger("click_visual")})},addButton:function(t,i){var s=this,n=e(this.button({text:t})).appendTo(this.$(".toolbar-function-buttons .toolbar-buttons")).click(function(t){t.preventDefault(),e(this).blur(),s.trigger("click_"+i)});return n}}),s.view.editor=Backbone.View.extend({codeMirror:null,snippets:null,toolbar:null,visualProperties:null,inspector:null,cssSelectors:[],initialize:function(e){this.setupEditor()},render:function(){var t=this;this.toolbar=new s.view.toolbar({editor:this,el:this.$(".custom-css-toolbar")}),this.toolbar.editor=this,this.toolbar.render(),this.visualProperties=new s.view.properties({editor:this,el:e("#so-custom-css-properties")}),this.visualProperties.render(),this.toolbar.on("click_expand",function(){t.toggleExpand()}),this.toolbar.on("click_visual",function(){t.visualProperties.loadCSS(t.codeMirror.getValue().trim()),t.visualProperties.show()}),this.preview=new s.view.preview({editor:this,el:this.$(".custom-css-preview")}),this.preview.render()},setupEditor:function(){var t=this;this.registerCodeMirrorAutocomplete();for(var s=this.$("textarea.css-editor"),n=s.val(),r=n.match(/\n/gm),o=r?r.length+1:1,a=15-o,l=n,c=0;a>c;c++)l+="\n";s.val(l),this.codeMirror=CodeMirror.fromTextArea(s.get(0),{tabSize:2,lineNumbers:!0,mode:"css",theme:"neat",inputStyle:"contenteditable",gutters:["CodeMirror-lint-markers"],lint:!0}),this.$el.on("submit",function(){n=t.codeMirror.getValue().trim()}),e(window).bind("beforeunload",function(){var e=t.codeMirror.getValue().trim();return e!==n?i.loc.leave:void 0}),this.$el.find(".custom-css-container").css("overflow","visible"),this.scaleEditor(),e(window).resize(function(){t.scaleEditor()}),this.setupCodeMirrorExtensions()},registerCodeMirrorAutocomplete:function(){var e=this,t={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(i){function s(e){for(var t in e)c&&0!==t.lastIndexOf(c,0)||p.push(t)}var n=i.getCursor(),r=i.getTokenAt(n),o=CodeMirror.innerMode(i.getMode(),r.state);if("css"===o.mode.name){if("keyword"===r.type&&0==="!important".indexOf(r.string))return{list:["!important"],from:CodeMirror.Pos(n.line,r.start),to:CodeMirror.Pos(n.line,r.end)};var a=r.start,l=n.ch,c=r.string.slice(0,l-a);/[^\w$_-]/.test(c)&&(c="",a=l=n.ch);var d=CodeMirror.resolveMode("text/css"),p=[],h=o.state.state;if("top"===h){for(var u=i.getLine(n.line).trim(),v=e.cssSelectors,f=0;f<v.length;f++)-1!==v[f].selector.indexOf(u)&&p.push(v[f].selector);if(p.length)return{list:p,from:CodeMirror.Pos(n.line,0),to:CodeMirror.Pos(n.line,l)}}else if("pseudo"===h||"variable-3"===r.type?s(t):"block"===h||"maybeprop"===h?s(d.propertyKeywords):"prop"===h||"parens"===h||"at"===h||"params"===h?(s(d.valueKeywords),s(d.colorKeywords)):("media"===h||"media_parens"===h)&&(s(d.mediaTypes),s(d.mediaFeatures)),p.length)return{list:p,from:CodeMirror.Pos(n.line,a),to:CodeMirror.Pos(n.line,l)}}})},setupCodeMirrorExtensions:function(){var e=this;this.codeMirror.on("cursorActivity",function(t){var i=t.getCursor(),s=t.getTokenAt(i);CodeMirror.innerMode(t.getMode(),s.state);if("qualifier"===s.type||"tag"===s.type||"builtin"===s.type){var n=t.getLine(i.line),r=n.substring(0,s.end);e.preview.highlight(r)}else e.preview.clearHighlight()}),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(){this.$el.hasClass("expanded")?this.codeMirror.setSize("100%",e(window).outerHeight()-this.$(".custom-css-toolbar").outerHeight()):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()},setSnippets:function(e){if(!t.isEmpty(e)){var i=this;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(){i.snippets.show()})}},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){var t=this;this.inspector=e,this.cssSelectors=e.pageSelectors,e.on("click_selector",function(e){t.visualProperties.isVisible()?t.visualProperties.addSelector(e):t.addEmptySelector(e)}),e.on("click_property",function(e){t.visualProperties.isVisible()||t.codeMirror.replaceSelection(e+";\n ")}),e.on("set_active_element",function(e,i){t.visualProperties.isVisible()&&i.length&&t.visualProperties.addSelector(i[0].selector)})}}),s.view.preview=Backbone.View.extend({template:t.template('<iframe class="preview-iframe" seamless="seamless"></iframe>'),editor:null,initialize:function(e){this.editor=e.editor;var t=this;this.editor.codeMirror.on("change",function(e,i){t.updatePreviewCss()})},render:function(){var t=this;this.$el.html(this.template()),this.$(".preview-iframe").attr("src",i.homeURL).load(function(){var i=e(this);i.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")}),t.updatePreviewCss()}).mouseleave(function(){t.clearHighlight()})},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(t){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"},currentSnippet:null,initialize:function(e){this.snippets=e.snippets},render:function(){var t=this,i=function(i){i.preventDefault();var s=e(this);t.$(".snippets li.snippet").removeClass("active"),e(this).addClass("active"),t.viewSnippet({name:s.html(),description:s.data("description"),css:s.data("css")})};this.$el.html(this.template());for(var s=0;s<this.snippets.length;s++)e(this.snippet({name:this.snippets[s].Name})).data({description:this.snippets[s].Description,css:this.snippets[s].css}).appendTo(this.$("ul.snippets")).click(i);return t.$(".snippets li.snippet").eq(0).click(),this.attach(),this},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({model:s.model.cssRules,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"},initialize:function(e){this.parser=new cssjs,this.editor=e.editor},render:function(){var n=this,r=i.propertyControllers;for(var o in r){var a=(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 c,d=e(n.controllerTemplate({title:r[o].controllers[l].title})).appendTo(a.find("tbody")),p=r[o].controllers[l];c="undefined"==typeof s.view.properties.controllers[p.type]?new s.view.propertyController({el:d.find("td"),propertiesView:n,args:"undefined"==typeof p.args?{}:p.args}):new s.view.properties.controllers[p.type]({el:d.find("td"),propertiesView:n,args:"undefined"==typeof p.args?{}:p.args}),n.propertyControllers.push(c),c.render(),c.initChangeEvents()}}this.$(".section-tabs li").click(function(){var t=e(this),i=n.$('.sections .section[data-section="'+t.data("section")+'"]');n.$(".sections .section").not(i).hide().removeClass("active"),i.show().addClass("active"),n.$(".section-tabs li").not(t).removeClass("active"),t.addClass("active")}).eq(0).click(),this.$(".toolbar select").change(function(){n.setActivateSelector(e(this).find(":selected").data("selector"))})},setRuleValue:function(e,t){if("undefined"!=typeof this.activeSelector&&"undefined"!=typeof this.activeSelector.rules){for(var i=!0,s=0;s<this.activeSelector.rules.length;s++)if(this.activeSelector.rules[s].directive===e){this.activeSelector.rules[s].value=t,i=!1;break}i&&this.activeSelector.rules.push({directive:e,value:t}),this.updateMainEditor(!1)}},getRuleValue:function(e){if("undefined"==typeof this.activeSelector||"undefined"==typeof this.activeSelector.rules)return"";for(var t=0;t<this.activeSelector.rules.length;t++)if(this.activeSelector.rules[t].directive===e)return this.activeSelector.rules[t].value;return""},updateMainEditor:function(e){var t;"undefined"==typeof e||e===!0?(t=this.parser.compressCSS(this.parsed),t=t.filter(function(e){return"undefined"!=typeof e.type||e.rules.length>0})):t=this.parsed,this.editor.codeMirror.setValue(this.parser.getCSSForEditor(t).trim())},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(t,i){this.css=t,this.parsed=this.parser.compressCSS(this.parser.parseCSS(t));for(var s=this.$(".toolbar select").empty(),n=0;n<this.parsed.length;n++){var r=this.parsed[n];if("undefined"!=typeof r.subStyles)for(var o=0;o<r.subStyles.length;o++){var a=r.subStyles[o];s.append(e("<option>").html(r.selector+": "+a.selector).attr("val",r.selector+": "+a.selector).data("selector",a))}else s.append(e("<option>").html(r.selector).attr("val",r.selector).data("selector",r))}"undefined"==typeof i&&(i=s.find("option").eq(0).attr("val")),s.val(i).change()},setActivateSelector: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="" />'),activeRule:null,args:null,propertiesView:null,initialize:function(e){this.args=e.args,this.propertiesView=e.propertiesView,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")},initChangeEvents:function(){var t=this;this.field.on("change keyup",function(){t.trigger("change",e(this).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({template:t.template('<input type="text" value="" />'),render:function(){this.$el.append(e(this.template({}))),this.field=this.$el.find("input"),this.field.minicolors({})},initChangeEvents:function(){var e=this;this.field.on("change keyup",function(){e.trigger("change",e.field.minicolors("value"))})},getValue:function(){return this.field.minicolors("value")},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></select>"),render:function(){this.$el.append(e(this.template({}))),this.field=this.$el.find("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]));"undefined"!=typeof this.args.option_icons&&this.setupVisualSelect()},setupVisualSelect:function(){var t=this;this.field.hide();var i=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(i);for(var s in this.args.option_icons)e('<div class="select-tab"></div>').appendTo(i).append(e('<span class="fa"></span>').addClass("fa-"+this.args.option_icons[s])).attr("data-value",s);i.find(".select-tab").css("width",100/i.find(">div").length+"%").click(function(){var s=e(this);i.find(".select-tab").removeClass("active"),s.addClass("active"),t.field.val(s.data("value")).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>'),render:function(){var t=this;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.$(".select").click(function(){t.media.open()}),this.media.on("select",function(){var e=this.state().get("selection").first().attributes,i=t.args.value.replace("{{url}}",e.url);t.field.val(i).change(),t.media.close()},this.media)}}),s.view.properties.controllers.measurement=s.view.propertyController.extend({wrapperClass:"socss-field-measurement",render:function(){this.$el.append(e(this.template({}))),this.field=this.$("input"),this.setupMeasurementField(this.field,{})},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"),n=s.exec(e);return null===n?{value:"",unit:""}:{value:n[1],unit:void 0===n[2]?"":n[2]}},setupMeasurementField:function(i,s){var n=this,r=i.parent();s=t.extend({defaultUnit:"px"},s),i.hide(),r.addClass(this.wrapperClass).data("unit",s.defaultUnit);for(var o=e('<input type="text" class="socss-field-input"/>').appendTo(r),a=e('<span class="dashicons dashicons-arrow-down"></span>').appendTo(r),l=e('<ul class="dropdown"></ul>').appendTo(r),c=e('<span class="units"></span>').html(s.defaultUnit).appendTo(r),d=0;d<n.units.length;d++){var p=e("<li></li>").html(n.units[d]).data("unit",n.units[d]);n.units[d]===s.defaultUnit&&p.addClass("active"),l.append(p)}var h=function(){var e=n.parseUnits(o.val());""!==e.unit&&e.unit!==r.data("unit")&&(o.val(e.value),u(e.unit)),""===e.value?i.val(""):i.val(e.value+r.data("unit"))},u=function(e){c.html(e),r.data("unit",e),o.trigger("keydown")};a.click(function(){l.toggle()}),l.find("li").click(function(){l.toggle(),u(e(this).data("unit")),h(),i.trigger("change")}),o.on("keyup keydown",function(t){var i=(e(this),"");"keydown"===t.type&&(t.keyCode>=48&&t.keyCode<=57?i=String.fromCharCode(t.keyCode):189===t.keyCode?i="-":190===t.keyCode&&(i="."));var s=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(o.val()+i).appendTo("body"),n=s.width();n=Math.min(n,63),s.remove(),c.css("left",n+12)}),o.on("keyup",function(e){h(),i.trigger("change")}),i.on("measurement_refresh",function(){var t=n.parseUnits(i.val());o.val(t.value);var a=""===t.unit?s.defaultUnit:t.unit;r.data("unit",a),c.html(a);var l=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(t.value).appendTo("body"),d=l.width();d=Math.min(d,63),l.remove(),c.css("left",d+12)});var v=e('<div class="socss-diw"></div>').appendTo(r),f=e('<div class="dec-button socss-button"><span class="fa fa-minus"></span></div>').appendTo(v),m=e('<div class="inc-button socss-button"><span class="fa fa-plus"></span></div>').appendTo(v);m.click(function(){var e=n.parseUnits(i.val());if(""===e.value)return!0;var t=Math.ceil(1.05*e.value);o.val(t),h(),i.trigger("change").trigger("measurement_refresh")}),f.click(function(){var e=n.parseUnits(i.val());if(""===e.value)return!0;var t=Math.floor(e.value/1.05);o.val(t),h(),i.trigger("change").trigger("measurement_refresh")})}}),s.view.properties.controllers.number=s.view.propertyController.extend({render:function(){this.$el.append(e(this.template({}))),this.field=this.$("input"),this.setupNumberField(this.field,this.args)},setupNumberField:function(i,s){s=t.extend({change:null,"default":0,increment:1,decrement:-1,max:null,min:null},s);var n=i.parent();n.addClass("socss-field-number");var r=e('<div class="socss-diw"></div>').appendTo(n),o=e('<div class="dec-button socss-button">-</div>').appendTo(r);e('<div class="inc-button socss-button">+</div>').appendTo(r);return r.find("> div").click(function(t){t.preventDefault();var n=s["default"];""!==i.val()&&(n=Number(i.val())),n+=e(this).is(o)?s.decrement:s.increment,n=Math.round(100*n)/100,null!==s.max&&(n=Math.min(s.max,n)),null!==s.min&&(n=Math.max(s.min,n)),i.val(n),i.trigger("change")}),this}}),s.view.properties.controllers.sides=s.view.propertyController.extend({template:t.template(e("#template-sides-field").html().trim()),controllers:[],render:function(){var i=this;this.$el.append(e(this.template({}))),this.field=this.$el.find("input"),i.args.hasAll||(this.$(".select-tab").eq(0).remove(),this.$(".select-tab").css("width","25%")),this.$(".select-tab").each(function(){for(var n=e(this).data("direction"),r=e('<li class="side">').appendTo(i.$(".sides")).hide(),o=0;o<i.args.controllers.length;o++){var a=i.args.controllers[o],l="";l="all"===n?a.args.propertyAll:a.args.property.replace("{dir}",n);var c=t.extend({},a.args,{property:l}),d=new s.view.properties.controllers[a.type]({el:e("<div>").appendTo(r),propertiesView:i.propertiesView,args:c});d.render(),d.initChangeEvents(),i.propertiesView.propertyControllers.push(d)}e(this).on("click",function(){i.$(".select-tab").removeClass("active"),e(this).addClass("active"),i.$(".sides .side").hide(),r.show()})}),this.$(".select-tab").eq(0).click()}})}(jQuery,_,socssOptions),jQuery(function(e){var t=window.socss,i=new t.view.editor({el:e("#so-custom-css-form").get(0)});i.render(),i.setSnippets(socssOptions.snippets),window.socss.mainEditor=i,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"))})});
|
1 |
+
!function(e,t,i){var s={model:{},collection:{},view:{},fn:{}};window.socss=s,s.view.toolbar=Backbone.View.extend({button:t.template('<li><a href="#" class="toolbar-button socss-button"><%= text %></a></li>'),editor:null,initialize:function(t){this.editor=t.editor;var i=this;this.$(".editor-expand").click(function(t){t.preventDefault(),e(this).blur(),i.trigger("click_expand")}),this.$(".editor-visual").click(function(t){t.preventDefault(),e(this).blur(),i.trigger("click_visual")})},addButton:function(t,i){var s=this,r=e(this.button({text:t})).appendTo(this.$(".toolbar-function-buttons .toolbar-buttons")).click(function(t){t.preventDefault(),e(this).blur(),s.trigger("click_"+i)});return r}}),s.view.editor=Backbone.View.extend({codeMirror:null,snippets:null,toolbar:null,visualProperties:null,inspector:null,cssSelectors:[],initialize:function(e){this.setupEditor()},render:function(){var t=this;this.toolbar=new s.view.toolbar({editor:this,el:this.$(".custom-css-toolbar")}),this.toolbar.editor=this,this.toolbar.render(),this.visualProperties=new s.view.properties({editor:this,el:e("#so-custom-css-properties")}),this.visualProperties.render(),this.toolbar.on("click_expand",function(){t.toggleExpand()}),this.toolbar.on("click_visual",function(){t.visualProperties.loadCSS(t.codeMirror.getValue().trim()),t.visualProperties.show()}),this.preview=new s.view.preview({editor:this,el:this.$(".custom-css-preview")}),this.preview.render()},setupEditor:function(){var t=this;this.registerCodeMirrorAutocomplete();for(var s=this.$("textarea.css-editor"),r=s.val(),n=r.match(/\n/gm),o=n?n.length+1:1,a=15-o,l=r,c=0;a>c;c++)l+="\n";s.val(l),this.codeMirror=CodeMirror.fromTextArea(s.get(0),{tabSize:2,lineNumbers:!0,mode:"css",theme:"neat",inputStyle:"contenteditable",gutters:["CodeMirror-lint-markers"],lint:!0}),this.$el.on("submit",function(){r=t.codeMirror.getValue().trim()}),e(window).bind("beforeunload",function(){var e=t.codeMirror.getValue().trim();return e!==r?i.loc.leave:void 0}),this.$el.find(".custom-css-container").css("overflow","visible"),this.scaleEditor(),e(window).resize(function(){t.scaleEditor()}),this.setupCodeMirrorExtensions()},registerCodeMirrorAutocomplete:function(){var e=this,t={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(i){function s(e){for(var t in e)c&&0!==t.lastIndexOf(c,0)||p.push(t)}var r=i.getCursor(),n=i.getTokenAt(r),o=CodeMirror.innerMode(i.getMode(),n.state);if("css"===o.mode.name){if("keyword"===n.type&&0==="!important".indexOf(n.string))return{list:["!important"],from:CodeMirror.Pos(r.line,n.start),to:CodeMirror.Pos(r.line,n.end)};var a=n.start,l=r.ch,c=n.string.slice(0,l-a);/[^\w$_-]/.test(c)&&(c="",a=l=r.ch);var d=CodeMirror.resolveMode("text/css"),p=[],h=o.state.state;if("top"===h){for(var u=i.getLine(r.line).trim(),f=e.cssSelectors,v=0;v<f.length;v++)-1!==f[v].selector.indexOf(u)&&p.push(f[v].selector);if(p.length)return{list:p,from:CodeMirror.Pos(r.line,0),to:CodeMirror.Pos(r.line,l)}}else if("pseudo"===h||"variable-3"===n.type?s(t):"block"===h||"maybeprop"===h?s(d.propertyKeywords):"prop"===h||"parens"===h||"at"===h||"params"===h?(s(d.valueKeywords),s(d.colorKeywords)):("media"===h||"media_parens"===h)&&(s(d.mediaTypes),s(d.mediaFeatures)),p.length)return{list:p,from:CodeMirror.Pos(r.line,a),to:CodeMirror.Pos(r.line,l)}}})},setupCodeMirrorExtensions:function(){var e=this;this.codeMirror.on("cursorActivity",function(t){var i=t.getCursor(),s=t.getTokenAt(i);CodeMirror.innerMode(t.getMode(),s.state);if("qualifier"===s.type||"tag"===s.type||"builtin"===s.type){var r=t.getLine(i.line),n=r.substring(0,s.end);e.preview.highlight(n)}else e.preview.clearHighlight()}),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(){this.$el.hasClass("expanded")?this.codeMirror.setSize("100%",e(window).outerHeight()-this.$(".custom-css-toolbar").outerHeight()):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()},setSnippets:function(e){if(!t.isEmpty(e)){var i=this;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(){i.snippets.show()})}},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){var t=this;this.inspector=e,this.cssSelectors=e.pageSelectors,e.on("click_selector",function(e){t.visualProperties.isVisible()?t.visualProperties.addSelector(e):t.addEmptySelector(e)}),e.on("click_property",function(e){t.visualProperties.isVisible()||t.codeMirror.replaceSelection(e+";\n ")}),e.on("set_active_element",function(e,i){t.visualProperties.isVisible()&&i.length&&t.visualProperties.addSelector(i[0].selector)})}}),s.view.preview=Backbone.View.extend({template:t.template('<iframe class="preview-iframe" seamless="seamless"></iframe>'),editor:null,initialize:function(e){this.editor=e.editor;var t=this;this.editor.codeMirror.on("change",function(e,i){t.updatePreviewCss()})},render:function(){var t=this;this.$el.html(this.template()),this.$(".preview-iframe").attr("src",i.homeURL).load(function(){var i=e(this);i.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")}),t.updatePreviewCss()}).mouseleave(function(){t.clearHighlight()})},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(t){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"},currentSnippet:null,initialize:function(e){this.snippets=e.snippets},render:function(){var t=this,i=function(i){i.preventDefault();var s=e(this);t.$(".snippets li.snippet").removeClass("active"),e(this).addClass("active"),t.viewSnippet({name:s.html(),description:s.data("description"),css:s.data("css")})};this.$el.html(this.template());for(var s=0;s<this.snippets.length;s++)e(this.snippet({name:this.snippets[s].Name})).data({description:this.snippets[s].Description,css:this.snippets[s].css}).appendTo(this.$("ul.snippets")).click(i);return t.$(".snippets li.snippet").eq(0).click(),this.attach(),this},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({model:s.model.cssRules,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"},initialize:function(e){this.parser=new cssjs,this.editor=e.editor},render:function(){var r=this;this.$(".section-tabs").empty(),this.$(".sections").empty(),this.$(".toolbar select").off(),r.propertyControllers=[];var n=i.propertyControllers;for(var o in n){var a=(e(this.tabTemplate({id:o,icon:n[o].icon,title:n[o].title})).appendTo(this.$(".section-tabs")),e(this.sectionTemplate({id:o})).appendTo(this.$(".sections")));if(!t.isEmpty(n[o].controllers))for(var l=0;l<n[o].controllers.length;l++){var c,d=e(r.controllerTemplate({title:n[o].controllers[l].title})).appendTo(a.find("tbody")),p=n[o].controllers[l];c="undefined"==typeof s.view.properties.controllers[p.type]?new s.view.propertyController({el:d.find("td"),propertiesView:r,args:"undefined"==typeof p.args?{}:p.args}):new s.view.properties.controllers[p.type]({el:d.find("td"),propertiesView:r,args:"undefined"==typeof p.args?{}:p.args}),r.propertyControllers.push(c),c.render(),c.initChangeEvents()}}this.$(".section-tabs li").click(function(){var t=e(this),i=r.$('.sections .section[data-section="'+t.data("section")+'"]');r.$(".sections .section").not(i).hide().removeClass("active"),i.show().addClass("active"),r.$(".section-tabs li").not(t).removeClass("active"),t.addClass("active")}).eq(0).click(),this.$(".toolbar select").change(function(){r.setActivateSelector(e(this).find(":selected").data("selector"))})},setRuleValue:function(e,t){if("undefined"!=typeof this.activeSelector&&"undefined"!=typeof this.activeSelector.rules){for(var i=!0,s=0;s<this.activeSelector.rules.length;s++)if(this.activeSelector.rules[s].directive===e){this.activeSelector.rules[s].value=t,i=!1;break}i&&this.activeSelector.rules.push({directive:e,value:t}),this.updateMainEditor(!1)}},addImport:function(e){var i=t.filter(this.parsed,function(e){return e.selector.startsWith("@import")}),s=t.any(i,function(t){return t.styles===e});if(!s){var r={selector:"@imports",styles:e,type:"imports"};this.parsed.unshift(r)}this.updateMainEditor(!1)},findImport:function(e){return t.find(this.parsed,function(t){return t.selector.startsWith("@import")&&t.styles.indexOf(e)>-1})},getRuleValue:function(e){if("undefined"==typeof this.activeSelector||"undefined"==typeof this.activeSelector.rules)return"";for(var t=0;t<this.activeSelector.rules.length;t++)if(this.activeSelector.rules[t].directive===e)return this.activeSelector.rules[t].value;return""},updateMainEditor:function(e){var t;"undefined"==typeof e||e===!0?(t=this.parser.compressCSS(this.parsed),t=t.filter(function(e){return"undefined"!=typeof e.type||e.rules.length>0})):t=this.parsed,this.editor.codeMirror.setValue(this.parser.getCSSForEditor(t).trim())},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.compressCSS(this.parser.parseCSS(i));for(var r=this.$(".toolbar select").empty(),n=0;n<this.parsed.length;n++){var o=this.parsed[n];if("imports"!==o.type)if("undefined"!=typeof o.subStyles)for(var a=0;a<o.subStyles.length;a++){var l=o.subStyles[a];r.append(e("<option>").html(o.selector+": "+l.selector).attr("val",o.selector+": "+l.selector).data("selector",l))}else r.append(e("<option>").html(o.selector).attr("val",o.selector).data("selector",o))}"undefined"==typeof s&&(s=r.find("option").eq(0).attr("val")),t.isEmpty(s)||r.val(s).change()},setActivateSelector: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="" />'),activeRule:null,args:null,propertiesView:null,initialize:function(e){this.args=e.args,this.propertiesView=e.propertiesView,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")},initChangeEvents:function(){var t=this;this.field.on("change keyup",function(){t.trigger("change",e(this).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({template:t.template('<input type="text" value="" />'),render:function(){this.$el.append(e(this.template({}))),this.field=this.$el.find("input"),this.field.minicolors({})},initChangeEvents:function(){var e=this;this.field.on("change keyup",function(){e.trigger("change",e.field.minicolors("value"))})},getValue:function(){return this.field.minicolors("value")},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></select>"),render:function(){this.$el.append(e(this.template({}))),this.field=this.$el.find("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]));"undefined"!=typeof this.args.option_icons&&this.setupVisualSelect()},setupVisualSelect:function(){var t=this;this.field.hide();var i=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(i);for(var s in this.args.option_icons)e('<div class="select-tab"></div>').appendTo(i).append(e('<span class="fa"></span>').addClass("fa-"+this.args.option_icons[s])).attr("data-value",s);i.find(".select-tab").css("width",100/i.find(">div").length+"%").click(function(){var s=e(this);i.find(".select-tab").removeClass("active"),s.addClass("active"),t.field.val(s.data("value")).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>'),render:function(){var t=this;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.$(".select").click(function(){t.media.open()}),this.media.on("select",function(){var e=this.state().get("selection").first().attributes,i=t.args.value.replace("{{url}}",e.url);t.field.val(i).change(),t.media.close()},this.media)}}),s.view.properties.controllers.measurement=s.view.propertyController.extend({wrapperClass:"socss-field-measurement",render:function(){this.$el.append(e(this.template({}))),this.field=this.$("input"),this.setupMeasurementField(this.field,{})},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(i,s){var r=this,n=i.parent();s=t.extend({defaultUnit:"px"},s),i.hide(),n.addClass(this.wrapperClass).data("unit",s.defaultUnit);for(var o=e('<input type="text" class="socss-field-input"/>').appendTo(n),a=e('<span class="dashicons dashicons-arrow-down"></span>').appendTo(n),l=e('<ul class="dropdown"></ul>').appendTo(n),c=e('<span class="units"></span>').html(s.defaultUnit).appendTo(n),d=0;d<r.units.length;d++){var p=e("<li></li>").html(r.units[d]).data("unit",r.units[d]);r.units[d]===s.defaultUnit&&p.addClass("active"),l.append(p)}var h=function(){var e=r.parseUnits(o.val());""!==e.unit&&e.unit!==n.data("unit")&&(o.val(e.value),u(e.unit)),""===e.value?i.val(""):i.val(e.value+n.data("unit"))},u=function(e){c.html(e),n.data("unit",e),o.trigger("keydown")};a.click(function(){l.toggle()}),l.find("li").click(function(){l.toggle(),u(e(this).data("unit")),h(),i.trigger("change")}),o.on("keyup keydown",function(t){var i=(e(this),"");"keydown"===t.type&&(t.keyCode>=48&&t.keyCode<=57?i=String.fromCharCode(t.keyCode):189===t.keyCode?i="-":190===t.keyCode&&(i="."));var s=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(o.val()+i).appendTo("body"),r=s.width();r=Math.min(r,63),s.remove(),c.css("left",r+12)}),o.on("keyup",function(e){h(),i.trigger("change")}),i.on("measurement_refresh",function(){var t=r.parseUnits(i.val());o.val(t.value);var a=""===t.unit?s.defaultUnit:t.unit;n.data("unit",a),c.html(a);var l=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(t.value).appendTo("body"),d=l.width();d=Math.min(d,63),l.remove(),c.css("left",d+12)});var f=e('<div class="socss-diw"></div>').appendTo(n),v=e('<div class="dec-button socss-button"><span class="fa fa-minus"></span></div>').appendTo(f),m=e('<div class="inc-button socss-button"><span class="fa fa-plus"></span></div>').appendTo(f);m.click(function(){var e=r.parseUnits(i.val());if(""===e.value)return!0;var t=Math.ceil(1.05*e.value);o.val(t),h(),i.trigger("change").trigger("measurement_refresh")}),v.click(function(){var e=r.parseUnits(i.val());if(""===e.value)return!0;var t=Math.floor(e.value/1.05);o.val(t),h(),i.trigger("change").trigger("measurement_refresh")})}}),s.view.properties.controllers.number=s.view.propertyController.extend({render:function(){this.$el.append(e(this.template({}))),this.field=this.$("input"),this.setupNumberField(this.field,this.args)},setupNumberField:function(i,s){s=t.extend({change:null,"default":0,increment:1,decrement:-1,max:null,min:null},s);var r=i.parent();r.addClass("socss-field-number");var n=e('<div class="socss-diw"></div>').appendTo(r),o=e('<div class="dec-button socss-button">-</div>').appendTo(n);e('<div class="inc-button socss-button">+</div>').appendTo(n);return n.find("> div").click(function(t){t.preventDefault();var r=s["default"];""!==i.val()&&(r=Number(i.val())),r+=e(this).is(o)?s.decrement:s.increment,r=Math.round(100*r)/100,null!==s.max&&(r=Math.min(s.max,r)),null!==s.min&&(r=Math.max(s.min,r)),i.val(r),i.trigger("change")}),this}}),s.view.properties.controllers.sides=s.view.propertyController.extend({template:t.template(e("#template-sides-field").html().trim()),controllers:[],render:function(){var i=this;this.$el.append(e(this.template({}))),this.field=this.$el.find("input"),i.args.hasAll||(this.$(".select-tab").eq(0).remove(),this.$(".select-tab").css("width","25%")),this.$(".select-tab").each(function(){for(var r=e(this).data("direction"),n=e('<li class="side">').appendTo(i.$(".sides")).hide(),o=0;o<i.args.controllers.length;o++){var a=i.args.controllers[o],l="";l="all"===r?a.args.propertyAll:a.args.property.replace("{dir}",r);var c=t.extend({},a.args,{property:l}),d=new s.view.properties.controllers[a.type]({el:e("<div>").appendTo(n),propertiesView:i.propertiesView,args:c});d.render(),d.initChangeEvents(),i.propertiesView.propertyControllers.push(d)}e(this).on("click",function(){i.$(".select-tab").removeClass("active"),e(this).addClass("active"),i.$(".sides .side").hide(),n.show()})}),this.$(".select-tab").eq(0).click()}})}(jQuery,_,socssOptions),jQuery(function(e){var t=window.socss,i=new t.view.editor({el:e("#so-custom-css-form").get(0)});i.render(),i.setSnippets(socssOptions.snippets),window.socss.mainEditor=i,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"))})});
|
readme.txt
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
=== SiteOrigin CSS ===
|
2 |
Tags: css, design, edit, customize
|
3 |
Requires at least: 3.9
|
4 |
-
Tested up to: 4.
|
5 |
-
Stable tag: 1.0.
|
6 |
Build time: unbuilt
|
7 |
License: GPLv2 or later
|
8 |
Contributors: gpriday
|
@@ -62,6 +62,12 @@ We offer free support on the [SiteOrigin support forums](https://siteorigin.com/
|
|
62 |
|
63 |
== Changelog ==
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
= 1.0.7 - 4 July 2016 =
|
66 |
* Ensure user can copy/paste in editor via context menu.
|
67 |
* Added plugin action links
|
1 |
=== SiteOrigin CSS ===
|
2 |
Tags: css, design, edit, customize
|
3 |
Requires at least: 3.9
|
4 |
+
Tested up to: 4.6
|
5 |
+
Stable tag: 1.0.8
|
6 |
Build time: unbuilt
|
7 |
License: GPLv2 or later
|
8 |
Contributors: gpriday
|
62 |
|
63 |
== Changelog ==
|
64 |
|
65 |
+
= 1.0.8 - 15 August 2016 =
|
66 |
+
* Fixed action link.
|
67 |
+
* Support for GlotPress.
|
68 |
+
* Removed unused code.
|
69 |
+
* Handling of @imports for future addons.
|
70 |
+
|
71 |
= 1.0.7 - 4 July 2016 =
|
72 |
* Ensure user can copy/paste in editor via context menu.
|
73 |
* Added plugin action links
|
so-css.php
CHANGED
@@ -2,18 +2,19 @@
|
|
2 |
/*
|
3 |
Plugin Name: SiteOrigin CSS
|
4 |
Description: An advanced CSS editor from SiteOrigin.
|
5 |
-
Version: 1.0.
|
6 |
Author: SiteOrigin
|
7 |
Author URI: https://siteorigin.com
|
8 |
Plugin URI: https://siteorigin.com/css/
|
9 |
License: GPL3
|
10 |
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
|
|
11 |
*/
|
12 |
|
13 |
// Handle the legacy CSS editor that came with SiteOrigin themes
|
14 |
include plugin_dir_path(__FILE__) . '/inc/legacy.php';
|
15 |
|
16 |
-
define('SOCSS_VERSION', '1.0.
|
17 |
define('SOCSS_JS_SUFFIX', '.min');
|
18 |
|
19 |
/**
|
@@ -28,6 +29,7 @@ class SiteOrigin_CSS {
|
|
28 |
$this->snippet_paths = array();
|
29 |
|
30 |
// Main header actions
|
|
|
31 |
add_action( 'wp_head', array($this, 'action_wp_head'), 20 );
|
32 |
|
33 |
// All the admin actions
|
@@ -45,7 +47,7 @@ class SiteOrigin_CSS {
|
|
45 |
|
46 |
if( isset($_GET['so_css_preview']) && !is_admin() ) {
|
47 |
|
48 |
-
add_action('plugins_loaded', array($this, 'disable_ngg_resource_manager'));
|
49 |
add_filter( 'show_admin_bar', '__return_false' );
|
50 |
add_filter( 'wp_enqueue_scripts', array($this, 'enqueue_inspector_scripts') );
|
51 |
add_filter( 'wp_footer', array($this, 'inspector_templates') );
|
@@ -55,13 +57,6 @@ class SiteOrigin_CSS {
|
|
55 |
}
|
56 |
}
|
57 |
|
58 |
-
function disable_ngg_resource_manager() {
|
59 |
-
if( !current_user_can('edit_theme_options') ) return;
|
60 |
-
|
61 |
-
//The NextGen Gallery plugin does some weird interfering with the output buffer.
|
62 |
-
define('NGG_DISABLE_RESOURCE_MANAGER', true);
|
63 |
-
}
|
64 |
-
|
65 |
/**
|
66 |
* Get a singleton of the SiteOrigin CSS.
|
67 |
*
|
@@ -90,6 +85,10 @@ class SiteOrigin_CSS {
|
|
90 |
echo "</style>\n";
|
91 |
}
|
92 |
|
|
|
|
|
|
|
|
|
93 |
/**
|
94 |
* Action to run on the admin action.
|
95 |
*/
|
@@ -231,7 +230,7 @@ class SiteOrigin_CSS {
|
|
231 |
|
232 |
function plugin_action_links( $links ){
|
233 |
if( isset($links['edit']) ) unset( $links['edit'] );
|
234 |
-
$links['css_editor'] = '<a href="' . admin_url('
|
235 |
$links['support'] = '<a href="https://siteorigin.com/thread/" target="_blank">'.__('Support', 'so-css').'</a>';
|
236 |
return $links;
|
237 |
}
|
@@ -242,7 +241,7 @@ class SiteOrigin_CSS {
|
|
242 |
$custom_css = get_option( 'siteorigin_custom_css[' . $theme . ']', '' );
|
243 |
$custom_css_revisions = get_option('siteorigin_custom_css_revisions[' . $theme . ']');
|
244 |
|
245 |
-
if(!empty($_GET['theme']) && $_GET['theme'] == $theme && !empty($_GET['time']) && !empty($custom_css_revisions[$_GET['time']])) {
|
246 |
$custom_css = $custom_css_revisions[$_GET['time']];
|
247 |
$revision = true;
|
248 |
}
|
@@ -257,7 +256,7 @@ class SiteOrigin_CSS {
|
|
257 |
if( !isset($_GET['_wpnonce']) || !wp_verify_nonce( $_GET['_wpnonce'], 'hide' ) ) return;
|
258 |
|
259 |
$user = wp_get_current_user();
|
260 |
-
if( !empty($user) ) {
|
261 |
update_user_meta( $user->ID, 'socss_hide_gs', true );
|
262 |
}
|
263 |
}
|
@@ -426,23 +425,13 @@ class SiteOrigin_CSS {
|
|
426 |
}
|
427 |
}
|
428 |
|
429 |
-
|
430 |
-
|
431 |
-
*/
|
432 |
-
function get_tweet_url(){
|
433 |
-
$tweet = __('I changed my site design using @SiteOrigin CSS (http://siteorigin.com/css/). What do you think?', 'so-css');
|
434 |
-
$tweet .= ' ';
|
435 |
-
$tweet .= get_site_url();
|
436 |
-
|
437 |
-
return add_query_arg(
|
438 |
-
'text',
|
439 |
-
urlencode($tweet),
|
440 |
-
'https://twitter.com/intent/tweet'
|
441 |
-
);
|
442 |
-
|
443 |
|
|
|
|
|
444 |
}
|
445 |
}
|
446 |
|
447 |
// Initialize the single
|
448 |
-
SiteOrigin_CSS::single();
|
2 |
/*
|
3 |
Plugin Name: SiteOrigin CSS
|
4 |
Description: An advanced CSS editor from SiteOrigin.
|
5 |
+
Version: 1.0.8
|
6 |
Author: SiteOrigin
|
7 |
Author URI: https://siteorigin.com
|
8 |
Plugin URI: https://siteorigin.com/css/
|
9 |
License: GPL3
|
10 |
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
11 |
+
Text Domain: so-css
|
12 |
*/
|
13 |
|
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.0.8');
|
18 |
define('SOCSS_JS_SUFFIX', '.min');
|
19 |
|
20 |
/**
|
29 |
$this->snippet_paths = array();
|
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
|
47 |
|
48 |
if( isset($_GET['so_css_preview']) && !is_admin() ) {
|
49 |
|
50 |
+
add_action( 'plugins_loaded', array($this, 'disable_ngg_resource_manager') );
|
51 |
add_filter( 'show_admin_bar', '__return_false' );
|
52 |
add_filter( 'wp_enqueue_scripts', array($this, 'enqueue_inspector_scripts') );
|
53 |
add_filter( 'wp_footer', array($this, 'inspector_templates') );
|
57 |
}
|
58 |
}
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
/**
|
61 |
* Get a singleton of the SiteOrigin CSS.
|
62 |
*
|
85 |
echo "</style>\n";
|
86 |
}
|
87 |
|
88 |
+
function set_plugin_textdomain(){
|
89 |
+
load_plugin_textdomain('so-css', false, plugin_dir_path( __FILE__ ). '/languages/');
|
90 |
+
}
|
91 |
+
|
92 |
/**
|
93 |
* Action to run on the admin action.
|
94 |
*/
|
230 |
|
231 |
function plugin_action_links( $links ){
|
232 |
if( isset($links['edit']) ) unset( $links['edit'] );
|
233 |
+
$links['css_editor'] = '<a href="' . admin_url('themes.php?page=so_custom_css') . '">'.__('CSS Editor', 'so-css').'</a>';
|
234 |
$links['support'] = '<a href="https://siteorigin.com/thread/" target="_blank">'.__('Support', 'so-css').'</a>';
|
235 |
return $links;
|
236 |
}
|
241 |
$custom_css = get_option( 'siteorigin_custom_css[' . $theme . ']', '' );
|
242 |
$custom_css_revisions = get_option('siteorigin_custom_css_revisions[' . $theme . ']');
|
243 |
|
244 |
+
if( !empty( $_GET['theme'] ) && $_GET['theme'] == $theme && !empty( $_GET['time'] ) && !empty( $custom_css_revisions[$_GET['time']] ) ) {
|
245 |
$custom_css = $custom_css_revisions[$_GET['time']];
|
246 |
$revision = true;
|
247 |
}
|
256 |
if( !isset($_GET['_wpnonce']) || !wp_verify_nonce( $_GET['_wpnonce'], 'hide' ) ) return;
|
257 |
|
258 |
$user = wp_get_current_user();
|
259 |
+
if( !empty( $user ) ) {
|
260 |
update_user_meta( $user->ID, 'socss_hide_gs', true );
|
261 |
}
|
262 |
}
|
425 |
}
|
426 |
}
|
427 |
|
428 |
+
function disable_ngg_resource_manager() {
|
429 |
+
if( !current_user_can('edit_theme_options') ) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
430 |
|
431 |
+
//The NextGen Gallery plugin does some weird interfering with the output buffer.
|
432 |
+
define('NGG_DISABLE_RESOURCE_MANAGER', true);
|
433 |
}
|
434 |
}
|
435 |
|
436 |
// Initialize the single
|
437 |
+
SiteOrigin_CSS::single();
|
tpl/page.php
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
|
3 |
<div class="wrap" id="siteorigin-custom-css">
|
4 |
<h2>
|
@@ -43,12 +47,18 @@
|
|
43 |
<div class="inside">
|
44 |
<ol data-confirm="<?php esc_attr_e('Are you sure you want to load this revision?', 'so-css') ?>">
|
45 |
<?php
|
46 |
-
if( is_array($custom_css_revisions) ) {
|
47 |
-
|
|
|
48 |
?>
|
49 |
<li>
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
</li>
|
53 |
<?php
|
54 |
}
|
@@ -124,4 +134,4 @@
|
|
124 |
|
125 |
<div class="clear"></div>
|
126 |
|
127 |
-
</div>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @var $custom_css_revisions array Saved revisions for the current theme.
|
4 |
+
*/
|
5 |
+
$snippets = SiteOrigin_CSS::single()->get_snippets(); ?>
|
6 |
|
7 |
<div class="wrap" id="siteorigin-custom-css">
|
8 |
<h2>
|
47 |
<div class="inside">
|
48 |
<ol data-confirm="<?php esc_attr_e('Are you sure you want to load this revision?', 'so-css') ?>">
|
49 |
<?php
|
50 |
+
if ( is_array( $custom_css_revisions ) ) {
|
51 |
+
$is_current = true;
|
52 |
+
foreach ( $custom_css_revisions as $time => $css ) {
|
53 |
?>
|
54 |
<li>
|
55 |
+
<?php if ( $is_current ) : ?>
|
56 |
+
<?php echo date('j F Y @ H:i:s', $time + get_option('gmt_offset') * 60 * 60) ?> (Current)
|
57 |
+
<?php $is_current = false; ?>
|
58 |
+
<?php else : ?>
|
59 |
+
<a href="<?php echo esc_url( add_query_arg( array( 'theme' => $theme, 'time' => $time ) ) ) ?>" class="load-css-revision"><?php echo date('j F Y @ H:i:s', $time + get_option('gmt_offset') * 60 * 60) ?></a>
|
60 |
+
(<?php printf(__('%d chars', 'so-css'), strlen($css)) ?>)
|
61 |
+
<?php endif; ?>
|
62 |
</li>
|
63 |
<?php
|
64 |
}
|
134 |
|
135 |
<div class="clear"></div>
|
136 |
|
137 |
+
</div>
|