Flexishore_Codemirror - Version 0.1.0

Version Notes

Notes

Download this release

Release Info

Developer Magento Core Team
Extension Flexishore_Codemirror
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Flexishore/Codemirror/Model/Config.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @category Flexishore
4
+ * @package Flexishore_Codemirror
5
+ * @copyright Copyright (c) 2011 Flexishore (http://www.flexishore.com)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ /**
10
+ * Widgets Plugin Config for CodeMirror
11
+ *
12
+ * @category Flexishore
13
+ * @package Flexishore_Codemirror
14
+ * @author Rafał Kos <rafal.k@flexishore.com>
15
+ */
16
+ class Flexishore_Codemirror_Model_Config extends Varien_Object
17
+ {
18
+
19
+ /**
20
+ * Return config settings for widgets insertion plugin based on editor element config
21
+ *
22
+ * @param Varien_Object $config
23
+ *
24
+ * @return array
25
+ */
26
+ public function getPluginSettings($config)
27
+ {
28
+
29
+ $codemirrorWysiwygPlugin = array(array('name' => 'codemagic',
30
+ 'src' => Mage::getBaseUrl('js').'tiny_mce/plugins/codemagic/editor_plugin.js',
31
+ ));
32
+
33
+ $configPlugins = $config->getData('plugins');
34
+ $variableConfig['plugins'] = array_merge($codemirrorWysiwygPlugin, $configPlugins);
35
+
36
+ return $variableConfig;
37
+ }
38
+ }
app/code/local/Flexishore/Codemirror/Model/Observer.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @category Flexishore
4
+ * @package Flexishore_Codemirror
5
+ * @copyright Copyright (c) 2011 Flexishore (http://www.flexishore.com)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ /**
10
+ * Flexishore Cms Observer
11
+ *
12
+ * @category Flexishore
13
+ * @package Flexishore_Codemirror
14
+ * @author Rafał Kos <rafal.k@flexishore.com>
15
+ */
16
+ class Flexishore_Codemirror_Model_Observer
17
+ {
18
+ /**
19
+ * Add additional settings to wysiwyg config (CodeMirror)
20
+ *
21
+ * @param Varien_Event_Observer $observer
22
+ *
23
+ * @return Mage_Widget_Model_Observer
24
+ */
25
+ public function prepareWidgetsPluginConfig(Varien_Event_Observer $observer)
26
+ {
27
+ $config = $observer->getEvent()->getConfig();
28
+
29
+ if ($config->getData('add_widgets')) {
30
+ $settings = Mage::getModel('codemirror/config')->getPluginSettings($config);
31
+ $config->addData($settings);
32
+ }
33
+
34
+ return $this;
35
+ }
36
+
37
+ }
app/code/local/Flexishore/Codemirror/etc/config.xml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Flexishore_Codemirror>
5
+ <version>0.1</version>
6
+ </Flexishore_Codemirror>
7
+ </modules>
8
+
9
+ <global>
10
+ <models>
11
+ <codemirror>
12
+ <class>Flexishore_Codemirror_Model</class>
13
+ </codemirror>
14
+ </models>
15
+ </global>
16
+
17
+ <adminhtml>
18
+ <events>
19
+ <cms_wysiwyg_config_prepare>
20
+ <observers>
21
+ <wysiwyg_observer>
22
+ <type>singleton</type>
23
+ <class>codemirror/observer</class>
24
+ <method>prepareWidgetsPluginConfig</method>
25
+ </wysiwyg_observer>
26
+ </observers>
27
+ </cms_wysiwyg_config_prepare>
28
+ </events>
29
+ </adminhtml>
30
+
31
+ </config>
app/etc/modules/Flexishore_Codemirror.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Flexishore_Codemirror>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Flexishore_Codemirror>
8
+ </modules>
9
+ </config>
js/tiny_mce/plugins/codemagic/codemagic.htm ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html xmlns="http://www.w3.org/1999/xhtml">
2
+ <head>
3
+ <title>{#codemagic_dlg.code_title}</title>
4
+ <script type="text/javascript" src="../../tiny_mce_popup.js"></script>
5
+ <script type="text/javascript" src="js/codemirror-compressed.js"></script>
6
+ <script type="text/javascript" src="js/codemagic.js"></script>
7
+ <script type="text/javascript" src="js/beautify.js"></script>
8
+ <script type="text/javascript" src="js/beautify-html.js"></script>
9
+
10
+ <link rel="stylesheet" media="all" type="text/css" href="css/style.css" />
11
+ <link rel="stylesheet" media="all" type="text/css" href="css/codemirror.css" />
12
+ <link rel="stylesheet" media="all" type="text/css" href="css/default.css" />
13
+ </head>
14
+
15
+ <body onresize="resizeInputs();" style="display: none; overflow: hidden;">
16
+ <form name="source" onsubmit="saveContent(); return false;" action="#">
17
+ <div style="float: left" class="title"><label for="htmlSource">{#codemagic_dlg.code_label}</label></div>
18
+
19
+ <div class="editor-buttons">
20
+ <a id="undo" class="disabled" href="javascript: void(0)" title="{#codemagic_dlg.undo}" onclick="undo();"><img src="img/icons/undo.png" alt="{#codemagic_dlg.undo}" /></a>
21
+ <a id="redo" class="disabled" href="javascript: void(0)" title="{#codemagic_dlg.redo}" onclick="redo();"><img src="img/icons/redo.png" alt="{#codemagic_dlg.redo}" /></a>
22
+ <a id="search_replace" href="javascript: void(0)" title="{#codemagic_dlg.search_replace}" onclick="toggleSearch(this, 'searchWindow');"><img src="img/icons/lens.png" alt="{#codemagic_dlg.search_replace}" /></a>
23
+ <a id="reintendt" href="javascript: void(0)" title="{#codemagic_dlg.reintendt}" onclick="reIntendt('htmlSource');"><img src="img/icons/file.png" alt="{#codemagic_dlg.reintendt}" /></a>
24
+ <div style="clear: both;"></div>
25
+ </div>
26
+
27
+ <div id="wrapline" style="float: right">
28
+ <input type="checkbox" name="autocompletion" id="autocompletion" onclick="toggleAutocompletion(this);" class="wordWrapCode" checked="checked" /><label for="autocompletion">{#codemagic_dlg.toggle_autocompletion}</label> &nbsp;&nbsp;&nbsp;&nbsp;
29
+ <input type="checkbox" name="highlighting" id="highlighting" onclick="toggleHighlighting(this, 'htmlSource');" class="wordWrapCode" checked="checked" /><label for="highlighting">{#codemagic_dlg.toggle_highlighting}</label>
30
+ </div>
31
+ <div style="clear: both;"></div>
32
+
33
+
34
+ <div id="searchWindow" class="search-window" style="display: none;">
35
+ <h2>{#codemagic_dlg.search_replace}</h2>
36
+ <table>
37
+ <tr>
38
+ <td colspan="2">&nbsp;</td>
39
+ </tr>
40
+ <tr>
41
+ <td><label for="query">{#codemagic_dlg.search}</label>:</td>
42
+ <td><input id="query" type="text" style="width: 150px" /></td>
43
+ </tr>
44
+ <tr>
45
+ <td><label for="replace">{#codemagic_dlg.replace}</label>:</td>
46
+ <td><input id="replace" type="text" style="width: 150px" /></td>
47
+ </tr>
48
+ <tr>
49
+ <td colspan="2">&nbsp;</td>
50
+ </tr>
51
+ <tr>
52
+ <td align="left"><input onclick="searchCode(); return false;" type="submit" value="{#codemagic_dlg.search}" class="button" style="float: none" /></td>
53
+ <td align="right"><input onclick="replaceCode(); return false;" type="submit" value="{#codemagic_dlg.replace}" class="button" style="float: none" /></td>
54
+ </tr>
55
+ </table>
56
+ </div>
57
+
58
+ <textarea name="htmlSource" id="htmlSource" rows="15" cols="100" dir="ltr" class="htmlSource"></textarea>
59
+
60
+ <div class="mceActionPanel">
61
+ <input type="submit" role="button" name="insert" value="{#update}" id="insert" />
62
+ <input type="button" role="button" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" id="cancel" />
63
+ </div>
64
+ </form>
65
+ </body>
66
+ </html>
js/tiny_mce/plugins/codemagic/css/codemirror.css ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .CodeMirror {
2
+ overflow: auto;
3
+ height: 90%;
4
+ line-height: 14px;
5
+ font-size: 13px;
6
+ font-family: monospace;
7
+ background-color: #fff;
8
+ border:1px solid #abc6dd;
9
+ _position: relative; /* IE6 hack */
10
+ }
11
+
12
+ .CodeMirror-gutter {
13
+ position: absolute; left: 0; top: 0;
14
+ background-color: #f7f7f7;
15
+ border-right: 1px solid #eee;
16
+ min-width: 2em;
17
+ height: 100%;
18
+ }
19
+ .CodeMirror-gutter-text {
20
+ color: #aaa;
21
+ text-align: right;
22
+ padding: .4em .2em .4em .4em;
23
+ }
24
+ .CodeMirror-lines {
25
+ padding: .4em;
26
+ }
27
+
28
+ .CodeMirror pre {
29
+ -moz-border-radius: 0;
30
+ -webkit-border-radius: 0;
31
+ -o-border-radius: 0;
32
+ border-radius: 0;
33
+ border-width: 0; margin: 0; padding: 0; background: transparent;
34
+ font-family: inherit;
35
+ }
36
+
37
+ .CodeMirror pre.activeline {
38
+ background: none repeat scroll 0 0 #efefef !important;
39
+ }
40
+
41
+ .CodeMirror-cursor {
42
+ z-index: 10;
43
+ position: absolute;
44
+ visibility: hidden;
45
+ border-left: 1px solid black !important;
46
+ }
47
+ .CodeMirror-focused .CodeMirror-cursor {
48
+ visibility: visible;
49
+ }
50
+
51
+ span.CodeMirror-selected {
52
+ background: #ccc !important;
53
+ color: HighlightText !important;
54
+ }
55
+ .CodeMirror-focused span.CodeMirror-selected {
56
+ background: Highlight !important;
57
+ }
58
+
59
+ .CodeMirror-matchingbracket {color: #000 !important; background-color: #a0e0fc !important;}
60
+ .CodeMirror-nonmatchingbracket {color: #f22 !important;}
61
+
62
+ .CodeMirrorToolBar
63
+ {
64
+ border:1px solid #abc6dd;
65
+ border-bottom: 0;
66
+ background:#e5effd;
67
+ margin:0px;
68
+ padding:0;
69
+ }
70
+ .CMBtn
71
+ {
72
+ border:1px solid #b0c8e8;
73
+ background:#cadcf0;
74
+ font :700 10px verdana;
75
+ margin:5px;
76
+ border-radius: 2px;
77
+ -moz-border-radius: 2px;
78
+ -webkit-border-radius: 2px;
79
+ color: #6497d9;
80
+ }
81
+
82
+ .searched {
83
+ background-color: yellow;
84
+ }
85
+
86
+ .completions {
87
+ position: absolute;
88
+ border: 1px solid #000000;
89
+ background-color: #F0F0EE;
90
+ padding: 3px;
91
+ }
92
+
93
+ .completions select {
94
+ background-color: #FFFFFF;
95
+ border: 1px solid #B5A69C;
96
+ width: 200px;
97
+ height: 144px;
98
+ }
js/tiny_mce/plugins/codemagic/css/default.css ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ span.css-at {color: #0000ff;}
2
+ span.css-unit {color: #0000ff;}
3
+ span.css-value {color: #0000ff;}
4
+ span.css-identifier {color: #800000; font-weight: bold;}
5
+ span.css-selector {color: #ff00ff;}
6
+ span.css-important {color: #00F;}
7
+ span.css-colorcode {color: #0000ff;}
8
+ span.css-comment {color: gray;}
9
+ span.css-string {color: #008000;}
10
+
11
+
12
+ span.js-keyword {color: #000000; font-weight: bold;}
13
+ span.js-variable {color: #0000FF;}
14
+ span.js-property {color: #0000FF; font-weight: bold;}
15
+ span.js-atom {color: #ff0000;}
16
+ span.js-variabledef {color: #0000FF;}
17
+ span.js-localvariable {color: #0000FF;}
18
+ span.js-comment {color: #008000;}
19
+ span.js-string {color: #b70000;}
20
+
21
+
22
+ span.xml-tag {color: #800080; font-weight: bold;}
23
+ span.xml-attribute {color: #8080ff;}
24
+ span.xml-attname {color: #008080;}
25
+ span.xml-comment {color: #008000;}
26
+ span.xml-cdata {color: #48a;}
27
+ span.xml-processing {color: #999;}
28
+ span.xml-entity {color: #008000; font-weight: bold;}
js/tiny_mce/plugins/codemagic/css/style.css ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ a, img,
2
+ a img {
3
+ border: none;
4
+ }
5
+
6
+ .editor-buttons {
7
+ margin-left: -46px;
8
+ position: absolute;
9
+ left: 50%;
10
+ width: 95px;
11
+ top: 3px;
12
+ }
13
+
14
+ .editor-buttons a {
15
+ float: left;
16
+ display: block;
17
+ text-align: center;
18
+ width: 16px;
19
+ padding: 2px;
20
+ border: 1px solid #F0F0EE;
21
+ margin-right: 1px;
22
+ }
23
+
24
+ .editor-buttons a:hover,
25
+ .editor-buttons a.selected {
26
+ background-color: #C2CBE0;
27
+ border: 1px solid #0A246A;
28
+ }
29
+
30
+ .editor-buttons a.disabled,
31
+ .editor-buttons a.disabled:hover {
32
+ background-color: transparent;
33
+ border: 1px solid #F0F0EE;
34
+ cursor: default;
35
+ }
36
+
37
+ .editor-buttons a.disabled img {
38
+ opacity: .35;
39
+ filter: alpha(opacity=35);
40
+ -ms-filter: "alpha(opacity=35)";
41
+ }
42
+
43
+ .search-window {
44
+ background-color: #F0F0EE;
45
+ border: 1px solid #ABC6DD;
46
+ padding: 10px;
47
+ position: absolute;
48
+ right: -1px;
49
+ top: -1px;
50
+ z-index: 1000;
51
+ }
52
+
53
+ .htmlSource {
54
+ display: block;
55
+ width: 100%;
56
+ height: 100%;
57
+ font-family: 'Courier New', Courier, monospace;
58
+ font-size: 12px;
59
+ }
js/tiny_mce/plugins/codemagic/editor_plugin.js ADDED
@@ -0,0 +1 @@
 
1
+ (function(){tinymce.PluginManager.requireLangPack('codemagic');tinymce.create('tinymce.plugins.CodeMagic',{init:function(ed,url){ed.addCommand('mceCodeMagic',function(){ed.windowManager.open({file:url+'/codemagic.htm',width:900,height:600,inline:1,maximizable:true},{plugin_url:url})});ed.addButton('codemagic',{title:'codemagic.editor_button',cmd:'mceCodeMagic',image:url+'/img/code.png'});ed.onNodeChange.add(function(ed,cm,n,co){cm.setDisabled('link',co&&n.nodeName!='A');cm.setActive('link',n.nodeName=='A'&&!n.name)})},getInfo:function(){return{longname:'CodeMagic - syntax coloring and intendation',author:'Sutulustus',authorurl:'http://www.triad.sk/#/en',version:'0.9.5'}}});tinymce.PluginManager.add('codemagic',tinymce.plugins.CodeMagic)})();
js/tiny_mce/plugins/codemagic/editor_plugin_src.js ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * editor_plugin_src.js
3
+ *
4
+ * Copyright 2011, Sutulustus - Triad Advertising
5
+ * Released under MIT License.
6
+ *
7
+ * License: http://www.opensource.org/licenses/mit-license.php
8
+ */
9
+
10
+ (function () {
11
+ tinymce.PluginManager.requireLangPack('codemagic');
12
+ tinymce.create('tinymce.plugins.CodeMagic', {
13
+
14
+ init: function (ed, url) {
15
+
16
+ // Register commands
17
+ ed.addCommand('mceCodeMagic', function() {
18
+ ed.windowManager.open({
19
+ file : url + '/codemagic.htm',
20
+ width : 900,
21
+ height : 600,
22
+ inline : 1,
23
+ maximizable: true
24
+ }, {
25
+ plugin_url : url
26
+ });
27
+ });
28
+
29
+ // Register buttons
30
+ ed.addButton('codemagic', {
31
+ title: 'codemagic.editor_button',
32
+ cmd: 'mceCodeMagic',
33
+ image: url + '/img/code.png'
34
+ });
35
+
36
+ ed.onNodeChange.add(function(ed, cm, n, co) {
37
+ cm.setDisabled('link', co && n.nodeName != 'A');
38
+ cm.setActive('link', n.nodeName == 'A' && !n.name);
39
+ });
40
+ },
41
+
42
+ getInfo: function () {
43
+ return {
44
+ longname: 'CodeMagic - syntax coloring and intendation',
45
+ author: 'Sutulustus',
46
+ authorurl: 'http://www.triad.sk/#/en',
47
+ version: '0.9.5'
48
+ };
49
+ }
50
+ });
51
+
52
+ // Register plugin
53
+ tinymce.PluginManager.add('codemagic', tinymce.plugins.CodeMagic);
54
+ })();
js/tiny_mce/plugins/codemagic/img/code.png ADDED
Binary file
js/tiny_mce/plugins/codemagic/img/icons/file.png ADDED
Binary file
js/tiny_mce/plugins/codemagic/img/icons/lens.png ADDED
Binary file
js/tiny_mce/plugins/codemagic/img/icons/redo.png ADDED
Binary file
js/tiny_mce/plugins/codemagic/img/icons/undo.png ADDED
Binary file
js/tiny_mce/plugins/codemagic/js/beautify-html.js ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+
3
+ Style HTML
4
+ ---------------
5
+
6
+ Written by Nochum Sossonko, (nsossonko@hotmail.com)
7
+
8
+ Based on code initially developed by: Einar Lielmanis, <elfz@laacz.lv>
9
+ http://jsbeautifier.org
10
+
11
+
12
+ You are free to use this in any way you want, in case you find this useful or working for you.
13
+
14
+ Usage:
15
+ style_html(html_source);
16
+
17
+ */
18
+
19
+ function style_html(html_source, indent_size, indent_character, max_char, brace_style) {
20
+ //Wrapper function to invoke all the necessary constructors and deal with the output.
21
+
22
+ var Parser, multi_parser;
23
+
24
+ function Parser() {
25
+
26
+ this.pos = 0; //Parser position
27
+ this.token = '';
28
+ this.current_mode = 'CONTENT'; //reflects the current Parser mode: TAG/CONTENT
29
+ this.tags = { //An object to hold tags, their position, and their parent-tags, initiated with default values
30
+ parent: 'parent1',
31
+ parentcount: 1,
32
+ parent1: ''
33
+ };
34
+ this.tag_type = '';
35
+ this.token_text = this.last_token = this.last_text = this.token_type = '';
36
+
37
+
38
+ this.Utils = { //Uilities made available to the various functions
39
+ whitespace: "\n\r\t ".split(''),
40
+ single_token: 'br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed'.split(','), //all the single tags for HTML
41
+ extra_liners: 'head,body,/html'.split(','), //for tags that need a line of whitespace before them
42
+ in_array: function (what, arr) {
43
+ for (var i=0; i<arr.length; i++) {
44
+ if (what === arr[i]) {
45
+ return true;
46
+ }
47
+ }
48
+ return false;
49
+ }
50
+ }
51
+
52
+ this.get_content = function () { //function to capture regular content between tags
53
+
54
+ var input_char = '';
55
+ var content = [];
56
+ var space = false; //if a space is needed
57
+ while (this.input.charAt(this.pos) !== '<') {
58
+ if (this.pos >= this.input.length) {
59
+ return content.length?content.join(''):['', 'TK_EOF'];
60
+ }
61
+
62
+ input_char = this.input.charAt(this.pos);
63
+ this.pos++;
64
+ this.line_char_count++;
65
+
66
+
67
+ if (this.Utils.in_array(input_char, this.Utils.whitespace)) {
68
+ if (content.length) {
69
+ space = true;
70
+ }
71
+ this.line_char_count--;
72
+ continue; //don't want to insert unnecessary space
73
+ }
74
+ else if (space) {
75
+ if (this.line_char_count >= this.max_char) { //insert a line when the max_char is reached
76
+ content.push('\n');
77
+ for (var i=0; i<this.indent_level; i++) {
78
+ content.push(this.indent_string);
79
+ }
80
+ this.line_char_count = 0;
81
+ }
82
+ else{
83
+ content.push(' ');
84
+ this.line_char_count++;
85
+ }
86
+ space = false;
87
+ }
88
+ content.push(input_char); //letter at-a-time (or string) inserted to an array
89
+ }
90
+ return content.length?content.join(''):'';
91
+ }
92
+
93
+ this.get_script = function () { //get the full content of a script to pass to js_beautify
94
+
95
+ var input_char = '';
96
+ var content = [];
97
+ var reg_match = new RegExp('\<\/script' + '\>', 'igm');
98
+ reg_match.lastIndex = this.pos;
99
+ var reg_array = reg_match.exec(this.input);
100
+ var end_script = reg_array?reg_array.index:this.input.length; //absolute end of script
101
+ while(this.pos < end_script) { //get everything in between the script tags
102
+ if (this.pos >= this.input.length) {
103
+ return content.length?content.join(''):['', 'TK_EOF'];
104
+ }
105
+
106
+ input_char = this.input.charAt(this.pos);
107
+ this.pos++;
108
+
109
+
110
+ content.push(input_char);
111
+ }
112
+ return content.length?content.join(''):''; //we might not have any content at all
113
+ }
114
+
115
+ this.record_tag = function (tag){ //function to record a tag and its parent in this.tags Object
116
+ if (this.tags[tag + 'count']) { //check for the existence of this tag type
117
+ this.tags[tag + 'count']++;
118
+ this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
119
+ }
120
+ else { //otherwise initialize this tag type
121
+ this.tags[tag + 'count'] = 1;
122
+ this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
123
+ }
124
+ this.tags[tag + this.tags[tag + 'count'] + 'parent'] = this.tags.parent; //set the parent (i.e. in the case of a div this.tags.div1parent)
125
+ this.tags.parent = tag + this.tags[tag + 'count']; //and make this the current parent (i.e. in the case of a div 'div1')
126
+ }
127
+
128
+ this.retrieve_tag = function (tag) { //function to retrieve the opening tag to the corresponding closer
129
+ if (this.tags[tag + 'count']) { //if the openener is not in the Object we ignore it
130
+ var temp_parent = this.tags.parent; //check to see if it's a closable tag.
131
+ while (temp_parent) { //till we reach '' (the initial value);
132
+ if (tag + this.tags[tag + 'count'] === temp_parent) { //if this is it use it
133
+ break;
134
+ }
135
+ temp_parent = this.tags[temp_parent + 'parent']; //otherwise keep on climbing up the DOM Tree
136
+ }
137
+ if (temp_parent) { //if we caught something
138
+ this.indent_level = this.tags[tag + this.tags[tag + 'count']]; //set the indent_level accordingly
139
+ this.tags.parent = this.tags[temp_parent + 'parent']; //and set the current parent
140
+ }
141
+ delete this.tags[tag + this.tags[tag + 'count'] + 'parent']; //delete the closed tags parent reference...
142
+ delete this.tags[tag + this.tags[tag + 'count']]; //...and the tag itself
143
+ if (this.tags[tag + 'count'] == 1) {
144
+ delete this.tags[tag + 'count'];
145
+ }
146
+ else {
147
+ this.tags[tag + 'count']--;
148
+ }
149
+ }
150
+ }
151
+
152
+ this.get_tag = function () { //function to get a full tag and parse its type
153
+ var input_char = '';
154
+ var content = [];
155
+ var space = false;
156
+
157
+ do {
158
+ if (this.pos >= this.input.length) {
159
+ return content.length?content.join(''):['', 'TK_EOF'];
160
+ }
161
+
162
+ input_char = this.input.charAt(this.pos);
163
+ this.pos++;
164
+ this.line_char_count++;
165
+
166
+ if (this.Utils.in_array(input_char, this.Utils.whitespace)) { //don't want to insert unnecessary space
167
+ space = true;
168
+ this.line_char_count--;
169
+ continue;
170
+ }
171
+
172
+ if (input_char === "'" || input_char === '"') {
173
+ if (!content[1] || content[1] !== '!') { //if we're in a comment strings don't get treated specially
174
+ input_char += this.get_unformatted(input_char);
175
+ space = true;
176
+ }
177
+ }
178
+
179
+ if (input_char === '=') { //no space before =
180
+ space = false;
181
+ }
182
+
183
+ if (content.length && content[content.length-1] !== '=' && input_char !== '>'
184
+ && space) { //no space after = or before >
185
+ if (this.line_char_count >= this.max_char) {
186
+ this.print_newline(false, content);
187
+ this.line_char_count = 0;
188
+ }
189
+ else {
190
+ content.push(' ');
191
+ this.line_char_count++;
192
+ }
193
+ space = false;
194
+ }
195
+ content.push(input_char); //inserts character at-a-time (or string)
196
+ } while (input_char !== '>');
197
+
198
+ var tag_complete = content.join('');
199
+ var tag_index;
200
+ if (tag_complete.indexOf(' ') != -1) { //if there's whitespace, thats where the tag name ends
201
+ tag_index = tag_complete.indexOf(' ');
202
+ }
203
+ else { //otherwise go with the tag ending
204
+ tag_index = tag_complete.indexOf('>');
205
+ }
206
+ var tag_check = tag_complete.substring(1, tag_index).toLowerCase();
207
+ if (tag_complete.charAt(tag_complete.length-2) === '/' ||
208
+ this.Utils.in_array(tag_check, this.Utils.single_token)) { //if this tag name is a single tag type (either in the list or has a closing /)
209
+ this.tag_type = 'SINGLE';
210
+ }
211
+ else if (tag_check === 'script') { //for later script handling
212
+ this.record_tag(tag_check);
213
+ this.tag_type = 'SCRIPT';
214
+ }
215
+ else if (tag_check === 'style') { //for future style handling (for now it justs uses get_content)
216
+ this.record_tag(tag_check);
217
+ this.tag_type = 'STYLE';
218
+ }
219
+ /*else if (tag_check === 'a') { // do not reformat the <a> links
220
+ var comment = this.get_unformatted('</a>', tag_complete); //...delegate to get_unformatted function
221
+ content.push(comment);
222
+ this.tag_type = 'SINGLE';
223
+ }*/
224
+ else if (tag_check.charAt(0) === '!') { //peek for <!-- comment
225
+ if (tag_check.indexOf('[if') != -1) { //peek for <!--[if conditional comment
226
+ if (tag_complete.indexOf('!IE') != -1) { //this type needs a closing --> so...
227
+ var comment = this.get_unformatted('-->', tag_complete); //...delegate to get_unformatted
228
+ content.push(comment);
229
+ }
230
+ this.tag_type = 'START';
231
+ }
232
+ else if (tag_check.indexOf('[endif') != -1) {//peek for <!--[endif end conditional comment
233
+ this.tag_type = 'END';
234
+ this.unindent();
235
+ }
236
+ else if (tag_check.indexOf('[cdata[') != -1) { //if it's a <[cdata[ comment...
237
+ var comment = this.get_unformatted(']]>', tag_complete); //...delegate to get_unformatted function
238
+ content.push(comment);
239
+ this.tag_type = 'SINGLE'; //<![CDATA[ comments are treated like single tags
240
+ }
241
+ else {
242
+ var comment = this.get_unformatted('-->', tag_complete);
243
+ content.push(comment);
244
+ this.tag_type = 'SINGLE';
245
+ }
246
+ }
247
+ else {
248
+ if (tag_check.charAt(0) === '/') { //this tag is a double tag so check for tag-ending
249
+ this.retrieve_tag(tag_check.substring(1)); //remove it and all ancestors
250
+ this.tag_type = 'END';
251
+ }
252
+ else { //otherwise it's a start-tag
253
+ this.record_tag(tag_check); //push it on the tag stack
254
+ this.tag_type = 'START';
255
+ }
256
+ if (this.Utils.in_array(tag_check, this.Utils.extra_liners)) { //check if this double needs an extra line
257
+ this.print_newline(true, this.output);
258
+ }
259
+ }
260
+ return content.join(''); //returns fully formatted tag
261
+ }
262
+
263
+ this.get_unformatted = function (delimiter, orig_tag) { //function to return unformatted content in its entirety
264
+
265
+ if (orig_tag && orig_tag.indexOf(delimiter) != -1) {
266
+ return '';
267
+ }
268
+ var input_char = '';
269
+ var content = '';
270
+ var space = true;
271
+ do {
272
+
273
+ if (this.pos >= this.input.length) {
274
+ return content;
275
+ }
276
+
277
+ input_char = this.input.charAt(this.pos);
278
+ this.pos++
279
+
280
+ if (this.Utils.in_array(input_char, this.Utils.whitespace)) {
281
+ if (!space) {
282
+ this.line_char_count--;
283
+ continue;
284
+ }
285
+ if (input_char === '\n' || input_char === '\r') {
286
+ content += '\n';
287
+ for (var i=0; i<this.indent_level; i++) {
288
+ content += this.indent_string;
289
+ }
290
+ space = false; //...and make sure other indentation is erased
291
+ this.line_char_count = 0;
292
+ continue;
293
+ }
294
+ }
295
+ content += input_char;
296
+ this.line_char_count++;
297
+ space = true;
298
+
299
+
300
+ } while (content.indexOf(delimiter) == -1);
301
+ return content;
302
+ }
303
+
304
+ this.get_token = function () { //initial handler for token-retrieval
305
+ var token;
306
+
307
+ if (this.last_token === 'TK_TAG_SCRIPT') { //check if we need to format javascript
308
+ var temp_token = this.get_script();
309
+ if (typeof temp_token !== 'string') {
310
+ return temp_token;
311
+ }
312
+ token = js_beautify(temp_token,
313
+ {indent_size: this.indent_size, indent_char: this.indent_character, indent_level: this.indent_level, brace_style: this.brace_style}); //call the JS Beautifier
314
+ return [token, 'TK_CONTENT'];
315
+ }
316
+ if (this.current_mode === 'CONTENT') {
317
+ token = this.get_content();
318
+ if (typeof token !== 'string') {
319
+ return token;
320
+ }
321
+ else {
322
+ return [token, 'TK_CONTENT'];
323
+ }
324
+ }
325
+
326
+ if(this.current_mode === 'TAG') {
327
+ token = this.get_tag();
328
+ if (typeof token !== 'string') {
329
+ return token;
330
+ }
331
+ else {
332
+ var tag_name_type = 'TK_TAG_' + this.tag_type;
333
+ return [token, tag_name_type];
334
+ }
335
+ }
336
+ }
337
+
338
+ this.printer = function (js_source, indent_character, indent_size, max_char, brace_style) { //handles input/output and some other printing functions
339
+
340
+ this.input = js_source || ''; //gets the input for the Parser
341
+ this.output = [];
342
+ this.indent_character = indent_character || ' ';
343
+ this.indent_string = '';
344
+ this.indent_size = indent_size || 2;
345
+ this.brace_style = brace_style || 'collapse';
346
+ this.indent_level = 0;
347
+ this.max_char = max_char || 70; //maximum amount of characters per line
348
+ this.line_char_count = 0; //count to see if max_char was exceeded
349
+
350
+ for (var i=0; i<this.indent_size; i++) {
351
+ this.indent_string += this.indent_character;
352
+ }
353
+
354
+ this.print_newline = function (ignore, arr) {
355
+ this.line_char_count = 0;
356
+ if (!arr || !arr.length) {
357
+ return;
358
+ }
359
+ if (!ignore) { //we might want the extra line
360
+ while (this.Utils.in_array(arr[arr.length-1], this.Utils.whitespace)) {
361
+ arr.pop();
362
+ }
363
+ }
364
+ arr.push('\n');
365
+ for (var i=0; i<this.indent_level; i++) {
366
+ arr.push(this.indent_string);
367
+ }
368
+ }
369
+
370
+
371
+ this.print_token = function (text) {
372
+ this.output.push(text);
373
+ }
374
+
375
+ this.indent = function () {
376
+ this.indent_level++;
377
+ }
378
+
379
+ this.unindent = function () {
380
+ if (this.indent_level > 0) {
381
+ this.indent_level--;
382
+ }
383
+ }
384
+ }
385
+ return this;
386
+ }
387
+
388
+ /*_____________________--------------------_____________________*/
389
+
390
+
391
+
392
+ multi_parser = new Parser(); //wrapping functions Parser
393
+ multi_parser.printer(html_source, indent_character, indent_size, max_char, brace_style); //initialize starting values
394
+
395
+
396
+
397
+ while (true) {
398
+ var t = multi_parser.get_token();
399
+ multi_parser.token_text = t[0];
400
+ multi_parser.token_type = t[1];
401
+
402
+ if (multi_parser.token_type === 'TK_EOF') {
403
+ break;
404
+ }
405
+
406
+
407
+ switch (multi_parser.token_type) {
408
+ case 'TK_TAG_START': case 'TK_TAG_SCRIPT': case 'TK_TAG_STYLE':
409
+ multi_parser.print_newline(false, multi_parser.output);
410
+ multi_parser.print_token(multi_parser.token_text);
411
+ multi_parser.indent();
412
+ multi_parser.current_mode = 'CONTENT';
413
+ break;
414
+ case 'TK_TAG_END':
415
+ multi_parser.print_newline(true, multi_parser.output);
416
+ multi_parser.print_token(multi_parser.token_text);
417
+ multi_parser.current_mode = 'CONTENT';
418
+ break;
419
+ case 'TK_TAG_SINGLE':
420
+ multi_parser.print_newline(false, multi_parser.output);
421
+ multi_parser.print_token(multi_parser.token_text);
422
+ multi_parser.current_mode = 'CONTENT';
423
+ break;
424
+ case 'TK_CONTENT':
425
+ if (multi_parser.token_text !== '') {
426
+ multi_parser.print_newline(false, multi_parser.output);
427
+ multi_parser.print_token(multi_parser.token_text);
428
+ }
429
+ multi_parser.current_mode = 'TAG';
430
+ break;
431
+ }
432
+ multi_parser.last_token = multi_parser.token_type;
433
+ multi_parser.last_text = multi_parser.token_text;
434
+ }
435
+ return multi_parser.output.join('');
436
+ }
js/tiny_mce/plugins/codemagic/js/beautify.js ADDED
@@ -0,0 +1,1147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*jslint onevar: false, plusplus: false */
2
+ /*
3
+
4
+ JS Beautifier
5
+ ---------------
6
+
7
+
8
+ Written by Einar Lielmanis, <einar@jsbeautifier.org>
9
+ http://jsbeautifier.org/
10
+
11
+ Originally converted to javascript by Vital, <vital76@gmail.com>
12
+ "End braces on own line" added by Chris J. Shull, <chrisjshull@gmail.com>
13
+
14
+ You are free to use this in any way you want, in case you find this useful or working for you.
15
+
16
+ Usage:
17
+ js_beautify(js_source_text);
18
+ js_beautify(js_source_text, options);
19
+
20
+ The options are:
21
+ indent_size (default 4) — indentation size,
22
+ indent_char (default space) — character to indent with,
23
+ preserve_newlines (default true) — whether existing line breaks should be preserved,
24
+ preserve_max_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
25
+ indent_level (default 0) — initial indentation level, you probably won't need this ever,
26
+
27
+ jslint_happy (default false) — if true, then jslint-stricter mode is enforced.
28
+
29
+ jslint_happy !jslint_happy
30
+ ---------------------------------
31
+ function () function()
32
+
33
+ brace_style (default "collapse") - "collapse" | "expand" | "end-expand"
34
+ put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line.
35
+
36
+ e.g
37
+
38
+ js_beautify(js_source_text, {indent_size: 1, indent_char: '\t'});
39
+
40
+
41
+ */
42
+
43
+
44
+
45
+ function js_beautify(js_source_text, options) {
46
+
47
+ var input, output, token_text, last_type, last_text, last_last_text, last_word, flags, flag_store, indent_string;
48
+ var whitespace, wordchar, punct, parser_pos, line_starters, digits;
49
+ var prefix, token_type, do_block_just_closed;
50
+ var wanted_newline, just_added_newline, n_newlines;
51
+
52
+
53
+ // Some interpreters have unexpected results with foo = baz || bar;
54
+ options = options ? options : {};
55
+
56
+ var opt_brace_style;
57
+
58
+ // compatibility
59
+ if (options.space_after_anon_function !== undefined && options.jslint_happy === undefined) {
60
+ options.jslint_happy = options.space_after_anon_function;
61
+ }
62
+ if (options.braces_on_own_line !== undefined) { //graceful handling of depricated option
63
+ opt_brace_style = options.braces_on_own_line ? "expand" : "collapse";
64
+ }
65
+ opt_brace_style = options.brace_style ? options.brace_style : (opt_brace_style ? opt_brace_style : "collapse");
66
+
67
+
68
+ var opt_indent_size = options.indent_size ? options.indent_size : 4;
69
+ var opt_indent_char = options.indent_char ? options.indent_char : ' ';
70
+ var opt_preserve_newlines = typeof options.preserve_newlines === 'undefined' ? true : options.preserve_newlines;
71
+ var opt_max_preserve_newlines = typeof options.max_preserve_newlines === 'undefined' ? false : options.max_preserve_newlines;
72
+ var opt_indent_level = options.indent_level ? options.indent_level : 0; // starting indentation
73
+ var opt_jslint_happy = options.jslint_happy === 'undefined' ? false : options.jslint_happy;
74
+ var opt_keep_array_indentation = typeof options.keep_array_indentation === 'undefined' ? false : options.keep_array_indentation;
75
+
76
+ just_added_newline = false;
77
+
78
+ // cache the source's length.
79
+ var input_length = js_source_text.length;
80
+
81
+ function trim_output(eat_newlines) {
82
+ eat_newlines = typeof eat_newlines === 'undefined' ? false : eat_newlines;
83
+ while (output.length && (output[output.length - 1] === ' '
84
+ || output[output.length - 1] === indent_string
85
+ || (eat_newlines && (output[output.length - 1] === '\n' || output[output.length - 1] === '\r')))) {
86
+ output.pop();
87
+ }
88
+ }
89
+
90
+ function trim(s) {
91
+ return s.replace(/^\s\s*|\s\s*$/, '');
92
+ }
93
+
94
+ function print_newline(ignore_repeated) {
95
+
96
+ flags.eat_next_space = false;
97
+ if (opt_keep_array_indentation && is_array(flags.mode)) {
98
+ return;
99
+ }
100
+
101
+ ignore_repeated = typeof ignore_repeated === 'undefined' ? true : ignore_repeated;
102
+
103
+ flags.if_line = false;
104
+ trim_output();
105
+
106
+ if (!output.length) {
107
+ return; // no newline on start of file
108
+ }
109
+
110
+ if (output[output.length - 1] !== "\n" || !ignore_repeated) {
111
+ just_added_newline = true;
112
+ output.push("\n");
113
+ }
114
+ for (var i = 0; i < flags.indentation_level; i += 1) {
115
+ output.push(indent_string);
116
+ }
117
+ if (flags.var_line && flags.var_line_reindented) {
118
+ if (opt_indent_char === ' ') {
119
+ output.push(' '); // var_line always pushes 4 spaces, so that the variables would be one under another
120
+ } else {
121
+ output.push(indent_string); // skip space-stuffing, if indenting with a tab
122
+ }
123
+ }
124
+ }
125
+
126
+
127
+
128
+ function print_single_space() {
129
+ if (flags.eat_next_space) {
130
+ flags.eat_next_space = false;
131
+ return;
132
+ }
133
+ var last_output = ' ';
134
+ if (output.length) {
135
+ last_output = output[output.length - 1];
136
+ }
137
+ if (last_output !== ' ' && last_output !== '\n' && last_output !== indent_string) { // prevent occassional duplicate space
138
+ output.push(' ');
139
+ }
140
+ }
141
+
142
+
143
+ function print_token() {
144
+ just_added_newline = false;
145
+ flags.eat_next_space = false;
146
+ output.push(token_text);
147
+ }
148
+
149
+ function indent() {
150
+ flags.indentation_level += 1;
151
+ }
152
+
153
+
154
+ function remove_indent() {
155
+ if (output.length && output[output.length - 1] === indent_string) {
156
+ output.pop();
157
+ }
158
+ }
159
+
160
+ function set_mode(mode) {
161
+ if (flags) {
162
+ flag_store.push(flags);
163
+ }
164
+ flags = {
165
+ previous_mode: flags ? flags.mode : 'BLOCK',
166
+ mode: mode,
167
+ var_line: false,
168
+ var_line_tainted: false,
169
+ var_line_reindented: false,
170
+ in_html_comment: false,
171
+ if_line: false,
172
+ in_case: false,
173
+ eat_next_space: false,
174
+ indentation_baseline: -1,
175
+ indentation_level: (flags ? flags.indentation_level + ((flags.var_line && flags.var_line_reindented) ? 1 : 0) : opt_indent_level),
176
+ ternary_depth: 0
177
+ };
178
+ }
179
+
180
+ function is_array(mode) {
181
+ return mode === '[EXPRESSION]' || mode === '[INDENTED-EXPRESSION]';
182
+ }
183
+
184
+ function is_expression(mode) {
185
+ return mode === '[EXPRESSION]' || mode === '[INDENTED-EXPRESSION]' || mode === '(EXPRESSION)';
186
+ }
187
+
188
+ function restore_mode() {
189
+ do_block_just_closed = flags.mode === 'DO_BLOCK';
190
+ if (flag_store.length > 0) {
191
+ flags = flag_store.pop();
192
+ }
193
+ }
194
+
195
+
196
+ function in_array(what, arr) {
197
+ for (var i = 0; i < arr.length; i += 1) {
198
+ if (arr[i] === what) {
199
+ return true;
200
+ }
201
+ }
202
+ return false;
203
+ }
204
+
205
+ function get_next_token() {
206
+ n_newlines = 0;
207
+
208
+ if (parser_pos >= input_length) {
209
+ return ['', 'TK_EOF'];
210
+ }
211
+
212
+ wanted_newline = false;
213
+
214
+ var c = input.charAt(parser_pos);
215
+ parser_pos += 1;
216
+
217
+
218
+ var keep_whitespace = opt_keep_array_indentation && is_array(flags.mode);
219
+
220
+ if (keep_whitespace) {
221
+
222
+ //
223
+ // slight mess to allow nice preservation of array indentation and reindent that correctly
224
+ // first time when we get to the arrays:
225
+ // var a = [
226
+ // ....'something'
227
+ // we make note of whitespace_count = 4 into flags.indentation_baseline
228
+ // so we know that 4 whitespaces in original source match indent_level of reindented source
229
+ //
230
+ // and afterwards, when we get to
231
+ // 'something,
232
+ // .......'something else'
233
+ // we know that this should be indented to indent_level + (7 - indentation_baseline) spaces
234
+ //
235
+ var whitespace_count = 0;
236
+
237
+ while (in_array(c, whitespace)) {
238
+
239
+ if (c === "\n") {
240
+ trim_output();
241
+ output.push("\n");
242
+ just_added_newline = true;
243
+ whitespace_count = 0;
244
+ } else {
245
+ if (c === '\t') {
246
+ whitespace_count += 4;
247
+ } else if (c === '\r') {
248
+ // nothing
249
+ } else {
250
+ whitespace_count += 1;
251
+ }
252
+ }
253
+
254
+ if (parser_pos >= input_length) {
255
+ return ['', 'TK_EOF'];
256
+ }
257
+
258
+ c = input.charAt(parser_pos);
259
+ parser_pos += 1;
260
+
261
+ }
262
+ if (flags.indentation_baseline === -1) {
263
+ flags.indentation_baseline = whitespace_count;
264
+ }
265
+
266
+ if (just_added_newline) {
267
+ var i;
268
+ for (i = 0; i < flags.indentation_level + 1; i += 1) {
269
+ output.push(indent_string);
270
+ }
271
+ if (flags.indentation_baseline !== -1) {
272
+ for (i = 0; i < whitespace_count - flags.indentation_baseline; i++) {
273
+ output.push(' ');
274
+ }
275
+ }
276
+ }
277
+
278
+ } else {
279
+ while (in_array(c, whitespace)) {
280
+
281
+ if (c === "\n") {
282
+ n_newlines += ( (opt_max_preserve_newlines) ? (n_newlines <= opt_max_preserve_newlines) ? 1: 0: 1 );
283
+ }
284
+
285
+
286
+ if (parser_pos >= input_length) {
287
+ return ['', 'TK_EOF'];
288
+ }
289
+
290
+ c = input.charAt(parser_pos);
291
+ parser_pos += 1;
292
+
293
+ }
294
+
295
+ if (opt_preserve_newlines) {
296
+ if (n_newlines > 1) {
297
+ for (i = 0; i < n_newlines; i += 1) {
298
+ print_newline(i === 0);
299
+ just_added_newline = true;
300
+ }
301
+ }
302
+ }
303
+ wanted_newline = n_newlines > 0;
304
+ }
305
+
306
+
307
+ if (in_array(c, wordchar)) {
308
+ if (parser_pos < input_length) {
309
+ while (in_array(input.charAt(parser_pos), wordchar)) {
310
+ c += input.charAt(parser_pos);
311
+ parser_pos += 1;
312
+ if (parser_pos === input_length) {
313
+ break;
314
+ }
315
+ }
316
+ }
317
+
318
+ // small and surprisingly unugly hack for 1E-10 representation
319
+ if (parser_pos !== input_length && c.match(/^[0-9]+[Ee]$/) && (input.charAt(parser_pos) === '-' || input.charAt(parser_pos) === '+')) {
320
+
321
+ var sign = input.charAt(parser_pos);
322
+ parser_pos += 1;
323
+
324
+ var t = get_next_token(parser_pos);
325
+ c += sign + t[0];
326
+ return [c, 'TK_WORD'];
327
+ }
328
+
329
+ if (c === 'in') { // hack for 'in' operator
330
+ return [c, 'TK_OPERATOR'];
331
+ }
332
+ if (wanted_newline && last_type !== 'TK_OPERATOR'
333
+ && last_type !== 'TK_EQUALS'
334
+ && !flags.if_line && (opt_preserve_newlines || last_text !== 'var')) {
335
+ print_newline();
336
+ }
337
+ return [c, 'TK_WORD'];
338
+ }
339
+
340
+ if (c === '(' || c === '[') {
341
+ return [c, 'TK_START_EXPR'];
342
+ }
343
+
344
+ if (c === ')' || c === ']') {
345
+ return [c, 'TK_END_EXPR'];
346
+ }
347
+
348
+ if (c === '{') {
349
+ return [c, 'TK_START_BLOCK'];
350
+ }
351
+
352
+ if (c === '}') {
353
+ return [c, 'TK_END_BLOCK'];
354
+ }
355
+
356
+ if (c === ';') {
357
+ return [c, 'TK_SEMICOLON'];
358
+ }
359
+
360
+ if (c === '/') {
361
+ var comment = '';
362
+ // peek for comment /* ... */
363
+ var inline_comment = true;
364
+ if (input.charAt(parser_pos) === '*') {
365
+ parser_pos += 1;
366
+ if (parser_pos < input_length) {
367
+ while (! (input.charAt(parser_pos) === '*' && input.charAt(parser_pos + 1) && input.charAt(parser_pos + 1) === '/') && parser_pos < input_length) {
368
+ c = input.charAt(parser_pos);
369
+ comment += c;
370
+ if (c === '\x0d' || c === '\x0a') {
371
+ inline_comment = false;
372
+ }
373
+ parser_pos += 1;
374
+ if (parser_pos >= input_length) {
375
+ break;
376
+ }
377
+ }
378
+ }
379
+ parser_pos += 2;
380
+ if (inline_comment) {
381
+ return ['/*' + comment + '*/', 'TK_INLINE_COMMENT'];
382
+ } else {
383
+ return ['/*' + comment + '*/', 'TK_BLOCK_COMMENT'];
384
+ }
385
+ }
386
+ // peek for comment // ...
387
+ if (input.charAt(parser_pos) === '/') {
388
+ comment = c;
389
+ while (input.charAt(parser_pos) !== '\r' && input.charAt(parser_pos) !== '\n') {
390
+ comment += input.charAt(parser_pos);
391
+ parser_pos += 1;
392
+ if (parser_pos >= input_length) {
393
+ break;
394
+ }
395
+ }
396
+ parser_pos += 1;
397
+ if (wanted_newline) {
398
+ print_newline();
399
+ }
400
+ return [comment, 'TK_COMMENT'];
401
+ }
402
+
403
+ }
404
+
405
+ if (c === "'" || // string
406
+ c === '"' || // string
407
+ (c === '/' &&
408
+ ((last_type === 'TK_WORD' && in_array(last_text, ['return', 'do'])) ||
409
+ (last_type === 'TK_COMMENT' || last_type === 'TK_START_EXPR' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EQUALS' || last_type === 'TK_EOF' || last_type === 'TK_SEMICOLON')))) { // regexp
410
+ var sep = c;
411
+ var esc = false;
412
+ var resulting_string = c;
413
+
414
+ if (parser_pos < input_length) {
415
+ if (sep === '/') {
416
+ //
417
+ // handle regexp separately...
418
+ //
419
+ var in_char_class = false;
420
+ while (esc || in_char_class || input.charAt(parser_pos) !== sep) {
421
+ resulting_string += input.charAt(parser_pos);
422
+ if (!esc) {
423
+ esc = input.charAt(parser_pos) === '\\';
424
+ if (input.charAt(parser_pos) === '[') {
425
+ in_char_class = true;
426
+ } else if (input.charAt(parser_pos) === ']') {
427
+ in_char_class = false;
428
+ }
429
+ } else {
430
+ esc = false;
431
+ }
432
+ parser_pos += 1;
433
+ if (parser_pos >= input_length) {
434
+ // incomplete string/rexp when end-of-file reached.
435
+ // bail out with what had been received so far.
436
+ return [resulting_string, 'TK_STRING'];
437
+ }
438
+ }
439
+
440
+ } else {
441
+ //
442
+ // and handle string also separately
443
+ //
444
+ while (esc || input.charAt(parser_pos) !== sep) {
445
+ resulting_string += input.charAt(parser_pos);
446
+ if (!esc) {
447
+ esc = input.charAt(parser_pos) === '\\';
448
+ } else {
449
+ esc = false;
450
+ }
451
+ parser_pos += 1;
452
+ if (parser_pos >= input_length) {
453
+ // incomplete string/rexp when end-of-file reached.
454
+ // bail out with what had been received so far.
455
+ return [resulting_string, 'TK_STRING'];
456
+ }
457
+ }
458
+ }
459
+
460
+
461
+
462
+ }
463
+
464
+ parser_pos += 1;
465
+
466
+ resulting_string += sep;
467
+
468
+ if (sep === '/') {
469
+ // regexps may have modifiers /regexp/MOD , so fetch those, too
470
+ while (parser_pos < input_length && in_array(input.charAt(parser_pos), wordchar)) {
471
+ resulting_string += input.charAt(parser_pos);
472
+ parser_pos += 1;
473
+ }
474
+ }
475
+ return [resulting_string, 'TK_STRING'];
476
+ }
477
+
478
+ if (c === '#') {
479
+
480
+
481
+ if (output.length === 0 && input.charAt(parser_pos) === '!') {
482
+ // shebang
483
+ resulting_string = c;
484
+ while (parser_pos < input_length && c != '\n') {
485
+ c = input.charAt(parser_pos);
486
+ resulting_string += c;
487
+ parser_pos += 1;
488
+ }
489
+ output.push(trim(resulting_string) + '\n');
490
+ print_newline();
491
+ return get_next_token();
492
+ }
493
+
494
+
495
+
496
+ // Spidermonkey-specific sharp variables for circular references
497
+ // https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
498
+ // http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
499
+ var sharp = '#';
500
+ if (parser_pos < input_length && in_array(input.charAt(parser_pos), digits)) {
501
+ do {
502
+ c = input.charAt(parser_pos);
503
+ sharp += c;
504
+ parser_pos += 1;
505
+ } while (parser_pos < input_length && c !== '#' && c !== '=');
506
+ if (c === '#') {
507
+ //
508
+ } else if (input.charAt(parser_pos) === '[' && input.charAt(parser_pos + 1) === ']') {
509
+ sharp += '[]';
510
+ parser_pos += 2;
511
+ } else if (input.charAt(parser_pos) === '{' && input.charAt(parser_pos + 1) === '}') {
512
+ sharp += '{}';
513
+ parser_pos += 2;
514
+ }
515
+ return [sharp, 'TK_WORD'];
516
+ }
517
+ }
518
+
519
+ if (c === '<' && input.substring(parser_pos - 1, parser_pos + 3) === '<!--') {
520
+ parser_pos += 3;
521
+ flags.in_html_comment = true;
522
+ return ['<!--', 'TK_COMMENT'];
523
+ }
524
+
525
+ if (c === '-' && flags.in_html_comment && input.substring(parser_pos - 1, parser_pos + 2) === '-->') {
526
+ flags.in_html_comment = false;
527
+ parser_pos += 2;
528
+ if (wanted_newline) {
529
+ print_newline();
530
+ }
531
+ return ['-->', 'TK_COMMENT'];
532
+ }
533
+
534
+ if (in_array(c, punct)) {
535
+ while (parser_pos < input_length && in_array(c + input.charAt(parser_pos), punct)) {
536
+ c += input.charAt(parser_pos);
537
+ parser_pos += 1;
538
+ if (parser_pos >= input_length) {
539
+ break;
540
+ }
541
+ }
542
+
543
+ if (c === '=') {
544
+ return [c, 'TK_EQUALS'];
545
+ } else {
546
+ return [c, 'TK_OPERATOR'];
547
+ }
548
+ }
549
+
550
+ return [c, 'TK_UNKNOWN'];
551
+ }
552
+
553
+ //----------------------------------
554
+ indent_string = '';
555
+ while (opt_indent_size > 0) {
556
+ indent_string += opt_indent_char;
557
+ opt_indent_size -= 1;
558
+ }
559
+
560
+ input = js_source_text;
561
+
562
+ last_word = ''; // last 'TK_WORD' passed
563
+ last_type = 'TK_START_EXPR'; // last token type
564
+ last_text = ''; // last token text
565
+ last_last_text = ''; // pre-last token text
566
+ output = [];
567
+
568
+ do_block_just_closed = false;
569
+
570
+ whitespace = "\n\r\t ".split('');
571
+ wordchar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split('');
572
+ digits = '0123456789'.split('');
573
+
574
+ punct = '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::'.split(' ');
575
+
576
+ // words which should always start on new line.
577
+ line_starters = 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function'.split(',');
578
+
579
+ // states showing if we are currently in expression (i.e. "if" case) - 'EXPRESSION', or in usual block (like, procedure), 'BLOCK'.
580
+ // some formatting depends on that.
581
+ flag_store = [];
582
+ set_mode('BLOCK');
583
+
584
+ parser_pos = 0;
585
+ while (true) {
586
+ var t = get_next_token(parser_pos);
587
+ token_text = t[0];
588
+ token_type = t[1];
589
+ if (token_type === 'TK_EOF') {
590
+ break;
591
+ }
592
+
593
+ switch (token_type) {
594
+
595
+ case 'TK_START_EXPR':
596
+
597
+ if (token_text === '[') {
598
+
599
+ if (last_type === 'TK_WORD' || last_text === ')') {
600
+ // this is array index specifier, break immediately
601
+ // a[x], fn()[x]
602
+ if (in_array(last_text, line_starters)) {
603
+ print_single_space();
604
+ }
605
+ set_mode('(EXPRESSION)');
606
+ print_token();
607
+ break;
608
+ }
609
+
610
+ if (flags.mode === '[EXPRESSION]' || flags.mode === '[INDENTED-EXPRESSION]') {
611
+ if (last_last_text === ']' && last_text === ',') {
612
+ // ], [ goes to new line
613
+ if (flags.mode === '[EXPRESSION]') {
614
+ flags.mode = '[INDENTED-EXPRESSION]';
615
+ if (!opt_keep_array_indentation) {
616
+ indent();
617
+ }
618
+ }
619
+ set_mode('[EXPRESSION]');
620
+ if (!opt_keep_array_indentation) {
621
+ print_newline();
622
+ }
623
+ } else if (last_text === '[') {
624
+ if (flags.mode === '[EXPRESSION]') {
625
+ flags.mode = '[INDENTED-EXPRESSION]';
626
+ if (!opt_keep_array_indentation) {
627
+ indent();
628
+ }
629
+ }
630
+ set_mode('[EXPRESSION]');
631
+
632
+ if (!opt_keep_array_indentation) {
633
+ print_newline();
634
+ }
635
+ } else {
636
+ set_mode('[EXPRESSION]');
637
+ }
638
+ } else {
639
+ set_mode('[EXPRESSION]');
640
+ }
641
+
642
+
643
+
644
+ } else {
645
+ set_mode('(EXPRESSION)');
646
+ }
647
+
648
+ if (last_text === ';' || last_type === 'TK_START_BLOCK') {
649
+ print_newline();
650
+ } else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || last_text === '.') {
651
+ // do nothing on (( and )( and ][ and ]( and .(
652
+ } else if (last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
653
+ print_single_space();
654
+ } else if (last_word === 'function' || last_word === 'typeof') {
655
+ // function() vs function ()
656
+ if (opt_jslint_happy) {
657
+ print_single_space();
658
+ }
659
+ } else if (in_array(last_text, line_starters) || last_text === 'catch') {
660
+ print_single_space();
661
+ }
662
+ print_token();
663
+
664
+ break;
665
+
666
+ case 'TK_END_EXPR':
667
+ if (token_text === ']') {
668
+ if (opt_keep_array_indentation) {
669
+ if (last_text === '}') {
670
+ // trim_output();
671
+ // print_newline(true);
672
+ remove_indent();
673
+ print_token();
674
+ restore_mode();
675
+ break;
676
+ }
677
+ } else {
678
+ if (flags.mode === '[INDENTED-EXPRESSION]') {
679
+ if (last_text === ']') {
680
+ restore_mode();
681
+ print_newline();
682
+ print_token();
683
+ break;
684
+ }
685
+ }
686
+ }
687
+ }
688
+ restore_mode();
689
+ print_token();
690
+ break;
691
+
692
+ case 'TK_START_BLOCK':
693
+
694
+ if (last_word === 'do') {
695
+ set_mode('DO_BLOCK');
696
+ } else {
697
+ set_mode('BLOCK');
698
+ }
699
+ if (opt_brace_style=="expand") {
700
+ if (last_type !== 'TK_OPERATOR') {
701
+ if (last_text === 'return' || last_text === '=') {
702
+ print_single_space();
703
+ } else {
704
+ print_newline(true);
705
+ }
706
+ }
707
+ print_token();
708
+ indent();
709
+ } else {
710
+ if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
711
+ if (last_type === 'TK_START_BLOCK') {
712
+ print_newline();
713
+ } else {
714
+ print_single_space();
715
+ }
716
+ } else {
717
+ // if TK_OPERATOR or TK_START_EXPR
718
+ if (is_array(flags.previous_mode) && last_text === ',') {
719
+ if (last_last_text === '}') {
720
+ // }, { in array context
721
+ print_single_space();
722
+ } else {
723
+ print_newline(); // [a, b, c, {
724
+ }
725
+ }
726
+ }
727
+ indent();
728
+ print_token();
729
+ }
730
+
731
+ break;
732
+
733
+ case 'TK_END_BLOCK':
734
+ restore_mode();
735
+ if (opt_brace_style=="expand") {
736
+ if (last_text !== '{') {
737
+ print_newline();
738
+ }
739
+ print_token();
740
+ } else {
741
+ if (last_type === 'TK_START_BLOCK') {
742
+ // nothing
743
+ if (just_added_newline) {
744
+ remove_indent();
745
+ } else {
746
+ // {}
747
+ trim_output();
748
+ }
749
+ } else {
750
+ if (is_array(flags.mode) && opt_keep_array_indentation) {
751
+ // we REALLY need a newline here, but newliner would skip that
752
+ opt_keep_array_indentation = false;
753
+ print_newline();
754
+ opt_keep_array_indentation = true;
755
+
756
+ } else {
757
+ print_newline();
758
+ }
759
+ }
760
+ print_token();
761
+ }
762
+ break;
763
+
764
+ case 'TK_WORD':
765
+
766
+ // no, it's not you. even I have problems understanding how this works
767
+ // and what does what.
768
+ if (do_block_just_closed) {
769
+ // do {} ## while ()
770
+ print_single_space();
771
+ print_token();
772
+ print_single_space();
773
+ do_block_just_closed = false;
774
+ break;
775
+ }
776
+
777
+ if (token_text === 'function') {
778
+ if (flags.var_line) {
779
+ flags.var_line_reindented = true;
780
+ }
781
+ if ((just_added_newline || last_text === ';') && last_text !== '{') {
782
+ // make sure there is a nice clean space of at least one blank line
783
+ // before a new function definition
784
+ n_newlines = just_added_newline ? n_newlines : 0;
785
+ if ( ! opt_preserve_newlines) {
786
+ n_newlines = 1;
787
+ }
788
+
789
+ for (var i = 0; i < 2 - n_newlines; i++) {
790
+ print_newline(false);
791
+ }
792
+ }
793
+ }
794
+
795
+ if (token_text === 'case' || token_text === 'default') {
796
+ if (last_text === ':') {
797
+ // switch cases following one another
798
+ remove_indent();
799
+ } else {
800
+ // case statement starts in the same line where switch
801
+ flags.indentation_level--;
802
+ print_newline();
803
+ flags.indentation_level++;
804
+ }
805
+ print_token();
806
+ flags.in_case = true;
807
+ break;
808
+ }
809
+
810
+ prefix = 'NONE';
811
+
812
+ if (last_type === 'TK_END_BLOCK') {
813
+
814
+ if (!in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
815
+ prefix = 'NEWLINE';
816
+ } else {
817
+ if (opt_brace_style=="expand" || opt_brace_style=="end-expand") {
818
+ prefix = 'NEWLINE';
819
+ } else {
820
+ prefix = 'SPACE';
821
+ print_single_space();
822
+ }
823
+ }
824
+ } else if (last_type === 'TK_SEMICOLON' && (flags.mode === 'BLOCK' || flags.mode === 'DO_BLOCK')) {
825
+ prefix = 'NEWLINE';
826
+ } else if (last_type === 'TK_SEMICOLON' && is_expression(flags.mode)) {
827
+ prefix = 'SPACE';
828
+ } else if (last_type === 'TK_STRING') {
829
+ prefix = 'NEWLINE';
830
+ } else if (last_type === 'TK_WORD') {
831
+ if (last_text === 'else') {
832
+ // eat newlines between ...else *** some_op...
833
+ // won't preserve extra newlines in this place (if any), but don't care that much
834
+ trim_output(true);
835
+ }
836
+ prefix = 'SPACE';
837
+ } else if (last_type === 'TK_START_BLOCK') {
838
+ prefix = 'NEWLINE';
839
+ } else if (last_type === 'TK_END_EXPR') {
840
+ print_single_space();
841
+ prefix = 'NEWLINE';
842
+ }
843
+
844
+ if (in_array(token_text, line_starters) && last_text !== ')') {
845
+ if (last_text == 'else') {
846
+ prefix = 'SPACE';
847
+ } else {
848
+ prefix = 'NEWLINE';
849
+ }
850
+ }
851
+
852
+ if (flags.if_line && last_type === 'TK_END_EXPR') {
853
+ flags.if_line = false;
854
+ }
855
+ if (in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
856
+ if (last_type !== 'TK_END_BLOCK' || opt_brace_style=="expand" || opt_brace_style=="end-expand") {
857
+ print_newline();
858
+ } else {
859
+ trim_output(true);
860
+ print_single_space();
861
+ }
862
+ } else if (prefix === 'NEWLINE') {
863
+ if ((last_type === 'TK_START_EXPR' || last_text === '=' || last_text === ',') && token_text === 'function') {
864
+ // no need to force newline on 'function': (function
865
+ // DONOTHING
866
+ } else if (token_text === 'function' && last_text == 'new') {
867
+ print_single_space();
868
+ } else if (last_text === 'return' || last_text === 'throw') {
869
+ // no newline between 'return nnn'
870
+ print_single_space();
871
+ } else if (last_type !== 'TK_END_EXPR') {
872
+ if ((last_type !== 'TK_START_EXPR' || token_text !== 'var') && last_text !== ':') {
873
+ // no need to force newline on 'var': for (var x = 0...)
874
+ if (token_text === 'if' && last_word === 'else' && last_text !== '{') {
875
+ // no newline for } else if {
876
+ print_single_space();
877
+ } else {
878
+ flags.var_line = false;
879
+ flags.var_line_reindented = false;
880
+ print_newline();
881
+ }
882
+ }
883
+ } else if (in_array(token_text, line_starters) && last_text != ')') {
884
+ flags.var_line = false;
885
+ flags.var_line_reindented = false;
886
+ print_newline();
887
+ }
888
+ } else if (is_array(flags.mode) && last_text === ',' && last_last_text === '}') {
889
+ print_newline(); // }, in lists get a newline treatment
890
+ } else if (prefix === 'SPACE') {
891
+ print_single_space();
892
+ }
893
+ print_token();
894
+ last_word = token_text;
895
+
896
+ if (token_text === 'var') {
897
+ flags.var_line = true;
898
+ flags.var_line_reindented = false;
899
+ flags.var_line_tainted = false;
900
+ }
901
+
902
+ if (token_text === 'if') {
903
+ flags.if_line = true;
904
+ }
905
+ if (token_text === 'else') {
906
+ flags.if_line = false;
907
+ }
908
+
909
+ break;
910
+
911
+ case 'TK_SEMICOLON':
912
+
913
+ print_token();
914
+ flags.var_line = false;
915
+ flags.var_line_reindented = false;
916
+ if (flags.mode == 'OBJECT') {
917
+ // OBJECT mode is weird and doesn't get reset too well.
918
+ flags.mode = 'BLOCK';
919
+ }
920
+ break;
921
+
922
+ case 'TK_STRING':
923
+
924
+ if (last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_SEMICOLON') {
925
+ print_newline();
926
+ } else if (last_type === 'TK_WORD') {
927
+ print_single_space();
928
+ }
929
+ print_token();
930
+ break;
931
+
932
+ case 'TK_EQUALS':
933
+ if (flags.var_line) {
934
+ // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
935
+ flags.var_line_tainted = true;
936
+ }
937
+ print_single_space();
938
+ print_token();
939
+ print_single_space();
940
+ break;
941
+
942
+ case 'TK_OPERATOR':
943
+
944
+ var space_before = true;
945
+ var space_after = true;
946
+
947
+ if (flags.var_line && token_text === ',' && (is_expression(flags.mode))) {
948
+ // do not break on comma, for(var a = 1, b = 2)
949
+ flags.var_line_tainted = false;
950
+ }
951
+
952
+ if (flags.var_line) {
953
+ if (token_text === ',') {
954
+ if (flags.var_line_tainted) {
955
+ print_token();
956
+ flags.var_line_reindented = true;
957
+ flags.var_line_tainted = false;
958
+ print_newline();
959
+ break;
960
+ } else {
961
+ flags.var_line_tainted = false;
962
+ }
963
+ // } else if (token_text === ':') {
964
+ // hmm, when does this happen? tests don't catch this
965
+ // flags.var_line = false;
966
+ }
967
+ }
968
+
969
+ if (last_text === 'return' || last_text === 'throw') {
970
+ // "return" had a special handling in TK_WORD. Now we need to return the favor
971
+ print_single_space();
972
+ print_token();
973
+ break;
974
+ }
975
+
976
+ if (token_text === ':' && flags.in_case) {
977
+ print_token(); // colon really asks for separate treatment
978
+ print_newline();
979
+ flags.in_case = false;
980
+ break;
981
+ }
982
+
983
+ if (token_text === '::') {
984
+ // no spaces around exotic namespacing syntax operator
985
+ print_token();
986
+ break;
987
+ }
988
+
989
+ if (token_text === ',') {
990
+ if (flags.var_line) {
991
+ if (flags.var_line_tainted) {
992
+ print_token();
993
+ print_newline();
994
+ flags.var_line_tainted = false;
995
+ } else {
996
+ print_token();
997
+ print_single_space();
998
+ }
999
+ } else if (last_type === 'TK_END_BLOCK' && flags.mode !== "(EXPRESSION)") {
1000
+ print_token();
1001
+ if (flags.mode === 'OBJECT' && last_text === '}') {
1002
+ print_newline();
1003
+ } else {
1004
+ print_single_space();
1005
+ }
1006
+ } else {
1007
+ if (flags.mode === 'OBJECT') {
1008
+ print_token();
1009
+ print_newline();
1010
+ } else {
1011
+ // EXPR or DO_BLOCK
1012
+ print_token();
1013
+ print_single_space();
1014
+ }
1015
+ }
1016
+ break;
1017
+ // } else if (in_array(token_text, ['--', '++', '!']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS']) || in_array(last_text, line_starters) || in_array(last_text, ['==', '!=', '+=', '-=', '*=', '/=', '+', '-'])))) {
1018
+ } else if (in_array(token_text, ['--', '++', '!']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']) || in_array(last_text, line_starters)))) {
1019
+ // unary operators (and binary +/- pretending to be unary) special cases
1020
+
1021
+ space_before = false;
1022
+ space_after = false;
1023
+
1024
+ if (last_text === ';' && is_expression(flags.mode)) {
1025
+ // for (;; ++i)
1026
+ // ^^^
1027
+ space_before = true;
1028
+ }
1029
+ if (last_type === 'TK_WORD' && in_array(last_text, line_starters)) {
1030
+ space_before = true;
1031
+ }
1032
+
1033
+ if (flags.mode === 'BLOCK' && (last_text === '{' || last_text === ';')) {
1034
+ // { foo; --i }
1035
+ // foo(); --bar;
1036
+ print_newline();
1037
+ }
1038
+ } else if (token_text === '.') {
1039
+ // decimal digits or object.property
1040
+ space_before = false;
1041
+
1042
+ } else if (token_text === ':') {
1043
+ if (flags.ternary_depth == 0) {
1044
+ flags.mode = 'OBJECT';
1045
+ space_before = false;
1046
+ } else {
1047
+ flags.ternary_depth -= 1;
1048
+ }
1049
+ } else if (token_text === '?') {
1050
+ flags.ternary_depth += 1;
1051
+ }
1052
+ if (space_before) {
1053
+ print_single_space();
1054
+ }
1055
+
1056
+ print_token();
1057
+
1058
+ if (space_after) {
1059
+ print_single_space();
1060
+ }
1061
+
1062
+ if (token_text === '!') {
1063
+ // flags.eat_next_space = true;
1064
+ }
1065
+
1066
+ break;
1067
+
1068
+ case 'TK_BLOCK_COMMENT':
1069
+
1070
+ var lines = token_text.split(/\x0a|\x0d\x0a/);
1071
+
1072
+ if (/^\/\*\*/.test(token_text)) {
1073
+ // javadoc: reformat and reindent
1074
+ print_newline();
1075
+ output.push(lines[0]);
1076
+ for (i = 1; i < lines.length; i++) {
1077
+ print_newline();
1078
+ output.push(' ');
1079
+ output.push(trim(lines[i]));
1080
+ }
1081
+
1082
+ } else {
1083
+
1084
+ // simple block comment: leave intact
1085
+ if (lines.length > 1) {
1086
+ // multiline comment block starts with a new line
1087
+ print_newline();
1088
+ trim_output();
1089
+ } else {
1090
+ // single-line /* comment */ stays where it is
1091
+ print_single_space();
1092
+
1093
+ }
1094
+
1095
+ for (i = 0; i < lines.length; i++) {
1096
+ output.push(lines[i]);
1097
+ output.push('\n');
1098
+ }
1099
+
1100
+ }
1101
+ print_newline();
1102
+ break;
1103
+
1104
+ case 'TK_INLINE_COMMENT':
1105
+
1106
+ print_single_space();
1107
+ print_token();
1108
+ if (is_expression(flags.mode)) {
1109
+ print_single_space();
1110
+ } else {
1111
+ print_newline();
1112
+ }
1113
+ break;
1114
+
1115
+ case 'TK_COMMENT':
1116
+
1117
+ // print_newline();
1118
+ if (wanted_newline) {
1119
+ print_newline();
1120
+ } else {
1121
+ print_single_space();
1122
+ }
1123
+ print_token();
1124
+ print_newline();
1125
+ break;
1126
+
1127
+ case 'TK_UNKNOWN':
1128
+ if (last_text === 'return' || last_text === 'throw') {
1129
+ print_single_space();
1130
+ }
1131
+ print_token();
1132
+ break;
1133
+ }
1134
+
1135
+ last_last_text = last_text;
1136
+ last_type = token_type;
1137
+ last_text = token_text;
1138
+ }
1139
+
1140
+ return output.join('').replace(/[\n ]+$/, '');
1141
+
1142
+ }
1143
+
1144
+ // Add support for CommonJS. Just put this file somewhere on your require.paths
1145
+ // and you will be able to `var js_beautify = require("beautify").js_beautify`.
1146
+ if (typeof exports !== "undefined")
1147
+ exports.js_beautify = js_beautify;
js/tiny_mce/plugins/codemagic/js/codemagic.js ADDED
@@ -0,0 +1,581 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //vatriable definition
2
+ var the = {
3
+ beautify_in_progress: false,
4
+ coloring_active: true,
5
+ autocompletion_active: true
6
+ }
7
+ var hlLine = null;
8
+ var lastPos = null;
9
+ var lastQuery = null;
10
+ var marked = [];
11
+ var pluginCodeMirror = null;
12
+ var pluginOptions = {
13
+ lineNumbers: true,
14
+ mode: "text/html",
15
+ indentUnit: 4,
16
+ matchBrackets: true,
17
+ onCursorActivity: function() {
18
+ pluginCodeMirror.setLineClass(hlLine, null);
19
+ hlLine = pluginCodeMirror.setLineClass(pluginCodeMirror.getCursor().line, "activeline");
20
+ },
21
+ onKeyEvent: function(i, e) {
22
+ if(the.autocompletion_active) {
23
+ /* Hook into charcode < */
24
+ if(String.fromCharCode(e.which == null ? e.keyCode : e.which) == "<") {
25
+ e.stop();
26
+
27
+ var cur = pluginCodeMirror.getCursor(false), token = pluginCodeMirror.getTokenAt(cur);
28
+ pluginCodeMirror.replaceRange("<", cur);
29
+
30
+ setTimeout(startComplete, 50);
31
+ return true;
32
+
33
+ // Hook into ctrl + space
34
+ } if (e.keyCode == 32 && (e.ctrlKey || e.metaKey) && !e.altKey) {
35
+ e.stop();
36
+ return startComplete();
37
+ }
38
+ }
39
+ },
40
+ onHighlightComplete: onChangeCallback
41
+ }
42
+
43
+ //language and init
44
+ tinyMCEPopup.requireLangPack();
45
+ tinyMCEPopup.onInit.add(onLoadInit);
46
+
47
+
48
+ //onload
49
+ function onLoadInit() {
50
+ tinyMCEPopup.resizeToInnerSize();
51
+
52
+ // Remove Gecko spellchecking
53
+ if (tinymce.isGecko)
54
+ document.body.spellcheck = tinyMCEPopup.editor.getParam("gecko_spellcheck");
55
+
56
+ //insert html from tinymce to htmlSource textarea
57
+ document.getElementById("htmlSource").value = tinyMCEPopup.editor.getContent({ source_view : true });
58
+
59
+ //format the source code using JS Beautifier plugin
60
+ beautify("htmlSource");
61
+
62
+ if(the.coloring_active) {
63
+ //activate syntax coloring
64
+ activateCodeColoring("htmlSource");
65
+ }
66
+
67
+ //resize window to fit the textarea
68
+ resizeInputs("htmlSource");
69
+
70
+ window.onresize = function(event) {
71
+ //resize window to fit the textarea
72
+ resizeInputs("htmlSource");
73
+ }
74
+
75
+ }
76
+
77
+
78
+ //activating syntax coloring
79
+ function activateCodeColoring(id) {
80
+ the.coloring_active = true;
81
+
82
+ document.getElementById("search_replace").className = "";
83
+ document.getElementById("reintendt").className = "";
84
+ document.getElementById("autocompletion").disabled = false;
85
+
86
+ pluginCodeMirror = CodeMirror.fromTextArea(document.getElementById(id), pluginOptions);
87
+ hlLine = pluginCodeMirror.setLineClass(0, "activeline");
88
+ pluginCodeMirror.focus();
89
+ }
90
+
91
+
92
+ //deactivating syntax coloring
93
+ function deactivateCodeColoring() {
94
+ the.coloring_active = false;
95
+
96
+ document.getElementById("undo").className = "disabled";
97
+ document.getElementById("redo").className = "disabled";
98
+ document.getElementById("search_replace").className = "disabled";
99
+ document.getElementById("reintendt").className = "disabled";
100
+ document.getElementById("autocompletion").disabled = true;
101
+
102
+ pluginCodeMirror.toTextArea();
103
+ pluginCodeMirror = null;
104
+
105
+ //resize window to fit the textarea
106
+ resizeInputs("htmlSource");
107
+ }
108
+
109
+
110
+ //toggle highlighting usint a checkbox
111
+ function toggleHighlighting(elm, id) {
112
+ if (elm.checked) {
113
+ activateCodeColoring(id);
114
+ } else {
115
+ deactivateCodeColoring();
116
+ }
117
+ }
118
+
119
+ //toggle code autocompletion
120
+ function toggleAutocompletion(elm) {
121
+ if (elm.checked) {
122
+ the.autocompletion_active = true;
123
+ } else {
124
+ the.autocompletion_active = false;
125
+ }
126
+ }
127
+
128
+ //save content bact to tinymce editor
129
+ function saveContent() {
130
+ tinyMCEPopup.editor.setContent(pluginCodeMirror.getValue(), { source_view : true });
131
+ tinyMCEPopup.close();
132
+ }
133
+
134
+
135
+ //resize textarea input
136
+ function resizeInputs(id) {
137
+ var vp = tinyMCEPopup.dom.getViewPort(window), el;
138
+
139
+ el = document.getElementById(id);
140
+
141
+ if (el) {
142
+ //el.style.width = (vp.w - 20) + "px";
143
+ el.style.height = (vp.h - 65) + "px";
144
+ }
145
+ }
146
+
147
+
148
+ //toggle search window
149
+ function toggleSearch(elm, id) {
150
+ if(!the.coloring_active) return false;
151
+
152
+ elm.className = "";
153
+ var element = document.getElementById(id);
154
+
155
+ if(element.style.display == "none") {
156
+ elm.className = "selected";
157
+ element.style.display = "block";
158
+ }
159
+ else element.style.display = "none";
160
+ }
161
+
162
+
163
+
164
+
165
+
166
+
167
+ /**
168
+ * CodeMirror 2
169
+ * -------------
170
+ *
171
+ * CodeMirror 2 is a rewrite of CodeMirror 1 (http://github.com/marijnh/CodeMirror).
172
+ * The docs live here http://codemirror.net/2/manual.html,
173
+ * and the project page is http://codemirror.net/2/.
174
+ * *
175
+ * http://codemirror.net/
176
+ *
177
+ * Copyright (C) 2011 by Marijn Haverbeke <marijnh@gmail.com>
178
+ */
179
+
180
+
181
+ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
182
+ var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
183
+ var jsMode = CodeMirror.getMode(config, "javascript");
184
+ var cssMode = CodeMirror.getMode(config, "css");
185
+
186
+ function html(stream, state) {
187
+ var style = htmlMode.token(stream, state.htmlState);
188
+ if (style == "xml-tag" && stream.current() == ">" && state.htmlState.context) {
189
+ if (/^script$/i.test(state.htmlState.context.tagName)) {
190
+ state.token = javascript;
191
+ state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
192
+ } else if (/^style$/i.test(state.htmlState.context.tagName)) {
193
+ state.token = css;
194
+ state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
195
+ }
196
+ }
197
+ return style;
198
+ }
199
+ function maybeBackup(stream, pat, style) {
200
+ var cur = stream.current();
201
+ var close = cur.search(pat);
202
+ if (close > -1) stream.backUp(cur.length - close);
203
+ return style;
204
+ }
205
+
206
+ function javascript(stream, state) {
207
+ if (stream.match(/^<\/\s*script\s*>/i, false)) {
208
+ state.token = html;
209
+ state.curState = null;
210
+ return html(stream, state);
211
+ }
212
+ return maybeBackup(stream, /<\/\s*script\s*>/, jsMode.token(stream, state.localState));
213
+ }
214
+ function css(stream, state) {
215
+ if (stream.match(/^<\/\s*style\s*>/i, false)) {
216
+ state.token = html;
217
+ state.localState = null;
218
+ return html(stream, state);
219
+ }
220
+ return maybeBackup(stream, /<\/\s*style\s*>/, cssMode.token(stream, state.localState));
221
+ }
222
+
223
+ return {
224
+ startState: function() {
225
+ var state = htmlMode.startState();
226
+ return {token: html, localState: null, htmlState: state};
227
+ },
228
+
229
+ copyState: function(state) {
230
+ if (state.localState)
231
+ var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState);
232
+ return {token: state.token, localState: local, htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
233
+ },
234
+
235
+ token: function(stream, state) {
236
+ return state.token(stream, state);
237
+ },
238
+
239
+ indent: function(state, textAfter) {
240
+ if (state.token == html || /^\s*<\//.test(textAfter))
241
+ return htmlMode.indent(state.htmlState, textAfter);
242
+ else if (state.token == javascript)
243
+ return jsMode.indent(state.localState, textAfter);
244
+ else
245
+ return cssMode.indent(state.localState, textAfter);
246
+ },
247
+
248
+ electricChars: "/{}:"
249
+ }
250
+ });
251
+
252
+ CodeMirror.defineMIME("text/html", "htmlmixed");
253
+
254
+ ////////////////////////
255
+ //undo last action
256
+ function undo() {
257
+ pluginCodeMirror.undo();
258
+ }
259
+
260
+
261
+ //redo last action
262
+ function redo() {
263
+ pluginCodeMirror.redo();
264
+ }
265
+
266
+
267
+ //callback to onchange event on editor
268
+ function onChangeCallback(editor) {
269
+ var undo = editor.historySize().undo;
270
+ var redo = editor.historySize().redo;
271
+
272
+ if(undo > 0) document.getElementById("undo").className = "";
273
+ else document.getElementById("undo").className = "disabled";
274
+
275
+ if(redo > 0) document.getElementById("redo").className = "";
276
+ else document.getElementById("redo").className = "disabled";
277
+ }
278
+
279
+ ////////////////////////
280
+ //reintendt html source code
281
+ function reIntendt(id) {
282
+ if(!the.coloring_active) return false;
283
+
284
+ deactivateCodeColoring();
285
+ document.getElementById("searchWindow").style.display = "none";
286
+ beautify(id);
287
+ activateCodeColoring(id);
288
+ }
289
+
290
+ ////////////////////////
291
+ //search and replace
292
+
293
+ //unmarks all searched words
294
+ function unmark() {
295
+ for (var i = 0; i < marked.length; ++i) marked[i]();
296
+ marked.length = 0;
297
+ }
298
+
299
+ //search for query from #query input
300
+ function searchCode() {
301
+ unmark();
302
+
303
+ var text = document.getElementById("query").value;
304
+ if (!text) return false;
305
+
306
+ if(!pluginCodeMirror.getSearchCursor(text).findNext()) {
307
+ alert(tinyMCEPopup.getLang('codemagic_dlg.nothing_found'));
308
+ return false;
309
+ }
310
+
311
+ for (var cursor = pluginCodeMirror.getSearchCursor(text); cursor.findNext();)
312
+ marked.push(pluginCodeMirror.markText(cursor.from(), cursor.to(), "searched"));
313
+
314
+ if (lastQuery != text) lastPos = null;
315
+
316
+ var cursor = pluginCodeMirror.getSearchCursor(text, lastPos || pluginCodeMirror.getCursor());
317
+ if (!cursor.findNext()) {
318
+ cursor = pluginCodeMirror.getSearchCursor(text);
319
+ if (!cursor.findNext()) return;
320
+ }
321
+ pluginCodeMirror.setSelection(cursor.from(), cursor.to());
322
+ lastQuery = text; lastPos = cursor.to();
323
+ }
324
+
325
+ //replace
326
+ function replaceCode() {
327
+ unmark();
328
+
329
+ var text = document.getElementById("query").value;
330
+ var replace = document.getElementById("replace").value;
331
+
332
+ if (!text) return false;
333
+
334
+ if(!pluginCodeMirror.getSearchCursor(text).findNext()) {
335
+ alert(tinyMCEPopup.getLang('codemagic_dlg.nothing_to_replace'));
336
+ return false;
337
+ }
338
+
339
+ for (var cursor = pluginCodeMirror.getSearchCursor(text); cursor.findNext();)
340
+ pluginCodeMirror.replaceRange(replace, cursor.from(), cursor.to());
341
+ }
342
+
343
+
344
+ ////////////////////////
345
+ //autocompletion
346
+ var tagNames = ("a abbr acronym address applet area b base basefont bdo big blockquote body br button" +
347
+ " caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame " +
348
+ " frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map" +
349
+ " menu meta noframes noscript object ol optgroup option p param pre q s samp script select small" +
350
+ " span strike strong style sub sup table tbody td textarea tfoot th thead title tr tt u ul var").split(" ");
351
+
352
+ var pairedTags = ("a abbr acronym address applet b bdo big blockquote body button" +
353
+ " caption center cite code colgroup del dfn dir div dl em fieldset font form" +
354
+ " frameset h1 h2 h3 h4 h5 h6 head html i iframe ins kbd label legend li map" +
355
+ " menu noframes noscript object ol optgroup option p pre q s samp script select small" +
356
+ " span strike strong style sub sup table tbody td textarea tfoot th thead title tr tt u ul var").split(" ");
357
+
358
+ var unPairedTags = ("area base basefont br col dd dt frame hr img input isindex link meta param").split(" ");
359
+
360
+ var specialTags = {
361
+ "applet" : { tag: 'applet width="" height=""></applet>', cusror: 8 },
362
+ "area" : { tag: 'area alt="" />', cusror: 6 },
363
+ "base" : { tag: 'base href="" />', cusror: 7 },
364
+ "form" : { tag: 'form action=""></form>', cusror: 9 },
365
+ "img" : { tag: 'img src="" alt="" />', cusror: 6 },
366
+ "map" : { tag: 'map name=""></map>', cusror: 7 },
367
+ "meta" : { tag: 'meta content="" />', cusror: 10 },
368
+ "optgroup" : { tag: 'optgroup label=""></optgroup>', cusror: 8 },
369
+ "param" : { tag: 'param name="" />', cusror: 7 },
370
+ "script" : { tag: 'script type=""></script>', cusror: 7 },
371
+ "style" : { tag: 'style type=""></style>', cusror: 7 },
372
+ "textarea" : { tag: 'textarea cols="" rows=""></textarea>', cusror: 7 }
373
+ }
374
+
375
+ // Minimal event-handling wrapper.
376
+ function stopEvent() {
377
+ if (this.preventDefault) {this.preventDefault(); this.stopPropagation();}
378
+ else {this.returnValue = false; this.cancelBubble = true;}
379
+ }
380
+ function addStop(event) {
381
+ if (!event.stop) event.stop = stopEvent;
382
+ return event;
383
+ }
384
+ function connect(node, type, handler) {
385
+ function wrapHandler(event) {
386
+ handler(addStop(event || window.event));
387
+ }
388
+
389
+ if (typeof node.addEventListener == "function")
390
+ node.addEventListener(type, wrapHandler, false);
391
+ else
392
+ node.attachEvent("on" + type, wrapHandler);
393
+ }
394
+
395
+ function forEach(arr, f) {
396
+ for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
397
+ }
398
+
399
+ Array.prototype.inArray = function(value){
400
+ for (var key in this)
401
+ if (this[key] === value) return true;
402
+ return false;
403
+ }
404
+
405
+
406
+
407
+ //autocompletion start
408
+ function startComplete() {
409
+ var startingTag, unPaired;
410
+
411
+ // We want a single cursor position.
412
+ if (pluginCodeMirror.somethingSelected()) return;
413
+
414
+ // Find the token at the cursor
415
+ var cur = pluginCodeMirror.getCursor(false), token = pluginCodeMirror.getTokenAt(cur), tprop = token;
416
+
417
+ if(token.string.indexOf("<") == 0 && token.string.indexOf("</") != 0) {
418
+ token.string = token.string.replace("<", "");
419
+ token.start++;
420
+ startingTag = true;
421
+ } else if(token.string.indexOf("</") == 0) {
422
+ token.string = token.string.replace("</", "");
423
+ token.start += 2;
424
+ startingTag = false;
425
+ } else {
426
+ return;
427
+ }
428
+
429
+ //get the tags
430
+ var completions = getCompletions(token, startingTag);
431
+ if (!completions.length) return;
432
+
433
+
434
+ function insert(str) {
435
+ if(str == "") return;
436
+
437
+ //trim
438
+ str = str.replace(/^\s+|\s+$/g,"");
439
+
440
+ //is this an unpaired tag?
441
+ unPaired = unPairedTags.inArray(str) ? true : false;
442
+
443
+ if(specialTags[str] != null && startingTag) {
444
+ var insertTag = specialTags[str].tag;
445
+ var jumpTo = (token.start + str.length + specialTags[str].cusror);
446
+ } else if(startingTag && unPaired) {
447
+ var insertTag = str + " />";
448
+ var jumpTo = (token.start + str.length + 3);
449
+ } else if (startingTag) {
450
+ var insertTag = str + "></" + str + ">";
451
+ var jumpTo = (token.start + str.length + 1);
452
+ } else {
453
+ var insertTag = str + ">";
454
+ var jumpTo = (token.start + str.length + 1);
455
+ }
456
+
457
+ pluginCodeMirror.replaceRange(insertTag, {line: cur.line, ch: token.start}, {line: cur.line, ch: token.end});
458
+ pluginCodeMirror.setCursor({line: cur.line, ch: jumpTo});
459
+ }
460
+
461
+ // When there is only one completion, use it directly.
462
+ /*if (completions.length == 1) {
463
+ insert(completions[0]); return true;
464
+ }*/
465
+
466
+ // Build the select widget
467
+ var complete = document.createElement("div");
468
+ complete.className = "completions";
469
+
470
+ var sel = complete.appendChild(document.createElement("select"));
471
+ sel.multiple = false;
472
+
473
+ if (completions.length == 1) sel.multiple = true;
474
+
475
+ for (var i = 0; i < completions.length; ++i) {
476
+ var opt = sel.appendChild(document.createElement("option"));
477
+ opt.appendChild(document.createTextNode(completions[i]));
478
+ }
479
+
480
+ sel.firstChild.selected = true;
481
+ sel.size = Math.min(10, completions.length);
482
+
483
+ var pos = pluginCodeMirror.cursorCoords();
484
+ complete.style.left = pos.x + "px";
485
+
486
+ //top position
487
+ if(pos.yBot > 448) pos.yBot = pos.yBot - 165;
488
+ complete.style.top = pos.yBot + "px";
489
+
490
+ document.body.appendChild(complete);
491
+
492
+
493
+ var done = false;
494
+ function close() {
495
+ if (done) return;
496
+ done = true;
497
+ complete.parentNode.removeChild(complete);
498
+ }
499
+ function pick() {
500
+ insert(sel.options[sel.selectedIndex].innerHTML);
501
+ close();
502
+ setTimeout(function(){
503
+ pluginCodeMirror.focus();
504
+ }, 50);
505
+ }
506
+
507
+ //bind events
508
+ connect(sel, "blur", close);
509
+ connect(sel, "keydown", function(event) {
510
+ var code = event.keyCode;
511
+
512
+ // Enter, space, tab
513
+ if (code == 13 || code == 32 || code == 9) {event.stop(); pick();}
514
+ // Escape (FIX: closes the tinymce popup window)
515
+ else if (code == 27) {
516
+ event.stop(); close(); pluginCodeMirror.focus();
517
+ }
518
+ //other than arrow up/down
519
+ else if (code != 38 && code != 40 && code != 16 && code != 17 && code != 18 && code != 91 && code != 92) {
520
+ console.log([code]);
521
+ close();
522
+ pluginCodeMirror.focus();
523
+ if(code != 39 && code != 37) setTimeout(startComplete, 50);
524
+ else event.stop();
525
+ }
526
+ });
527
+ connect(sel, "dblclick", pick);
528
+
529
+ sel.focus();
530
+
531
+ // Opera sometimes ignores focusing a freshly created node
532
+ if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100);
533
+ return true;
534
+ }
535
+
536
+ function getCompletions(token, startingTag) {
537
+ var found = [], start = token.string;
538
+
539
+ function maybeAdd(str) {
540
+ if (str.indexOf(start) == 0) found.push(str);
541
+ }
542
+
543
+ if(startingTag) {
544
+ forEach(tagNames, maybeAdd)
545
+ } else {
546
+ forEach(pairedTags, maybeAdd)
547
+ }
548
+
549
+ return found;
550
+ }
551
+
552
+
553
+
554
+
555
+
556
+ /**
557
+ * JS Beautifier
558
+ * ---------------
559
+ * ...or, more specifically, all of the code powering jsbeautifier.org.
560
+ *
561
+ *
562
+ * Written by Einar Lielmanis, <einar@jsbeautifier.org>
563
+ *
564
+ * Thanks to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, Dave
565
+ * Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Hull and
566
+ * others.
567
+ */
568
+ function beautify(id) {
569
+
570
+ if (the.beautify_in_progress) return;
571
+ the.beautify_in_progress = true;
572
+
573
+ var source = document.getElementById(id).value.replace(/^\s+/, '');
574
+
575
+ var indent_size = 4;
576
+ var indent_char = ' ';
577
+ var brace_style = 'collapse'; //collapse, expand, end-expand
578
+
579
+ document.getElementById(id).value = style_html(source, indent_size, indent_char, 120, brace_style);
580
+ the.beautify_in_progress = false;
581
+ }
js/tiny_mce/plugins/codemagic/js/codemirror-compressed.js ADDED
@@ -0,0 +1 @@
 
1
+ var CodeMirror=function(){function D(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;c<d;++c)if(a[c]==b)return c;return-1}function C(a,b){if(!b)return a?a.length:0;if(!a)return b.length;for(var c=a.length,d=b.length;c>=0&&d>=0;--c,--d)if(a.charAt(c)!=b.charAt(d))break;return d+1}function B(a){return a.replace(/[<>&]/g,function(a){return a=="&"?"&amp;":a=="<"?"&lt;":"&gt;"})}function A(a){return{line:a.line,ch:a.ch}}function z(a,b){return a.line<b.line||a.line==b.line&&a.ch<b.ch}function y(a,b){return a.line==b.line&&a.ch==b.ch}function x(a){return a.textContent||a.innerText||a.nodeValue||""}function w(a,b){var c=a.ownerDocument.body,d=0,e=0,f=!1;for(var g=a;g;g=g.offsetParent)d+=g.offsetLeft,e+=g.offsetTop,g==c&&(f=!0);var h=b&&f?null:c;for(var g=a.parentNode;g!=h;g=g.parentNode)g.scrollLeft!=null&&(d-=g.scrollLeft,e-=g.scrollTop);return{left:d,top:e}}function v(a,b){b==null&&(b=a.search(/[^\s\u00a0]/),b==-1&&(b=a.length));for(var c=0,d=0;c<b;++c)a.charAt(c)=="\t"?d+=r-d%r:++d;return d}function n(){this.id=null}function m(a,b,c,d){function e(a){c(new l(a||window.event))}if(typeof a.addEventListener=="function"){a.addEventListener(b,e,!1);if(d)return function(){a.removeEventListener(b,e,!1)}}else{a.attachEvent("on"+b,e);if(d)return function(){a.detachEvent("on"+b,e)}}}function l(a){this.e=a}function k(a){a.stop||(a.stop=j);return a}function j(){this.preventDefault?(this.preventDefault(),this.stopPropagation()):(this.returnValue=!1,this.cancelBubble=!0)}function i(){this.time=0,this.done=[],this.undone=[]}function h(a,b,c,d){for(var e=0,f=0,g=0;f<b;e+=2){var h=c[e],i=f+h.length;g==0?(i>a&&d.push(h.slice(a-f,Math.min(h.length,b-f)),c[e+1]),i>=a&&(g=1)):g==1&&(i>b?d.push(h.slice(0,b-f),c[e+1]):d.push(h,c[e+1])),f=i}}function g(a,b){this.styles=b||[a,null],this.stateAfter=null,this.text=a,this.marked=this.gutterMarker=this.className=null}function f(a){this.pos=this.start=0,this.string=a}function e(a,b,c){return a.startState?a.startState(b,c):!0}function d(a,b){if(b===!0)return b;if(a.copyState)return a.copyState(b);var c={};for(var d in b){var e=b[d];e instanceof Array&&(e=e.concat([])),c[d]=e}return c}function a(b,c){function cI(a,b,c){this.atOccurrence=!1,c==null&&(c=typeof a=="string"&&a==a.toLowerCase()),b&&typeof b=="object"?b=bZ(b):b={line:0,ch:0},this.pos={from:b,to:b};if(typeof a!="string")this.matches=function(b,c){if(b){var d=T[c.line].text.slice(0,c.ch),e=d.match(a),f=0;while(e){var g=d.indexOf(e[0]);f+=g,d=d.slice(g+1);var h=d.match(a);if(h)e=h;else break;f++}}else var d=T[c.line].text.slice(c.ch),e=d.match(a),f=e&&c.ch+d.indexOf(e[0]);if(e)return{from:{line:c.line,ch:f},to:{line:c.line,ch:f+e[0].length},match:e}};else{c&&(a=a.toLowerCase());var d=c?function(a){return a.toLowerCase()}:function(a){return a},e=a.split("\n");e.length==1?this.matches=function(b,c){var e=d(T[c.line].text),f=a.length,g;if(b?c.ch>=f&&(g=e.lastIndexOf(a,c.ch-f))!=-1:(g=e.indexOf(a,c.ch))!=-1)return{from:{line:c.line,ch:g},to:{line:c.line,ch:g+f}}}:this.matches=function(a,b){var c=b.line,f=a?e.length-1:0,g=e[f],h=d(T[c].text),i=a?h.indexOf(g)+g.length:h.lastIndexOf(g);if(!(a?i>=b.ch||i!=g.length:i<=b.ch||i!=h.length-g.length))for(;;){if(a?!c:c==T.length-1)return;h=d(T[c+=a?-1:1].text),g=e[a?--f:++f];if(f>0&&f<e.length-1){if(h!=g)return;continue}var j=a?h.lastIndexOf(g):h.indexOf(g)+g.length;if(a?j!=h.length-g.length:j!=g.length)return;var k={line:b.line,ch:i},l={line:c,ch:j};return{from:a?l:k,to:a?k:l}}}}}function cH(a){return function(){cG++||cE();try{var b=a.apply(this,arguments)}finally{--cG||cF()}return b}}function cF(){var a=!1;bc&&(a=!bN()),ba.length?bQ(ba):bc&&bU(),a&&bN(),bc&&cx(),!bd&&(_===!0||_!==!1&&bc)&&bL(),bc&&f.matchBrackets&&setTimeout(cH(function(){bj&&(bj(),bj=null),cz(!1)}),20);var b=bb;bc&&f.onCursorActivity&&f.onCursorActivity(bm),b&&f.onChange&&bm&&f.onChange(bm,b)}function cE(){_=null,ba=[],bb=bc=!1}function cD(a){!U.length||Q.set(a,cH(cC))}function cC(){var a=+(new Date)+f.workTime,b=!1;while(U.length){if(!T[be].stateAfter)var c=be;else var c=U.pop();if(c>=T.length)continue;b=!0;var g=cA(c),h=g&&T[g-1].stateAfter;h?h=d(S,h):h=e(S);for(var i=g,j=T.length;i<j;++i){var k=T[i],l=k.stateAfter;if(+(new Date)>a){U.push(i),cD(f.workDelay),ba.push({from:c,to:i});return}var m=k.highlight(S,h);k.stateAfter=d(S,h);if(l&&!m&&k.text)break}ba.push({from:c,to:i})}b&&f.onHighlightComplete&&f.onHighlightComplete(bm)}function cB(a){var b=cA(a),c=b&&T[b-1].stateAfter;c?c=d(S,c):c=e(S);for(var f=b;f<a;++f){var g=T[f];g.highlight(S,c),g.stateAfter=d(S,c)}T[a].stateAfter||U.push(a);return c}function cA(a){var b,c;for(var d=a,e=a-40;d>e;--d){if(d==0)return 0;var f=T[d-1];if(f.stateAfter)return d;var g=f.indentation();if(c==null||b>g)c=d,b=g}return c}function cz(a){function p(a,b,c){if(!!a.text){var d=a.styles,e=g?0:a.text.length-1,f;for(var i=g?0:d.length-2,j=g?d.length:-2;i!=j;i+=2*h){var k=d[i];if(d[i+1]!=null&&d[i+1]!=m){e+=h*k.length;continue}for(var l=g?0:k.length-1,p=g?k.length:-1;l!=p;l+=h,e+=h)if(e>=b&&e<c&&o.test(f=k.charAt(l))){var q=cy[f];if(q.charAt(1)==">"==g)n.push(f);else{if(n.pop()!=q.charAt(0))return{pos:e,match:!1};if(!n.length)return{pos:e,match:!0}}}}}}var b=X.inverted?X.from:X.to,c=T[b.line],d=b.ch-1,e=d>=0&&cy[c.text.charAt(d)]||cy[c.text.charAt(++d)];if(!!e){var f=e.charAt(0),g=e.charAt(1)==">",h=g?1:-1,i=c.styles;for(var j=d+1,k=0,l=i.length;k<l;k+=2)if((j-=i[k].length)<=0){var m=i[k+1];break}var n=[c.text.charAt(d)],o=/[(){}[\]]/;for(var k=b.line,l=g?Math.min(k+50,T.length):Math.max(-1,k-50);k!=l;k+=h){var c=T[k],q=k==b.line,r=p(c,q&&g?d+1:0,q&&!g?d:c.text.length);if(r){var m=r.match?"CodeMirror-matchingbracket":"CodeMirror-nonmatchingbracket",s=ci({line:b.line,ch:d},{line:b.line,ch:d+1},m),t=ci({line:k,ch:r.pos},{line:k,ch:r.pos+1},m),u=cH(function(){s(),t()});a?setTimeout(u,800):bj=u;break}}}}function cx(){clearInterval(R);var a=!0;N.style.visibility="",R=setInterval(function(){N.style.visibility=(a=!a)?"":"hidden"},650)}function cw(a){function e(){L.value!=d&&cH(bD)(L.value,"end"),L.style.cssText=c,bd=!1,bL(),bI()}var b=cv(a);if(!!b&&!window.opera){(y(X.from,X.to)||z(b,X.from)||!z(b,X.to))&&bX(b.line,b.ch);var c=L.style.cssText;L.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(a.pageY()-1)+"px; left: "+(a.pageX()-1)+"px; z-index: 1000; background: white; "+"border-width: 0; outline: none; overflow: hidden;";var d=L.value=bG();bM(),G(L,0,L.value.length),bd=!0;if(p){a.stop();var f=m(window,"mouseup",function(){f(),setTimeout(e,20)},!0)}else setTimeout(e,50)}}function cv(a,b){var c=w(u,!0),d=a.e.clientX,e=a.e.clientY;if(!b&&(d-c.left>u.clientWidth||e-c.top>u.clientHeight))return null;var f=w(M,!0),g=be+Math.floor((e-f.top)/cs());return bZ({line:g,ch:cp(bY(g),d-f.left)})}function cu(){return M.offsetLeft}function ct(){return M.offsetTop}function cs(){var a=O.childNodes.length;if(a)return O.offsetHeight/a||1;B.innerHTML="<pre>x</pre>";return B.firstChild.offsetHeight||1}function cr(a){var b=cq(a,!0),c=w(M);return{x:c.left+b.x,y:c.top+b.y,yBot:c.top+b.yBot}}function cq(a,b){var c=cs(),d=a.line-(b?be:0);return{x:co(a.line,a.ch),y:d*c,yBot:(d+1)*c}}function cp(a,b){function e(a){B.innerHTML="<pre><span>"+c.getHTML(null,null,!1,a)+"</span></pre>";return B.firstChild.firstChild.offsetWidth}if(b<=0)return 0;var c=T[a],d=c.text,f=0,g=0,h=d.length,i,j=Math.min(h,Math.ceil(b/cn("x")));for(;;){var k=e(j);if(k<=b&&j<h)j=Math.min(h,Math.ceil(j*1.2));else{i=k,h=j;break}}if(b>i)return h;j=Math.floor(h*.8),k=e(j),k<b&&(f=j,g=k);for(;;){if(h-f<=1)return i-b>b-g?f:h;var l=Math.ceil((f+h)/2),m=e(l);m>b?(h=l,i=m):(f=l,g=m)}}function co(a,b){if(b==0)return 0;B.innerHTML="<pre><span>"+T[a].getHTML(null,null,!1,b)+"</span></pre>";return B.firstChild.firstChild.offsetWidth}function cn(a){B.innerHTML="<pre><span>x</span></pre>",B.firstChild.firstChild.firstChild.nodeValue=a;return B.firstChild.firstChild.offsetWidth||10}function cm(a){if(typeof a=="number"){var b=a;a=T[a];if(!a)return null}else{var b=D(T,a);if(b==-1)return null}var c=a.gutterMarker;return{line:b,text:a.text,markerText:c&&c.text,markerClass:c&&c.style}}function cl(a,b){if(typeof a=="number"){var c=a;a=T[bY(a)]}else{var c=D(T,a);if(c==-1)return null}a.className!=b&&(a.className=b,ba.push({from:c,to:c+1}));return a}function ck(a){typeof a=="number"&&(a=T[bY(a)]),a.gutterMarker=null,bT()}function cj(a,b,c){typeof a=="number"&&(a=T[bY(a)]),a.gutterMarker={text:b,style:c},bT();return a}function ci(a,b,c){function e(a,b,c,e){var a=T[a],f=a.addMark(b,c,e);f.line=a,d.push(f)}a=bZ(a),b=bZ(b);var d=[];if(a.line==b.line)e(a.line,a.ch,b.ch,c);else{e(a.line,a.ch,null,c);for(var f=a.line+1,g=b.line;f<g;++f)e(f,0,null,c);e(b.line,0,b.ch,c)}ba.push({from:a.line,to:b.line+1});return function(){var a,b;for(var c=0;c<d.length;++c){var e=d[c],f=D(T,e.line);e.line.removeMark(e),f>-1&&(a==null&&(a=f),b=f)}a!=null&&ba.push({from:a,to:b+1})}}function ch(){var a=f.gutter||f.lineNumbers;I.style.display=a?"":"none",a?bT():O.parentNode.style.marginLeft=0}function cg(){S=a.getMode(f,f.mode);for(var b=0,c=T.length;b<c;++b)T[b].stateAfter=null;U=[0],cD()}function cf(a,b){if(b=="smart")if(!S.indent)b="prev";else var c=cB(a);var d=T[a],e=d.indentation(),g=d.text.match(/^\s*/)[0],h;b=="prev"?a?h=T[a-1].indentation():h=0:b=="smart"?h=S.indent(c,d.text.slice(g.length)):b=="add"?h=e+f.indentUnit:b=="subtract"&&(h=e-f.indentUnit),h=Math.max(0,h);var i=h-e;if(!i){if(X.from.line!=a&&X.to.line!=a)return;var j=g}else{var j="",k=0;if(f.indentWithTabs)for(var l=Math.floor(h/r);l;--l)k+=r,j+="\t";while(k<h)++k,j+=" "}bC(j,{line:a,ch:0},{line:a,ch:g.length})}function ce(a){Y=null;switch(f.tabMode){case"default":return!1;case"indent":for(var b=X.from.line,c=X.to.line;b<=c;++b)cf(b,"smart");break;case"classic":if(y(X.from,X.to)){a?cf(X.from.line,"smart"):bD("\t","end");break};case"shift":for(var b=X.from.line,c=X.to.line;b<=c;++b)cf(b,a?"subtract":"add")}return!0}function cd(){bD("\n","end"),f.enterMode!="flat"&&cf(X.from.line,f.enterMode=="keep"?"prev":"smart")}function cc(a){bV({line:a,ch:0},{line:a,ch:T[a].text.length})}function cb(a){var b=T[a.line].text,c=a.ch,d=a.ch;while(c>0&&/\w/.test(b.charAt(c-1)))--c;while(d<b.length&&/\w/.test(b.charAt(d)))++d;bV({line:a.line,ch:c},{line:a.line,ch:d})}function ca(){var a=T.length-1;bW({line:0,ch:0},{line:a,ch:T[a].text.length})}function b_(a){bX(a?0:T.length-1,!0)}function b$(a){var b=Math.floor(u.clientHeight/cs()),c=X.inverted?X.from:X.to;bX(c.line+Math.max(b-1,1)*(a?1:-1),c.ch,!0)}function bZ(a){if(a.line<0)return{line:0,ch:0};if(a.line>=T.length)return{line:T.length-1,ch:T[T.length-1].text.length};var b=a.ch,c=T[a.line].text.length;return b==null||b>c?{line:a.line,ch:c}:b<0?{line:a.line,ch:0}:a}function bY(a){return Math.max(0,Math.min(a,T.length-1))}function bX(a,b,c){var d=bZ({line:a,ch:b||0});(c?bV:bW)(d,d)}function bW(a,b,c,d){if(!y(X.from,a)||!y(X.to,b)){if(z(b,a)){var e=b;b=a,a=e}var f=y(X.to,b),g=y(X.from,a);y(a,b)?X.inverted=!1:f&&!g?X.inverted=!0:g&&!f&&(X.inverted=!1),c==null&&(c=X.from.line,d=X.to.line),y(a,b)?y(X.from,X.to)||ba.push({from:c,to:d+1}):y(X.from,X.to)?ba.push({from:a.line,to:b.line+1}):(y(a,X.from)||(a.line<c?ba.push({from:a.line,to:Math.min(b.line,c)+1}):ba.push({from:c,to:Math.min(d,a.line)+1})),y(b,X.to)||(b.line<d?ba.push({from:Math.max(c,a.line),to:d+1}):ba.push({from:Math.max(a.line,d),to:b.line+1}))),X.from=a,X.to=b,bc=!0}}function bV(a,b){var c=Y&&bZ(Y);c&&(z(c,a)?a=c:z(b,c)&&(b=c)),bW(a,b)}function bU(){var a=X.inverted?X.from:X.to,b=co(a.line,a.ch)+"px",c=(a.line-be)*cs()+"px";K.style.top=c,y(X.from,X.to)?(N.style.top=c,N.style.left=b,N.style.display=""):N.style.display="none"}function bT(){if(!!f.gutter||!!f.lineNumbers){var a=H.offsetHeight,b=u.clientHeight;I.style.height=(a-b<2?b:a)+"px";var c=[];for(var d=be;d<bf;++d){var e=T[d].gutterMarker,g=f.lineNumbers?d+f.firstLineNumber:null;e&&e.text?g=e.text.replace("%N%",g!=null?g:""):g==null&&(g="\u00a0"),c.push(e&&e.style?'<pre class="'+e.style+'">':"<pre>",g,"</pre>")}I.style.display="none",J.innerHTML=c.join("");var h=String(T.length).length,i=J.firstChild,j=x(i),k="";while(j.length+k.length<h)k+="\u00a0";k&&i.insertBefore(l.createTextNode(k),i.firstChild),I.style.display="",M.style.marginLeft=I.offsetWidth+"px"}}function bS(a){var b=X.from.line,c=X.to.line,d=0,e=o&&l.createElement("div");for(var f=0,g=a.length;f<g;++f){var h=a[f],i=h.to-h.from-h.domSize,j=O.childNodes[h.domStart+h.domSize+d]||null;if(o)for(var k=Math.max(-i,h.domSize);k>0;--k)O.removeChild(j?j.previousSibling:O.lastChild);else if(i){for(var k=Math.max(0,i);k>0;--k)O.insertBefore(l.createElement("pre"),j);for(var k=Math.max(0,-i);k>0;--k)O.removeChild(j?j.previousSibling:O.lastChild)}var m=O.childNodes[h.domStart+d],n=b<h.from&&c>=h.from;for(var k=h.from;k<h.to;++k){var p=null,q=null;n?(p=0,c==k&&(n=!1,q=X.to.ch)):b==k&&(c==k?(p=X.from.ch,q=X.to.ch):(n=!0,p=X.from.ch)),o?(e.innerHTML=T[k].getHTML(p,q,!0),O.insertBefore(e.firstChild,j)):(m.innerHTML=T[k].getHTML(p,q,!1),m.className=T[k].className||"",m=m.nextSibling)}d+=i}}function bR(a,b){var c=[],d={line:a,ch:0},e=z(X.from,d)&&!z(X.to,d);for(var f=a;f<b;++f){var g=null,h=null;e?(g=0,X.to.line==f&&(e=!1,h=X.to.ch)):X.from.line==f&&(X.to.line==f?(g=X.from.ch,h=X.to.ch):(e=!0,g=X.from.ch)),c.push(T[f].getHTML(g,h,!0))}O.innerHTML=c.join("")}function bQ(a){if(!u.clientWidth)be=bf=0;else{var b=a===!0?[]:[{from:be,to:bf,domStart:0}];for(var c=0,d=a.length||0;c<d;++c){var e=a[c],f=[],g=e.diff||0;for(var h=0,i=b.length;h<i;++h){var j=b[h];e.to<=j.from?f.push({from:j.from+g,to:j.to+g,domStart:j.domStart}):j.to<=e.from?f.push(j):(e.from>j.from&&f.push({from:j.from,to:e.from,domStart:j.domStart}),e.to<j.to&&f.push({from:e.to+g,to:j.to+g,domStart:j.domStart+(e.to-j.from)}))}b=f}var k=bP(),l=Math.min(be,Math.max(k.from-3,0)),m=Math.min(T.length,Math.max(bf,k.to+3)),n=[],o=0,p=bf-be,q=l,r=0;for(var c=0,d=b.length;c<d;++c){var j=b[c];if(j.to<=l)continue;if(j.from>=m)break;if(j.domStart>o||j.from>q)n.push({from:q,to:j.from,domSize:j.domStart-o,domStart:o}),r+=j.from-q;q=j.to,o=j.domStart+(j.to-j.from)}if(o!=p||q!=m)r+=Math.abs(m-q),n.push({from:q,to:m,domSize:p-o,domStart:o});if(!n.length)return;O.style.display="none",r>(k.to-k.from)*.3?bR(l=Math.max(k.from-10,0),m=Math.min(k.to+7,T.length)):bS(n),O.style.display="";var s=l!=be||m!=bf||bg!=u.clientHeight;be=l,bf=m,H.style.top=l*cs()+"px",s&&(bg=u.clientHeight,v.style.height=T.length*cs()+2*ct()+"px",bT());var t=cn(bk);M.style.width=t>u.clientWidth?t+"px":"";if(O.childNodes.length!=bf-be)throw new Error("BAD PATCH! "+JSON.stringify(n)+" size="+(bf-be)+" nodes="+O.childNodes.length);bU()}}function bP(){var a=cs(),b=u.scrollTop-ct();return{from:Math.min(T.length,Math.max(0,Math.floor(b/a))),to:Math.min(T.length,Math.ceil((b+u.clientHeight)/a))}}function bO(a,b,c,d){var e=cu(),g=ct(),h=cs();b+=g,d+=g,a+=e,c+=e;var i=u.clientHeight,j=u.scrollTop,k=!1,l=!0;b<j?(u.scrollTop=Math.max(0,b-2*h),k=!0):d>j+i&&(u.scrollTop=d+h-i,k=!0);var m=u.clientWidth,n=u.scrollLeft;a<n?(u.scrollLeft=Math.max(0,a-10),k=!0):c>m+n&&(u.scrollLeft=c+10-m,k=!0,c>v.clientWidth&&(l=!1)),k&&f.onScroll&&f.onScroll(bm);return l}function bN(){var a=cq(X.inverted?X.from:X.to);return bO(a.x,a.y,a.x,a.yBot)}function bM(){f.readOnly!="nocursor"&&L.focus()}function bL(){var a=[],b=Math.max(0,X.from.line-1),c=Math.min(T.length,X.to.line+2);for(var d=b;d<c;++d)a.push(T[d].text);a=L.value=a.join(q);var e=X.from.ch,f=X.to.ch;for(var d=b;d<X.from.line;++d)e+=q.length+T[d].text.length;for(var d=b;d<X.to.line;++d)f+=q.length+T[d].text.length;bi={text:a,from:b,to:c,start:e,end:f},G(L,e,Z?e:f)}function bK(){function g(a,c){var d=0;for(;;){var e=b.indexOf("\n",d);if(e==-1||(b.charAt(e-1)=="\r"?e-1:e)>=a)return{line:c,ch:a-d};++c,d=e+1}}if(!bd){var a=!1,b=L.value,c=F(L);if(!c)return!1;var a=bi.text!=b,d=Z,e=a||c.start!=bi.start||c.end!=(d?bi.start:bi.end);if(!e&&!d)return!1;if(a){Y=Z=null;if(f.readOnly){_=!0;return"changed"}}var h=g(c.start,bi.from),i=g(c.end,bi.from);if(d){h=c.start==d.anchor?i:h,i=Y?X.to:c.start==d.anchor?h:i;if(!z(h,i)){Z=null,X.inverted=!1;var j=h;h=i,i=j}}h.line==i.line&&h.line==X.from.line&&h.line==X.to.line&&!Y&&(_=!1);if(a){var k=0,l=b.length,m=Math.min(l,bi.text.length),n,o=bi.from,p=-1;while(k<m&&(n=b.charAt(k))==bi.text.charAt(k))++k,n=="\n"&&(o++,p=k);var q=p>-1?k-p:k,r=bi.to-1,s=bi.text.length;for(;;){n=bi.text.charAt(s),n=="\n"&&r--;if(b.charAt(l)!=n){++l,++s;break}if(s<=k||l<=k)break;--l,--s}var p=bi.text.lastIndexOf("\n",s-1),t=p==-1?s:s-p-1;bx({line:o,ch:q},{line:r,ch:t},E(b.slice(k,l)),h,i);if(o!=r||h.line!=o)_=!0}else bW(h,i);bi.text=b,bi.start=c.start,bi.end=c.end;return a?"changed":e?"moved":!1}}function bJ(a){function c(){cE();var d=bK();d=="moved"&&a&&(t[a]=!0),!d&&!b?(b=!0,P.set(80,c)):(bH=!1,bI()),cF()}var b=!1;bH=!0,P.set(20,c)}function bI(){bH||P.set(2e3,function(){cE(),bK(),W&&bI(),cF()})}function bG(){return bF(X.from,X.to)}function bF(a,b){var c=a.line,d=b.line;if(c==d)return T[c].text.slice(a.ch,b.ch);var e=[T[c].text.slice(a.ch)];for(var f=c+1;f<d;++f)e.push(T[f].text);e.push(T[d].text.slice(0,b.ch));return e.join("\n")}function bE(a,b,c,d){var e=a.length==1?a[0].length+b.ch:a[a.length-1].length,f=d({line:b.line+a.length-1,ch:e});bx(b,c,a,f.from,f.to)}function bD(a,b){bE(E(a),X.from,X.to,function(a){return b=="end"?{from:a,to:a}:b=="start"?{from:X.from,to:X.from}:{from:X.from,to:a}})}function bC(a,b,c){function d(d){if(z(d,b))return d;if(!z(c,d))return e;var f=d.line+a.length-(c.line-b.line)-1,g=d.ch;d.line==c.line&&(g+=a[a.length-1].length-(c.ch-(c.line==b.line?b.ch:0)));return{line:f,ch:g}}b=bZ(b),c?c=bZ(c):c=b,a=E(a);var e;bE(a,b,c,function(a){e=a;return{from:d(X.from),to:d(X.to)}});return e}function bB(a,b,c,d,e){function s(a){return a<=Math.min(b.line,b.line+q)?a:a+q}var f=!1,h=bk.length;for(var i=a.line;i<b.line;++i)if(T[i].text.length==h){f=!0;break}var j=b.line-a.line,k=T[a.line],l=T[b.line];if(k==l)if(c.length==1)k.replace(a.ch,b.ch,c[0]);else{l=k.split(b.ch,c[c.length-1]);var m=[a.line+1,j];k.replace(a.ch,k.text.length,c[0]);for(var i=1,n=c.length-1;i<n;++i)m.push(new g(c[i]));m.push(l),T.splice.apply(T,m)}else if(c.length==1)k.replace(a.ch,k.text.length,c[0]+l.text.slice(b.ch)),T.splice(a.line+1,j);else{var m=[a.line+1,j-1];k.replace(a.ch,k.text.length,c[0]),l.replace(0,b.ch,c[c.length-1]);for(var i=1,n=c.length-1;i<n;++i)m.push(new g(c[i]));T.splice.apply(T,m)}for(var i=a.line,n=i+c.length;i<n;++i){var o=T[i].text;o.length>h&&(bk=o,h=o.length,f=!1)}if(f){h=0;for(var i=0,n=T.length;i<n;++i){var o=T[i].text;o.length>h&&(h=o.length,bk=o)}}var p=[],q=c.length-j-1;for(var i=0,o=U.length;i<o;++i){var r=U[i];r<a.line?p.push(r):r>b.line&&p.push(r+q)}c.length&&p.push(a.line),U=p,cD(100),ba.push({from:a.line,to:b.line+1,diff:q}),bb={from:a,to:b,text:c},bW(d,e,s(X.from.line),s(X.to.line)),v.style.height=T.length*cs()+2*ct()+"px"}function bA(){by(V.undone,V.done)}function bz(){by(V.done,V.undone)}function by(a,b){var c=a.pop();if(c){var d=[],e=c.start+c.added;for(var f=c.start;f<e;++f)d.push(T[f].text);b.push({start:c.start,added:c.old.length,old:d});var g=bZ({line:c.start+c.old.length-1,ch:C(d[d.length-1],c.old[c.old.length-1])});bB({line:c.start,ch:0},{line:e-1,ch:T[e-1].text.length},c.old,g,g)}}function bx(a,b,c,d,e){if(V){var g=[];for(var h=a.line,i=b.line+1;h<i;++h)g.push(T[h].text);V.addChange(a.line,c.length,g);while(V.done.length>f.undoDepth)V.done.shift()}bB(a,b,c,d,e)}function bw(){W&&f.onBlur&&f.onBlur(bm),clearInterval(R),Y=null,W=!1,u.className=u.className.replace(" CodeMirror-focused","")}function bv(){f.readOnly!="nocursor"&&(!W&&f.onFocus&&f.onFocus(bm),W=!0,bI(),u.className.search(/\bCodeMirror-focused\b/)==-1&&(u.className+=" CodeMirror-focused"),cx())}function bu(a){if(!f.onKeyEvent||!f.onKeyEvent(bm,k(a.e))){if(f.electricChars&&S.electricChars){var b=String.fromCharCode(a.e.charCode==null?a.e.keyCode:a.e.charCode);S.electricChars.indexOf(b)>-1&&setTimeout(cH(function(){cf(X.to.line,"smart")}),50)}var c=a.e.keyCode;c==13?(f.readOnly||cd(),a.stop()):!a.e.ctrlKey&&!a.e.altKey&&!a.e.metaKey&&c==9&&f.tabMode!="default"?a.stop():bJ(bh)}}function bt(a){if(!f.onKeyEvent||!f.onKeyEvent(bm,k(a.e)))Z&&(Z=null,_=!0),a.e.keyCode==16&&(Y=null)}function bs(a){W||bv();var b=a.e.keyCode,c=(s?a.e.metaKey:a.e.ctrlKey)&&!a.e.altKey,d=a.e.ctrlKey||a.e.altKey||a.e.metaKey;b==16||a.e.shiftKey?Y=Y||(X.inverted?X.to:X.from):Y=null;if(!f.onKeyEvent||!f.onKeyEvent(bm,k(a.e))){if(b==33||b==34){b$(b==34);return a.stop()}if(c&&(b==36||b==35||s&&(b==38||b==40))){b_(b==36||b==38);return a.stop()}if(c&&b==65){ca();return a.stop()}if(!f.readOnly){if(!d&&b==13)return;if(!d&&b==9&&ce(a.e.shiftKey))return a.stop();if(c&&b==90){bz();return a.stop()}if(c&&(a.e.shiftKey&&b==90||b==89)){bA();return a.stop()}}bh=(c?"c":"")+b;if(X.inverted&&t.hasOwnProperty(bh)){var e=F(L);e&&(Z={anchor:e.start},G(L,e.start,e.start))}bJ(bh)}}function br(a){var b=cv(a,!0),c=a.e.dataTransfer.files;if(!!b&&!f.readOnly)if(c&&c.length&&window.FileReader&&window.File){var d=c.length,e=Array(d),g=0;for(var h=0;h<d;++h)i(c[h],h);function i(a,c){var f=new FileReader;f.onload=function(){e[c]=f.result,++g==d&&bC(e.join(""),bZ(b),bZ(b))},f.readAsText(a)}}else try{var e=a.e.dataTransfer.getData("Text");e&&bC(e,b,b)}catch(a){}}function bq(a){var b=cv(a);!b||(cb(b),a.stop(),$=+(new Date))}function bp(a){function i(a){var b=cv(a,!0);if(b&&!y(b,e)){W||bv(),e=b,bV(d,b),_=!1;var c=bP();if(b.line>=c.to||b.line<c.from)g=setTimeout(cH(function(){i(a)}),150)}}function h(){bM(),_=!0,j(),k()}var b=$;$=null;for(var c=a.target();c!=u;c=c.parentNode)if(c.parentNode==J){f.onGutterClick&&f.onGutterClick(bm,D(J.childNodes,c)+be);return a.stop()}p&&a.button()==3&&cw(a);if(a.button()==1){var d=cv(a),e=d,g;if(!d){a.target()==u&&a.stop();return}W||bv(),a.stop();if(b&&+(new Date)-b<400)return cc(d.line);bX(d.line,d.ch,!0);var j=m(l,"mousemove",cH(function(a){clearTimeout(g),a.stop(),i(a)}),!0),k=m(l,"mouseup",cH(function(a){clearTimeout(g);var b=cv(a);b&&bV(d,b),a.stop(),h()}),!0)}}function bo(a){var b=[];for(var c=0,d=T.length;c<d;++c)b.push(T[c].text);return b.join("\n")}function bn(a){V=null;var b={line:0,ch:0};bx(b,{line:T.length-1,ch:T[T.length-1].text.length},E(a),b,b),V=new i}function bl(a){return a>=0&&a<T.length}var f={},h=a.defaults;for(var j in h)h.hasOwnProperty(j)&&(f[j]=(c&&c.hasOwnProperty(j)?c:h)[j]);var l=f.document,u=l.createElement("div");u.className="CodeMirror",window.ActiveXObject&&/MSIE [1-7]\b/.test(navigator.userAgent)&&(u.style.position="relative"),u.innerHTML='<div style="position: relative"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"></div><div style="position: relative"><div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div style="overflow: hidden; position: absolute; width: 1px; height: 0; left: 0"><textarea style="position: absolute; width: 100000px;" wrap="off"></textarea></div><div class="CodeMirror-lines"><div style="position: relative"><pre class="CodeMirror-cursor">&#160;</pre><div></div></div></div></div></div>',b.appendChild?b.appendChild(u):b(u);var v=u.firstChild,B=v.firstChild,H=B.nextSibling,I=H.firstChild,J=I.firstChild,K=I.nextSibling,L=K.firstChild,M=K.nextSibling.firstChild,N=M.firstChild,O=N.nextSibling;f.tabindex!=null&&(L.tabindex=f.tabindex),!f.gutter&&!f.lineNumbers&&(I.style.display="none");var P=new n,Q=new n,R,S,T=[new g("")],U,V=new i,W;cg();var X={from:{line:0,ch:0},to:{line:0,ch:0},inverted:!1},Y,Z,$,_,ba,bb,bc,bd,be=0,bf=0,bg=0,bh=null,bi,bj,bk="";cH(function(){bn(f.value||""),_=!1})(),setTimeout(bL,20),m(u,"mousedown",cH(bp)),p||m(u,"contextmenu",cH(cw)),m(v,"dblclick",cH(bq)),m(u,"scroll",function(){bQ([]),f.onScroll&&f.onScroll(bm)}),m(window,"resize",function(){bQ(!0)}),m(L,"keyup",cH(bt)),m(L,"keydown",cH(bs)),m(L,"keypress",cH(bu)),m(L,"focus",bv),m(L,"blur",bw),m(u,"dragenter",function(a){a.stop()}),m(u,"dragover",function(a){a.stop()}),m(u,"drop",cH(br)),m(u,"paste",function(){bM(),bJ()}),m(L,"paste",function(){bJ()}),m(L,"cut",function(){bJ()}),l.activeElement==L?bv():bw();var bm={getValue:bo,setValue:cH(bn),getSelection:bG,replaceSelection:cH(bD),focus:function(){bM(),bv(),bJ()},setOption:function(a,b){f[a]=b,a=="lineNumbers"||a=="gutter"?ch():a=="mode"||a=="indentUnit"?cg():a=="readOnly"&&b=="nocursor"&&L.blur()},getOption:function(a){return f[a]},undo:cH(bz),redo:cH(bA),indentLine:cH(function(a){bl(a)&&cf(a,"smart")}),historySize:function(){return{undo:V.done.length,redo:V.undone.length}},matchBrackets:cH(function(){cz(!0)}),getTokenAt:function(a){a=bZ(a);return T[a.line].getTokenAt(S,cB(a.line),a.ch)},cursorCoords:function(a){a==null&&(a=X.inverted);return cr(a?X.from:X.to)},charCoords:function(a){return cr(bZ(a))},coordsChar:function(a){var b=w(M),c=bY(Math.min(T.length-1,be+Math.floor((a.y-b.top)/cs())));return bZ({line:c,ch:cp(bY(c),a.x-b.left)})},getSearchCursor:function(a,b,c){return new cI(a,b,c)},markText:cH(function(a,b,c){return cH(ci(a,b,c))}),setMarker:cj,clearMarker:ck,setLineClass:cH(cl),lineInfo:cm,addWidget:function(a,b,c){var a=cq(bZ(a),!0);b.style.top=be*cs()+a.yBot+ct()+"px",b.style.left=a.x+cu()+"px",v.appendChild(b),c&&bO(a.x,a.yBot,a.x+b.offsetWidth,a.yBot+b.offsetHeight)},lineCount:function(){return T.length},getCursor:function(a){a==null&&(a=X.inverted);return A(a?X.from:X.to)},somethingSelected:function(){return!y(X.from,X.to)},setCursor:cH(function(a,b){b==null&&typeof a.line=="number"?bX(a.line,a.ch):bX(a,b)}),setSelection:cH(function(a,b){bW(bZ(a),bZ(b||a))}),getLine:function(a){if(bl(a))return T[a].text},setLine:cH(function(a,b){bl(a)&&bC(b,{line:a,ch:0},{line:a,ch:T[a].text.length})}),removeLine:cH(function(a){bl(a)&&bC("",{line:a,ch:0},bZ({line:a+1,ch:0}))}),replaceRange:cH(bC),getRange:function(a,b){return bF(bZ(a),bZ(b))},operation:function(a){return cH(a)()},refresh:function(){bQ(!0)},getInputField:function(){return L},getWrapperElement:function(){return u}},bH=!1,cy={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<"},cG=0;cI.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(a){function d(a){var c={line:a,ch:0};b.pos={from:c,to:c},b.atOccurrence=!1;return!1}var b=this,c=bZ(a?this.pos.from:this.pos.to);for(;;){if(this.pos=this.matches(a,c)){this.atOccurrence=!0;return this.pos.match||!0}if(a){if(!c.line)return d(0);c={line:c.line-1,ch:T[c.line-1].text.length}}else{if(c.line==T.length-1)return d(T.length);c={line:c.line+1,ch:0}}}},from:function(){if(this.atOccurrence)return A(this.pos.from)},to:function(){if(this.atOccurrence)return A(this.pos.to)}};return bm}a.defaults={value:"",mode:null,indentUnit:2,indentWithTabs:!1,tabMode:"classic",enterMode:"indent",electricChars:!0,onKeyEvent:null,lineNumbers:!1,gutter:!1,firstLineNumber:1,readOnly:!1,onChange:null,onCursorActivity:null,onGutterClick:null,onHighlightComplete:null,onFocus:null,onBlur:null,onScroll:null,matchBrackets:!1,workTime:100,workDelay:200,undoDepth:40,tabindex:null,document:window.document};var b={},c={};a.defineMode=function(c,d){!a.defaults.mode&&c!="null"&&(a.defaults.mode=c),b[c]=d},a.defineMIME=function(a,b){c[a]=b},a.getMode=function(d,e){typeof e=="string"&&c.hasOwnProperty(e)&&(e=c[e]);if(typeof e=="string")var f=e,g={};else if(e!=null)var f=e.name,g=e;var h=b[f];if(!h){window.console&&console.warn("No mode "+f+" found, falling back to plain text.");return a.getMode(d,"text/plain")}return h(d,g||{})},a.listModes=function(){var a=[];for(var c in b)b.propertyIsEnumerable(c)&&a.push(c);return a},a.listMIMEs=function(){var a=[];for(var b in c)c.propertyIsEnumerable(b)&&a.push(b);return a},a.fromTextArea=function(b,c){function d(){b.value=h.getValue()}c||(c={}),c.value=b.value,!c.tabindex&&b.tabindex&&(c.tabindex=b.tabindex);if(b.form){var e=m(b.form,"submit",d,!0);if(typeof b.form.submit=="function"){var f=b.form.submit;function g(){d(),b.form.submit=f,b.form.submit(),b.form.submit=g}b.form.submit=g}}b.style.display="none";var h=a(function(a){b.parentNode.insertBefore(a,b.nextSibling)},c);h.save=d,h.toTextArea=function(){d(),b.parentNode.removeChild(h.getWrapperElement()),b.style.display="",b.form&&(e(),typeof b.form.submit=="function"&&(b.form.submit=f))};return h},a.startState=e,a.copyState=d,f.prototype={eol:function(){return this.pos>=this.string.length},sol:function(){return this.pos==0},peek:function(){return this.string.charAt(this.pos)},next:function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},eat:function(a){var b=this.string.charAt(this.pos);if(typeof a=="string")var c=b==a;else var c=b&&(a.test?a.test(b):a(b));if(c){++this.pos;return b}},eatWhile:function(a){var b=this.start;while(this.eat(a));return this.pos>b},eatSpace:function(){var a=this.pos;while(/[\s\u00a0]/.test(this.string.charAt(this.pos)))++this.pos;return this.pos>a},skipToEnd:function(){this.pos=this.string.length},skipTo:function(a){var b=this.string.indexOf(a,this.pos);if(b>-1){this.pos=b;return!0}},backUp:function(a){this.pos-=a},column:function(){return v(this.string,this.start)},indentation:function(){return v(this.string)},match:function(a,b,c){if(typeof a!="string"){var e=this.string.slice(this.pos).match(a);e&&b!==!1&&(this.pos+=e[0].length);return e}function d(a){return c?a.toLowerCase():a}if(d(this.string).indexOf(d(a),this.pos)==this.pos){b!==!1&&(this.pos+=a.length);return!0}},current:function(){return this.string.slice(this.start,this.pos)}},g.prototype={replace:function(a,b,c){var d=[],e=this.marked;h(0,a,this.styles,d),c&&d.push(c,null),h(b,this.text.length,this.styles,d),this.styles=d,this.text=this.text.slice(0,a)+c+this.text.slice(b),this.stateAfter=null;if(e){var f=c.length-(b-a),g=this.text.length;function i(a){return a<=Math.min(b,b+f)?a:a+f}for(var j=0;j<e.length;++j){var k=e[j],l=!1;k.from>=g?l=!0:(k.from=i(k.from),k.to!=null&&(k.to=i(k.to)));if(l||k.from>=k.to)e.splice(j,1),j--}}},split:function(a,b){var c=[b,null];h(a,this.text.length,this.styles,c);return new g(b+this.text.slice(a),c)},addMark:function(a,b,c){var d=this.marked,e={from:a,to:b,style:c};this.marked==null&&(this.marked=[]),this.marked.push(e),this.marked.sort(function(a,b){return a.from-b.from});return e},removeMark:function(a){var b=this.marked;if(!!b)for(var c=0;c<b.length;++c)if(b[c]==a){b.splice(c,1);break}},highlight:function(a,b){var c=new f(this.text),d=this.styles,e=0,g=!1,h=d[0],i;this.text==""&&a.blankLine&&a.blankLine(b);while(!c.eol()){var j=a.token(c,b),k=this.text.slice(c.start,c.pos);c.start=c.pos,e&&d[e-1]==j?d[e-2]+=k:k&&(!g&&(d[e+1]!=j||e&&d[e-2]!=i)&&(g=!0),d[e++]=k,d[e++]=j,i=h,h=d[e]);if(c.pos>5e3){d[e++]=this.text.slice(c.pos),d[e++]=null;break}}d.length!=e&&(d.length=e,g=!0),e&&d[e-2]!=i&&(g=!0);return g},getTokenAt:function(a,b,c){var d=this.text,e=new f(d);while(e.pos<c&&!e.eol()){e.start=e.pos;var g=a.token(e,b)}return{start:e.start,end:e.pos,string:e.current(),className:g||null,state:b}},indentation:function(){return v(this.text)},getHTML:function(a,b,c,d){function f(a,b){!a||(b?e.push('<span class="',b,'">',B(a),"</span>"):e.push(B(a)))}var e=[];c&&e.push(this.className?'<pre class="'+this.className+'">':"<pre>");var g=this.styles,h=this.text,i=this.marked;a==b&&(a=null);var j=h.length;d!=null&&(j=Math.min(d,j));if(!h&&d==null)f(" ",a!=null&&b==null?"CodeMirror-selected":null);else if(!i&&a==null)for(var k=0,l=0;l<j;k+=2){var m=g[k],n=m.length;l+n>j&&(m=m.slice(0,j-l)),l+=n,f(m,g[k+1])}else{var o=0,k=0,p="",q,r=0,s=-1,t=null;function u(){i&&(s+=1,t=s<i.length?i[s]:null)}u();while(o<j){var v=j,w="";if(a!=null)if(a>o)v=a;else if(b==null||b>o)w=" CodeMirror-selected",b!=null&&(v=Math.min(v,b));while(t&&t.to!=null&&t.to<=o)u();t&&(t.from>o?v=Math.min(v,t.from):(w+=" "+t.style,t.to!=null&&(v=Math.min(v,t.to))));for(;;){var x=o+p.length,y=q;w&&(y=q?q+w:w),f(x>v?p.slice(0,v-o):p,y);if(x>=v){p=p.slice(v-o),o=v;break}o=x,p=g[k++],q=g[k++]}}a!=null&&b==null&&f(" ","CodeMirror-selected")}c&&e.push("</pre>");return e.join("")}},i.prototype={addChange:function(a,b,c){this.undone.length=0;var d=+(new Date),e=this.done[this.done.length-1];if(d-this.time>400||!e||e.start>a+b||e.start+e.added<a-e.added+e.old.length)this.done.push({start:a,added:b,old:c});else{var f=0;if(a<e.start){for(var g=e.start-a-1;g>=0;--g)e.old.unshift(c[g]);e.added+=e.start-a,e.start=a}else e.start<a&&(f=a-e.start,b+=f);for(var g=e.added-f,h=c.length;g<h;++g)e.old.push(c[g]);e.added<b&&(e.added=b)}this.time=d}},l.prototype={stop:function(){j.call(this.e)},target:function(){return this.e.target||this.e.srcElement},button:function(){if(this.e.which)return this.e.which;if(this.e.button&1)return 1;if(this.e.button&2)return 3;if(this.e.button&4)return 2},pageX:function(){if(this.e.pageX!=null)return this.e.pageX;var a=this.target().ownerDocument;return this.e.clientX+a.body.scrollLeft+a.documentElement.scrollLeft},pageY:function(){if(this.e.pageY!=null)return this.e.pageY;var a=this.target().ownerDocument;return this.e.clientY+a.body.scrollTop+a.documentElement.scrollTop}},n.prototype={set:function(a,b){clearTimeout(this.id),this.id=setTimeout(b,a)}};var o=function(){var a=document.createElement("pre");a.innerHTML=" ";return!a.innerHTML}(),p=/gecko\/\d{7}/i.test(navigator.userAgent),q="\n";(function(){var a=document.createElement("textarea");a.value="foo\nbar",a.value.indexOf("\r")>-1&&(q="\r\n")})();var r=8,s=/Mac/.test(navigator.platform),t={};for(var u=35;u<=40;++u)t[u]=t["c"+u]=!0;if("\n\nb".split(/\n/).length!=3)var E=function(a){var b=0,c,d=[];while((c=a.indexOf("\n",b))>-1)d.push(a.slice(b,a.charAt(c-1)=="\r"?c-1:c)),b=c+1;d.push(a.slice(b));return d};else var E=function(a){return a.split(/\r?\n/)};if(window.getSelection)var F=function(a){try{return{start:a.selectionStart,end:a.selectionEnd}}catch(b){return null}},G=function(a,b,c){try{a.setSelectionRange(b,c)}catch(d){}};else var F=function(a){try{var b=a.ownerDocument.selection.createRange()}catch(c){return null}if(!b||b.parentElement()!=a)return null;var d=a.value,e=d.length,f=a.createTextRange();f.moveToBookmark(b.getBookmark());var g=a.createTextRange();g.collapse(!1);if(f.compareEndPoints("StartToEnd",g)>-1)return{start:e,end:e};var h=-f.moveStart("character",-e);for(var i=d.indexOf("\r");i>-1&&i<h;i=d.indexOf("\r",i+1),h++);if(f.compareEndPoints("EndToEnd",g)>-1)return{start:h,end:e};var j=-f.moveEnd("character",-e);for(var i=d.indexOf("\r");i>-1&&i<j;i=d.indexOf("\r",i+1),j++);return{start:h,end:j}},G=function(a,b,c){var d=a.createTextRange();d.collapse(!0);var e=d.duplicate(),f=0,g=a.value;for(var h=g.indexOf("\n");h>-1&&h<b;h=g.indexOf("\n",h+1))++f;d.move("character",b-f);for(;h>-1&&h<c;h=g.indexOf("\n",h+1))++f;e.move("character",c-f),d.setEndPoint("EndToEnd",e),d.select()};a.defineMode("null",function(){return{token:function(a){a.skipToEnd()}}}),a.defineMIME("text/plain","null");return a}();CodeMirror.defineMode("javascript",function(a,b){function R(a,b){if(a=="variable"){v(b);return u()}}function Q(a,b){if(a=="variable"){v(b);return u(Q)}if(a=="(")return u(z(")"),x,I(R,")"),A,C,y)}function P(a){a!=")"&&u(D)}function O(a,b){if(a==";")return u(P);if(b=="in")return u(D);return u(D,B(";"),P)}function N(a,b){if(b=="in")return u(D);return u(E,O)}function M(a){if(a=="var")return u(K,O);if(a==";")return t(O);if(a=="variable")return u(N);return t(O)}function L(a,b){if(b=="=")return u(D,L);if(a==",")return u(K)}function K(a,b){if(a=="variable"){v(b);return u(L)}return u()}function J(a){if(a=="}")return u();return t(C,J)}function I(a,b){function c(d){if(d==",")return u(a,c);if(d==b)return u();return u(B(b))}return function(d){return d==b?u():t(a,c)}}function H(a){a=="variable"&&(s.marked="js-property");if(o.hasOwnProperty(a))return u(B(":"),D)}function G(a){if(a=="variable"){s.marked="js-property";return u()}}function F(a){if(a==":")return u(A,C);return t(E,B(";"),A)}function E(a,b){if(a=="operator"&&/\+\+|--/.test(b))return u(E);if(a=="operator")return u(D);if(a!=";"){if(a=="(")return u(z(")"),I(D,")"),A,E);if(a==".")return u(G,E);if(a=="[")return u(z("]"),D,B("]"),A,E)}}function D(a){if(o.hasOwnProperty(a))return u(E);if(a=="function")return u(Q);if(a=="keyword c")return u(D);if(a=="(")return u(z(")"),D,B(")"),A,E);if(a=="operator")return u(D);if(a=="[")return u(z("]"),I(D,"]"),A,E);if(a=="{")return u(z("}"),I(H,"}"),A,E);return u()}function C(a){if(a=="var")return u(z("vardef"),K,B(";"),A);if(a=="keyword a")return u(z("form"),D,C,A);if(a=="keyword b")return u(z("form"),C,A);if(a=="{")return u(z("}"),J,A);if(a==";")return u();if(a=="function")return u(Q);if(a=="for")return u(z("form"),B("("),z(")"),M,B(")"),A,C,A);if(a=="variable")return u(z("stat"),F);if(a=="switch")return u(z("form"),D,z("}","switch"),B("{"),J,A,A);if(a=="case")return u(D,B(":"));if(a=="default")return u(B(":"));if(a=="catch")return u(z("form"),x,B("("),R,B(")"),C,A,y);return t(z("stat"),D,B(";"),A)}function B(a){return function(b){return b==a?u():a==";"?t():u(arguments.callee)}}function A(){var a=s.state;a.lexical.prev&&(a.lexical.type==")"&&(a.indented=a.lexical.indented),a.lexical=a.lexical.prev)}function z(a,b){var c=function(){var c=s.state;c.lexical=new p(c.indented,s.stream.column(),a,null,c.lexical,b)};c.lex=!0;return c}function y(){s.state.localVars=s.state.context.vars,s.state.context=s.state.context.prev}function x(){s.state.context||(s.state.localVars=w),s.state.context={prev:s.state.context,vars:s.state.localVars}}function v(a){var b=s.state;if(b.context){s.marked="js-variabledef";for(var c=b.localVars;c;c=c.next)if(c.name==a)return;b.localVars={name:a,next:b.localVars}}}function u(){t.apply(null,arguments);return!0}function t(){for(var a=arguments.length-1;a>=0;a--)s.cc.push(arguments[a])}function r(a,b,c,e,f){var g=a.cc;s.state=a,s.stream=f,s.marked=null,s.cc=g,a.lexical.hasOwnProperty("align")||(a.lexical.align=!0);for(;;){var h=g.length?g.pop():d?D:C;if(h(c,e)){while(g.length&&g[g.length-1].lex)g.pop()();if(s.marked)return s.marked;if(c=="variable"&&q(a,e))return"js-localvariable";return b}}}function q(a,b){for(var c=a.localVars;c;c=c.next)if(c.name==b)return!0}function p(a,b,c,d,e,f){this.indented=a,this.column=b,this.type=c,this.prev=e,this.info=f,d!=null&&(this.align=d)}function n(a,b){var c=!1,d;while(d=a.next()){if(d=="/"&&c){b.tokenize=l;break}c=d=="*"}return k("comment","js-comment")}function m(a){return function(b,c){h(b,a)||(c.tokenize=l);return k("string","js-string")}}function l(a,b){var c=a.next();if(c=='"'||c=="'")return g(a,b,m(c));if(/[\[\]{}\(\),;\:\.]/.test(c))return k(c);if(c=="0"&&a.eat(/x/i)){a.eatWhile(/[\da-f]/i);return k("number","js-atom")}if(/\d/.test(c)){a.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/);return k("number","js-atom")}if(c=="/"){if(a.eat("*"))return g(a,b,n);if(a.eat("/")){a.skipToEnd();return k("comment","js-comment")}if(b.reAllowed){h(a,"/"),a.eatWhile(/[gimy]/);return k("regexp","js-string")}a.eatWhile(f);return k("operator",null,a.current())}if(f.test(c)){a.eatWhile(f);return k("operator",null,a.current())}a.eatWhile(/[\w\$_]/);var d=a.current(),i=e.propertyIsEnumerable(d)&&e[d];return i?k(i.type,i.style,d):k("variable","js-variable",d)}function k(a,b,c){i=a,j=c;return b}function h(a,b){var c=!1,d;while((d=a.next())!=null){if(d==b&&!c)return!1;c=!c&&d=="\\"}return c}function g(a,b,c){b.tokenize=c;return c(a,b)}var c=a.indentUnit,d=b.json,e=function(){function a(a){return{type:a,style:"js-keyword"}}var b=a("keyword a"),c=a("keyword b"),d=a("keyword c"),e=a("operator"),f={type:"atom",style:"js-atom"};return{"if":b,"while":b,"with":b,"else":c,"do":c,"try":c,"finally":c,"return":d,"break":d,"continue":d,"new":d,"delete":d,"throw":d,"var":a("var"),"function":a("function"),"catch":a("catch"),"for":a("for"),"switch":a("switch"),"case":a("case"),"default":a("default"),"in":e,"typeof":e,"instanceof":e,"true":f,"false":f,"null":f,"undefined":f,NaN:f,Infinity:f}}(),f=/[+\-*&%=<>!?|]/,i,j,o={atom:!0,number:!0,variable:!0,string:!0,regexp:!0},s={state:null,column:null,marked:null,cc:null},w={name:"this",next:{name:"arguments"}};A.lex=!0;return{startState:function(a){return{tokenize:l,reAllowed:!0,cc:[],lexical:new p((a||0)-c,0,"block",!1),localVars:null,context:null,indented:0}},token:function(a,b){a.sol()&&(b.lexical.hasOwnProperty("align")||(b.lexical.align=!1),b.indented=a.indentation());if(a.eatSpace())return null;var c=b.tokenize(a,b);if(i=="comment")return c;b.reAllowed=i=="operator"||i=="keyword c"||i.match(/^[\[{}\(,;:]$/);return r(b,c,i,j,a)},indent:function(a,b){if(a.tokenize!=l)return 0;var d=b&&b.charAt(0),e=a.lexical,f=e.type,g=d==f;return f=="vardef"?e.indented+4:f=="form"&&d=="{"?e.indented:f=="stat"||f=="form"?e.indented+c:e.info=="switch"&&!g?e.indented+(/^(?:case|default)\b/.test(b)?c:2*c):e.align?e.column+(g?0:1):e.indented+(g?0:c)},electricChars:":{}"}}),CodeMirror.defineMIME("text/javascript","javascript"),CodeMirror.defineMIME("application/json",{name:"javascript",json:!0}),CodeMirror.defineMode("xml",function(a,b){function v(a){if(a=="xml-word"&&d.allowUnquoted){m="xml-attribute";return o()}if(a=="xml-attribute")return o();return n()}function u(a){if(a=="xml-word"){m="xml-attname";return o(u)}if(a=="equals")return o(v,u);return n()}function t(a){if(a=="endTag")return o();return n()}function s(a){return function(b){if(b=="selfcloseTag"||b=="endTag"&&d.autoSelfClosers.hasOwnProperty(l.tagName.toLowerCase()))return o();if(b=="endTag"){p(l.tagName,a);return o()}return o()}}function r(a){if(a=="openTag"){l.tagName=f;return o(u,s(l.startOfLine))}if(a=="closeTag"){q();return o(t)}if(a=="xml-cdata"){(!l.context||l.context.name!="!cdata")&&p("!cdata"),l.tokenize==h&&q();return o()}return o()}function q(){l.context&&(l.context=l.context.prev)}function p(a,b){var c=d.doNotIndent.hasOwnProperty(a)||l.context&&l.context.noIndent;l.context={prev:l.context,tagName:a,indent:l.indented,startOfLine:b,noIndent:c}}function o(){n.apply(null,arguments);return!0}function n(){for(var a=arguments.length-1;a>=0;a--)l.cc.push(arguments[a])}function k(a,b){return function(c,d){while(!c.eol()){if(c.match(b)){d.tokenize=h;break}c.next()}return a}}function j(a){return function(b,c){while(!b.eol())if(b.next()==a){c.tokenize=i;break}return"xml-attribute"}}function i(a,b){var c=a.next();if(c==">"||c=="/"&&a.eat(">")){b.tokenize=h,g=c==">"?"endTag":"selfcloseTag";return"xml-tag"}if(c=="="){g="equals";return null}if(/[\'\"]/.test(c)){b.tokenize=j(c);return b.tokenize(a,b)}a.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);return"xml-word"}function h(a,b){function c(c){b.tokenize=c;return c(a,b)}var d=a.next();if(d=="<"){if(a.eat("!")){if(a.eat("["))return a.match("CDATA[")?c(k("xml-cdata","]]>")):null;if(a.match("--"))return c(k("xml-comment","-->"));if(a.match("DOCTYPE")){a.eatWhile(/[\w\._\-]/);return c(k("xml-doctype",">"))}return null}if(a.eat("?")){a.eatWhile(/[\w\._\-]/),b.tokenize=k("xml-processing","?>");return"xml-processing"}g=a.eat("/")?"closeTag":"openTag",a.eatSpace(),f="";var e;while(e=a.eat(/[^\s\u00a0=<>\"\'\/?]/))f+=e;b.tokenize=i;return"xml-tag"}if(d=="&"){a.eatWhile(/[^;]/),a.eat(";");return"xml-entity"}a.eatWhile(/[^&<]/);return null}var c=a.indentUnit,d=b.htmlMode?{autoSelfClosers:{br:!0,img:!0,hr:!0,link:!0,input:!0,meta:!0,col:!0,frame:!0,base:!0,area:!0},doNotIndent:{pre:!0,"!cdata":!0},allowUnquoted:!0}:{autoSelfClosers:{},doNotIndent:{"!cdata":!0},allowUnquoted:!1},e=b.alignCDATA,f,g,l,m;return{startState:function(){return{tokenize:h,cc:[],indented:0,startOfLine:!0,tagName:null,context:null}},token:function(a,b){a.sol()&&(b.startOfLine=!0,b.indented=a.indentation());if(a.eatSpace())return null;m=g=f=null;var c=b.tokenize(a,b);if((c||g)&&c!="xml-comment"){l=b;for(;;){var d=b.cc.pop()||r;if(d(g||c))break}}b.startOfLine=!1;return m||c},indent:function(a,b){var d=a.context;if(d&&d.noIndent)return 0;if(e&&/<!\[CDATA\[/.test(b))return 0;d&&/^<\//.test(b)&&(d=d.prev);while(d&&!d.startOfLine)d=d.prev;return d?d.indent+c:0},electricChars:"/"}}),CodeMirror.defineMIME("application/xml","xml"),CodeMirror.defineMIME("text/html",{name:"xml",htmlMode:!0}),CodeMirror.defineMode("css",function(a){function h(a){return function(b,c){var f=!1,g;while((g=b.next())!=null){if(g==a&&!f)break;f=!f&&g=="\\"}f||(c.tokenize=e);return d("css-string","string")}}function g(a,b){var c=0,f;while((f=a.next())!=null){if(c>=2&&f==">"){b.tokenize=e;break}c=f=="-"?c+1:0}return d("css-comment","comment")}function f(a,b){var c=!1,f;while((f=a.next())!=null){if(c&&f=="/"){b.tokenize=e;break}c=f=="*"}return d("css-comment","comment")}function e(a,b){var c=a.next();if(c=="@"){a.eatWhile(/\w/);return d("css-at",a.current())}if(c=="/"&&a.eat("*")){b.tokenize=f;return f(a,b)}if(c=="<"&&a.eat("!")){b.tokenize=g;return g(a,b)}if(c=="=")d(null,"compare");else{if(c!="~"&&c!="|"||!a.eat("=")){if(c=='"'||c=="'"){b.tokenize=h(c);return b.tokenize(a,b)}if(c=="#"){a.eatWhile(/\w/);return d("css-selector","hash")}if(c=="!"){a.match(/^\s*\w*/);return d("css-important","important")}if(/\d/.test(c)){a.eatWhile(/[\w.%]/);return d("css-unit","unit")}if(/[,.+>*\/]/.test(c))return d(null,"select-op");if(/[;{}:\[\]]/.test(c))return d(null,c);a.eatWhile(/[\w\\\-_]/);return d("css-identifier","identifier")}return d(null,"compare")}}function d(a,b){c=b;return a}var b=a.indentUnit,c;return{startState:function(a){return{tokenize:e,baseIndent:a||0,stack:[]}},token:function(a,b){if(a.eatSpace())return null;var d=b.tokenize(a,b),e=b.stack[b.stack.length-1];if(c=="hash"&&e=="rule")d="css-colorcode";else if(d=="css-identifier")if(e=="rule")d="css-value";else if(!e||e=="@media{")d="css-selector";e=="rule"&&/^[\{\};]$/.test(c)&&b.stack.pop(),c=="{"?e=="@media"?b.stack[b.stack.length-1]="@media{":b.stack.push("{"):c=="}"?b.stack.pop():c=="@media"?b.stack.push("@media"):e!="rule"&&e!="@media"&&c!="comment"&&b.stack.push("rule");return d},indent:function(a,c){var d=a.stack.length;/^\}/.test(c)&&(d-=a.stack[a.stack.length-1]=="rule"?2:1);return a.baseIndent+d*b},electricChars:"}"}}),CodeMirror.defineMIME("text/css","css"),CodeMirror.defineMode("htmlmixed",function(a,b){function i(a,b){if(a.match(/^<\/\s*style\s*>/i,!1)){b.token=f,b.localState=null;return f(a,b)}return g(a,/<\/\s*style\s*>/,e.token(a,b.localState))}function h(a,b){if(a.match(/^<\/\s*script\s*>/i,!1)){b.token=f,b.curState=null;return f(a,b)}return g(a,/<\/\s*script\s*>/,d.token(a,b.localState))}function g(a,b,c){var d=a.current(),e=d.search(b);e>-1&&a.backUp(d.length-e);return c}function f(a,b){var f=c.token(a,b.htmlState);f=="xml-tag"&&a.current()==">"&&b.htmlState.context&&(/^script$/i.test(b.htmlState.context.tagName)?(b.token=h,b.localState=d.startState(c.indent(b.htmlState,""))):/^style$/i.test(b.htmlState.context.tagName)&&(b.token=i,b.localState=e.startState(c.indent(b.htmlState,""))));return f}var c=CodeMirror.getMode(a,{name:"xml",htmlMode:!0}),d=CodeMirror.getMode(a,"javascript"),e=CodeMirror.getMode(a,"css");return{startState:function(){var a=c.startState();return{token:f,localState:null,htmlState:a}},copyState:function(a){if(a.localState)var b=CodeMirror.copyState(a.token==i?e:d,a.localState);return{token:a.token,localState:b,htmlState:CodeMirror.copyState(c,a.htmlState)}},token:function(a,b){return b.token(a,b)},indent:function(a,b){return a.token==f||/^\s*<\//.test(b)?c.indent(a.htmlState,b):a.token==h?d.indent(a.localState,b):e.indent(a.localState,b)},electricChars:"/{}:"}}),CodeMirror.defineMIME("text/html","htmlmixed")
js/tiny_mce/plugins/codemagic/langs/cs.js ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ tinyMCE.addI18n('cs.codemagic',{
2
+ editor_button: "Upravit HTML kód"
3
+ });
js/tiny_mce/plugins/codemagic/langs/cs_dlg.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tinyMCE.addI18n('cs.codemagic',{
2
+ code_title: "CodeMagic - zvýraznení syntaxe a formátování kódu",
3
+ code_label: "Editovat kód",
4
+ toggle_highlighting: "Zvýraznení kódu",
5
+ toggle_autocompletion: "Doplňování kódu",
6
+ search: "Hledat",
7
+ replace: "Nahradit",
8
+ undo: "Zpět",
9
+ redo: "Opakovat",
10
+ search_replace: "Hledat a nahradit",
11
+ reintendt: "Zformátovat kód",
12
+ nothing_found: "Hledaný výraz nebyl nalezen.",
13
+ nothing_to_replace: "Není co nahradit."
14
+ });
js/tiny_mce/plugins/codemagic/langs/en.js ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ tinyMCE.addI18n('en.codemagic',{
2
+ editor_button: "Edit source code"
3
+ });
js/tiny_mce/plugins/codemagic/langs/en_dlg.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tinyMCE.addI18n('en.codemagic_dlg',{
2
+ code_title: "CodeMagic - syntax coloring and intendation",
3
+ code_label: "Edit code",
4
+ toggle_highlighting: "Syntax highlighting",
5
+ toggle_autocompletion: "Auto completion",
6
+ search: "Search",
7
+ replace: "Replace",
8
+ undo: "Undo",
9
+ redo: "Redo",
10
+ search_replace: "Search and Replace",
11
+ reintendt: "Format HTML code",
12
+ nothing_found: "Nothing found.",
13
+ nothing_to_replace: "Nothing to replace."
14
+ });
js/tiny_mce/plugins/codemagic/langs/sk.js ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ tinyMCE.addI18n('sk.codemagic',{
2
+ editor_button: "Upraviť HTML kód"
3
+ });
js/tiny_mce/plugins/codemagic/langs/sk_dlg.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tinyMCE.addI18n('sk.codemagic',{
2
+ code_title: "CodeMagic - zvýraznenie syntaxe a formátovanie kódu",
3
+ code_label: "Editovať kód",
4
+ toggle_highlighting: "Zvýraznenie kódu",
5
+ toggle_autocompletion: "Doplňovenie kódu",
6
+ search: "Hľadať",
7
+ replace: "Nahradiť",
8
+ undo: "Späť",
9
+ redo: "Opakovať",
10
+ search_replace: "Hľadať a nahradiť",
11
+ reintendt: "Sformátovať kód",
12
+ nothing_found: "Hľadaný výraz nebol nájdený.",
13
+ nothing_to_replace: "Nie je čo nahradiť."
14
+ });
js/tiny_mce/plugins/codemagic/licence.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011 sutulustus.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
6
+ to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
13
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Flexishore_Codemirror</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Summary</summary>
10
+ <description>Flexishore Codemirror extension</description>
11
+ <notes>Notes</notes>
12
+ <authors><author><name>Rafa&#x142;</name><user>auto-converted</user><email>rafal.k@flexishore.com</email></author></authors>
13
+ <date>2011-08-02</date>
14
+ <time>09:13:58</time>
15
+ <contents><target name="magelocal"><dir name="Flexishore"><dir name="Codemirror"><dir name="Model"><file name="Config.php" hash="527b596f89ae804e5c7648d7fe132ce9"/><file name="Observer.php" hash="e92756473644f1c4156099e79573fa91"/></dir><dir name="etc"><file name="config.xml" hash="836964580dd22949bcc813aaaafb3b28"/></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="tiny_mce"><dir name="plugins"><dir name="codemagic"><dir name="css"><file name="codemirror.css" hash="5f09dd1d711781f7d14f49d386140f98"/><file name="default.css" hash="143d799e6d9cb2d11e52475291977342"/><file name="style.css" hash="977c810c95b945951dccad098452c79c"/></dir><dir name="img"><dir name="icons"><file name="file.png" hash="2ca9835eae486975d6d58978ec1a282d"/><file name="lens.png" hash="bfd1802b619a875743ef5718f8ae4b4b"/><file name="redo.png" hash="2f88c4360c2b7ba8775621291fac395f"/><file name="undo.png" hash="3f0b4f17998f7c86acd3fecf83df2fc8"/></dir><file name="code.png" hash="1d70003026d4577eb0dc782c197eb037"/></dir><dir name="js"><file name="beautify-html.js" hash="360f4bb0b3ab60b46733dbd0056c5165"/><file name="beautify.js" hash="d940a624216e7c5ffdd62fafc06d75f2"/><file name="codemagic.js" hash="c8358b150fd549ade2adf5d32de9a9cb"/><file name="codemirror-compressed.js" hash="ca2c5fc57ad7e4955582f33972e7da07"/></dir><dir name="langs"><file name="cs.js" hash="c62f709c7411ef37577f415eecc5bd96"/><file name="cs_dlg.js" hash="a09a7f5070d4843a79bc141d3de5099e"/><file name="en.js" hash="5111ba5b1886d33f4aa11c2173c1450f"/><file name="en_dlg.js" hash="115d2e3fba3caa163d86b72e0b30942d"/><file name="sk.js" hash="b3f123af4914dfd4eb2470cca3aeec1b"/><file name="sk_dlg.js" hash="84780f09ffe8bae8811fa12829691aa1"/></dir><file name="codemagic.htm" hash="08cdd695e695f46e95aa74720b1742a1"/><file name="editor_plugin.js" hash="889d9f77bc75cc353fb63ab1975af809"/><file name="editor_plugin_src.js" hash="1085e2d91509cee2932b79be7683e0d0"/><file name="licence.txt" hash="04264441a94d5e6625a4cd37ce9516be"/></dir></dir></dir></dir><dir name="app"><dir name="etc"><dir name="modules"><file name="Flexishore_Codemirror.xml" hash="f28bd5f91883ed9406cdffafba51b5b7"/></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>