SiteOrigin CSS - Version 1.1.4

Version Description

  • 31 January 2017 =
  • Updated CodeMirror to 2.25.2.
  • Removed extra line padding.
  • Better integration with WordPress.org translation.
Download this release

Release Info

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

Code changes from version 1.1.3 to 1.1.4

js/editor.js CHANGED
@@ -117,11 +117,7 @@
117
  // options in context menu.
118
  var newlineMatches = initValue.match(/\n/gm);
119
  var lineCount = newlineMatches ? newlineMatches.length+1 : 1;
120
- var numPadLines = 15 - lineCount;
121
  var paddedValue = initValue;
122
- for(var i = 0; i < numPadLines; i++) {
123
- paddedValue += '\n';
124
- }
125
  $textArea.val(paddedValue);
126
  this.codeMirror = CodeMirror.fromTextArea($textArea.get(0), {
127
  tabSize: 2,
117
  // options in context menu.
118
  var newlineMatches = initValue.match(/\n/gm);
119
  var lineCount = newlineMatches ? newlineMatches.length+1 : 1;
 
120
  var paddedValue = initValue;
 
 
 
121
  $textArea.val(paddedValue);
122
  this.codeMirror = CodeMirror.fromTextArea($textArea.get(0), {
123
  tabSize: 2,
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,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;c<a;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();if(e!==r)return i.loc.leave}),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)||d.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 p=CodeMirror.resolveMode("text/css"),d=[],h=o.state.state;if("top"===h){for(var u=i.getLine(r.line).trim(),v=e.cssSelectors,f=0;f<v.length;f++)v[f].selector.indexOf(u)!==-1&&d.push(v[f].selector);if(d.length)return{list:d,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(p.propertyKeywords):"prop"===h||"parens"===h||"at"===h||"params"===h?(s(p.valueKeywords),s(p.colorKeywords)):"media"!==h&&"media_parens"!==h||(s(p.mediaTypes),s(p.mediaFeatures)),d.length)return{list:d,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(e("#template-preview-window").html()),editor:null,originalUri:null,currentUri: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).on("load",function(){var i=e(this);t.currentUri=new URI(i.contents().get(0).location.href),t.currentUri.removeQuery("so_css_preview"),t.$("#preview-navigator input").val(t.currentUri.toString()),t.currentUri.addQuery("so_css_preview",1),i.contents().find("a").each(function(){var t=e(this).attr("href");if(void 0===t)return!0;var i=t.indexOf("?")===-1?"?":"&";e(this).attr("href",t+i+"so_css_preview=1")}),t.updatePreviewCss()}).mouseleave(function(){t.clearHighlight()}),this.$("#preview-navigator input").keydown(function(i){var s=e(this);if(13==i.keyCode){i.preventDefault();var r=new URI(s.val());t.originalUri.host()!==r.host()||t.originalUri.protocol()!==r.protocol()?(s.blur(),alert(s.data("invalid-uri")),s.focus()):(r.addQuery("so_css_preview",1),t.$("#preview-iframe").attr("src",r.toString()))}}),this.originalUri=new URI(i.homeURL),this.currentUri=new URI(i.homeURL),this.currentUri.removeQuery("so_css_preview"),this.$("#preview-navigator input").val(this.currentUri.toString()),this.currentUri.addQuery("so_css_preview",1)},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=window.css,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,p=e(r.controllerTemplate({title:n[o].controllers[l].title})).appendTo(a.find("tbody")),d=n[o].controllers[l];c="undefined"==typeof s.view.properties.controllers[d.type]?new s.view.propertyController({el:p.find("td"),propertiesView:r,args:"undefined"==typeof d.args?{}:d.args}):new s.view.properties.controllers[d.type]({el:p.find("td"),propertiesView:r,args:"undefined"==typeof d.args?{}:d.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,i){if("undefined"!=typeof this.activeSelector&&"undefined"!=typeof this.activeSelector.declarations){for(var s=this.activeSelector.declarations,r=!0,n=!1,o=0;o<s.length;o++)if(s[o].property===e){r=!1;var a=s[o];a.value!==i&&(a.value=i,n=!0),t.isEmpty(a.value)&&s.splice(s.indexOf(a));break}r&&!t.isEmpty(i)&&(s.push({property:e,value:i,type:"declaration"}),n=!0),n&&this.updateMainEditor(!1)}},addImport:function(e){var i=t.filter(this.parsed.stylesheet.rules,function(e){return"import"===e.type}),s=t.any(i,function(t){return t["import"]===e["import"]});s||(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("undefined"==typeof this.activeSelector||"undefined"==typeof 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,n=this.$(".toolbar select").empty(),o=0;o<r.length;o++){var a=r[o];if(t.contains(["rule","media"],a.type))if("media"===a.type)for(var l=0;l<a.rules.length;l++){var c="@media "+a.media,p=a.rules[l];"rule"==p.type&&n.append(e("<option>").html(c+": "+p.selectors.join(",")).attr("val",c+": "+p.selectors.join(",")).data("selector",p))}else n.append(e("<option>").html(a.selectors.join(",")).attr("val",a.selectors.join(",")).data("selector",a))}"undefined"==typeof s&&(s=n.find("option").eq(0).attr("val")),t.isEmpty(s)||n.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").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></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),p=0;p<r.units.length;p++){var d=e("<li></li>").html(r.units[p]).data("unit",r.units[p]);r.units[p]===s.defaultUnit&&d.addClass("active"),l.append(d)}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"),p=l.width();p=Math.min(p,63),l.remove(),c.css("left",p+12)});var v=e('<div class="socss-diw"></div>').appendTo(n),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=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")}),f.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}),p=new s.view.properties.controllers[a.type]({el:e("<div>").appendTo(n),propertiesView:i.propertiesView,args:c});p.render(),p.initChangeEvents(),i.propertiesView.propertyControllers.push(p)}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"))})});
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();var s=this.$("textarea.css-editor"),r=s.val(),n=r.match(/\n/gm),o=(n?n.length+1:1,r);s.val(o),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();if(e!==r)return i.loc.leave}),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)||d.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 p=CodeMirror.resolveMode("text/css"),d=[],h=o.state.state;if("top"===h){for(var u=i.getLine(r.line).trim(),v=e.cssSelectors,f=0;f<v.length;f++)v[f].selector.indexOf(u)!==-1&&d.push(v[f].selector);if(d.length)return{list:d,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(p.propertyKeywords):"prop"===h||"parens"===h||"at"===h||"params"===h?(s(p.valueKeywords),s(p.colorKeywords)):"media"!==h&&"media_parens"!==h||(s(p.mediaTypes),s(p.mediaFeatures)),d.length)return{list:d,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(e("#template-preview-window").html()),editor:null,originalUri:null,currentUri: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).on("load",function(){var i=e(this);t.currentUri=new URI(i.contents().get(0).location.href),t.currentUri.removeQuery("so_css_preview"),t.$("#preview-navigator input").val(t.currentUri.toString()),t.currentUri.addQuery("so_css_preview",1),i.contents().find("a").each(function(){var t=e(this).attr("href");if(void 0===t)return!0;var i=t.indexOf("?")===-1?"?":"&";e(this).attr("href",t+i+"so_css_preview=1")}),t.updatePreviewCss()}).mouseleave(function(){t.clearHighlight()}),this.$("#preview-navigator input").keydown(function(i){var s=e(this);if(13==i.keyCode){i.preventDefault();var r=new URI(s.val());t.originalUri.host()!==r.host()||t.originalUri.protocol()!==r.protocol()?(s.blur(),alert(s.data("invalid-uri")),s.focus()):(r.addQuery("so_css_preview",1),t.$("#preview-iframe").attr("src",r.toString()))}}),this.originalUri=new URI(i.homeURL),this.currentUri=new URI(i.homeURL),this.currentUri.removeQuery("so_css_preview"),this.$("#preview-navigator input").val(this.currentUri.toString()),this.currentUri.addQuery("so_css_preview",1)},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=window.css,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,p=e(r.controllerTemplate({title:n[o].controllers[l].title})).appendTo(a.find("tbody")),d=n[o].controllers[l];c="undefined"==typeof s.view.properties.controllers[d.type]?new s.view.propertyController({el:p.find("td"),propertiesView:r,args:"undefined"==typeof d.args?{}:d.args}):new s.view.properties.controllers[d.type]({el:p.find("td"),propertiesView:r,args:"undefined"==typeof d.args?{}:d.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,i){if("undefined"!=typeof this.activeSelector&&"undefined"!=typeof this.activeSelector.declarations){for(var s=this.activeSelector.declarations,r=!0,n=!1,o=0;o<s.length;o++)if(s[o].property===e){r=!1;var a=s[o];a.value!==i&&(a.value=i,n=!0),t.isEmpty(a.value)&&s.splice(s.indexOf(a));break}r&&!t.isEmpty(i)&&(s.push({property:e,value:i,type:"declaration"}),n=!0),n&&this.updateMainEditor(!1)}},addImport:function(e){var i=t.filter(this.parsed.stylesheet.rules,function(e){return"import"===e.type}),s=t.any(i,function(t){return t["import"]===e["import"]});s||(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("undefined"==typeof this.activeSelector||"undefined"==typeof 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,n=this.$(".toolbar select").empty(),o=0;o<r.length;o++){var a=r[o];if(t.contains(["rule","media"],a.type))if("media"===a.type)for(var l=0;l<a.rules.length;l++){var c="@media "+a.media,p=a.rules[l];"rule"==p.type&&n.append(e("<option>").html(c+": "+p.selectors.join(",")).attr("val",c+": "+p.selectors.join(",")).data("selector",p))}else n.append(e("<option>").html(a.selectors.join(",")).attr("val",a.selectors.join(",")).data("selector",a))}"undefined"==typeof s&&(s=n.find("option").eq(0).attr("val")),t.isEmpty(s)||n.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").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></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),p=0;p<r.units.length;p++){var d=e("<li></li>").html(r.units[p]).data("unit",r.units[p]);r.units[p]===s.defaultUnit&&d.addClass("active"),l.append(d)}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"),p=l.width();p=Math.min(p,63),l.remove(),c.css("left",p+12)});var v=e('<div class="socss-diw"></div>').appendTo(n),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=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")}),f.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}),p=new s.view.properties.controllers[a.type]({el:e("<div>").appendTo(n),propertiesView:i.propertiesView,args:c});p.render(),p.initChangeEvents(),i.propertiesView.propertyControllers.push(p)}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"))})});
lang/so-css.pot ADDED
@@ -0,0 +1,506 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2017 so-css
2
+ # This file is distributed under the same license as the so-css package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: so-css\n"
6
+ "Report-Msgid-Bugs-To: http://www.siteorigin.com\n"
7
+ "MIME-Version: 1.0\n"
8
+ "Content-Type: text/plain; charset=UTF-8\n"
9
+ "Content-Transfer-Encoding: 8bit\n"
10
+ "PO-Revision-Date: 2017-MO-DA HO:MI+ZONE\n"
11
+ "Last-Translator: SiteOrigin <support@siteorigin.com>\n"
12
+ "Language-Team: SiteOrigin <support@siteorigin.com>\n"
13
+ "X-Poedit-Basepath: ..\n"
14
+ "X-Poedit-SourceCharset: UTF-8\n"
15
+ "X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
16
+ "X-Poedit-SearchPath-0: .\n"
17
+ "X-Poedit-SearchPathExcluded-0: *.js\n"
18
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
+
20
+ #: tmp/inc/controller-config.php:5
21
+ msgid "Text"
22
+ msgstr ""
23
+
24
+ #: tmp/inc/controller-config.php:9
25
+ msgid "Text Color"
26
+ msgstr ""
27
+
28
+ #: tmp/inc/controller-config.php:16
29
+ msgid "Font Size"
30
+ msgstr ""
31
+
32
+ #: tmp/inc/controller-config.php:24
33
+ msgid "Line Height"
34
+ msgstr ""
35
+
36
+ #: tmp/inc/controller-config.php:32
37
+ msgid "Font Weight"
38
+ msgstr ""
39
+
40
+ #: tmp/inc/controller-config.php:37, tmp/inc/controller-config.php:60, tmp/inc/controller-config.php:93, tmp/inc/controller-config.php:164
41
+ msgid "Normal"
42
+ msgstr ""
43
+
44
+ #: tmp/inc/controller-config.php:38
45
+ msgid "Bold"
46
+ msgstr ""
47
+
48
+ #: tmp/inc/controller-config.php:39
49
+ msgid "Bolder"
50
+ msgstr ""
51
+
52
+ #: tmp/inc/controller-config.php:40
53
+ msgid "Lighter"
54
+ msgstr ""
55
+
56
+ #: tmp/inc/controller-config.php:54
57
+ msgid "Font Style"
58
+ msgstr ""
59
+
60
+ #: tmp/inc/controller-config.php:59, tmp/inc/controller-config.php:75, tmp/inc/controller-config.php:104, tmp/inc/controller-config.php:397, tmp/inc/controller-config.php:424, tmp/inc/controller-config.php:436
61
+ msgid "None"
62
+ msgstr ""
63
+
64
+ #: tmp/inc/controller-config.php:61
65
+ msgid "Italic"
66
+ msgstr ""
67
+
68
+ #: tmp/inc/controller-config.php:70
69
+ msgid "Text Decoration"
70
+ msgstr ""
71
+
72
+ #: tmp/inc/controller-config.php:76
73
+ msgid "Underline"
74
+ msgstr ""
75
+
76
+ #: tmp/inc/controller-config.php:77
77
+ msgid "Overline"
78
+ msgstr ""
79
+
80
+ #: tmp/inc/controller-config.php:78
81
+ msgid "Line Through"
82
+ msgstr ""
83
+
84
+ #: tmp/inc/controller-config.php:88
85
+ msgid "Font Variant"
86
+ msgstr ""
87
+
88
+ #: tmp/inc/controller-config.php:94
89
+ msgid "Small Caps"
90
+ msgstr ""
91
+
92
+ #: tmp/inc/controller-config.php:99
93
+ msgid "Text Transform"
94
+ msgstr ""
95
+
96
+ #: tmp/inc/controller-config.php:105
97
+ msgid "Capitalize"
98
+ msgstr ""
99
+
100
+ #: tmp/inc/controller-config.php:106
101
+ msgid "Uppercase"
102
+ msgstr ""
103
+
104
+ #: tmp/inc/controller-config.php:107
105
+ msgid "Lowercase"
106
+ msgstr ""
107
+
108
+ #: tmp/inc/controller-config.php:112
109
+ msgid "Font Family"
110
+ msgstr ""
111
+
112
+ #: tmp/inc/controller-config.php:119
113
+ msgid "Text Align"
114
+ msgstr ""
115
+
116
+ #: tmp/inc/controller-config.php:124, tmp/inc/controller-config.php:425, tmp/inc/controller-config.php:437
117
+ msgid "Left"
118
+ msgstr ""
119
+
120
+ #: tmp/inc/controller-config.php:125, tmp/inc/controller-config.php:426, tmp/inc/controller-config.php:438
121
+ msgid "Right"
122
+ msgstr ""
123
+
124
+ #: tmp/inc/controller-config.php:126
125
+ msgid "Center"
126
+ msgstr ""
127
+
128
+ #: tmp/inc/controller-config.php:127
129
+ msgid "Justify"
130
+ msgstr ""
131
+
132
+ #: tmp/inc/controller-config.php:138
133
+ msgid "Text Indent"
134
+ msgstr ""
135
+
136
+ #: tmp/inc/controller-config.php:145
137
+ msgid "Letter Spacing"
138
+ msgstr ""
139
+
140
+ #: tmp/inc/controller-config.php:152
141
+ msgid "Word Spacing"
142
+ msgstr ""
143
+
144
+ #: tmp/inc/controller-config.php:159
145
+ msgid "White Space"
146
+ msgstr ""
147
+
148
+ #: tmp/inc/controller-config.php:165
149
+ msgid "Encountered"
150
+ msgstr ""
151
+
152
+ #: tmp/inc/controller-config.php:166
153
+ msgid "Pre"
154
+ msgstr ""
155
+
156
+ #: tmp/inc/controller-config.php:167
157
+ msgid "Pre Line"
158
+ msgstr ""
159
+
160
+ #: tmp/inc/controller-config.php:168
161
+ msgid "Pre Wrap"
162
+ msgstr ""
163
+
164
+ #: tmp/inc/controller-config.php:173
165
+ msgid "Text Shadow"
166
+ msgstr ""
167
+
168
+ #: tmp/inc/controller-config.php:185
169
+ msgid "Decoration"
170
+ msgstr ""
171
+
172
+ #: tmp/inc/controller-config.php:189
173
+ msgid "Background Color"
174
+ msgstr ""
175
+
176
+ #: tmp/inc/controller-config.php:196
177
+ msgid "Background image"
178
+ msgstr ""
179
+
180
+ #: tmp/inc/controller-config.php:204
181
+ msgid "Background Position"
182
+ msgstr ""
183
+
184
+ #: tmp/inc/controller-config.php:211
185
+ msgid "Background Repeat"
186
+ msgstr ""
187
+
188
+ #: tmp/inc/controller-config.php:216
189
+ msgid "repeat"
190
+ msgstr ""
191
+
192
+ #: tmp/inc/controller-config.php:217
193
+ msgid "repeat-x"
194
+ msgstr ""
195
+
196
+ #: tmp/inc/controller-config.php:218
197
+ msgid "repeat-y"
198
+ msgstr ""
199
+
200
+ #: tmp/inc/controller-config.php:219
201
+ msgid "no-repeat"
202
+ msgstr ""
203
+
204
+ #: tmp/inc/controller-config.php:224
205
+ msgid "Background Size"
206
+ msgstr ""
207
+
208
+ #: tmp/inc/controller-config.php:229
209
+ msgid "auto"
210
+ msgstr ""
211
+
212
+ #: tmp/inc/controller-config.php:230
213
+ msgid "length"
214
+ msgstr ""
215
+
216
+ #: tmp/inc/controller-config.php:231
217
+ msgid "percentage"
218
+ msgstr ""
219
+
220
+ #: tmp/inc/controller-config.php:232
221
+ msgid "cover"
222
+ msgstr ""
223
+
224
+ #: tmp/inc/controller-config.php:233
225
+ msgid "contain"
226
+ msgstr ""
227
+
228
+ #: tmp/inc/controller-config.php:239
229
+ msgid "Box Shadow"
230
+ msgstr ""
231
+
232
+ #: tmp/inc/controller-config.php:247
233
+ msgid "Opacity"
234
+ msgstr ""
235
+
236
+ #: tmp/inc/controller-config.php:260
237
+ msgid "Borders"
238
+ msgstr ""
239
+
240
+ #: tmp/inc/controller-config.php:308
241
+ msgid "Layout"
242
+ msgstr ""
243
+
244
+ #: tmp/inc/controller-config.php:312
245
+ msgid "Margin"
246
+ msgstr ""
247
+
248
+ #: tmp/inc/controller-config.php:329
249
+ msgid "Padding"
250
+ msgstr ""
251
+
252
+ #: tmp/inc/controller-config.php:346
253
+ msgid "Position"
254
+ msgstr ""
255
+
256
+ #: tmp/inc/controller-config.php:351
257
+ msgid "Absolute"
258
+ msgstr ""
259
+
260
+ #: tmp/inc/controller-config.php:352
261
+ msgid "Fixed"
262
+ msgstr ""
263
+
264
+ #: tmp/inc/controller-config.php:353
265
+ msgid "Relative"
266
+ msgstr ""
267
+
268
+ #: tmp/inc/controller-config.php:354
269
+ msgid "Static"
270
+ msgstr ""
271
+
272
+ #: tmp/inc/controller-config.php:355
273
+ msgid "Inherit"
274
+ msgstr ""
275
+
276
+ #: tmp/inc/controller-config.php:360
277
+ msgid "Absolute Position"
278
+ msgstr ""
279
+
280
+ #: tmp/inc/controller-config.php:376
281
+ msgid "Width"
282
+ msgstr ""
283
+
284
+ #: tmp/inc/controller-config.php:384
285
+ msgid "Height"
286
+ msgstr ""
287
+
288
+ #: tmp/inc/controller-config.php:392
289
+ msgid "Display"
290
+ msgstr ""
291
+
292
+ #: tmp/inc/controller-config.php:398
293
+ msgid "Inline"
294
+ msgstr ""
295
+
296
+ #: tmp/inc/controller-config.php:399
297
+ msgid "Block"
298
+ msgstr ""
299
+
300
+ #: tmp/inc/controller-config.php:400
301
+ msgid "Flex"
302
+ msgstr ""
303
+
304
+ #: tmp/inc/controller-config.php:401
305
+ msgid "Inline Block"
306
+ msgstr ""
307
+
308
+ #: tmp/inc/controller-config.php:402
309
+ msgid "Inline Flex"
310
+ msgstr ""
311
+
312
+ #: tmp/inc/controller-config.php:403
313
+ msgid "Inline Table"
314
+ msgstr ""
315
+
316
+ #: tmp/inc/controller-config.php:404
317
+ msgid "List Item"
318
+ msgstr ""
319
+
320
+ #: tmp/inc/controller-config.php:405
321
+ msgid "Run In"
322
+ msgstr ""
323
+
324
+ #: tmp/inc/controller-config.php:406
325
+ msgid "Table"
326
+ msgstr ""
327
+
328
+ #: tmp/inc/controller-config.php:407
329
+ msgid "Table Caption"
330
+ msgstr ""
331
+
332
+ #: tmp/inc/controller-config.php:408
333
+ msgid "Table Column Group"
334
+ msgstr ""
335
+
336
+ #: tmp/inc/controller-config.php:409
337
+ msgid "Table Header Group"
338
+ msgstr ""
339
+
340
+ #: tmp/inc/controller-config.php:410
341
+ msgid "Table Footer Group"
342
+ msgstr ""
343
+
344
+ #: tmp/inc/controller-config.php:411
345
+ msgid "Table Row Group"
346
+ msgstr ""
347
+
348
+ #: tmp/inc/controller-config.php:412
349
+ msgid "Table Cell"
350
+ msgstr ""
351
+
352
+ #: tmp/inc/controller-config.php:413
353
+ msgid "Table Column"
354
+ msgstr ""
355
+
356
+ #: tmp/inc/controller-config.php:414
357
+ msgid "Table Row"
358
+ msgstr ""
359
+
360
+ #: tmp/inc/controller-config.php:419
361
+ msgid "Float"
362
+ msgstr ""
363
+
364
+ #: tmp/inc/controller-config.php:431
365
+ msgid "Clear"
366
+ msgstr ""
367
+
368
+ #: tmp/inc/controller-config.php:439
369
+ msgid "Both"
370
+ msgstr ""
371
+
372
+ #: tmp/inc/controller-config.php:444
373
+ msgid "Visibility"
374
+ msgstr ""
375
+
376
+ #: tmp/inc/controller-config.php:449, tmp/inc/controller-config.php:461, tmp/inc/controller-config.php:474, tmp/inc/controller-config.php:487
377
+ msgid "Visible"
378
+ msgstr ""
379
+
380
+ #: tmp/inc/controller-config.php:450, tmp/inc/controller-config.php:462, tmp/inc/controller-config.php:475, tmp/inc/controller-config.php:488
381
+ msgid "Hidden"
382
+ msgstr ""
383
+
384
+ #: tmp/inc/controller-config.php:451
385
+ msgid "Collapse"
386
+ msgstr ""
387
+
388
+ #: tmp/inc/controller-config.php:456
389
+ msgid "Overflow"
390
+ msgstr ""
391
+
392
+ #: tmp/inc/controller-config.php:463, tmp/inc/controller-config.php:476, tmp/inc/controller-config.php:489
393
+ msgid "Scroll"
394
+ msgstr ""
395
+
396
+ #: tmp/inc/controller-config.php:464, tmp/inc/controller-config.php:477, tmp/inc/controller-config.php:490
397
+ msgid "Auto"
398
+ msgstr ""
399
+
400
+ #: tmp/inc/controller-config.php:469
401
+ msgid "Overflow X"
402
+ msgstr ""
403
+
404
+ #: tmp/inc/controller-config.php:482
405
+ msgid "Overflow Y"
406
+ msgstr ""
407
+
408
+ #: tmp/inc/controller-config.php:495
409
+ msgid "Z-Index"
410
+ msgstr ""
411
+
412
+ #: tmp/so-css.php:96, tmp/so-css.php:96, tmp/so-css.php:138
413
+ msgid "Custom CSS"
414
+ msgstr ""
415
+
416
+ #: tmp/so-css.php:140
417
+ msgid "SiteOrigin CSS adds any custom CSS you enter here into your site's header. "
418
+ msgstr ""
419
+
420
+ #: tmp/so-css.php:141
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:195
425
+ msgid "Unchanged"
426
+ msgstr ""
427
+
428
+ #: tmp/so-css.php:196
429
+ msgid "Select"
430
+ msgstr ""
431
+
432
+ #: tmp/so-css.php:197
433
+ msgid "Select Image"
434
+ msgstr ""
435
+
436
+ #: tmp/so-css.php:198
437
+ msgid "Are you sure you want to leave without saving?"
438
+ msgstr ""
439
+
440
+ #: tmp/so-css.php:234
441
+ msgid "CSS Editor"
442
+ msgstr ""
443
+
444
+ #: tmp/so-css.php:235
445
+ msgid "Support"
446
+ msgstr ""
447
+
448
+ #: tmp/so-css.php:373
449
+ msgid "Changes apply to %s and its child themes"
450
+ msgstr ""
451
+
452
+ #: tmp/tpl/inspector-templates.php:4
453
+ msgid "Navigate To: "
454
+ msgstr ""
455
+
456
+ #: tmp/tpl/js-templates.php:8
457
+ msgid "CSS Snippets"
458
+ msgstr ""
459
+
460
+ #: tmp/tpl/js-templates.php:14
461
+ msgid "Search Snippets"
462
+ msgstr ""
463
+
464
+ #: tmp/tpl/js-templates.php:26
465
+ msgid "Insert Snippet"
466
+ msgstr ""
467
+
468
+ #: tmp/tpl/js-templates.php:51
469
+ msgid "Invalid URI. Please make sure you're using a URL from the same site."
470
+ msgstr ""
471
+
472
+ #: tmp/tpl/page.php:13
473
+ msgid "SiteOrigin CSS"
474
+ msgstr ""
475
+
476
+ #: tmp/tpl/page.php:18
477
+ msgid "Site design updated."
478
+ msgstr ""
479
+
480
+ #: tmp/tpl/page.php:23
481
+ msgid "Viewing a revision. Save CSS to keep using this revision."
482
+ msgstr ""
483
+
484
+ #: tmp/tpl/page.php:33
485
+ msgid "Getting Started Video"
486
+ msgstr ""
487
+
488
+ #: tmp/tpl/page.php:34
489
+ msgid "Dismiss"
490
+ msgstr ""
491
+
492
+ #: tmp/tpl/page.php:43
493
+ msgid "CSS Revisions"
494
+ msgstr ""
495
+
496
+ #: tmp/tpl/page.php:45
497
+ msgid "Are you sure you want to load this revision?"
498
+ msgstr ""
499
+
500
+ #: tmp/tpl/page.php:57
501
+ msgid "%d chars"
502
+ msgstr ""
503
+
504
+ #: tmp/tpl/page.php:101
505
+ msgid "Save CSS"
506
+ msgstr ""
lib/codemirror/addon/fold/indent-fold.js CHANGED
@@ -11,32 +11,36 @@
11
  })(function(CodeMirror) {
12
  "use strict";
13
 
 
 
 
 
 
 
 
 
14
  CodeMirror.registerHelper("fold", "indent", function(cm, start) {
15
- var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
16
- if (!/\S/.test(firstLine)) return;
17
- var getIndent = function(line) {
18
- return CodeMirror.countColumn(line, null, tabSize);
19
- };
20
- var myIndent = getIndent(firstLine);
21
- var lastLineInFold = null;
22
  // Go through lines until we find a line that definitely doesn't belong in
23
  // the block we're folding, or to the end.
24
  for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
25
- var curLine = cm.getLine(i);
26
- var curIndent = getIndent(curLine);
27
- if (curIndent > myIndent) {
28
  // Lines with a greater indent are considered part of the block.
29
  lastLineInFold = i;
30
- } else if (!/\S/.test(curLine)) {
31
- // Empty lines might be breaks within the block we're trying to fold.
32
  } else {
33
- // A non-empty line at an indent equal to or less than ours marks the
34
- // start of another block.
 
35
  break;
36
  }
37
  }
38
  if (lastLineInFold) return {
39
- from: CodeMirror.Pos(start.line, firstLine.length),
40
  to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
41
  };
42
  });
11
  })(function(CodeMirror) {
12
  "use strict";
13
 
14
+ function lineIndent(cm, lineNo) {
15
+ var text = cm.getLine(lineNo)
16
+ var spaceTo = text.search(/\S/)
17
+ if (spaceTo == -1 || /\bcomment\b/.test(cm.getTokenTypeAt(CodeMirror.Pos(lineNo, spaceTo + 1))))
18
+ return -1
19
+ return CodeMirror.countColumn(text, null, cm.getOption("tabSize"))
20
+ }
21
+ !
22
  CodeMirror.registerHelper("fold", "indent", function(cm, start) {
23
+ var myIndent = lineIndent(cm, start.line)
24
+ if (myIndent < 0) return
25
+ var lastLineInFold = null
26
+
 
 
 
27
  // Go through lines until we find a line that definitely doesn't belong in
28
  // the block we're folding, or to the end.
29
  for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
30
+ var indent = lineIndent(cm, i)
31
+ if (indent == -1) {
32
+ } else if (indent > myIndent) {
33
  // Lines with a greater indent are considered part of the block.
34
  lastLineInFold = i;
 
 
35
  } else {
36
+ // If this line has non-space, non-comment content, and is
37
+ // indented less or equal to the start line, it is the start of
38
+ // another block.
39
  break;
40
  }
41
  }
42
  if (lastLineInFold) return {
43
+ from: CodeMirror.Pos(start.line, cm.getLine(start.line).length),
44
  to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
45
  };
46
  });
lib/codemirror/addon/fold/indent-fold.min.js CHANGED
@@ -1 +1 @@
1
- !function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.registerHelper("fold","indent",function(t,n){var i=t.getOption("tabSize"),o=t.getLine(n.line);if(/\S/.test(o)){for(var r=function(t){return e.countColumn(t,null,i)},f=r(o),l=null,u=n.line+1,c=t.lastLine();u<=c;++u){var d=t.getLine(u),s=r(d);if(s>f)l=u;else if(/\S/.test(d))break}return l?{from:e.Pos(n.line,o.length),to:e.Pos(l,t.getLine(l).length)}:void 0}})});
1
+ !function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function n(n,t){var i=n.getLine(t),o=i.search(/\S/);return o==-1||/\bcomment\b/.test(n.getTokenTypeAt(e.Pos(t,o+1)))?-1:e.countColumn(i,null,n.getOption("tabSize"))}!e.registerHelper("fold","indent",function(t,i){var o=n(t,i.line);if(!(o<0)){for(var r=null,l=i.line+1,f=t.lastLine();l<=f;++l){var u=n(t,l);if(u==-1);else{if(!(u>o))break;r=l}}return r?{from:e.Pos(i.line,t.getLine(i.line).length),to:e.Pos(r,t.getLine(r).length)}:void 0}})});
lib/codemirror/addon/fold/xml-fold.js CHANGED
@@ -163,10 +163,10 @@
163
  }
164
  };
165
 
166
- CodeMirror.findEnclosingTag = function(cm, pos, range) {
167
  var iter = new Iter(cm, pos.line, pos.ch, range);
168
  for (;;) {
169
- var open = findMatchingOpen(iter);
170
  if (!open) break;
171
  var forward = new Iter(cm, pos.line, pos.ch, range);
172
  var close = findMatchingClose(forward, open.tag);
163
  }
164
  };
165
 
166
+ CodeMirror.findEnclosingTag = function(cm, pos, range, tag) {
167
  var iter = new Iter(cm, pos.line, pos.ch, range);
168
  for (;;) {
169
+ var open = findMatchingOpen(iter, tag);
170
  if (!open) break;
171
  var forward = new Iter(cm, pos.line, pos.ch, range);
172
  var close = findMatchingClose(forward, open.tag);
lib/codemirror/addon/fold/xml-fold.min.js CHANGED
@@ -1 +1 @@
1
- !function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function n(e,n){return e.line-n.line||e.ch-n.ch}function t(e,n,t,i){this.line=n,this.ch=t,this.cm=e,this.text=e.getLine(n),this.min=i?Math.max(i.from,e.firstLine()):e.firstLine(),this.max=i?Math.min(i.to-1,e.lastLine()):e.lastLine()}function i(e,n){var t=e.cm.getTokenTypeAt(h(e.line,n));return t&&/\btag\b/.test(t)}function r(e){if(!(e.line>=e.max))return e.ch=0,e.text=e.cm.getLine(++e.line),!0}function f(e){if(!(e.line<=e.min))return e.text=e.cm.getLine(--e.line),e.ch=e.text.length,!0}function o(e){for(;;){var n=e.text.indexOf(">",e.ch);if(n==-1){if(r(e))continue;return}{if(i(e,n+1)){var t=e.text.lastIndexOf("/",n),f=t>-1&&!/\S/.test(e.text.slice(t+1,n));return e.ch=n+1,f?"selfClose":"regular"}e.ch=n+1}}}function u(e){for(;;){var n=e.ch?e.text.lastIndexOf("<",e.ch-1):-1;if(n==-1){if(f(e))continue;return}if(i(e,n+1)){v.lastIndex=n,e.ch=n;var t=v.exec(e.text);if(t&&t.index==n)return t}else e.ch=n}}function l(e){for(;;){v.lastIndex=e.ch;var n=v.exec(e.text);if(!n){if(r(e))continue;return}{if(i(e,n.index+1))return e.ch=n.index+n[0].length,n;e.ch=n.index+1}}}function c(e){for(;;){var n=e.ch?e.text.lastIndexOf(">",e.ch-1):-1;if(n==-1){if(f(e))continue;return}{if(i(e,n+1)){var t=e.text.lastIndexOf("/",n),r=t>-1&&!/\S/.test(e.text.slice(t+1,n));return e.ch=n+1,r?"selfClose":"regular"}e.ch=n}}}function a(e,n){for(var t=[];;){var i,r=l(e),f=e.line,u=e.ch-(r?r[0].length:0);if(!r||!(i=o(e)))return;if("selfClose"!=i)if(r[1]){for(var c=t.length-1;c>=0;--c)if(t[c]==r[2]){t.length=c;break}if(c<0&&(!n||n==r[2]))return{tag:r[2],from:h(f,u),to:h(e.line,e.ch)}}else t.push(r[2])}}function s(e,n){for(var t=[];;){var i=c(e);if(!i)return;if("selfClose"!=i){var r=e.line,f=e.ch,o=u(e);if(!o)return;if(o[1])t.push(o[2]);else{for(var l=t.length-1;l>=0;--l)if(t[l]==o[2]){t.length=l;break}if(l<0&&(!n||n==o[2]))return{tag:o[2],from:h(e.line,e.ch),to:h(r,f)}}}else u(e)}}var h=e.Pos,x="A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",g=x+"-:.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040",v=new RegExp("<(/?)(["+x+"]["+g+"]*)","g");e.registerHelper("fold","xml",function(e,n){for(var i=new t(e,n.line,0);;){var r,f=l(i);if(!f||i.line!=n.line||!(r=o(i)))return;if(!f[1]&&"selfClose"!=r){var u=h(i.line,i.ch),c=a(i,f[2]);return c&&{from:u,to:c.from}}}}),e.findMatchingTag=function(e,i,r){var f=new t(e,i.line,i.ch,r);if(f.text.indexOf(">")!=-1||f.text.indexOf("<")!=-1){var l=o(f),c=l&&h(f.line,f.ch),x=l&&u(f);if(l&&x&&!(n(f,i)>0)){var g={from:h(f.line,f.ch),to:c,tag:x[2]};return"selfClose"==l?{open:g,close:null,at:"open"}:x[1]?{open:s(f,x[2]),close:g,at:"close"}:(f=new t(e,c.line,c.ch,r),{open:g,close:a(f,x[2]),at:"open"})}}},e.findEnclosingTag=function(e,n,i){for(var r=new t(e,n.line,n.ch,i);;){var f=s(r);if(!f)break;var o=new t(e,n.line,n.ch,i),u=a(o,f.tag);if(u)return{open:f,close:u}}},e.scanForClosingTag=function(e,n,i,r){var f=new t(e,n.line,n.ch,r?{from:0,to:r}:null);return a(f,i)}});
1
+ !function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function n(e,n){return e.line-n.line||e.ch-n.ch}function t(e,n,t,i){this.line=n,this.ch=t,this.cm=e,this.text=e.getLine(n),this.min=i?Math.max(i.from,e.firstLine()):e.firstLine(),this.max=i?Math.min(i.to-1,e.lastLine()):e.lastLine()}function i(e,n){var t=e.cm.getTokenTypeAt(h(e.line,n));return t&&/\btag\b/.test(t)}function r(e){if(!(e.line>=e.max))return e.ch=0,e.text=e.cm.getLine(++e.line),!0}function f(e){if(!(e.line<=e.min))return e.text=e.cm.getLine(--e.line),e.ch=e.text.length,!0}function o(e){for(;;){var n=e.text.indexOf(">",e.ch);if(n==-1){if(r(e))continue;return}{if(i(e,n+1)){var t=e.text.lastIndexOf("/",n),f=t>-1&&!/\S/.test(e.text.slice(t+1,n));return e.ch=n+1,f?"selfClose":"regular"}e.ch=n+1}}}function u(e){for(;;){var n=e.ch?e.text.lastIndexOf("<",e.ch-1):-1;if(n==-1){if(f(e))continue;return}if(i(e,n+1)){v.lastIndex=n,e.ch=n;var t=v.exec(e.text);if(t&&t.index==n)return t}else e.ch=n}}function l(e){for(;;){v.lastIndex=e.ch;var n=v.exec(e.text);if(!n){if(r(e))continue;return}{if(i(e,n.index+1))return e.ch=n.index+n[0].length,n;e.ch=n.index+1}}}function c(e){for(;;){var n=e.ch?e.text.lastIndexOf(">",e.ch-1):-1;if(n==-1){if(f(e))continue;return}{if(i(e,n+1)){var t=e.text.lastIndexOf("/",n),r=t>-1&&!/\S/.test(e.text.slice(t+1,n));return e.ch=n+1,r?"selfClose":"regular"}e.ch=n}}}function a(e,n){for(var t=[];;){var i,r=l(e),f=e.line,u=e.ch-(r?r[0].length:0);if(!r||!(i=o(e)))return;if("selfClose"!=i)if(r[1]){for(var c=t.length-1;c>=0;--c)if(t[c]==r[2]){t.length=c;break}if(c<0&&(!n||n==r[2]))return{tag:r[2],from:h(f,u),to:h(e.line,e.ch)}}else t.push(r[2])}}function s(e,n){for(var t=[];;){var i=c(e);if(!i)return;if("selfClose"!=i){var r=e.line,f=e.ch,o=u(e);if(!o)return;if(o[1])t.push(o[2]);else{for(var l=t.length-1;l>=0;--l)if(t[l]==o[2]){t.length=l;break}if(l<0&&(!n||n==o[2]))return{tag:o[2],from:h(e.line,e.ch),to:h(r,f)}}}else u(e)}}var h=e.Pos,x="A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",g=x+"-:.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040",v=new RegExp("<(/?)(["+x+"]["+g+"]*)","g");e.registerHelper("fold","xml",function(e,n){for(var i=new t(e,n.line,0);;){var r,f=l(i);if(!f||i.line!=n.line||!(r=o(i)))return;if(!f[1]&&"selfClose"!=r){var u=h(i.line,i.ch),c=a(i,f[2]);return c&&{from:u,to:c.from}}}}),e.findMatchingTag=function(e,i,r){var f=new t(e,i.line,i.ch,r);if(f.text.indexOf(">")!=-1||f.text.indexOf("<")!=-1){var l=o(f),c=l&&h(f.line,f.ch),x=l&&u(f);if(l&&x&&!(n(f,i)>0)){var g={from:h(f.line,f.ch),to:c,tag:x[2]};return"selfClose"==l?{open:g,close:null,at:"open"}:x[1]?{open:s(f,x[2]),close:g,at:"close"}:(f=new t(e,c.line,c.ch,r),{open:g,close:a(f,x[2]),at:"open"})}}},e.findEnclosingTag=function(e,n,i,r){for(var f=new t(e,n.line,n.ch,i);;){var o=s(f,r);if(!o)break;var u=new t(e,n.line,n.ch,i),l=a(u,o.tag);if(l)return{open:o,close:l}}},e.scanForClosingTag=function(e,n,i,r){var f=new t(e,n.line,n.ch,r?{from:0,to:r}:null);return a(f,i)}});
lib/codemirror/addon/hint/sql-hint.js CHANGED
@@ -14,6 +14,7 @@
14
  var tables;
15
  var defaultTable;
16
  var keywords;
 
17
  var CONS = {
18
  QUERY_DIV: ";",
19
  ALIAS_KEYWORD: "AS"
@@ -28,6 +29,12 @@
28
  return CodeMirror.resolveMode(mode).keywords;
29
  }
30
 
 
 
 
 
 
 
31
  function getText(item) {
32
  return typeof item == "string" ? item : item.text;
33
  }
@@ -86,17 +93,25 @@
86
  }
87
 
88
  function cleanName(name) {
89
- // Get rid name from backticks(`) and preceding dot(.)
90
  if (name.charAt(0) == ".") {
91
  name = name.substr(1);
92
  }
93
- return name.replace(/`/g, "");
 
 
 
 
 
94
  }
95
 
96
- function insertBackticks(name) {
97
  var nameParts = getText(name).split(".");
98
  for (var i = 0; i < nameParts.length; i++)
99
- nameParts[i] = "`" + nameParts[i] + "`";
 
 
 
100
  var escaped = nameParts.join(".");
101
  if (typeof name == "string") return escaped;
102
  name = shallowClone(name);
@@ -106,13 +121,13 @@
106
 
107
  function nameCompletion(cur, token, result, editor) {
108
  // Try to complete table, column names and return start position of completion
109
- var useBacktick = false;
110
  var nameParts = [];
111
  var start = token.start;
112
  var cont = true;
113
  while (cont) {
114
  cont = (token.string.charAt(0) == ".");
115
- useBacktick = useBacktick || (token.string.charAt(0) == "`");
116
 
117
  start = token.start;
118
  nameParts.unshift(cleanName(token.string));
@@ -127,12 +142,12 @@
127
  // Try to complete table names
128
  var string = nameParts.join(".");
129
  addMatches(result, string, tables, function(w) {
130
- return useBacktick ? insertBackticks(w) : w;
131
  });
132
 
133
  // Try to complete columns from defaultTable
134
  addMatches(result, string, defaultTable, function(w) {
135
- return useBacktick ? insertBackticks(w) : w;
136
  });
137
 
138
  // Try to complete columns
@@ -162,7 +177,7 @@
162
  w = shallowClone(w);
163
  w.text = tableInsert + "." + w.text;
164
  }
165
- return useBacktick ? insertBackticks(w) : w;
166
  });
167
  }
168
 
@@ -232,6 +247,7 @@
232
  var disableKeywords = options && options.disableKeywords;
233
  defaultTable = defaultTableName && getTable(defaultTableName);
234
  keywords = getKeywords(editor);
 
235
 
236
  if (defaultTableName && !defaultTable)
237
  defaultTable = findTableByAlias(defaultTableName, editor);
@@ -249,7 +265,7 @@
249
  token.string = token.string.slice(0, cur.ch - token.start);
250
  }
251
 
252
- if (token.string.match(/^[.`\w@]\w*$/)) {
253
  search = token.string;
254
  start = token.start;
255
  end = token.end;
@@ -257,7 +273,7 @@
257
  start = end = cur.ch;
258
  search = "";
259
  }
260
- if (search.charAt(0) == "." || search.charAt(0) == "`") {
261
  start = nameCompletion(cur, token, result, editor);
262
  } else {
263
  addMatches(result, search, tables, function(w) {return w;});
14
  var tables;
15
  var defaultTable;
16
  var keywords;
17
+ var identifierQuote;
18
  var CONS = {
19
  QUERY_DIV: ";",
20
  ALIAS_KEYWORD: "AS"
29
  return CodeMirror.resolveMode(mode).keywords;
30
  }
31
 
32
+ function getIdentifierQuote(editor) {
33
+ var mode = editor.doc.modeOption;
34
+ if (mode === "sql") mode = "text/x-sql";
35
+ return CodeMirror.resolveMode(mode).identifierQuote || "`";
36
+ }
37
+
38
  function getText(item) {
39
  return typeof item == "string" ? item : item.text;
40
  }
93
  }
94
 
95
  function cleanName(name) {
96
+ // Get rid name from identifierQuote and preceding dot(.)
97
  if (name.charAt(0) == ".") {
98
  name = name.substr(1);
99
  }
100
+ // replace doublicated identifierQuotes with single identifierQuotes
101
+ // and remove single identifierQuotes
102
+ var nameParts = name.split(identifierQuote+identifierQuote);
103
+ for (var i = 0; i < nameParts.length; i++)
104
+ nameParts[i] = nameParts[i].replace(new RegExp(identifierQuote,"g"), "");
105
+ return nameParts.join(identifierQuote);
106
  }
107
 
108
+ function insertIdentifierQuotes(name) {
109
  var nameParts = getText(name).split(".");
110
  for (var i = 0; i < nameParts.length; i++)
111
+ nameParts[i] = identifierQuote +
112
+ // doublicate identifierQuotes
113
+ nameParts[i].replace(new RegExp(identifierQuote,"g"), identifierQuote+identifierQuote) +
114
+ identifierQuote;
115
  var escaped = nameParts.join(".");
116
  if (typeof name == "string") return escaped;
117
  name = shallowClone(name);
121
 
122
  function nameCompletion(cur, token, result, editor) {
123
  // Try to complete table, column names and return start position of completion
124
+ var useIdentifierQuotes = false;
125
  var nameParts = [];
126
  var start = token.start;
127
  var cont = true;
128
  while (cont) {
129
  cont = (token.string.charAt(0) == ".");
130
+ useIdentifierQuotes = useIdentifierQuotes || (token.string.charAt(0) == identifierQuote);
131
 
132
  start = token.start;
133
  nameParts.unshift(cleanName(token.string));
142
  // Try to complete table names
143
  var string = nameParts.join(".");
144
  addMatches(result, string, tables, function(w) {
145
+ return useIdentifierQuotes ? insertIdentifierQuotes(w) : w;
146
  });
147
 
148
  // Try to complete columns from defaultTable
149
  addMatches(result, string, defaultTable, function(w) {
150
+ return useIdentifierQuotes ? insertIdentifierQuotes(w) : w;
151
  });
152
 
153
  // Try to complete columns
177
  w = shallowClone(w);
178
  w.text = tableInsert + "." + w.text;
179
  }
180
+ return useIdentifierQuotes ? insertIdentifierQuotes(w) : w;
181
  });
182
  }
183
 
247
  var disableKeywords = options && options.disableKeywords;
248
  defaultTable = defaultTableName && getTable(defaultTableName);
249
  keywords = getKeywords(editor);
250
+ identifierQuote = getIdentifierQuote(editor);
251
 
252
  if (defaultTableName && !defaultTable)
253
  defaultTable = findTableByAlias(defaultTableName, editor);
265
  token.string = token.string.slice(0, cur.ch - token.start);
266
  }
267
 
268
+ if (token.string.match(/^[.`"\w@]\w*$/)) {
269
  search = token.string;
270
  start = token.start;
271
  end = token.end;
273
  start = end = cur.ch;
274
  search = "";
275
  }
276
+ if (search.charAt(0) == "." || search.charAt(0) == identifierQuote) {
277
  start = nameCompletion(cur, token, result, editor);
278
  } else {
279
  addMatches(result, search, tables, function(w) {return w;});
lib/codemirror/addon/hint/sql-hint.min.js CHANGED
@@ -1 +1 @@
1
- !function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror"),require("../../mode/sql/sql")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../../mode/sql/sql"],t):t(CodeMirror)}(function(t){"use strict";function r(t){return"[object Array]"==Object.prototype.toString.call(t)}function e(r){var e=r.doc.modeOption;return"sql"===e&&(e="text/x-sql"),t.resolveMode(e).keywords}function n(t){return"string"==typeof t?t:t.text}function o(t,e){return r(e)&&(e={columns:e}),e.text||(e.text=t),e}function i(t){var e={};if(r(t))for(var i=t.length-1;i>=0;i--){var s=t[i];e[n(s).toUpperCase()]=o(n(s),s)}else if(t)for(var a in t)e[a.toUpperCase()]=o(a,t[a]);return e}function s(t){return v[t.toUpperCase()]}function a(t){var r={};for(var e in t)t.hasOwnProperty(e)&&(r[e]=t[e]);return r}function u(t,r){var e=t.length,o=n(r).substr(0,e);return t.toUpperCase()===o.toUpperCase()}function f(t,e,n,o){if(r(n))for(var i=0;i<n.length;i++)u(e,n[i])&&t.push(o(n[i]));else for(var s in n)if(n.hasOwnProperty(s)){var a=n[s];a=a&&a!==!0?a.displayText?{text:a.text,displayText:a.displayText}:a.text:s,u(e,a)&&t.push(o(a))}}function l(t){return"."==t.charAt(0)&&(t=t.substr(1)),t.replace(/`/g,"")}function c(t){for(var r=n(t).split("."),e=0;e<r.length;e++)r[e]="`"+r[e]+"`";var o=r.join(".");return"string"==typeof t?o:(t=a(t),t.text=o,t)}function p(t,r,e,n){for(var o=!1,i=[],u=r.start,p=!0;p;)p="."==r.string.charAt(0),o=o||"`"==r.string.charAt(0),u=r.start,i.unshift(l(r.string)),r=n.getTokenAt(y(t.line,r.start)),"."==r.string&&(p=!0,r=n.getTokenAt(y(t.line,r.start)));var g=i.join(".");f(e,g,v,function(t){return o?c(t):t}),f(e,g,h,function(t){return o?c(t):t}),g=i.pop();var x=i.join("."),m=!1,A=x;if(!s(x)){var b=x;x=d(x,n),x!==b&&(m=!0)}var C=s(x);return C&&C.columns&&(C=C.columns),C&&f(e,g,C,function(t){var r=x;return 1==m&&(r=A),"string"==typeof t?t=r+"."+t:(t=a(t),t.text=r+"."+t.text),o?c(t):t}),u}function g(t,r){if(t)for(var e=/[,;]/g,n=t.split(" "),o=0;o<n.length;o++)r(n[o]?n[o].replace(e,""):"")}function d(t,r){for(var e=r.doc,n=e.getValue(),o=t.toUpperCase(),i="",a="",u=[],f={start:y(0,0),end:y(r.lastLine(),r.getLineHandle(r.lastLine()).length)},l=n.indexOf(m.QUERY_DIV);l!=-1;)u.push(e.posFromIndex(l)),l=n.indexOf(m.QUERY_DIV,l+1);u.unshift(y(0,0)),u.push(y(r.lastLine(),r.getLineHandle(r.lastLine()).text.length));for(var c=null,p=r.getCursor(),d=0;d<u.length;d++){if((null==c||A(p,c)>0)&&A(p,u[d])<=0){f={start:c,end:u[d]};break}c=u[d]}for(var v=e.getRange(f.start,f.end,!1),d=0;d<v.length;d++){var h=v[d];if(g(h,function(t){var r=t.toUpperCase();r===o&&s(i)&&(a=i),r!==m.ALIAS_KEYWORD&&(i=t)}),a)break}return a}var v,h,x,m={QUERY_DIV:";",ALIAS_KEYWORD:"AS"},y=t.Pos,A=t.cmpPos;t.registerHelper("hint","sql",function(t,r){v=i(r&&r.tables);var n=r&&r.defaultTable,o=r&&r.disableKeywords;h=n&&s(n),x=e(t),n&&!h&&(h=d(n,t)),h=h||[],h.columns&&(h=h.columns);var a,u,l,c=t.getCursor(),g=[],m=t.getTokenAt(c);return m.end>c.ch&&(m.end=c.ch,m.string=m.string.slice(0,c.ch-m.start)),m.string.match(/^[.`\w@]\w*$/)?(l=m.string,a=m.start,u=m.end):(a=u=c.ch,l=""),"."==l.charAt(0)||"`"==l.charAt(0)?a=p(c,m,g,t):(f(g,l,v,function(t){return t}),f(g,l,h,function(t){return t}),o||f(g,l,x,function(t){return t.toUpperCase()})),{list:g,from:y(c.line,a),to:y(c.line,u)}})});
1
+ !function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror"),require("../../mode/sql/sql")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../../mode/sql/sql"],t):t(CodeMirror)}(function(t){"use strict";function e(t){return"[object Array]"==Object.prototype.toString.call(t)}function r(e){var r=e.doc.modeOption;return"sql"===r&&(r="text/x-sql"),t.resolveMode(r).keywords}function n(e){var r=e.doc.modeOption;return"sql"===r&&(r="text/x-sql"),t.resolveMode(r).identifierQuote||"`"}function o(t){return"string"==typeof t?t:t.text}function i(t,r){return e(r)&&(r={columns:r}),r.text||(r.text=t),r}function s(t){var r={};if(e(t))for(var n=t.length-1;n>=0;n--){var s=t[n];r[o(s).toUpperCase()]=i(o(s),s)}else if(t)for(var a in t)r[a.toUpperCase()]=i(a,t[a]);return r}function a(t){return h[t.toUpperCase()]}function u(t){var e={};for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e}function l(t,e){var r=t.length,n=o(e).substr(0,r);return t.toUpperCase()===n.toUpperCase()}function f(t,r,n,o){if(e(n))for(var i=0;i<n.length;i++)l(r,n[i])&&t.push(o(n[i]));else for(var s in n)if(n.hasOwnProperty(s)){var a=n[s];a=a&&a!==!0?a.displayText?{text:a.text,displayText:a.displayText}:a.text:s,l(r,a)&&t.push(o(a))}}function c(t){"."==t.charAt(0)&&(t=t.substr(1));for(var e=t.split(y+y),r=0;r<e.length;r++)e[r]=e[r].replace(new RegExp(y,"g"),"");return e.join(y)}function p(t){for(var e=o(t).split("."),r=0;r<e.length;r++)e[r]=y+e[r].replace(new RegExp(y,"g"),y+y)+y;var n=e.join(".");return"string"==typeof t?n:(t=u(t),t.text=n,t)}function g(t,e,r,n){for(var o=!1,i=[],s=e.start,l=!0;l;)l="."==e.string.charAt(0),o=o||e.string.charAt(0)==y,s=e.start,i.unshift(c(e.string)),e=n.getTokenAt(b(t.line,e.start)),"."==e.string&&(l=!0,e=n.getTokenAt(b(t.line,e.start)));var g=i.join(".");f(r,g,h,function(t){return o?p(t):t}),f(r,g,x,function(t){return o?p(t):t}),g=i.pop();var d=i.join("."),m=!1,A=d;if(!a(d)){var q=d;d=v(d,n),d!==q&&(m=!0)}var C=a(d);return C&&C.columns&&(C=C.columns),C&&f(r,g,C,function(t){var e=d;return 1==m&&(e=A),"string"==typeof t?t=e+"."+t:(t=u(t),t.text=e+"."+t.text),o?p(t):t}),s}function d(t,e){if(t)for(var r=/[,;]/g,n=t.split(" "),o=0;o<n.length;o++)e(n[o]?n[o].replace(r,""):"")}function v(t,e){for(var r=e.doc,n=r.getValue(),o=t.toUpperCase(),i="",s="",u=[],l={start:b(0,0),end:b(e.lastLine(),e.getLineHandle(e.lastLine()).length)},f=n.indexOf(A.QUERY_DIV);f!=-1;)u.push(r.posFromIndex(f)),f=n.indexOf(A.QUERY_DIV,f+1);u.unshift(b(0,0)),u.push(b(e.lastLine(),e.getLineHandle(e.lastLine()).text.length));for(var c=null,p=e.getCursor(),g=0;g<u.length;g++){if((null==c||q(p,c)>0)&&q(p,u[g])<=0){l={start:c,end:u[g]};break}c=u[g]}for(var v=r.getRange(l.start,l.end,!1),g=0;g<v.length;g++){var h=v[g];if(d(h,function(t){var e=t.toUpperCase();e===o&&a(i)&&(s=i),e!==A.ALIAS_KEYWORD&&(i=t)}),s)break}return s}var h,x,m,y,A={QUERY_DIV:";",ALIAS_KEYWORD:"AS"},b=t.Pos,q=t.cmpPos;t.registerHelper("hint","sql",function(t,e){h=s(e&&e.tables);var o=e&&e.defaultTable,i=e&&e.disableKeywords;x=o&&a(o),m=r(t),y=n(t),o&&!x&&(x=v(o,t)),x=x||[],x.columns&&(x=x.columns);var u,l,c,p=t.getCursor(),d=[],A=t.getTokenAt(p);return A.end>p.ch&&(A.end=p.ch,A.string=A.string.slice(0,p.ch-A.start)),A.string.match(/^[.`"\w@]\w*$/)?(c=A.string,u=A.start,l=A.end):(u=l=p.ch,c=""),"."==c.charAt(0)||c.charAt(0)==y?u=g(p,A,d,t):(f(d,c,h,function(t){return t}),f(d,c,x,function(t){return t}),i||f(d,c,m,function(t){return t.toUpperCase()})),{list:d,from:b(p.line,u),to:b(p.line,l)}})});
lib/codemirror/addon/lint/css-lint.js CHANGED
@@ -18,15 +18,14 @@
18
  CodeMirror.registerHelper("lint", "css", function(text) {
19
  var found = [];
20
  if (!window.CSSLint) return found;
21
- // This has been modified to only display certain errors
22
- var results = CSSLint.verify(text, {
23
- "box-model": 1,
24
- "display-property-grouping": 1,
25
- "duplicate-properties": 1,
26
- "empty-rules": 1,
27
- "known-properties": 1
28
- }), messages = results.messages, message = null;
29
-
30
  for ( var i = 0; i < messages.length; i++) {
31
  message = messages[i];
32
  var startLine = message.line -1, endLine = message.line -1, startCol = message.col -1, endCol = message.col;
18
  CodeMirror.registerHelper("lint", "css", function(text) {
19
  var found = [];
20
  if (!window.CSSLint) return found;
21
+ // This has been modified to only display certain errors
22
+ var results = CSSLint.verify(text, {
23
+ "box-model": 1,
24
+ "display-property-grouping": 1,
25
+ "duplicate-properties": 1,
26
+ "empty-rules": 1,
27
+ "known-properties": 1
28
+ }), messages = results.messages, message = null;
 
29
  for ( var i = 0; i < messages.length; i++) {
30
  message = messages[i];
31
  var startLine = message.line -1, endLine = message.line -1, startCol = message.col -1, endCol = message.col;
lib/codemirror/addon/lint/lint.js CHANGED
@@ -140,7 +140,12 @@
140
  if (options.async || getAnnotations.async) {
141
  lintAsync(cm, getAnnotations, passOptions)
142
  } else {
143
- updateLinting(cm, getAnnotations(cm.getValue(), passOptions, cm));
 
 
 
 
 
144
  }
145
  }
146
 
140
  if (options.async || getAnnotations.async) {
141
  lintAsync(cm, getAnnotations, passOptions)
142
  } else {
143
+ var annotations = getAnnotations(cm.getValue(), passOptions, cm);
144
+ if (!annotations) return;
145
+ if (annotations.then) annotations.then(function(issues) {
146
+ updateLinting(cm, issues);
147
+ });
148
+ else updateLinting(cm, annotations);
149
  }
150
  }
151
 
lib/codemirror/addon/lint/lint.min.js CHANGED
@@ -1 +1 @@
1
- !function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],t):t(CodeMirror)}(function(t){"use strict";function e(e,n){function o(e){return r.parentNode?(r.style.top=Math.max(0,e.clientY-r.offsetHeight-5)+"px",void(r.style.left=e.clientX+5+"px")):t.off(document,"mousemove",o)}var r=document.createElement("div");return r.className="CodeMirror-lint-tooltip",r.appendChild(n.cloneNode(!0)),document.body.appendChild(r),t.on(document,"mousemove",o),o(e),null!=r.style.opacity&&(r.style.opacity=1),r}function n(t){t.parentNode&&t.parentNode.removeChild(t)}function o(t){t.parentNode&&(null==t.style.opacity&&n(t),t.style.opacity=0,setTimeout(function(){n(t)},600))}function r(n,r,i){function a(){t.off(i,"mouseout",a),l&&(o(l),l=null)}var l=e(n,r),s=setInterval(function(){if(l)for(var t=i;;t=t.parentNode){if(t&&11==t.nodeType&&(t=t.host),t==document.body)return;if(!t){a();break}}if(!l)return clearInterval(s)},400);t.on(i,"mouseout",a)}function i(t,e,n){this.marked=[],this.options=e,this.timeout=null,this.hasGutter=n,this.onMouseOver=function(e){g(t,e)},this.waitingFor=0}function a(t,e){return e instanceof Function?{getAnnotations:e}:(e&&e!==!0||(e={}),e)}function l(t){var e=t.state.lint;e.hasGutter&&t.clearGutter(y);for(var n=0;n<e.marked.length;++n)e.marked[n].clear();e.marked.length=0}function s(e,n,o,i){var a=document.createElement("div"),l=a;return a.className="CodeMirror-lint-marker-"+n,o&&(l=a.appendChild(document.createElement("div")),l.className="CodeMirror-lint-marker-multiple"),0!=i&&t.on(l,"mouseover",function(t){r(t,e,l)}),a}function u(t,e){return"error"==t?t:e}function c(t){for(var e=[],n=0;n<t.length;++n){var o=t[n],r=o.from.line;(e[r]||(e[r]=[])).push(o)}return e}function f(t){var e=t.severity;e||(e="error");var n=document.createElement("div");return n.className="CodeMirror-lint-message-"+e,n.appendChild(document.createTextNode(t.message)),n}function m(e,n,o){function r(){a=-1,e.off("change",r)}var i=e.state.lint,a=++i.waitingFor;e.on("change",r),n(e.getValue(),function(n,o){e.off("change",r),i.waitingFor==a&&(o&&n instanceof t&&(n=o),p(e,n))},o,e)}function d(e){var n=e.state.lint,o=n.options,r=o.options||o,i=o.getAnnotations||e.getHelper(t.Pos(0,0),"lint");i&&(o.async||i.async?m(e,i,r):p(e,i(e.getValue(),r,e)))}function p(t,e){l(t);for(var n=t.state.lint,o=n.options,r=c(e),i=0;i<r.length;++i){var a=r[i];if(a){for(var m=null,d=n.hasGutter&&document.createDocumentFragment(),p=0;p<a.length;++p){var h=a[p],v=h.severity;v||(v="error"),m=u(m,v),o.formatAnnotation&&(h=o.formatAnnotation(h)),n.hasGutter&&d.appendChild(f(h)),h.to&&n.marked.push(t.markText(h.from,h.to,{className:"CodeMirror-lint-mark-"+v,__annotation:h}))}n.hasGutter&&t.setGutterMarker(i,y,s(d,m,a.length>1,n.options.tooltips))}}o.onUpdateLinting&&o.onUpdateLinting(e,r,t)}function h(t){var e=t.state.lint;e&&(clearTimeout(e.timeout),e.timeout=setTimeout(function(){d(t)},e.options.delay||500))}function v(t,e){for(var n=e.target||e.srcElement,o=document.createDocumentFragment(),i=0;i<t.length;i++){var a=t[i];o.appendChild(f(a))}r(e,o,n)}function g(t,e){var n=e.target||e.srcElement;if(/\bCodeMirror-lint-mark-/.test(n.className)){for(var o=n.getBoundingClientRect(),r=(o.left+o.right)/2,i=(o.top+o.bottom)/2,a=t.findMarksAt(t.coordsChar({left:r,top:i},"client")),l=[],s=0;s<a.length;++s){var u=a[s].__annotation;u&&l.push(u)}l.length&&v(l,e)}}var y="CodeMirror-lint-markers";t.defineOption("lint",!1,function(e,n,o){if(o&&o!=t.Init&&(l(e),e.state.lint.options.lintOnChange!==!1&&e.off("change",h),t.off(e.getWrapperElement(),"mouseover",e.state.lint.onMouseOver),clearTimeout(e.state.lint.timeout),delete e.state.lint),n){for(var r=e.getOption("gutters"),s=!1,u=0;u<r.length;++u)r[u]==y&&(s=!0);var c=e.state.lint=new i(e,a(e,n),s);c.options.lintOnChange!==!1&&e.on("change",h),0!=c.options.tooltips&&"gutter"!=c.options.tooltips&&t.on(e.getWrapperElement(),"mouseover",c.onMouseOver),d(e)}}),t.defineExtension("performLint",function(){this.state.lint&&d(this)})});
1
+ !function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],t):t(CodeMirror)}(function(t){"use strict";function e(e,n){function o(e){return r.parentNode?(r.style.top=Math.max(0,e.clientY-r.offsetHeight-5)+"px",void(r.style.left=e.clientX+5+"px")):t.off(document,"mousemove",o)}var r=document.createElement("div");return r.className="CodeMirror-lint-tooltip",r.appendChild(n.cloneNode(!0)),document.body.appendChild(r),t.on(document,"mousemove",o),o(e),null!=r.style.opacity&&(r.style.opacity=1),r}function n(t){t.parentNode&&t.parentNode.removeChild(t)}function o(t){t.parentNode&&(null==t.style.opacity&&n(t),t.style.opacity=0,setTimeout(function(){n(t)},600))}function r(n,r,i){function a(){t.off(i,"mouseout",a),l&&(o(l),l=null)}var l=e(n,r),u=setInterval(function(){if(l)for(var t=i;;t=t.parentNode){if(t&&11==t.nodeType&&(t=t.host),t==document.body)return;if(!t){a();break}}if(!l)return clearInterval(u)},400);t.on(i,"mouseout",a)}function i(t,e,n){this.marked=[],this.options=e,this.timeout=null,this.hasGutter=n,this.onMouseOver=function(e){g(t,e)},this.waitingFor=0}function a(t,e){return e instanceof Function?{getAnnotations:e}:(e&&e!==!0||(e={}),e)}function l(t){var e=t.state.lint;e.hasGutter&&t.clearGutter(y);for(var n=0;n<e.marked.length;++n)e.marked[n].clear();e.marked.length=0}function u(e,n,o,i){var a=document.createElement("div"),l=a;return a.className="CodeMirror-lint-marker-"+n,o&&(l=a.appendChild(document.createElement("div")),l.className="CodeMirror-lint-marker-multiple"),0!=i&&t.on(l,"mouseover",function(t){r(t,e,l)}),a}function s(t,e){return"error"==t?t:e}function c(t){for(var e=[],n=0;n<t.length;++n){var o=t[n],r=o.from.line;(e[r]||(e[r]=[])).push(o)}return e}function f(t){var e=t.severity;e||(e="error");var n=document.createElement("div");return n.className="CodeMirror-lint-message-"+e,n.appendChild(document.createTextNode(t.message)),n}function m(e,n,o){function r(){a=-1,e.off("change",r)}var i=e.state.lint,a=++i.waitingFor;e.on("change",r),n(e.getValue(),function(n,o){e.off("change",r),i.waitingFor==a&&(o&&n instanceof t&&(n=o),p(e,n))},o,e)}function d(e){var n=e.state.lint,o=n.options,r=o.options||o,i=o.getAnnotations||e.getHelper(t.Pos(0,0),"lint");if(i)if(o.async||i.async)m(e,i,r);else{var a=i(e.getValue(),r,e);if(!a)return;a.then?a.then(function(t){p(e,t)}):p(e,a)}}function p(t,e){l(t);for(var n=t.state.lint,o=n.options,r=c(e),i=0;i<r.length;++i){var a=r[i];if(a){for(var m=null,d=n.hasGutter&&document.createDocumentFragment(),p=0;p<a.length;++p){var h=a[p],v=h.severity;v||(v="error"),m=s(m,v),o.formatAnnotation&&(h=o.formatAnnotation(h)),n.hasGutter&&d.appendChild(f(h)),h.to&&n.marked.push(t.markText(h.from,h.to,{className:"CodeMirror-lint-mark-"+v,__annotation:h}))}n.hasGutter&&t.setGutterMarker(i,y,u(d,m,a.length>1,n.options.tooltips))}}o.onUpdateLinting&&o.onUpdateLinting(e,r,t)}function h(t){var e=t.state.lint;e&&(clearTimeout(e.timeout),e.timeout=setTimeout(function(){d(t)},e.options.delay||500))}function v(t,e){for(var n=e.target||e.srcElement,o=document.createDocumentFragment(),i=0;i<t.length;i++){var a=t[i];o.appendChild(f(a))}r(e,o,n)}function g(t,e){var n=e.target||e.srcElement;if(/\bCodeMirror-lint-mark-/.test(n.className)){for(var o=n.getBoundingClientRect(),r=(o.left+o.right)/2,i=(o.top+o.bottom)/2,a=t.findMarksAt(t.coordsChar({left:r,top:i},"client")),l=[],u=0;u<a.length;++u){var s=a[u].__annotation;s&&l.push(s)}l.length&&v(l,e)}}var y="CodeMirror-lint-markers";t.defineOption("lint",!1,function(e,n,o){if(o&&o!=t.Init&&(l(e),e.state.lint.options.lintOnChange!==!1&&e.off("change",h),t.off(e.getWrapperElement(),"mouseover",e.state.lint.onMouseOver),clearTimeout(e.state.lint.timeout),delete e.state.lint),n){for(var r=e.getOption("gutters"),u=!1,s=0;s<r.length;++s)r[s]==y&&(u=!0);var c=e.state.lint=new i(e,a(e,n),u);c.options.lintOnChange!==!1&&e.on("change",h),0!=c.options.tooltips&&"gutter"!=c.options.tooltips&&t.on(e.getWrapperElement(),"mouseover",c.onMouseOver),d(e)}}),t.defineExtension("performLint",function(){this.state.lint&&d(this)})});
lib/codemirror/addon/lint/yaml-lint.js CHANGED
@@ -19,8 +19,15 @@ CodeMirror.registerHelper("lint", "yaml", function(text) {
19
  var found = [];
20
  try { jsyaml.load(text); }
21
  catch(e) {
22
- var loc = e.mark;
23
- found.push({ from: CodeMirror.Pos(loc.line, loc.column), to: CodeMirror.Pos(loc.line, loc.column), message: e.message });
 
 
 
 
 
 
 
24
  }
25
  return found;
26
  });
19
  var found = [];
20
  try { jsyaml.load(text); }
21
  catch(e) {
22
+ var loc = e.mark,
23
+ // js-yaml YAMLException doesn't always provide an accurate lineno
24
+ // e.g., when there are multiple yaml docs
25
+ // ---
26
+ // ---
27
+ // foo:bar
28
+ from = loc ? CodeMirror.Pos(loc.line, loc.column) : CodeMirror.Pos(0, 0),
29
+ to = from;
30
+ found.push({ from: from, to: to, message: e.message });
31
  }
32
  return found;
33
  });
lib/codemirror/addon/lint/yaml-lint.min.js CHANGED
@@ -1 +1 @@
1
- !function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.registerHelper("lint","yaml",function(o){var r=[];try{jsyaml.load(o)}catch(i){var t=i.mark;r.push({from:e.Pos(t.line,t.column),to:e.Pos(t.line,t.column),message:i.message})}return r})});
1
+ !function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.registerHelper("lint","yaml",function(o){var r=[];try{jsyaml.load(o)}catch(t){var i=t.mark,n=i?e.Pos(i.line,i.column):e.Pos(0,0),c=n;r.push({from:n,to:c,message:t.message})}return r})});
lib/codemirror/addon/merge/merge.js CHANGED
@@ -37,23 +37,29 @@
37
  constructor: DiffView,
38
  init: function(pane, orig, options) {
39
  this.edit = this.mv.edit;
40
- (this.edit.state.diffViews || (this.edit.state.diffViews = [])).push(this);
41
  this.orig = CodeMirror(pane, copyObj({value: orig, readOnly: !this.mv.options.allowEditingOriginals}, copyObj(options)));
 
 
 
 
 
42
  this.orig.state.diffViews = [this];
43
  var classLocation = options.chunkClassLocation || "background";
44
  if (Object.prototype.toString.call(classLocation) != "[object Array]") classLocation = [classLocation]
45
  this.classes.classLocation = classLocation
46
 
47
- this.diff = getDiff(asString(orig), asString(options.value));
48
  this.chunks = getChunks(this.diff);
49
  this.diffOutOfDate = this.dealigned = false;
 
50
 
51
  this.showDifferences = options.showDifferences !== false;
52
  },
53
- registerEvents: function() {
54
  this.forceUpdate = registerUpdate(this);
55
  setScrollLock(this, true, false);
56
- registerScroll(this);
57
  },
58
  setShowDifferences: function(val) {
59
  val = val !== false;
@@ -66,7 +72,7 @@
66
 
67
  function ensureDiff(dv) {
68
  if (dv.diffOutOfDate) {
69
- dv.diff = getDiff(dv.orig.getValue(), dv.edit.getValue());
70
  dv.chunks = getChunks(dv.diff);
71
  dv.diffOutOfDate = false;
72
  CodeMirror.signal(dv.edit, "updateDiff", dv.diff);
@@ -97,6 +103,7 @@
97
  if (dv.mv.options.connect == "align")
98
  alignChunks(dv);
99
  makeConnections(dv);
 
100
 
101
  updating = false;
102
  }
@@ -121,41 +128,47 @@
121
  }
122
  function swapDoc() {
123
  dv.diffOutOfDate = true;
 
124
  update("full");
125
  }
126
  dv.edit.on("change", change);
127
  dv.orig.on("change", change);
128
  dv.edit.on("swapDoc", swapDoc);
129
  dv.orig.on("swapDoc", swapDoc);
130
- dv.edit.on("markerAdded", setDealign);
131
- dv.edit.on("markerCleared", setDealign);
132
- dv.orig.on("markerAdded", setDealign);
133
- dv.orig.on("markerCleared", setDealign);
134
  dv.edit.on("viewportChange", function() { set(false); });
135
  dv.orig.on("viewportChange", function() { set(false); });
136
  update();
137
  return update;
138
  }
139
 
140
- function registerScroll(dv) {
141
  dv.edit.on("scroll", function() {
142
- syncScroll(dv, DIFF_INSERT) && makeConnections(dv);
143
  });
144
  dv.orig.on("scroll", function() {
145
- syncScroll(dv, DIFF_DELETE) && makeConnections(dv);
 
146
  });
147
  }
148
 
149
- function syncScroll(dv, type) {
150
  // Change handler will do a refresh after a timeout when diff is out of date
151
- if (dv.diffOutOfDate) return false;
 
 
 
 
152
  if (!dv.lockScroll) return true;
153
  var editor, other, now = +new Date;
154
- if (type == DIFF_INSERT) { editor = dv.edit; other = dv.orig; }
155
  else { editor = dv.orig; other = dv.edit; }
156
  // Don't take action if the position of this editor was recently set
157
  // (to prevent feedback loops)
158
- if (editor.state.scrollSetBy == dv && (editor.state.scrollSetAt || 0) + 50 > now) return false;
159
 
160
  var sInfo = editor.getScrollInfo();
161
  if (dv.mv.options.connect == "align") {
@@ -163,9 +176,9 @@
163
  } else {
164
  var halfScreen = .5 * sInfo.clientHeight, midY = sInfo.top + halfScreen;
165
  var mid = editor.lineAtHeight(midY, "local");
166
- var around = chunkBoundariesAround(dv.chunks, mid, type == DIFF_INSERT);
167
- var off = getOffsets(editor, type == DIFF_INSERT ? around.edit : around.orig);
168
- var offOther = getOffsets(other, type == DIFF_INSERT ? around.orig : around.edit);
169
  var ratio = (midY - off.top) / (off.bot - off.top);
170
  var targetPos = (offOther.top - halfScreen) + ratio * (offOther.bot - offOther.top);
171
 
@@ -271,7 +284,7 @@
271
  }
272
  }
273
 
274
- var chunkStart = 0;
275
  for (var i = 0; i < diff.length; ++i) {
276
  var part = diff[i], tp = part[0], str = part[1];
277
  if (tp == DIFF_EQUAL) {
@@ -279,10 +292,11 @@
279
  moveOver(pos, str);
280
  var cleanTo = pos.line + (endOfLineClean(diff, i) ? 1 : 0);
281
  if (cleanTo > cleanFrom) {
282
- if (i) markChunk(chunkStart, cleanFrom);
283
  chunkStart = cleanTo;
284
  }
285
  } else {
 
286
  if (tp == type) {
287
  var end = moveOver(pos, str, true);
288
  var a = posMax(top, pos), b = posMin(bot, end);
@@ -292,7 +306,7 @@
292
  }
293
  }
294
  }
295
- if (chunkStart <= pos.line) markChunk(chunkStart, pos.line + 1);
296
  }
297
 
298
  // Updating the gap between editor and original
@@ -331,24 +345,81 @@
331
  return origStart + (editLine - editStart);
332
  }
333
 
334
- function findAlignedLines(dv, other) {
335
- var linesToAlign = [];
336
- for (var i = 0; i < dv.chunks.length; i++) {
337
- var chunk = dv.chunks[i];
338
- linesToAlign.push([chunk.origTo, chunk.editTo, other ? getMatchingOrigLine(chunk.editTo, other.chunks) : null]);
339
- }
340
- if (other) {
341
- chunkLoop: for (var i = 0; i < other.chunks.length; i++) {
342
- var chunk = other.chunks[i];
343
- for (var j = 0; j < linesToAlign.length; j++) {
344
- var diff = linesToAlign[j][1] - chunk.editTo;
345
- if (diff == 0) continue chunkLoop
346
- if (diff > 0) break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  }
348
- linesToAlign.splice(j, 0, [getMatchingOrigLine(chunk.editTo, dv.chunks), chunk.editTo, chunk.origTo]);
 
 
 
 
 
 
 
 
 
 
 
 
349
  }
350
  }
351
- return linesToAlign;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  }
353
 
354
  function alignChunks(dv, force) {
@@ -371,7 +442,7 @@
371
  aligners[i].clear();
372
  aligners.length = 0;
373
 
374
- var cm = [dv.orig, dv.edit], scroll = [];
375
  if (other) cm.push(other.orig);
376
  for (var i = 0; i < cm.length; i++)
377
  scroll.push(cm[i].getScrollInfo().top);
@@ -406,7 +477,7 @@
406
  var elt = document.createElement("div");
407
  elt.className = "CodeMirror-merge-spacer";
408
  elt.style.height = size + "px"; elt.style.minWidth = "1px";
409
- return cm.addLineWidget(line, elt, {height: size, above: above});
410
  }
411
 
412
  function drawConnectorsForChunk(dv, chunk, sTopOrig, sTopEdit, w) {
@@ -448,9 +519,15 @@
448
 
449
  function copyChunk(dv, to, from, chunk) {
450
  if (dv.diffOutOfDate) return;
451
- var editStart = chunk.editTo > to.lastLine() ? Pos(chunk.editFrom - 1) : Pos(chunk.editFrom, 0)
452
  var origStart = chunk.origTo > from.lastLine() ? Pos(chunk.origFrom - 1) : Pos(chunk.origFrom, 0)
453
- to.replaceRange(from.getRange(origStart, Pos(chunk.origTo, 0)), editStart, Pos(chunk.editTo, 0))
 
 
 
 
 
 
 
454
  }
455
 
456
  // Merge view, containing 0, 1, or 2 diff views.
@@ -500,8 +577,8 @@
500
  this.aligners = [];
501
  alignChunks(this.left || this.right, true);
502
  }
503
- if (left) left.registerEvents()
504
- if (right) right.registerEvents()
505
 
506
 
507
  var onResize = function() {
@@ -569,12 +646,12 @@
569
  // Operations on diffs
570
 
571
  var dmp = new diff_match_patch();
572
- function getDiff(a, b) {
573
  var diff = dmp.diff_main(a, b);
574
  // The library sometimes leaves in empty parts, which confuse the algorithm
575
  for (var i = 0; i < diff.length; ++i) {
576
  var part = diff[i];
577
- if (!part[1]) {
578
  diff.splice(i--, 1);
579
  } else if (i && diff[i - 1][0] == part[0]) {
580
  diff.splice(i--, 1);
@@ -591,7 +668,7 @@
591
  for (var i = 0; i < diff.length; ++i) {
592
  var part = diff[i], tp = part[0];
593
  if (tp == DIFF_EQUAL) {
594
- var startOff = startOfLineClean(diff, i) ? 0 : 1;
595
  var cleanFromEdit = edit.line + startOff, cleanFromOrig = orig.line + startOff;
596
  moveOver(edit, part[1], null, orig);
597
  var endOff = endOfLineClean(diff, i) ? 1 : 0;
@@ -614,10 +691,10 @@
614
  function endOfLineClean(diff, i) {
615
  if (i == diff.length - 1) return true;
616
  var next = diff[i + 1][1];
617
- if (next.length == 1 || next.charCodeAt(0) != 10) return false;
618
  if (i == diff.length - 2) return true;
619
  next = diff[i + 2][1];
620
- return next.length > 1 && next.charCodeAt(0) == 10;
621
  }
622
 
623
  function startOfLineClean(diff, i) {
@@ -751,6 +828,131 @@
751
  return out;
752
  }
753
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
754
  function posMin(a, b) { return (a.line - b.line || a.ch - b.ch) < 0 ? a : b; }
755
  function posMax(a, b) { return (a.line - b.line || a.ch - b.ch) > 0 ? a : b; }
756
  function posEq(a, b) { return a.line == b.line && a.ch == b.ch; }
37
  constructor: DiffView,
38
  init: function(pane, orig, options) {
39
  this.edit = this.mv.edit;
40
+ ;(this.edit.state.diffViews || (this.edit.state.diffViews = [])).push(this);
41
  this.orig = CodeMirror(pane, copyObj({value: orig, readOnly: !this.mv.options.allowEditingOriginals}, copyObj(options)));
42
+ if (this.mv.options.connect == "align") {
43
+ if (!this.edit.state.trackAlignable) this.edit.state.trackAlignable = new TrackAlignable(this.edit)
44
+ this.orig.state.trackAlignable = new TrackAlignable(this.orig)
45
+ }
46
+
47
  this.orig.state.diffViews = [this];
48
  var classLocation = options.chunkClassLocation || "background";
49
  if (Object.prototype.toString.call(classLocation) != "[object Array]") classLocation = [classLocation]
50
  this.classes.classLocation = classLocation
51
 
52
+ this.diff = getDiff(asString(orig), asString(options.value), this.mv.options.ignoreWhitespace);
53
  this.chunks = getChunks(this.diff);
54
  this.diffOutOfDate = this.dealigned = false;
55
+ this.needsScrollSync = null
56
 
57
  this.showDifferences = options.showDifferences !== false;
58
  },
59
+ registerEvents: function(otherDv) {
60
  this.forceUpdate = registerUpdate(this);
61
  setScrollLock(this, true, false);
62
+ registerScroll(this, otherDv);
63
  },
64
  setShowDifferences: function(val) {
65
  val = val !== false;
72
 
73
  function ensureDiff(dv) {
74
  if (dv.diffOutOfDate) {
75
+ dv.diff = getDiff(dv.orig.getValue(), dv.edit.getValue(), dv.mv.options.ignoreWhitespace);
76
  dv.chunks = getChunks(dv.diff);
77
  dv.diffOutOfDate = false;
78
  CodeMirror.signal(dv.edit, "updateDiff", dv.diff);
103
  if (dv.mv.options.connect == "align")
104
  alignChunks(dv);
105
  makeConnections(dv);
106
+ if (dv.needsScrollSync != null) syncScroll(dv, dv.needsScrollSync)
107
 
108
  updating = false;
109
  }
128
  }
129
  function swapDoc() {
130
  dv.diffOutOfDate = true;
131
+ dv.dealigned = true;
132
  update("full");
133
  }
134
  dv.edit.on("change", change);
135
  dv.orig.on("change", change);
136
  dv.edit.on("swapDoc", swapDoc);
137
  dv.orig.on("swapDoc", swapDoc);
138
+ if (dv.mv.options.connect == "align") {
139
+ CodeMirror.on(dv.edit.state.trackAlignable, "realign", setDealign)
140
+ CodeMirror.on(dv.orig.state.trackAlignable, "realign", setDealign)
141
+ }
142
  dv.edit.on("viewportChange", function() { set(false); });
143
  dv.orig.on("viewportChange", function() { set(false); });
144
  update();
145
  return update;
146
  }
147
 
148
+ function registerScroll(dv, otherDv) {
149
  dv.edit.on("scroll", function() {
150
+ syncScroll(dv, true) && makeConnections(dv);
151
  });
152
  dv.orig.on("scroll", function() {
153
+ syncScroll(dv, false) && makeConnections(dv);
154
+ if (otherDv) syncScroll(otherDv, true) && makeConnections(otherDv);
155
  });
156
  }
157
 
158
+ function syncScroll(dv, toOrig) {
159
  // Change handler will do a refresh after a timeout when diff is out of date
160
+ if (dv.diffOutOfDate) {
161
+ if (dv.lockScroll && dv.needsScrollSync == null) dv.needsScrollSync = toOrig
162
+ return false
163
+ }
164
+ dv.needsScrollSync = null
165
  if (!dv.lockScroll) return true;
166
  var editor, other, now = +new Date;
167
+ if (toOrig) { editor = dv.edit; other = dv.orig; }
168
  else { editor = dv.orig; other = dv.edit; }
169
  // Don't take action if the position of this editor was recently set
170
  // (to prevent feedback loops)
171
+ if (editor.state.scrollSetBy == dv && (editor.state.scrollSetAt || 0) + 250 > now) return false;
172
 
173
  var sInfo = editor.getScrollInfo();
174
  if (dv.mv.options.connect == "align") {
176
  } else {
177
  var halfScreen = .5 * sInfo.clientHeight, midY = sInfo.top + halfScreen;
178
  var mid = editor.lineAtHeight(midY, "local");
179
+ var around = chunkBoundariesAround(dv.chunks, mid, toOrig);
180
+ var off = getOffsets(editor, toOrig ? around.edit : around.orig);
181
+ var offOther = getOffsets(other, toOrig ? around.orig : around.edit);
182
  var ratio = (midY - off.top) / (off.bot - off.top);
183
  var targetPos = (offOther.top - halfScreen) + ratio * (offOther.bot - offOther.top);
184
 
284
  }
285
  }
286
 
287
+ var chunkStart = 0, pending = false;
288
  for (var i = 0; i < diff.length; ++i) {
289
  var part = diff[i], tp = part[0], str = part[1];
290
  if (tp == DIFF_EQUAL) {
292
  moveOver(pos, str);
293
  var cleanTo = pos.line + (endOfLineClean(diff, i) ? 1 : 0);
294
  if (cleanTo > cleanFrom) {
295
+ if (pending) { markChunk(chunkStart, cleanFrom); pending = false }
296
  chunkStart = cleanTo;
297
  }
298
  } else {
299
+ pending = true
300
  if (tp == type) {
301
  var end = moveOver(pos, str, true);
302
  var a = posMax(top, pos), b = posMin(bot, end);
306
  }
307
  }
308
  }
309
+ if (pending) markChunk(chunkStart, pos.line + 1);
310
  }
311
 
312
  // Updating the gap between editor and original
345
  return origStart + (editLine - editStart);
346
  }
347
 
348
+ // Combines information about chunks and widgets/markers to return
349
+ // an array of lines, in a single editor, that probably need to be
350
+ // aligned with their counterparts in the editor next to it.
351
+ function alignableFor(cm, chunks, isOrig) {
352
+ var tracker = cm.state.trackAlignable
353
+ var start = cm.firstLine(), trackI = 0
354
+ var result = []
355
+ for (var i = 0;; i++) {
356
+ var chunk = chunks[i]
357
+ var chunkStart = !chunk ? 1e9 : isOrig ? chunk.origFrom : chunk.editFrom
358
+ for (; trackI < tracker.alignable.length; trackI += 2) {
359
+ var n = tracker.alignable[trackI] + 1
360
+ if (n <= start) continue
361
+ if (n <= chunkStart) result.push(n)
362
+ else break
363
+ }
364
+ if (!chunk) break
365
+ result.push(start = isOrig ? chunk.origTo : chunk.editTo)
366
+ }
367
+ return result
368
+ }
369
+
370
+ // Given information about alignable lines in two editors, fill in
371
+ // the result (an array of three-element arrays) to reflect the
372
+ // lines that need to be aligned with each other.
373
+ function mergeAlignable(result, origAlignable, chunks, setIndex) {
374
+ var rI = 0, origI = 0, chunkI = 0, diff = 0
375
+ outer: for (;; rI++) {
376
+ var nextR = result[rI], nextO = origAlignable[origI]
377
+ if (!nextR && nextO == null) break
378
+
379
+ var rLine = nextR ? nextR[0] : 1e9, oLine = nextO == null ? 1e9 : nextO
380
+ while (chunkI < chunks.length) {
381
+ var chunk = chunks[chunkI]
382
+ if (chunk.origFrom <= oLine && chunk.origTo > oLine) {
383
+ origI++
384
+ rI--
385
+ continue outer;
386
+ }
387
+ if (chunk.editTo > rLine) {
388
+ if (chunk.editFrom <= rLine) continue outer;
389
+ break
390
  }
391
+ diff += (chunk.origTo - chunk.origFrom) - (chunk.editTo - chunk.editFrom)
392
+ chunkI++
393
+ }
394
+ if (rLine == oLine - diff) {
395
+ nextR[setIndex] = oLine
396
+ origI++
397
+ } else if (rLine < oLine - diff) {
398
+ nextR[setIndex] = rLine + diff
399
+ } else {
400
+ var record = [oLine - diff, null, null]
401
+ record[setIndex] = oLine
402
+ result.splice(rI, 0, record)
403
+ origI++
404
  }
405
  }
406
+ }
407
+
408
+ function findAlignedLines(dv, other) {
409
+ var alignable = alignableFor(dv.edit, dv.chunks, false), result = []
410
+ if (other) for (var i = 0, j = 0; i < other.chunks.length; i++) {
411
+ var n = other.chunks[i].editTo
412
+ while (j < alignable.length && alignable[j] < n) j++
413
+ if (j == alignable.length || alignable[j] != n) alignable.splice(j++, 0, n)
414
+ }
415
+ for (var i = 0; i < alignable.length; i++)
416
+ result.push([alignable[i], null, null])
417
+
418
+ mergeAlignable(result, alignableFor(dv.orig, dv.chunks, true), dv.chunks, 1)
419
+ if (other)
420
+ mergeAlignable(result, alignableFor(other.orig, other.chunks, true), other.chunks, 2)
421
+
422
+ return result
423
  }
424
 
425
  function alignChunks(dv, force) {
442
  aligners[i].clear();
443
  aligners.length = 0;
444
 
445
+ var cm = [dv.edit, dv.orig], scroll = [];
446
  if (other) cm.push(other.orig);
447
  for (var i = 0; i < cm.length; i++)
448
  scroll.push(cm[i].getScrollInfo().top);
477
  var elt = document.createElement("div");
478
  elt.className = "CodeMirror-merge-spacer";
479
  elt.style.height = size + "px"; elt.style.minWidth = "1px";
480
+ return cm.addLineWidget(line, elt, {height: size, above: above, mergeSpacer: true, handleMouseEvents: true});
481
  }
482
 
483
  function drawConnectorsForChunk(dv, chunk, sTopOrig, sTopEdit, w) {
519
 
520
  function copyChunk(dv, to, from, chunk) {
521
  if (dv.diffOutOfDate) return;
 
522
  var origStart = chunk.origTo > from.lastLine() ? Pos(chunk.origFrom - 1) : Pos(chunk.origFrom, 0)
523
+ var origEnd = Pos(chunk.origTo, 0)
524
+ var editStart = chunk.editTo > to.lastLine() ? Pos(chunk.editFrom - 1) : Pos(chunk.editFrom, 0)
525
+ var editEnd = Pos(chunk.editTo, 0)
526
+ var handler = dv.mv.options.revertChunk
527
+ if (handler)
528
+ handler(dv.mv, from, origStart, origEnd, to, editStart, editEnd)
529
+ else
530
+ to.replaceRange(from.getRange(origStart, origEnd), editStart, editEnd)
531
  }
532
 
533
  // Merge view, containing 0, 1, or 2 diff views.
577
  this.aligners = [];
578
  alignChunks(this.left || this.right, true);
579
  }
580
+ if (left) left.registerEvents(right)
581
+ if (right) right.registerEvents(left)
582
 
583
 
584
  var onResize = function() {
646
  // Operations on diffs
647
 
648
  var dmp = new diff_match_patch();
649
+ function getDiff(a, b, ignoreWhitespace) {
650
  var diff = dmp.diff_main(a, b);
651
  // The library sometimes leaves in empty parts, which confuse the algorithm
652
  for (var i = 0; i < diff.length; ++i) {
653
  var part = diff[i];
654
+ if (ignoreWhitespace ? !/[^ \t]/.test(part[1]) : !part[1]) {
655
  diff.splice(i--, 1);
656
  } else if (i && diff[i - 1][0] == part[0]) {
657
  diff.splice(i--, 1);
668
  for (var i = 0; i < diff.length; ++i) {
669
  var part = diff[i], tp = part[0];
670
  if (tp == DIFF_EQUAL) {
671
+ var startOff = !startOfLineClean(diff, i) || edit.line < startEdit || orig.line < startOrig ? 1 : 0;
672
  var cleanFromEdit = edit.line + startOff, cleanFromOrig = orig.line + startOff;
673
  moveOver(edit, part[1], null, orig);
674
  var endOff = endOfLineClean(diff, i) ? 1 : 0;
691
  function endOfLineClean(diff, i) {
692
  if (i == diff.length - 1) return true;
693
  var next = diff[i + 1][1];
694
+ if ((next.length == 1 && i < diff.length - 2) || next.charCodeAt(0) != 10) return false;
695
  if (i == diff.length - 2) return true;
696
  next = diff[i + 2][1];
697
+ return (next.length > 1 || i == diff.length - 3) && next.charCodeAt(0) == 10;
698
  }
699
 
700
  function startOfLineClean(diff, i) {
828
  return out;
829
  }
830
 
831
+ // Tracks collapsed markers and line widgets, in order to be able to
832
+ // accurately align the content of two editors.
833
+
834
+ var F_WIDGET = 1, F_WIDGET_BELOW = 2, F_MARKER = 4
835
+
836
+ function TrackAlignable(cm) {
837
+ this.cm = cm
838
+ this.alignable = []
839
+ this.height = cm.doc.height
840
+ var self = this
841
+ cm.on("markerAdded", function(_, marker) {
842
+ if (!marker.collapsed) return
843
+ var found = marker.find(1)
844
+ if (found != null) self.set(found.line, F_MARKER)
845
+ })
846
+ cm.on("markerCleared", function(_, marker, _min, max) {
847
+ if (max != null && marker.collapsed)
848
+ self.check(max, F_MARKER, self.hasMarker)
849
+ })
850
+ cm.on("markerChanged", this.signal.bind(this))
851
+ cm.on("lineWidgetAdded", function(_, widget, lineNo) {
852
+ if (widget.mergeSpacer) return
853
+ if (widget.above) self.set(lineNo - 1, F_WIDGET_BELOW)
854
+ else self.set(lineNo, F_WIDGET)
855
+ })
856
+ cm.on("lineWidgetCleared", function(_, widget, lineNo) {
857
+ if (widget.mergeSpacer) return
858
+ if (widget.above) self.check(lineNo - 1, F_WIDGET_BELOW, self.hasWidgetBelow)
859
+ else self.check(lineNo, F_WIDGET, self.hasWidget)
860
+ })
861
+ cm.on("lineWidgetChanged", this.signal.bind(this))
862
+ cm.on("change", function(_, change) {
863
+ var start = change.from.line, nBefore = change.to.line - change.from.line
864
+ var nAfter = change.text.length - 1, end = start + nAfter
865
+ if (nBefore || nAfter) self.map(start, nBefore, nAfter)
866
+ self.check(end, F_MARKER, self.hasMarker)
867
+ if (nBefore || nAfter) self.check(change.from.line, F_MARKER, self.hasMarker)
868
+ })
869
+ cm.on("viewportChange", function() {
870
+ if (self.cm.doc.height != self.height) self.signal()
871
+ })
872
+ }
873
+
874
+ TrackAlignable.prototype = {
875
+ signal: function() {
876
+ CodeMirror.signal(this, "realign")
877
+ this.height = this.cm.doc.height
878
+ },
879
+
880
+ set: function(n, flags) {
881
+ var pos = -1
882
+ for (; pos < this.alignable.length; pos += 2) {
883
+ var diff = this.alignable[pos] - n
884
+ if (diff == 0) {
885
+ if ((this.alignable[pos + 1] & flags) == flags) return
886
+ this.alignable[pos + 1] |= flags
887
+ this.signal()
888
+ return
889
+ }
890
+ if (diff > 0) break
891
+ }
892
+ this.signal()
893
+ this.alignable.splice(pos, 0, n, flags)
894
+ },
895
+
896
+ find: function(n) {
897
+ for (var i = 0; i < this.alignable.length; i += 2)
898
+ if (this.alignable[i] == n) return i
899
+ return -1
900
+ },
901
+
902
+ check: function(n, flag, pred) {
903
+ var found = this.find(n)
904
+ if (found == -1 || !(this.alignable[found + 1] & flag)) return
905
+ if (!pred.call(this, n)) {
906
+ this.signal()
907
+ var flags = this.alignable[found + 1] & ~flag
908
+ if (flags) this.alignable[found + 1] = flags
909
+ else this.alignable.splice(found, 2)
910
+ }
911
+ },
912
+
913
+ hasMarker: function(n) {
914
+ var handle = this.cm.getLineHandle(n)
915
+ if (handle.markedSpans) for (var i = 0; i < handle.markedSpans.length; i++)
916
+ if (handle.markedSpans[i].mark.collapsed && handle.markedSpans[i].to != null)
917
+ return true
918
+ return false
919
+ },
920
+
921
+ hasWidget: function(n) {
922
+ var handle = this.cm.getLineHandle(n)
923
+ if (handle.widgets) for (var i = 0; i < handle.widgets.length; i++)
924
+ if (!handle.widgets[i].above && !handle.widgets[i].mergeSpacer) return true
925
+ return false
926
+ },
927
+
928
+ hasWidgetBelow: function(n) {
929
+ if (n == this.cm.lastLine()) return false
930
+ var handle = this.cm.getLineHandle(n + 1)
931
+ if (handle.widgets) for (var i = 0; i < handle.widgets.length; i++)
932
+ if (handle.widgets[i].above && !handle.widgets[i].mergeSpacer) return true
933
+ return false
934
+ },
935
+
936
+ map: function(from, nBefore, nAfter) {
937
+ var diff = nAfter - nBefore, to = from + nBefore, widgetFrom = -1, widgetTo = -1
938
+ for (var i = 0; i < this.alignable.length; i += 2) {
939
+ var n = this.alignable[i]
940
+ if (n == from && (this.alignable[i + 1] & F_WIDGET_BELOW)) widgetFrom = i
941
+ if (n == to && (this.alignable[i + 1] & F_WIDGET_BELOW)) widgetTo = i
942
+ if (n <= from) continue
943
+ else if (n < to) this.alignable.splice(i--, 2)
944
+ else this.alignable[i] += diff
945
+ }
946
+ if (widgetFrom > -1) {
947
+ var flags = this.alignable[widgetFrom + 1]
948
+ if (flags == F_WIDGET_BELOW) this.alignable.splice(widgetFrom, 2)
949
+ else this.alignable[widgetFrom + 1] = flags & ~F_WIDGET_BELOW
950
+ }
951
+ if (widgetTo > -1 && nAfter)
952
+ this.set(from + nAfter, F_WIDGET_BELOW)
953
+ }
954
+ }
955
+
956
  function posMin(a, b) { return (a.line - b.line || a.ch - b.ch) < 0 ? a : b; }
957
  function posMax(a, b) { return (a.line - b.line || a.ch - b.ch) > 0 ? a : b; }
958
  function posEq(a, b) { return a.line == b.line && a.ch == b.ch; }
lib/codemirror/addon/merge/merge.min.js CHANGED
@@ -1 +1 @@
1
- !function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","diff_match_patch"],e):e(CodeMirror)}(function(e){"use strict";function t(e,t){this.mv=e,this.type=t,this.classes="left"==t?{chunk:"CodeMirror-merge-l-chunk",start:"CodeMirror-merge-l-chunk-start",end:"CodeMirror-merge-l-chunk-end",insert:"CodeMirror-merge-l-inserted",del:"CodeMirror-merge-l-deleted",connect:"CodeMirror-merge-l-connect"}:{chunk:"CodeMirror-merge-r-chunk",start:"CodeMirror-merge-r-chunk-start",end:"CodeMirror-merge-r-chunk-end",insert:"CodeMirror-merge-r-inserted",del:"CodeMirror-merge-r-deleted",connect:"CodeMirror-merge-r-connect"}}function r(t){t.diffOutOfDate&&(t.diff=y(t.orig.getValue(),t.edit.getValue()),t.chunks=D(t.diff),t.diffOutOfDate=!1,e.signal(t.edit,"updateDiff",t.diff))}function i(e){function t(t){Q=!0,g=!1,"full"==t&&(e.svg&&N(e.svg),e.copyButtons&&N(e.copyButtons),c(e.edit,s.marked,e.classes),c(e.orig,h.marked,e.classes),s.from=s.to=h.from=h.to=0),r(e),e.showDifferences&&(f(e.edit,e.diff,s,DIFF_INSERT,e.classes),f(e.orig,e.diff,h,DIFF_DELETE,e.classes)),"align"==e.mv.options.connect&&v(e),d(e),Q=!1}function i(t){Q||(e.dealigned=!0,o(t))}function o(e){Q||g||(clearTimeout(a),e===!0&&(g=!0),a=setTimeout(t,e===!0?20:250))}function n(t,r){e.diffOutOfDate||(e.diffOutOfDate=!0,s.from=s.to=h.from=h.to=0),i(r.text.length-1!=r.to.line-r.from.line)}function l(){e.diffOutOfDate=!0,t("full")}var a,s={from:0,to:0,marked:[]},h={from:0,to:0,marked:[]},g=!1;return e.edit.on("change",n),e.orig.on("change",n),e.edit.on("swapDoc",l),e.orig.on("swapDoc",l),e.edit.on("markerAdded",i),e.edit.on("markerCleared",i),e.orig.on("markerAdded",i),e.orig.on("markerCleared",i),e.edit.on("viewportChange",function(){o(!1)}),e.orig.on("viewportChange",function(){o(!1)}),t(),t}function o(e){e.edit.on("scroll",function(){n(e,DIFF_INSERT)&&d(e)}),e.orig.on("scroll",function(){n(e,DIFF_DELETE)&&d(e)})}function n(e,t){if(e.diffOutOfDate)return!1;if(!e.lockScroll)return!0;var r,i,o=+new Date;if(t==DIFF_INSERT?(r=e.edit,i=e.orig):(r=e.orig,i=e.edit),r.state.scrollSetBy==e&&(r.state.scrollSetAt||0)+50>o)return!1;var n=r.getScrollInfo();if("align"==e.mv.options.connect)v=n.top;else{var a,s,c=.5*n.clientHeight,f=n.top+c,h=r.lineAtHeight(f,"local"),g=E(e.chunks,h,t==DIFF_INSERT),d=l(r,t==DIFF_INSERT?g.edit:g.orig),u=l(i,t==DIFF_INSERT?g.orig:g.edit),m=(f-d.top)/(d.bot-d.top),v=u.top-c+m*(u.bot-u.top);if(v>n.top&&(s=n.top/c)<1)v=v*s+n.top*(1-s);else if((a=n.height-n.clientHeight-n.top)<c){var p=i.getScrollInfo(),k=p.height-p.clientHeight-v;k>a&&(s=a/c)<1&&(v=v*s+(p.height-p.clientHeight-a)*(1-s))}}return i.scrollTo(n.left,v),i.state.scrollSetAt=o,i.state.scrollSetBy=e,!0}function l(e,t){var r=t.after;return null==r&&(r=e.lastLine()+1),{top:e.heightAtLine(t.before||0,"local"),bot:e.heightAtLine(r,"local")}}function a(e,t,r){e.lockScroll=t,t&&0!=r&&n(e,DIFF_INSERT)&&d(e),e.lockButton.innerHTML=t?"⇛⇚":"⇛&nbsp;&nbsp;⇚"}function s(e,t,r){for(var i=r.classLocation,o=0;o<i.length;o++)e.removeLineClass(t,i[o],r.chunk),e.removeLineClass(t,i[o],r.start),e.removeLineClass(t,i[o],r.end)}function c(t,r,i){for(var o=0;o<r.length;++o){var n=r[o];n instanceof e.TextMarker?n.clear():n.parent&&s(t,n,i)}r.length=0}function f(e,t,r,i,o){var n=e.getViewport();e.operation(function(){r.from==r.to||n.from-r.to>20||r.from-n.to>20?(c(e,r.marked,o),g(e,t,i,r.marked,n.from,n.to,o),r.from=n.from,r.to=n.to):(n.from<r.from&&(g(e,t,i,r.marked,n.from,r.from,o),r.from=n.from),n.to>r.to&&(g(e,t,i,r.marked,r.to,n.to,o),r.to=n.to))})}function h(e,t,r,i,o,n){for(var l=r.classLocation,a=e.getLineHandle(t),s=0;s<l.length;s++)i&&e.addLineClass(a,l[s],r.chunk),o&&e.addLineClass(a,l[s],r.start),n&&e.addLineClass(a,l[s],r.end);return a}function g(e,t,r,i,o,n,l){function a(t,r){for(var a=Math.max(o,t),s=Math.min(n,r),c=a;c<s;++c)i.push(h(e,c,l,!0,c==t,c==r-1));t==r&&a==r&&s==r&&(a?i.push(h(e,a-1,l,!1,!1,!0)):i.push(h(e,a,l,!1,!0,!1)))}for(var s=W(0,0),c=W(o,0),f=e.clipPos(W(n-1)),g=r==DIFF_DELETE?l.del:l.insert,d=0,u=0;u<t.length;++u){var m=t[u],v=m[0],p=m[1];if(v==DIFF_EQUAL){var k=s.line+(L(t,u)?0:1);R(s,p);var C=s.line+(M(t,u)?1:0);C>k&&(u&&a(d,k),d=C)}else if(v==r){var T=R(s,p,!0),F=V(c,s),w=_(f,T);H(F,w)||i.push(e.markText(F,w,{className:g})),s=T}}d<=s.line&&a(d,s.line+1)}function d(e){if(e.showDifferences){if(e.svg){N(e.svg);var t=e.gap.offsetWidth;x(e.svg,"width",t,"height",e.gap.offsetHeight)}e.copyButtons&&N(e.copyButtons);for(var r=e.edit.getViewport(),i=e.orig.getViewport(),o=e.mv.wrap.getBoundingClientRect().top,n=o-e.edit.getScrollerElement().getBoundingClientRect().top+e.edit.getScrollInfo().top,l=o-e.orig.getScrollerElement().getBoundingClientRect().top+e.orig.getScrollInfo().top,a=0;a<e.chunks.length;a++){var s=e.chunks[a];s.editFrom<=r.to&&s.editTo>=r.from&&s.origFrom<=i.to&&s.origTo>=i.from&&C(e,s,l,n,t)}}}function u(e,t){for(var r=0,i=0,o=0;o<t.length;o++){var n=t[o];if(n.editTo>e&&n.editFrom<=e)return null;if(n.editFrom>e)break;r=n.editTo,i=n.origTo}return i+(e-r)}function m(e,t){for(var r=[],i=0;i<e.chunks.length;i++){var o=e.chunks[i];r.push([o.origTo,o.editTo,t?u(o.editTo,t.chunks):null])}if(t)e:for(var i=0;i<t.chunks.length;i++){for(var o=t.chunks[i],n=0;n<r.length;n++){var l=r[n][1]-o.editTo;if(0==l)continue e;if(l>0)break}r.splice(n,0,[u(o.editTo,e.chunks),o.editTo,o.origTo])}return r}function v(e,t){if(e.dealigned||t){if(!e.orig.curOp)return e.orig.operation(function(){v(e,t)});e.dealigned=!1;var i=e.mv.left==e?e.mv.right:e.mv.left;i&&(r(i),i.dealigned=!1);for(var o=m(e,i),n=e.mv.aligners,l=0;l<n.length;l++)n[l].clear();n.length=0;var a=[e.orig,e.edit],s=[];i&&a.push(i.orig);for(var l=0;l<a.length;l++)s.push(a[l].getScrollInfo().top);for(var c=0;c<o.length;c++)p(a,o[c],n);for(var l=0;l<a.length;l++)a[l].scrollTo(null,s[l])}}function p(e,t,r){for(var i=0,o=[],n=0;n<e.length;n++)if(null!=t[n]){var l=e[n].heightAtLine(t[n],"local");o[n]=l,i=Math.max(i,l)}for(var n=0;n<e.length;n++)if(null!=t[n]){var a=i-o[n];a>1&&r.push(k(e[n],t[n],a))}}function k(e,t,r){var i=!0;t>e.lastLine()&&(t--,i=!1);var o=document.createElement("div");return o.className="CodeMirror-merge-spacer",o.style.height=r+"px",o.style.minWidth="1px",e.addLineWidget(t,o,{height:r,above:i})}function C(e,t,r,i,o){var n="left"==e.type,l=e.orig.heightAtLine(t.origFrom,"local",!0)-r;if(e.svg){var a=l,s=e.edit.heightAtLine(t.editFrom,"local",!0)-i;if(n){var c=a;a=s,s=c}var f=e.orig.heightAtLine(t.origTo,"local",!0)-r,h=e.edit.heightAtLine(t.editTo,"local",!0)-i;if(n){var c=f;f=h,h=c}var g=" C "+o/2+" "+s+" "+o/2+" "+a+" "+(o+2)+" "+a,d=" C "+o/2+" "+f+" "+o/2+" "+h+" -1 "+h;x(e.svg.appendChild(document.createElementNS(z,"path")),"d","M -1 "+s+g+" L "+(o+2)+" "+f+d+" z","class",e.classes.connect)}if(e.copyButtons){var u=e.copyButtons.appendChild(A("div","left"==e.type?"⇝":"⇜","CodeMirror-merge-copy")),m=e.mv.options.allowEditingOriginals;if(u.title=m?"Push to left":"Revert chunk",u.chunk=t,u.style.top=(t.origTo>t.origFrom?l:e.edit.heightAtLine(t.editFrom,"local")-i)+"px",m){var v=e.edit.heightAtLine(t.editFrom,"local")-i,p=e.copyButtons.appendChild(A("div","right"==e.type?"⇝":"⇜","CodeMirror-merge-copy-reverse"));p.title="Push to right",p.chunk={editFrom:t.origFrom,editTo:t.origTo,origFrom:t.editFrom,origTo:t.editTo},p.style.top=v+"px","right"==e.type?p.style.left="2px":p.style.right="2px"}}}function T(e,t,r,i){if(!e.diffOutOfDate){var o=i.editTo>t.lastLine()?W(i.editFrom-1):W(i.editFrom,0),n=i.origTo>r.lastLine()?W(i.origFrom-1):W(i.origFrom,0);t.replaceRange(r.getRange(n,W(i.origTo,0)),o,W(i.editTo,0))}}function F(t){var r=t.lockButton=A("div",null,"CodeMirror-merge-scrolllock");r.title="Toggle locked scrolling";var i=A("div",[r],"CodeMirror-merge-scrolllock-wrap");e.on(r,"click",function(){a(t,!t.lockScroll)});var o=[i];if(t.mv.options.revertButtons!==!1&&(t.copyButtons=A("div",null,"CodeMirror-merge-copybuttons-"+t.type),e.on(t.copyButtons,"click",function(e){var r=e.target||e.srcElement;if(r.chunk)return"CodeMirror-merge-copy-reverse"==r.className?void T(t,t.orig,t.edit,r.chunk):void T(t,t.edit,t.orig,r.chunk)}),o.unshift(t.copyButtons)),"align"!=t.mv.options.connect){var n=document.createElementNS&&document.createElementNS(z,"svg");n&&!n.createSVGRect&&(n=null),t.svg=n,n&&o.push(n)}return t.gap=A("div",o,"CodeMirror-merge-gap")}function w(e){return"string"==typeof e?e:e.getValue()}function y(e,t){for(var r=G.diff_main(e,t),i=0;i<r.length;++i){var o=r[i];o[1]?i&&r[i-1][0]==o[0]&&(r.splice(i--,1),r[i][1]+=o[1]):r.splice(i--,1)}return r}function D(e){for(var t=[],r=0,i=0,o=W(0,0),n=W(0,0),l=0;l<e.length;++l){var a=e[l],s=a[0];if(s==DIFF_EQUAL){var c=L(e,l)?0:1,f=o.line+c,h=n.line+c;R(o,a[1],null,n);var g=M(e,l)?1:0,d=o.line+g,u=n.line+g;d>f&&(l&&t.push({origFrom:i,origTo:h,editFrom:r,editTo:f}),r=d,i=u)}else R(s==DIFF_INSERT?o:n,a[1])}return(r<=o.line||i<=n.line)&&t.push({origFrom:i,origTo:n.line+1,editFrom:r,editTo:o.line+1}),t}function M(e,t){if(t==e.length-1)return!0;var r=e[t+1][1];return 1!=r.length&&10==r.charCodeAt(0)&&(t==e.length-2||(r=e[t+2][1],r.length>1&&10==r.charCodeAt(0)))}function L(e,t){if(0==t)return!0;var r=e[t-1][1];return 10==r.charCodeAt(r.length-1)&&(1==t||(r=e[t-2][1],10==r.charCodeAt(r.length-1)))}function E(e,t,r){for(var i,o,n,l,a=0;a<e.length;a++){var s=e[a],c=r?s.editFrom:s.origFrom,f=r?s.editTo:s.origTo;null==o&&(c>t?(o=s.editFrom,l=s.origFrom):f>t&&(o=s.editTo,l=s.origTo)),f<=t?(i=s.editTo,n=s.origTo):c<=t&&(i=s.editFrom,n=s.origFrom)}return{edit:{before:i,after:o},orig:{before:n,after:l}}}function I(t,r,i){function o(){l.clear(),t.removeLineClass(r,"wrap","CodeMirror-merge-collapsed-line")}t.addLineClass(r,"wrap","CodeMirror-merge-collapsed-line");var n=document.createElement("span");n.className="CodeMirror-merge-collapsed-widget",n.title="Identical text collapsed. Click to expand.";var l=t.markText(W(r,0),W(i-1),{inclusiveLeft:!0,inclusiveRight:!0,replacedWith:n,clearOnEnter:!0});return e.on(n,"click",o),{mark:l,clear:o}}function S(e,t){function r(){for(var e=0;e<i.length;e++)i[e].clear()}for(var i=[],o=0;o<t.length;o++){var n=t[o],l=I(n.cm,n.line,n.line+e);i.push(l),l.mark.on("clear",r)}return i[0].mark}function O(e,t,r,i){for(var o=0;o<e.chunks.length;o++)for(var n=e.chunks[o],l=n.editFrom-t;l<n.editTo+t;l++){var a=l+r;a>=0&&a<i.length&&(i[a]=!1)}}function b(e,t){"number"!=typeof t&&(t=2);for(var r=[],i=e.editor(),o=i.firstLine(),n=o,l=i.lastLine();n<=l;n++)r.push(!0);e.left&&O(e.left,t,o,r),e.right&&O(e.right,t,o,r);for(var a=0;a<r.length;a++)if(r[a]){for(var s=a+o,c=1;a<r.length-1&&r[a+1];a++,c++);if(c>t){var f=[{line:s,cm:i}];e.left&&f.push({line:u(s,e.left.chunks),cm:e.left.orig}),e.right&&f.push({line:u(s,e.right.chunks),cm:e.right.orig});var h=S(c,f);e.options.onCollapse&&e.options.onCollapse(e,s,c,h)}}}function A(e,t,r,i){var o=document.createElement(e);if(r&&(o.className=r),i&&(o.style.cssText=i),"string"==typeof t)o.appendChild(document.createTextNode(t));else if(t)for(var n=0;n<t.length;++n)o.appendChild(t[n]);return o}function N(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild)}function x(e){for(var t=1;t<arguments.length;t+=2)e.setAttribute(arguments[t],arguments[t+1])}function B(e,t){t||(t={});for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t}function R(e,t,r,i){for(var o=r?W(e.line,e.ch):e,n=0;;){var l=t.indexOf("\n",n);if(l==-1)break;++o.line,i&&++i.line,n=l+1}return o.ch=(n?0:o.ch)+(t.length-n),i&&(i.ch=(n?0:i.ch)+(t.length-n)),o}function _(e,t){return(e.line-t.line||e.ch-t.ch)<0?e:t}function V(e,t){return(e.line-t.line||e.ch-t.ch)>0?e:t}function H(e,t){return e.line==t.line&&e.ch==t.ch}function P(e,t,r){for(var i=e.length-1;i>=0;i--){var o=e[i],n=(r?o.origTo:o.editTo)-1;if(n<t)return n}}function j(e,t,r){for(var i=0;i<e.length;i++){var o=e[i],n=r?o.origFrom:o.editFrom;if(n>t)return n}}function U(t,i){var o=null,n=t.state.diffViews,l=t.getCursor().line;if(n)for(var a=0;a<n.length;a++){var s=n[a],c=t==s.orig;r(s);var f=i<0?P(s.chunks,l,c):j(s.chunks,l,c);null==f||null!=o&&!(i<0?f>o:f<o)||(o=f)}return null==o?e.Pass:void t.setCursor(o,0)}var W=e.Pos,z="http://www.w3.org/2000/svg";t.prototype={constructor:t,init:function(t,r,i){this.edit=this.mv.edit,(this.edit.state.diffViews||(this.edit.state.diffViews=[])).push(this),this.orig=e(t,B({value:r,readOnly:!this.mv.options.allowEditingOriginals},B(i))),this.orig.state.diffViews=[this];var o=i.chunkClassLocation||"background";"[object Array]"!=Object.prototype.toString.call(o)&&(o=[o]),this.classes.classLocation=o,this.diff=y(w(r),w(i.value)),this.chunks=D(this.diff),this.diffOutOfDate=this.dealigned=!1,this.showDifferences=i.showDifferences!==!1},registerEvents:function(){this.forceUpdate=i(this),a(this,!0,!1),o(this)},setShowDifferences:function(e){e=e!==!1,e!=this.showDifferences&&(this.showDifferences=e,this.forceUpdate("full"))}};var Q=!1,q=e.MergeView=function(r,i){if(!(this instanceof q))return new q(r,i);this.options=i;var o=i.origLeft,n=null==i.origRight?i.orig:i.origRight,l=null!=o,a=null!=n,s=1+(l?1:0)+(a?1:0),c=[],f=this.left=null,h=this.right=null,g=this;if(l){f=this.left=new t(this,"left");var u=A("div",null,"CodeMirror-merge-pane CodeMirror-merge-left");c.push(u),c.push(F(f))}var m=A("div",null,"CodeMirror-merge-pane CodeMirror-merge-editor");if(c.push(m),a){h=this.right=new t(this,"right"),c.push(F(h));var p=A("div",null,"CodeMirror-merge-pane CodeMirror-merge-right");c.push(p)}(a?p:m).className+=" CodeMirror-merge-pane-rightmost",c.push(A("div",null,null,"height: 0; clear: both;"));var k=this.wrap=r.appendChild(A("div",c,"CodeMirror-merge CodeMirror-merge-"+s+"pane"));this.edit=e(m,B(i)),f&&f.init(u,o,i),h&&h.init(p,n,i),i.collapseIdentical&&this.editor().operation(function(){b(g,i.collapseIdentical)}),"align"==i.connect&&(this.aligners=[],v(this.left||this.right,!0)),f&&f.registerEvents(),h&&h.registerEvents();var C=function(){f&&d(f),h&&d(h)};e.on(window,"resize",C);var T=setInterval(function(){for(var t=k.parentNode;t&&t!=document.body;t=t.parentNode);t||(clearInterval(T),e.off(window,"resize",C))},5e3)};q.prototype={constructor:q,editor:function(){return this.edit},rightOriginal:function(){return this.right&&this.right.orig},leftOriginal:function(){return this.left&&this.left.orig},setShowDifferences:function(e){this.right&&this.right.setShowDifferences(e),this.left&&this.left.setShowDifferences(e)},rightChunks:function(){if(this.right)return r(this.right),this.right.chunks},leftChunks:function(){if(this.left)return r(this.left),this.left.chunks}};var G=new diff_match_patch;e.commands.goNextDiff=function(e){return U(e,1)},e.commands.goPrevDiff=function(e){return U(e,-1)}});
1
+ !function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","diff_match_patch"],e):e(CodeMirror)}(function(e){"use strict";function t(e,t){this.mv=e,this.type=t,this.classes="left"==t?{chunk:"CodeMirror-merge-l-chunk",start:"CodeMirror-merge-l-chunk-start",end:"CodeMirror-merge-l-chunk-end",insert:"CodeMirror-merge-l-inserted",del:"CodeMirror-merge-l-deleted",connect:"CodeMirror-merge-l-connect"}:{chunk:"CodeMirror-merge-r-chunk",start:"CodeMirror-merge-r-chunk-start",end:"CodeMirror-merge-r-chunk-end",insert:"CodeMirror-merge-r-inserted",del:"CodeMirror-merge-r-deleted",connect:"CodeMirror-merge-r-connect"}}function i(t){t.diffOutOfDate&&(t.diff=S(t.orig.getValue(),t.edit.getValue(),t.mv.options.ignoreWhitespace),t.chunks=M(t.diff),t.diffOutOfDate=!1,e.signal(t.edit,"updateDiff",t.diff))}function r(t){function r(e){J=!0,v=!1,"full"==e&&(t.svg&&N(t.svg),t.copyButtons&&N(t.copyButtons),c(t.edit,g.marked,t.classes),c(t.orig,u.marked,t.classes),g.from=g.to=u.from=u.to=0),i(t),t.showDifferences&&(h(t.edit,t.diff,g,DIFF_INSERT,t.classes),h(t.orig,t.diff,u,DIFF_DELETE,t.classes)),"align"==t.mv.options.connect&&k(t),d(t),null!=t.needsScrollSync&&o(t,t.needsScrollSync),J=!1}function n(e){J||(t.dealigned=!0,l(e))}function l(e){J||v||(clearTimeout(f),e===!0&&(v=!0),f=setTimeout(r,e===!0?20:250))}function a(e,i){t.diffOutOfDate||(t.diffOutOfDate=!0,g.from=g.to=u.from=u.to=0),n(i.text.length-1!=i.to.line-i.from.line)}function s(){t.diffOutOfDate=!0,t.dealigned=!0,r("full")}var f,g={from:0,to:0,marked:[]},u={from:0,to:0,marked:[]},v=!1;return t.edit.on("change",a),t.orig.on("change",a),t.edit.on("swapDoc",s),t.orig.on("swapDoc",s),"align"==t.mv.options.connect&&(e.on(t.edit.state.trackAlignable,"realign",n),e.on(t.orig.state.trackAlignable,"realign",n)),t.edit.on("viewportChange",function(){l(!1)}),t.orig.on("viewportChange",function(){l(!1)}),r(),r}function n(e,t){e.edit.on("scroll",function(){o(e,!0)&&d(e)}),e.orig.on("scroll",function(){o(e,!1)&&d(e),t&&o(t,!0)&&d(t)})}function o(e,t){if(e.diffOutOfDate)return e.lockScroll&&null==e.needsScrollSync&&(e.needsScrollSync=t),!1;if(e.needsScrollSync=null,!e.lockScroll)return!0;var i,r,n=+new Date;if(t?(i=e.edit,r=e.orig):(i=e.orig,r=e.edit),i.state.scrollSetBy==e&&(i.state.scrollSetAt||0)+250>n)return!1;var o=i.getScrollInfo();if("align"==e.mv.options.connect)m=o.top;else{var a,s,c=.5*o.clientHeight,h=o.top+c,f=i.lineAtHeight(h,"local"),g=A(e.chunks,f,t),d=l(i,t?g.edit:g.orig),u=l(r,t?g.orig:g.edit),v=(h-d.top)/(d.bot-d.top),m=u.top-c+v*(u.bot-u.top);if(m>o.top&&(s=o.top/c)<1)m=m*s+o.top*(1-s);else if((a=o.height-o.clientHeight-o.top)<c){var p=r.getScrollInfo(),k=p.height-p.clientHeight-m;k>a&&(s=a/c)<1&&(m=m*s+(p.height-p.clientHeight-a)*(1-s))}}return r.scrollTo(o.left,m),r.state.scrollSetAt=n,r.state.scrollSetBy=e,!0}function l(e,t){var i=t.after;return null==i&&(i=e.lastLine()+1),{top:e.heightAtLine(t.before||0,"local"),bot:e.heightAtLine(i,"local")}}function a(e,t,i){e.lockScroll=t,t&&0!=i&&o(e,DIFF_INSERT)&&d(e),e.lockButton.innerHTML=t?"⇛⇚":"⇛&nbsp;&nbsp;⇚"}function s(e,t,i){for(var r=i.classLocation,n=0;n<r.length;n++)e.removeLineClass(t,r[n],i.chunk),e.removeLineClass(t,r[n],i.start),e.removeLineClass(t,r[n],i.end)}function c(t,i,r){for(var n=0;n<i.length;++n){var o=i[n];o instanceof e.TextMarker?o.clear():o.parent&&s(t,o,r)}i.length=0}function h(e,t,i,r,n){var o=e.getViewport();e.operation(function(){i.from==i.to||o.from-i.to>20||i.from-o.to>20?(c(e,i.marked,n),g(e,t,r,i.marked,o.from,o.to,n),i.from=o.from,i.to=o.to):(o.from<i.from&&(g(e,t,r,i.marked,o.from,i.from,n),i.from=o.from),o.to>i.to&&(g(e,t,r,i.marked,i.to,o.to,n),i.to=o.to))})}function f(e,t,i,r,n,o){for(var l=i.classLocation,a=e.getLineHandle(t),s=0;s<l.length;s++)r&&e.addLineClass(a,l[s],i.chunk),n&&e.addLineClass(a,l[s],i.start),o&&e.addLineClass(a,l[s],i.end);return a}function g(e,t,i,r,n,o,l){function a(t,i){for(var a=Math.max(n,t),s=Math.min(o,i),c=a;c<s;++c)r.push(f(e,c,l,!0,c==t,c==i-1));t==i&&a==i&&s==i&&(a?r.push(f(e,a-1,l,!1,!1,!0)):r.push(f(e,a,l,!1,!0,!1)))}for(var s=q(0,0),c=q(n,0),h=e.clipPos(q(o-1)),g=i==DIFF_DELETE?l.del:l.insert,d=0,u=!1,v=0;v<t.length;++v){var m=t[v],p=m[0],k=m[1];if(p==DIFF_EQUAL){var C=s.line+(D(t,v)?0:1);V(s,k);var b=s.line+(L(t,v)?1:0);b>C&&(u&&(a(d,C),u=!1),d=b)}else if(u=!0,p==i){var w=V(s,k,!0),T=P(c,s),F=H(h,w);j(T,F)||r.push(e.markText(T,F,{className:g})),s=w}}u&&a(d,s.line+1)}function d(e){if(e.showDifferences){if(e.svg){N(e.svg);var t=e.gap.offsetWidth;R(e.svg,"width",t,"height",e.gap.offsetHeight)}e.copyButtons&&N(e.copyButtons);for(var i=e.edit.getViewport(),r=e.orig.getViewport(),n=e.mv.wrap.getBoundingClientRect().top,o=n-e.edit.getScrollerElement().getBoundingClientRect().top+e.edit.getScrollInfo().top,l=n-e.orig.getScrollerElement().getBoundingClientRect().top+e.orig.getScrollInfo().top,a=0;a<e.chunks.length;a++){var s=e.chunks[a];s.editFrom<=i.to&&s.editTo>=i.from&&s.origFrom<=r.to&&s.origTo>=r.from&&w(e,s,l,o,t)}}}function u(e,t){for(var i=0,r=0,n=0;n<t.length;n++){var o=t[n];if(o.editTo>e&&o.editFrom<=e)return null;if(o.editFrom>e)break;i=o.editTo,r=o.origTo}return r+(e-i)}function v(e,t,i){for(var r=e.state.trackAlignable,n=e.firstLine(),o=0,l=[],a=0;;a++){for(var s=t[a],c=s?i?s.origFrom:s.editFrom:1e9;o<r.alignable.length;o+=2){var h=r.alignable[o]+1;if(!(h<=n)){if(!(h<=c))break;l.push(h)}}if(!s)break;l.push(n=i?s.origTo:s.editTo)}return l}function m(e,t,i,r){var n=0,o=0,l=0,a=0;e:for(;;n++){var s=e[n],c=t[o];if(!s&&null==c)break;for(var h=s?s[0]:1e9,f=null==c?1e9:c;l<i.length;){var g=i[l];if(g.origFrom<=f&&g.origTo>f){o++,n--;continue e}if(g.editTo>h){if(g.editFrom<=h)continue e;break}a+=g.origTo-g.origFrom-(g.editTo-g.editFrom),l++}if(h==f-a)s[r]=f,o++;else if(h<f-a)s[r]=h+a;else{var d=[f-a,null,null];d[r]=f,e.splice(n,0,d),o++}}}function p(e,t){var i=v(e.edit,e.chunks,!1),r=[];if(t)for(var n=0,o=0;n<t.chunks.length;n++){for(var l=t.chunks[n].editTo;o<i.length&&i[o]<l;)o++;o!=i.length&&i[o]==l||i.splice(o++,0,l)}for(var n=0;n<i.length;n++)r.push([i[n],null,null]);return m(r,v(e.orig,e.chunks,!0),e.chunks,1),t&&m(r,v(t.orig,t.chunks,!0),t.chunks,2),r}function k(e,t){if(e.dealigned||t){if(!e.orig.curOp)return e.orig.operation(function(){k(e,t)});e.dealigned=!1;var r=e.mv.left==e?e.mv.right:e.mv.left;r&&(i(r),r.dealigned=!1);for(var n=p(e,r),o=e.mv.aligners,l=0;l<o.length;l++)o[l].clear();o.length=0;var a=[e.edit,e.orig],s=[];r&&a.push(r.orig);for(var l=0;l<a.length;l++)s.push(a[l].getScrollInfo().top);for(var c=0;c<n.length;c++)C(a,n[c],o);for(var l=0;l<a.length;l++)a[l].scrollTo(null,s[l])}}function C(e,t,i){for(var r=0,n=[],o=0;o<e.length;o++)if(null!=t[o]){var l=e[o].heightAtLine(t[o],"local");n[o]=l,r=Math.max(r,l)}for(var o=0;o<e.length;o++)if(null!=t[o]){var a=r-n[o];a>1&&i.push(b(e[o],t[o],a))}}function b(e,t,i){var r=!0;t>e.lastLine()&&(t--,r=!1);var n=document.createElement("div");return n.className="CodeMirror-merge-spacer",n.style.height=i+"px",n.style.minWidth="1px",e.addLineWidget(t,n,{height:i,above:r,mergeSpacer:!0,handleMouseEvents:!0})}function w(e,t,i,r,n){var o="left"==e.type,l=e.orig.heightAtLine(t.origFrom,"local",!0)-i;if(e.svg){var a=l,s=e.edit.heightAtLine(t.editFrom,"local",!0)-r;if(o){var c=a;a=s,s=c}var h=e.orig.heightAtLine(t.origTo,"local",!0)-i,f=e.edit.heightAtLine(t.editTo,"local",!0)-r;if(o){var c=h;h=f,f=c}var g=" C "+n/2+" "+s+" "+n/2+" "+a+" "+(n+2)+" "+a,d=" C "+n/2+" "+h+" "+n/2+" "+f+" -1 "+f;R(e.svg.appendChild(document.createElementNS(G,"path")),"d","M -1 "+s+g+" L "+(n+2)+" "+h+d+" z","class",e.classes.connect)}if(e.copyButtons){var u=e.copyButtons.appendChild(I("div","left"==e.type?"⇝":"⇜","CodeMirror-merge-copy")),v=e.mv.options.allowEditingOriginals;if(u.title=v?"Push to left":"Revert chunk",u.chunk=t,u.style.top=(t.origTo>t.origFrom?l:e.edit.heightAtLine(t.editFrom,"local")-r)+"px",v){var m=e.edit.heightAtLine(t.editFrom,"local")-r,p=e.copyButtons.appendChild(I("div","right"==e.type?"⇝":"⇜","CodeMirror-merge-copy-reverse"));p.title="Push to right",p.chunk={editFrom:t.origFrom,editTo:t.origTo,origFrom:t.editFrom,origTo:t.editTo},p.style.top=m+"px","right"==e.type?p.style.left="2px":p.style.right="2px"}}}function T(e,t,i,r){if(!e.diffOutOfDate){var n=r.origTo>i.lastLine()?q(r.origFrom-1):q(r.origFrom,0),o=q(r.origTo,0),l=r.editTo>t.lastLine()?q(r.editFrom-1):q(r.editFrom,0),a=q(r.editTo,0),s=e.mv.options.revertChunk;s?s(e.mv,i,n,o,t,l,a):t.replaceRange(i.getRange(n,o),l,a)}}function F(t){var i=t.lockButton=I("div",null,"CodeMirror-merge-scrolllock");i.title="Toggle locked scrolling";var r=I("div",[i],"CodeMirror-merge-scrolllock-wrap");e.on(i,"click",function(){a(t,!t.lockScroll)});var n=[r];if(t.mv.options.revertButtons!==!1&&(t.copyButtons=I("div",null,"CodeMirror-merge-copybuttons-"+t.type),e.on(t.copyButtons,"click",function(e){var i=e.target||e.srcElement;if(i.chunk)return"CodeMirror-merge-copy-reverse"==i.className?void T(t,t.orig,t.edit,i.chunk):void T(t,t.edit,t.orig,i.chunk)}),n.unshift(t.copyButtons)),"align"!=t.mv.options.connect){var o=document.createElementNS&&document.createElementNS(G,"svg");o&&!o.createSVGRect&&(o=null),t.svg=o,o&&n.push(o)}return t.gap=I("div",n,"CodeMirror-merge-gap")}function y(e){return"string"==typeof e?e:e.getValue()}function S(e,t,i){for(var r=X.diff_main(e,t),n=0;n<r.length;++n){var o=r[n];(i?/[^ \t]/.test(o[1]):o[1])?n&&r[n-1][0]==o[0]&&(r.splice(n--,1),r[n][1]+=o[1]):r.splice(n--,1)}return r}function M(e){for(var t=[],i=0,r=0,n=q(0,0),o=q(0,0),l=0;l<e.length;++l){var a=e[l],s=a[0];if(s==DIFF_EQUAL){var c=!D(e,l)||n.line<i||o.line<r?1:0,h=n.line+c,f=o.line+c;V(n,a[1],null,o);var g=L(e,l)?1:0,d=n.line+g,u=o.line+g;d>h&&(l&&t.push({origFrom:r,origTo:f,editFrom:i,editTo:h}),i=d,r=u)}else V(s==DIFF_INSERT?n:o,a[1])}return(i<=n.line||r<=o.line)&&t.push({origFrom:r,origTo:o.line+1,editFrom:i,editTo:n.line+1}),t}function L(e,t){if(t==e.length-1)return!0;var i=e[t+1][1];return!(1==i.length&&t<e.length-2||10!=i.charCodeAt(0))&&(t==e.length-2||(i=e[t+2][1],(i.length>1||t==e.length-3)&&10==i.charCodeAt(0)))}function D(e,t){if(0==t)return!0;var i=e[t-1][1];return 10==i.charCodeAt(i.length-1)&&(1==t||(i=e[t-2][1],10==i.charCodeAt(i.length-1)))}function A(e,t,i){for(var r,n,o,l,a=0;a<e.length;a++){var s=e[a],c=i?s.editFrom:s.origFrom,h=i?s.editTo:s.origTo;null==n&&(c>t?(n=s.editFrom,l=s.origFrom):h>t&&(n=s.editTo,l=s.origTo)),h<=t?(r=s.editTo,o=s.origTo):c<=t&&(r=s.editFrom,o=s.origFrom)}return{edit:{before:r,after:n},orig:{before:o,after:l}}}function E(t,i,r){function n(){l.clear(),t.removeLineClass(i,"wrap","CodeMirror-merge-collapsed-line")}t.addLineClass(i,"wrap","CodeMirror-merge-collapsed-line");var o=document.createElement("span");o.className="CodeMirror-merge-collapsed-widget",o.title="Identical text collapsed. Click to expand.";var l=t.markText(q(i,0),q(r-1),{inclusiveLeft:!0,inclusiveRight:!0,replacedWith:o,clearOnEnter:!0});return e.on(o,"click",n),{mark:l,clear:n}}function O(e,t){function i(){for(var e=0;e<r.length;e++)r[e].clear()}for(var r=[],n=0;n<t.length;n++){var o=t[n],l=E(o.cm,o.line,o.line+e);r.push(l),l.mark.on("clear",i)}return r[0].mark}function x(e,t,i,r){for(var n=0;n<e.chunks.length;n++)for(var o=e.chunks[n],l=o.editFrom-t;l<o.editTo+t;l++){var a=l+i;a>=0&&a<r.length&&(r[a]=!1)}}function B(e,t){"number"!=typeof t&&(t=2);for(var i=[],r=e.editor(),n=r.firstLine(),o=n,l=r.lastLine();o<=l;o++)i.push(!0);e.left&&x(e.left,t,n,i),e.right&&x(e.right,t,n,i);for(var a=0;a<i.length;a++)if(i[a]){for(var s=a+n,c=1;a<i.length-1&&i[a+1];a++,c++);if(c>t){var h=[{line:s,cm:r}];e.left&&h.push({line:u(s,e.left.chunks),cm:e.left.orig}),e.right&&h.push({line:u(s,e.right.chunks),cm:e.right.orig});var f=O(c,h);e.options.onCollapse&&e.options.onCollapse(e,s,c,f)}}}function I(e,t,i,r){var n=document.createElement(e);if(i&&(n.className=i),r&&(n.style.cssText=r),"string"==typeof t)n.appendChild(document.createTextNode(t));else if(t)for(var o=0;o<t.length;++o)n.appendChild(t[o]);return n}function N(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild)}function R(e){for(var t=1;t<arguments.length;t+=2)e.setAttribute(arguments[t],arguments[t+1])}function W(e,t){t||(t={});for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}function V(e,t,i,r){for(var n=i?q(e.line,e.ch):e,o=0;;){var l=t.indexOf("\n",o);if(l==-1)break;++n.line,r&&++r.line,o=l+1}return n.ch=(o?0:n.ch)+(t.length-o),r&&(r.ch=(o?0:r.ch)+(t.length-o)),n}function _(e){this.cm=e,this.alignable=[],this.height=e.doc.height;var t=this;e.on("markerAdded",function(e,i){if(i.collapsed){var r=i.find(1);null!=r&&t.set(r.line,$)}}),e.on("markerCleared",function(e,i,r,n){null!=n&&i.collapsed&&t.check(n,$,t.hasMarker)}),e.on("markerChanged",this.signal.bind(this)),e.on("lineWidgetAdded",function(e,i,r){i.mergeSpacer||(i.above?t.set(r-1,Z):t.set(r,Y))}),e.on("lineWidgetCleared",function(e,i,r){i.mergeSpacer||(i.above?t.check(r-1,Z,t.hasWidgetBelow):t.check(r,Y,t.hasWidget))}),e.on("lineWidgetChanged",this.signal.bind(this)),e.on("change",function(e,i){var r=i.from.line,n=i.to.line-i.from.line,o=i.text.length-1,l=r+o;(n||o)&&t.map(r,n,o),t.check(l,$,t.hasMarker),(n||o)&&t.check(i.from.line,$,t.hasMarker)}),e.on("viewportChange",function(){t.cm.doc.height!=t.height&&t.signal()})}function H(e,t){return(e.line-t.line||e.ch-t.ch)<0?e:t}function P(e,t){return(e.line-t.line||e.ch-t.ch)>0?e:t}function j(e,t){return e.line==t.line&&e.ch==t.ch}function U(e,t,i){for(var r=e.length-1;r>=0;r--){var n=e[r],o=(i?n.origTo:n.editTo)-1;if(o<t)return o}}function z(e,t,i){for(var r=0;r<e.length;r++){var n=e[r],o=i?n.origFrom:n.editFrom;if(o>t)return o}}function Q(t,r){var n=null,o=t.state.diffViews,l=t.getCursor().line;if(o)for(var a=0;a<o.length;a++){var s=o[a],c=t==s.orig;i(s);var h=r<0?U(s.chunks,l,c):z(s.chunks,l,c);null==h||null!=n&&!(r<0?h>n:h<n)||(n=h)}return null==n?e.Pass:void t.setCursor(n,0)}var q=e.Pos,G="http://www.w3.org/2000/svg";t.prototype={constructor:t,init:function(t,i,r){this.edit=this.mv.edit,(this.edit.state.diffViews||(this.edit.state.diffViews=[])).push(this),this.orig=e(t,W({value:i,readOnly:!this.mv.options.allowEditingOriginals},W(r))),"align"==this.mv.options.connect&&(this.edit.state.trackAlignable||(this.edit.state.trackAlignable=new _(this.edit)),this.orig.state.trackAlignable=new _(this.orig)),this.orig.state.diffViews=[this];var n=r.chunkClassLocation||"background";"[object Array]"!=Object.prototype.toString.call(n)&&(n=[n]),this.classes.classLocation=n,this.diff=S(y(i),y(r.value),this.mv.options.ignoreWhitespace),this.chunks=M(this.diff),this.diffOutOfDate=this.dealigned=!1,this.needsScrollSync=null,this.showDifferences=r.showDifferences!==!1},registerEvents:function(e){this.forceUpdate=r(this),a(this,!0,!1),n(this,e)},setShowDifferences:function(e){e=e!==!1,e!=this.showDifferences&&(this.showDifferences=e,this.forceUpdate("full"))}};var J=!1,K=e.MergeView=function(i,r){if(!(this instanceof K))return new K(i,r);this.options=r;var n=r.origLeft,o=null==r.origRight?r.orig:r.origRight,l=null!=n,a=null!=o,s=1+(l?1:0)+(a?1:0),c=[],h=this.left=null,f=this.right=null,g=this;if(l){h=this.left=new t(this,"left");var u=I("div",null,"CodeMirror-merge-pane CodeMirror-merge-left");c.push(u),c.push(F(h))}var v=I("div",null,"CodeMirror-merge-pane CodeMirror-merge-editor");if(c.push(v),a){f=this.right=new t(this,"right"),c.push(F(f));var m=I("div",null,"CodeMirror-merge-pane CodeMirror-merge-right");c.push(m)}(a?m:v).className+=" CodeMirror-merge-pane-rightmost",c.push(I("div",null,null,"height: 0; clear: both;"));var p=this.wrap=i.appendChild(I("div",c,"CodeMirror-merge CodeMirror-merge-"+s+"pane"));this.edit=e(v,W(r)),h&&h.init(u,n,r),f&&f.init(m,o,r),r.collapseIdentical&&this.editor().operation(function(){B(g,r.collapseIdentical)}),"align"==r.connect&&(this.aligners=[],k(this.left||this.right,!0)),h&&h.registerEvents(f),f&&f.registerEvents(h);var C=function(){h&&d(h),f&&d(f)};e.on(window,"resize",C);var b=setInterval(function(){for(var t=p.parentNode;t&&t!=document.body;t=t.parentNode);t||(clearInterval(b),e.off(window,"resize",C))},5e3)};K.prototype={constructor:K,editor:function(){return this.edit},rightOriginal:function(){return this.right&&this.right.orig},leftOriginal:function(){return this.left&&this.left.orig},setShowDifferences:function(e){this.right&&this.right.setShowDifferences(e),this.left&&this.left.setShowDifferences(e)},rightChunks:function(){if(this.right)return i(this.right),this.right.chunks},leftChunks:function(){if(this.left)return i(this.left),this.left.chunks}};var X=new diff_match_patch,Y=1,Z=2,$=4;_.prototype={signal:function(){e.signal(this,"realign"),this.height=this.cm.doc.height},set:function(e,t){for(var i=-1;i<this.alignable.length;i+=2){var r=this.alignable[i]-e;if(0==r){if((this.alignable[i+1]&t)==t)return;return this.alignable[i+1]|=t,void this.signal()}if(r>0)break}this.signal(),this.alignable.splice(i,0,e,t)},find:function(e){for(var t=0;t<this.alignable.length;t+=2)if(this.alignable[t]==e)return t;return-1},check:function(e,t,i){var r=this.find(e);if(r!=-1&&this.alignable[r+1]&t&&!i.call(this,e)){this.signal();var n=this.alignable[r+1]&~t;n?this.alignable[r+1]=n:this.alignable.splice(r,2)}},hasMarker:function(e){var t=this.cm.getLineHandle(e);if(t.markedSpans)for(var i=0;i<t.markedSpans.length;i++)if(t.markedSpans[i].mark.collapsed&&null!=t.markedSpans[i].to)return!0;return!1},hasWidget:function(e){var t=this.cm.getLineHandle(e);if(t.widgets)for(var i=0;i<t.widgets.length;i++)if(!t.widgets[i].above&&!t.widgets[i].mergeSpacer)return!0;return!1},hasWidgetBelow:function(e){if(e==this.cm.lastLine())return!1;var t=this.cm.getLineHandle(e+1);if(t.widgets)for(var i=0;i<t.widgets.length;i++)if(t.widgets[i].above&&!t.widgets[i].mergeSpacer)return!0;return!1},map:function(e,t,i){for(var r=i-t,n=e+t,o=-1,l=-1,a=0;a<this.alignable.length;a+=2){var s=this.alignable[a];s==e&&this.alignable[a+1]&Z&&(o=a),s==n&&this.alignable[a+1]&Z&&(l=a),s<=e||(s<n?this.alignable.splice(a--,2):this.alignable[a]+=r)}if(o>-1){var c=this.alignable[o+1];c==Z?this.alignable.splice(o,2):this.alignable[o+1]=c&~Z}l>-1&&i&&this.set(e+i,Z)}},e.commands.goNextDiff=function(e){return Q(e,1)},e.commands.goPrevDiff=function(e){return Q(e,-1)}});
lib/codemirror/lib/codemirror.css CHANGED
@@ -223,11 +223,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
223
  cursor: default;
224
  z-index: 4;
225
  }
226
- .CodeMirror-gutter-wrapper {
227
- -webkit-user-select: none;
228
- -moz-user-select: none;
229
- user-select: none;
230
- }
231
 
232
  .CodeMirror-lines {
233
  cursor: text;
@@ -272,6 +269,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
272
 
273
  .CodeMirror-widget {}
274
 
 
 
275
  .CodeMirror-code {
276
  outline: none;
277
  }
223
  cursor: default;
224
  z-index: 4;
225
  }
226
+ .CodeMirror-gutter-wrapper ::selection { background-color: transparent }
227
+ .CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent }
 
 
 
228
 
229
  .CodeMirror-lines {
230
  cursor: text;
269
 
270
  .CodeMirror-widget {}
271
 
272
+ .CodeMirror-rtl pre { direction: rtl; }
273
+
274
  .CodeMirror-code {
275
  outline: none;
276
  }
lib/codemirror/lib/codemirror.js CHANGED
@@ -21,19 +21,21 @@ var platform = navigator.platform
21
  var gecko = /gecko\/\d/i.test(userAgent)
22
  var ie_upto10 = /MSIE \d/.test(userAgent)
23
  var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent)
24
- var ie = ie_upto10 || ie_11up
25
- var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : ie_11up[1])
26
- var webkit = /WebKit\//.test(userAgent)
 
27
  var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent)
28
- var chrome = /Chrome\//.test(userAgent)
29
  var presto = /Opera\//.test(userAgent)
30
  var safari = /Apple Computer/.test(navigator.vendor)
31
  var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent)
32
  var phantom = /PhantomJS/.test(userAgent)
33
 
34
- var ios = /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent)
 
35
  // This is woefully incomplete. Suggestions for alternative methods welcome.
36
- var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent)
37
  var mac = ios || /Mac/.test(platform)
38
  var chromeOS = /\bCrOS\b/.test(userAgent)
39
  var windows = /win/i.test(platform)
@@ -74,6 +76,12 @@ function elt(tag, content, className, style) {
74
  else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]) } }
75
  return e
76
  }
 
 
 
 
 
 
77
 
78
  var range
79
  if (document.createRange) { range = function(node, start, end, endNode) {
@@ -113,8 +121,8 @@ function activeElt() {
113
  } catch(e) {
114
  activeElement = document.body || null
115
  }
116
- while (activeElement && activeElement.root && activeElement.root.activeElement)
117
- { activeElement = activeElement.root.activeElement }
118
  return activeElement
119
  }
120
 
@@ -165,11 +173,11 @@ function countColumn(string, end, tabSize, startIndex, startValue) {
165
  }
166
  }
167
 
168
- function Delayed() {this.id = null}
169
- Delayed.prototype.set = function(ms, f) {
170
  clearTimeout(this.id)
171
  this.id = setTimeout(f, ms)
172
- }
173
 
174
  function indexOf(array, elt) {
175
  for (var i = 0; i < array.length; ++i)
@@ -263,6 +271,23 @@ function isEmpty(obj) {
263
  var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/
264
  function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  // The display handles the DOM integration, both for input reading
267
  // and content drawing. It holds references to DOM nodes and
268
  // display-related state.
@@ -279,7 +304,7 @@ function Display(place, doc, input) {
279
  d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler")
280
  d.gutterFiller.setAttribute("cm-not-content", "true")
281
  // Will contain the actual code, positioned to cover the viewport.
282
- d.lineDiv = elt("div", null, "CodeMirror-code")
283
  // Elements are added to these to represent selection and cursors.
284
  d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1")
285
  d.cursorDiv = elt("div", null, "CodeMirror-cursors")
@@ -288,10 +313,11 @@ function Display(place, doc, input) {
288
  // When lines outside of the viewport are measured, they are drawn in this.
289
  d.lineMeasure = elt("div", null, "CodeMirror-measure")
290
  // Wraps everything that needs to exist inside the vertically-padded coordinate system
291
- d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
292
  null, "position: relative; outline: none")
 
293
  // Moved around its parent to cover visible view.
294
- d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative")
295
  // Set to the height of the document, allowing scrolling.
296
  d.sizer = elt("div", [d.mover], "CodeMirror-sizer")
297
  d.sizerWidth = null
@@ -450,15 +476,21 @@ function lineNumberFor(options, i) {
450
  }
451
 
452
  // A Pos instance represents a position within the text.
453
- function Pos (line, ch) {
454
- if (!(this instanceof Pos)) { return new Pos(line, ch) }
455
- this.line = line; this.ch = ch
 
 
 
 
456
  }
457
 
458
  // Compare two positions, return 0 if they are the same, a negative
459
  // number when a is less, and a positive number otherwise.
460