Skip to content
This repository
Browse code

Merge @somartist PR #92 (TinyMCE) + add CodeMagic to default TinyMCE …

…plugins in core.
  • Loading branch information...
commit a2aae40f313b7fd9a0a2ba0a17c32a52809660c0 1 parent 2a38449
Ryan Cramer authored March 24, 2012

Showing 25 changed files with 2,551 additions and 3 deletions. Show diff stats Hide diff stats

  1. 11  wire/modules/Inputfield/InputfieldTinyMCE/InputfieldTinyMCE.js
  2. 8  wire/modules/Inputfield/InputfieldTinyMCE/InputfieldTinyMCE.module
  3. 66  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/codemagic.htm
  4. 98  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/css/codemirror.css
  5. 28  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/css/default.css
  6. 59  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/css/style.css
  7. 1  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/editor_plugin.js
  8. 54  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/editor_plugin_src.js
  9. BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/_code.png
  10. BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/code.png
  11. BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/icons/file.png
  12. BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/icons/lens.png
  13. BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/icons/redo.png
  14. BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/icons/undo.png
  15. 436  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/js/beautify-html.js
  16. 1,147  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/js/beautify.js
  17. 581  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/js/codemagic.js
  18. 1  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/js/codemirror-compressed.js
  19. 3  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/langs/cs.js
  20. 14  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/langs/cs_dlg.js
  21. 3  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/langs/en.js
  22. 14  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/langs/en_dlg.js
  23. 3  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/langs/sk.js
  24. 14  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/langs/sk_dlg.js
  25. 13  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/licence.txt
11  wire/modules/Inputfield/InputfieldTinyMCE/InputfieldTinyMCE.js
@@ -93,6 +93,15 @@ var InputfieldTinyMCEConfigDefaults = {
93 93
 
94 94
 $(document).ready(function() {
95 95
 
  96
+	// Soma: convert config string that start with a [ to a js object
  97
+	// this ensures it works with object type of configurations like template_templates:[{title:'mytemplate'},...]
  98
+	function convertObjects(config) {
  99
+		$.each(config, function(key, value) {
  100
+			if(value.substr(0, 1) == "[" ) config[key] = eval(value);
  101
+		});
  102
+		return config;
  103
+	};
  104
+
96 105
 	var InputfieldTinyMCEPlugins = ['pwimage', 'pwlink', 'advimagescale', 'preelementfix']; 
97 106
 
98 107
 	$.each(InputfieldTinyMCEPlugins, function(key, value) {
@@ -100,6 +109,8 @@ $(document).ready(function() {
100 109
 	}); 
101 110
 
102 111
 	$.each(config.InputfieldTinyMCE.elements, function(key, value) {
  112
+		// Soma: convert config object values to objects if necessary
  113
+		config[value] = convertObjects(config[value]);
103 114
 
104 115
 		tinyMCE.settings = $.extend(InputfieldTinyMCEConfigDefaults, config[value]); 
105 116
 		if(config.InputfieldTinyMCE.language.length > 0) tinyMCE.settings.language = config.InputfieldTinyMCE.language; 
8  wire/modules/Inputfield/InputfieldTinyMCE/InputfieldTinyMCE.module
@@ -3,6 +3,8 @@
3 3
 /**
4 4
  * An Inputfield for handling XHTML "textarea" form inputs
5 5
  *
  6
+ * Note that the codemagic plugin must live in TinyMCE's plugin dir, and thus must be replaced when upgrading TinyMCE versions
  7
+ *
6 8
  */
7 9
 class InputfieldTinyMCE extends InputfieldTextarea {
8 10
 
@@ -10,10 +12,10 @@ class InputfieldTinyMCE extends InputfieldTextarea {
10 12
 	const TinyMCEVersion = '3.4.7';
11 13
 
12 14
 	protected $defaults = array(
13  
-		'theme_advanced_buttons1' => 'formatselect,|,bold,italic,|,bullist,numlist,|,link,unlink,|,image,|,code,|,fullscreen',
  15
+		'theme_advanced_buttons1' => 'formatselect,|,bold,italic,|,bullist,numlist,|,link,unlink,|,image,|,codemagic,|,fullscreen',
14 16
 		'theme_advanced_buttons2' => '',
15 17
 		'theme_advanced_blockformats' => 'p,h2,h3,h4,blockquote,pre,code',
16  
-		'plugins' => 'inlinepopups,safari,table,media,paste,fullscreen,preelementfix', 
  18
+		'plugins' => 'inlinepopups,safari,table,media,paste,fullscreen,preelementfix,codemagic', 
17 19
 		'valid_elements' => '@[id|class],a[href|target|name],strong/b,em/i,br,img[src|id|class|width|height|alt],ul,ol,li,p[class],h2,h3,h4,blockquote,-p,-table[border=0|cellspacing|cellpadding|width|frame|rules|height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor|scope],#th[colspan|rowspan|width|height|align|valign|scope],pre,code',
18 20
 		'content_css' => '',
19 21
 		'custom' => '',
@@ -22,7 +24,7 @@ class InputfieldTinyMCE extends InputfieldTextarea {
22 24
 	public static function getModuleInfo() {
23 25
 		return array(
24 26
 			'title' => 'TinyMCE',
25  
-			'version' => 100,
  27
+			'version' => 347,
26 28
 			'summary' => 'WYSIWYG rich text editor',
27 29
 			'permanent' => true, 
28 30
 			);
66  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/codemagic.htm
... ...
@@ -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>
98  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/css/codemirror.css
... ...
@@ -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
+}
28  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/css/default.css
... ...
@@ -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;}
59  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/css/style.css
... ...
@@ -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
+}
1  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/editor_plugin.js
... ...
@@ -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',author:'Sutulustus',authorurl:'http://www.triad.sk/#/en',version:'0.9.5'}}});tinymce.PluginManager.add('codemagic',tinymce.plugins.CodeMagic)})();
54  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/editor_plugin_src.js
... ...
@@ -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',
  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
+})();
BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/_code.png
BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/code.png
BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/icons/file.png
BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/icons/lens.png
BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/icons/redo.png
BIN  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/img/icons/undo.png
436  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/js/beautify-html.js
... ...
@@ -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
+}
1,147  wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.4.7/plugins/codemagic/js/beautify.js
... ...
@@ -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