Seditio Source
Root |
./othercms/xenForo 2.2.8/js/xf/code_editor.min.js
'use strict';!function(d,k,l,m){XF.CodeEditor=XF.Element.newHandler({options:{indentUnit:4,indentWithTabs:!0,lineNumbers:!0,lineWrapping:!1,autoCloseBrackets:!0,autoCloseTags:null,mode:null,config:null,submitSelector:null,scrollbarStyle:"simple"},editor:null,$wrapper:null,init:function(){if(this.isAdvancedEditorSupported())if(this.$target[0].parentNode.scrollHeight)this.initEditor();else this.$target.oneWithin("toggle:shown overlay:showing tab:shown",XF.proxy(this,"initEditor"));else this.$target.show()},
isAdvancedEditorSupported:function(){return"android"!==XF.browser.os},initEditor:function(){var a=this.$target,b={},c={};if(!a.data("cmInitialized")){try{c=d.parseJSON(this.options.config)}catch(e){c=this.options.config}try{b=d.parseJSON(d(".js-codeEditorLanguage").first().html())||{}}catch(e){console.error(e),b={}}c=d.extend({mode:this.options.mode,indentUnit:this.options.indentUnit,indentWithTabs:this.options.indentWithTabs,lineNumbers:this.options.lineNumbers,lineWrapping:this.options.lineWrapping,
autoCloseBrackets:this.options.autoCloseBrackets,readOnly:a.prop("readonly"),autofocus:a.prop("autofocus"),scrollbarStyle:this.options.scrollbarStyle,phrases:b},c);b=this.options.autoCloseTags;null!==b&&(c.autoCloseTags=b?!0:!1);this.editor=CodeMirror.fromTextArea(a.get(0),c);this.$wrapper=d(this.editor.getWrapperElement());c=a.attr("class").replace(/(^| )input(--[^ ]+)?(?= |$)/g,"$1");this.$wrapper.addClass(c).attr("dir","ltr");a.attr("class","");this.editor.refresh();XF.layoutChange();this.editor.on("keydown",
XF.proxy(this,"keydown"));a.closest("form").on("ajax-submit:before",XF.proxy(this,"onSubmit"));a.trigger("code-editor:init",this.editor);a.data("cmInitialized",!0)}},onSubmit:function(a){this.editor.save()},keydown:function(a,b){if(XF.isMac()&&b.metaKey&&b.ctrlKey&&"f"==b.key||!XF.isMac()&&"F11"==b.key)b.preventDefault(),a.setOption("fullScreen",!a.getOption("fullScreen"));"Escape"==b.key&&(b.stopPropagation(),a.getOption("fullScreen")&&a.setOption("fullScreen",!1));if(("s"==b.key||"Enter"==b.key)&&
(XF.isMac()?b.metaKey:b.ctrlKey)){b.preventDefault();a=d(a.getTextArea()).closest("form");b=this.options.submitSelector;var c=a.find(b);b&&c.length?a.find(b).click():a.submit()}}});XF.CodeEditorSwitcherContainer=XF.Element.newHandler({options:{switcher:".js-codeEditorSwitcher",templateSuffixMode:0},$switcher:null,editor:null,loading:!1,xhr:null,init:function(){this.$target.on("code-editor:init",XF.proxy(this,"initEditor"));this.$target.on("code-editor:reinit",XF.proxy(this,"change"))},initEditor:function(a,
b){var c=this.$target.find(this.options.switcher);if(c.length){this.$switcher=c;if(c.is("select, :radio"))c.on("change",XF.proxy(this,"change"));else if(c.is("input:not(:checkbox :radio)"))c.on("blur",XF.proxy(this,"blurInput")),setTimeout(function(){c.trigger("blur")},100);else{console.warn("Switcher only works for text inputs, radios and selects.");return}this.editor=b}else console.warn("Switcher container has no switcher: %o",this.$target)},change:function(a){this.editor&&(a=this.$switcher.find(":selected").val(),
this.switchLanguage(a))},blurInput:function(a){a=this.$switcher.val();this.options.templateSuffixMode&&(a=a.toLowerCase(),a=0<a.indexOf(".less")?"less":0<a.indexOf(".css")?"css":"html");this.switchLanguage(a)},switchLanguage:function(a){if(!this.loading){var b=this,c=this.editor,e=d(c.getTextArea());c.save();e.data("lang")!=a&&setTimeout(function(){var f="public"==d("html").data("app")?"index.php?misc/code-editor-mode-loader":"admin.php?templates/code-editor-mode-loader";b.xhr=XF.ajax("post",XF.canonicalizeUrl(f),
{language:a},XF.proxy(b,"handleAjax")).always(function(){b.loading=!1})},200)}},handleAjax:function(a){if(!a.errors&&!a.exception){a.redirect&&XF.redirect(a.redirect);var b=this.editor,c=d(b.getTextArea());XF.setupHtmlInsert(a.html,function(e,f){e="";a.mime?e=a.mime:a.mode&&(e=a.mode);b.setOption("mode",e);c.data("lang",a.language);c.data("config",JSON.stringify(a.config));a.config&&d.each(a.config,function(g,h){b.setOption(g,h)})})}}});XF.Element.register("code-editor","XF.CodeEditor");XF.Element.register("code-editor-switcher-container",
"XF.CodeEditorSwitcherContainer")}(jQuery,window,document);