summaryrefslogtreecommitdiff
path: root/public/javascripts/tiny_mce/plugins/template
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-02-17 21:54:39 +0100
committerhukl <contact@smyck.org>2009-02-17 21:54:39 +0100
commitf61b5b0597e0c25f084ee67d402f12a43a7a9947 (patch)
tree3b4c3f9f38637f1a7ecf703ece4fd3bc4c6e2934 /public/javascripts/tiny_mce/plugins/template
parent3d3b786cc43266f6292f5edd25733dbb9bd6ed06 (diff)
added tinymce editor for body area of pages
Diffstat (limited to 'public/javascripts/tiny_mce/plugins/template')
-rwxr-xr-xpublic/javascripts/tiny_mce/plugins/template/blank.htm12
-rwxr-xr-xpublic/javascripts/tiny_mce/plugins/template/css/template.css23
-rwxr-xr-xpublic/javascripts/tiny_mce/plugins/template/editor_plugin.js1
-rwxr-xr-xpublic/javascripts/tiny_mce/plugins/template/editor_plugin_src.js156
-rwxr-xr-xpublic/javascripts/tiny_mce/plugins/template/js/template.js106
-rwxr-xr-xpublic/javascripts/tiny_mce/plugins/template/langs/en_dlg.js15
-rwxr-xr-xpublic/javascripts/tiny_mce/plugins/template/template.htm39
7 files changed, 352 insertions, 0 deletions
diff --git a/public/javascripts/tiny_mce/plugins/template/blank.htm b/public/javascripts/tiny_mce/plugins/template/blank.htm
new file mode 100755
index 0000000..ecde53f
--- /dev/null
+++ b/public/javascripts/tiny_mce/plugins/template/blank.htm
@@ -0,0 +1,12 @@
1<html xmlns="http://www.w3.org/1999/xhtml">
2<head>
3 <title>blank_page</title>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5 <script type="text/javascript">
6 parent.TemplateDialog.loadCSSFiles(document);
7 </script>
8</head>
9<body id="mceTemplatePreview" class="mceContentBody">
10
11</body>
12</html>
diff --git a/public/javascripts/tiny_mce/plugins/template/css/template.css b/public/javascripts/tiny_mce/plugins/template/css/template.css
new file mode 100755
index 0000000..2d23a49
--- /dev/null
+++ b/public/javascripts/tiny_mce/plugins/template/css/template.css
@@ -0,0 +1,23 @@
1#frmbody {
2 padding: 10px;
3 background-color: #FFF;
4 border: 1px solid #CCC;
5}
6
7.frmRow {
8 margin-bottom: 10px;
9}
10
11#templatesrc {
12 border: none;
13 width: 320px;
14 height: 240px;
15}
16
17.title {
18 padding-bottom: 5px;
19}
20
21.mceActionPanel {
22 padding-top: 5px;
23}
diff --git a/public/javascripts/tiny_mce/plugins/template/editor_plugin.js b/public/javascripts/tiny_mce/plugins/template/editor_plugin.js
new file mode 100755
index 0000000..0f7fb01
--- /dev/null
+++ b/public/javascripts/tiny_mce/plugins/template/editor_plugin.js
@@ -0,0 +1 @@
(function(){var each=tinymce.each;tinymce.create('tinymce.plugins.TemplatePlugin',{init:function(ed,url){var t=this;t.editor=ed;ed.addCommand('mceTemplate',function(ui){ed.windowManager.open({file:url+'/template.htm',width:ed.getParam('template_popup_width',750),height:ed.getParam('template_popup_height',600),inline:1},{plugin_url:url});});ed.addCommand('mceInsertTemplate',t._insertTemplate,t);ed.addButton('template',{title:'template.desc',cmd:'mceTemplate'});ed.onPreProcess.add(function(ed,o){var dom=ed.dom;each(dom.select('div',o.node),function(e){if(dom.hasClass(e,'mceTmpl')){each(dom.select('*',e),function(e){if(dom.hasClass(e,ed.getParam('template_mdate_classes','mdate').replace(/\s+/g,'|')))e.innerHTML=t._getDateTime(new Date(),ed.getParam("template_mdate_format",ed.getLang("template.mdate_format")));});t._replaceVals(e);}});});},getInfo:function(){return{longname:'Template plugin',author:'Moxiecode Systems AB',authorurl:'http://www.moxiecode.com',infourl:'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template',version:tinymce.majorVersion+"."+tinymce.minorVersion};},_insertTemplate:function(ui,v){var t=this,ed=t.editor,h,el,dom=ed.dom,sel=ed.selection.getContent();h=v.content;each(t.editor.getParam('template_replace_values'),function(v,k){if(typeof(v)!='function')h=h.replace(new RegExp('\\{\\$'+k+'\\}','g'),v);});el=dom.create('div',null,h);n=dom.select('.mceTmpl',el);if(n&&n.length>0){el=dom.create('div',null);el.appendChild(n[0].cloneNode(true));}function hasClass(n,c){return new RegExp('\\b'+c+'\\b','g').test(n.className);};each(dom.select('*',el),function(n){if(hasClass(n,ed.getParam('template_cdate_classes','cdate').replace(/\s+/g,'|')))n.innerHTML=t._getDateTime(new Date(),ed.getParam("template_cdate_format",ed.getLang("template.cdate_format")));if(hasClass(n,ed.getParam('template_mdate_classes','mdate').replace(/\s+/g,'|')))n.innerHTML=t._getDateTime(new Date(),ed.getParam("template_mdate_format",ed.getLang("template.mdate_format")));if(hasClass(n,ed.getParam('template_selected_content_classes','selcontent').replace(/\s+/g,'|')))n.innerHTML=sel;});t._replaceVals(el);ed.execCommand('mceInsertContent',false,el.innerHTML);ed.addVisual();},_replaceVals:function(e){var dom=this.editor.dom,vl=this.editor.getParam('template_replace_values');each(dom.select('*',e),function(e){each(vl,function(v,k){if(dom.hasClass(e,k)){if(typeof(vl[k])=='function')vl[k](e);}});});},_getDateTime:function(d,fmt){if(!fmt)return"";function addZeros(value,len){var i;value=""+value;if(value.length<len){for(i=0;i<(len-value.length);i++)value="0"+value;}return value;}fmt=fmt.replace("%D","%m/%d/%y");fmt=fmt.replace("%r","%I:%M:%S %p");fmt=fmt.replace("%Y",""+d.getFullYear());fmt=fmt.replace("%y",""+d.getYear());fmt=fmt.replace("%m",addZeros(d.getMonth()+1,2));fmt=fmt.replace("%d",addZeros(d.getDate(),2));fmt=fmt.replace("%H",""+addZeros(d.getHours(),2));fmt=fmt.replace("%M",""+addZeros(d.getMinutes(),2));fmt=fmt.replace("%S",""+addZeros(d.getSeconds(),2));fmt=fmt.replace("%I",""+((d.getHours()+11)%12+1));fmt=fmt.replace("%p",""+(d.getHours()<12?"AM":"PM"));fmt=fmt.replace("%B",""+tinyMCE.getLang("template_months_long").split(',')[d.getMonth()]);fmt=fmt.replace("%b",""+tinyMCE.getLang("template_months_short").split(',')[d.getMonth()]);fmt=fmt.replace("%A",""+tinyMCE.getLang("template_day_long").split(',')[d.getDay()]);fmt=fmt.replace("%a",""+tinyMCE.getLang("template_day_short").split(',')[d.getDay()]);fmt=fmt.replace("%%","%");return fmt;}});tinymce.PluginManager.add('template',tinymce.plugins.TemplatePlugin);})(); \ No newline at end of file
diff --git a/public/javascripts/tiny_mce/plugins/template/editor_plugin_src.js b/public/javascripts/tiny_mce/plugins/template/editor_plugin_src.js
new file mode 100755
index 0000000..73ab39e
--- /dev/null
+++ b/public/javascripts/tiny_mce/plugins/template/editor_plugin_src.js
@@ -0,0 +1,156 @@
1/**
2 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
3 *
4 * @author Moxiecode
5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
6 */
7
8(function() {
9 var each = tinymce.each;
10
11 tinymce.create('tinymce.plugins.TemplatePlugin', {
12 init : function(ed, url) {
13 var t = this;
14
15 t.editor = ed;
16
17 // Register commands
18 ed.addCommand('mceTemplate', function(ui) {
19 ed.windowManager.open({
20 file : url + '/template.htm',
21 width : ed.getParam('template_popup_width', 750),
22 height : ed.getParam('template_popup_height', 600),
23 inline : 1
24 }, {
25 plugin_url : url
26 });
27 });
28
29 ed.addCommand('mceInsertTemplate', t._insertTemplate, t);
30
31 // Register buttons
32 ed.addButton('template', {title : 'template.desc', cmd : 'mceTemplate'});
33
34 ed.onPreProcess.add(function(ed, o) {
35 var dom = ed.dom;
36
37 each(dom.select('div', o.node), function(e) {
38 if (dom.hasClass(e, 'mceTmpl')) {
39 each(dom.select('*', e), function(e) {
40 if (dom.hasClass(e, ed.getParam('template_mdate_classes', 'mdate').replace(/\s+/g, '|')))
41 e.innerHTML = t._getDateTime(new Date(), ed.getParam("template_mdate_format", ed.getLang("template.mdate_format")));
42 });
43
44 t._replaceVals(e);
45 }
46 });
47 });
48 },
49
50 getInfo : function() {
51 return {
52 longname : 'Template plugin',
53 author : 'Moxiecode Systems AB',
54 authorurl : 'http://www.moxiecode.com',
55 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template',
56 version : tinymce.majorVersion + "." + tinymce.minorVersion
57 };
58 },
59
60 _insertTemplate : function(ui, v) {
61 var t = this, ed = t.editor, h, el, dom = ed.dom, sel = ed.selection.getContent();
62
63 h = v.content;
64
65 each(t.editor.getParam('template_replace_values'), function(v, k) {
66 if (typeof(v) != 'function')
67 h = h.replace(new RegExp('\\{\\$' + k + '\\}', 'g'), v);
68 });
69
70 el = dom.create('div', null, h);
71
72 // Find template element within div
73 n = dom.select('.mceTmpl', el);
74 if (n && n.length > 0) {
75 el = dom.create('div', null);
76 el.appendChild(n[0].cloneNode(true));
77 }
78
79 function hasClass(n, c) {
80 return new RegExp('\\b' + c + '\\b', 'g').test(n.className);
81 };
82
83 each(dom.select('*', el), function(n) {
84 // Replace cdate
85 if (hasClass(n, ed.getParam('template_cdate_classes', 'cdate').replace(/\s+/g, '|')))
86 n.innerHTML = t._getDateTime(new Date(), ed.getParam("template_cdate_format", ed.getLang("template.cdate_format")));
87
88 // Replace mdate
89 if (hasClass(n, ed.getParam('template_mdate_classes', 'mdate').replace(/\s+/g, '|')))
90 n.innerHTML = t._getDateTime(new Date(), ed.getParam("template_mdate_format", ed.getLang("template.mdate_format")));
91
92 // Replace selection
93 if (hasClass(n, ed.getParam('template_selected_content_classes', 'selcontent').replace(/\s+/g, '|')))
94 n.innerHTML = sel;
95 });
96
97 t._replaceVals(el);
98
99 ed.execCommand('mceInsertContent', false, el.innerHTML);
100 ed.addVisual();
101 },
102
103 _replaceVals : function(e) {
104 var dom = this.editor.dom, vl = this.editor.getParam('template_replace_values');
105
106 each(dom.select('*', e), function(e) {
107 each(vl, function(v, k) {
108 if (dom.hasClass(e, k)) {
109 if (typeof(vl[k]) == 'function')
110 vl[k](e);
111 }
112 });
113 });
114 },
115
116 _getDateTime : function(d, fmt) {
117 if (!fmt)
118 return "";
119
120 function addZeros(value, len) {
121 var i;
122
123 value = "" + value;
124
125 if (value.length < len) {
126 for (i=0; i<(len-value.length); i++)
127 value = "0" + value;
128 }
129
130 return value;
131 }
132
133 fmt = fmt.replace("%D", "%m/%d/%y");
134 fmt = fmt.replace("%r", "%I:%M:%S %p");
135 fmt = fmt.replace("%Y", "" + d.getFullYear());
136 fmt = fmt.replace("%y", "" + d.getYear());
137 fmt = fmt.replace("%m", addZeros(d.getMonth()+1, 2));
138 fmt = fmt.replace("%d", addZeros(d.getDate(), 2));
139 fmt = fmt.replace("%H", "" + addZeros(d.getHours(), 2));
140 fmt = fmt.replace("%M", "" + addZeros(d.getMinutes(), 2));
141 fmt = fmt.replace("%S", "" + addZeros(d.getSeconds(), 2));
142 fmt = fmt.replace("%I", "" + ((d.getHours() + 11) % 12 + 1));
143 fmt = fmt.replace("%p", "" + (d.getHours() < 12 ? "AM" : "PM"));
144 fmt = fmt.replace("%B", "" + tinyMCE.getLang("template_months_long").split(',')[d.getMonth()]);
145 fmt = fmt.replace("%b", "" + tinyMCE.getLang("template_months_short").split(',')[d.getMonth()]);
146 fmt = fmt.replace("%A", "" + tinyMCE.getLang("template_day_long").split(',')[d.getDay()]);
147 fmt = fmt.replace("%a", "" + tinyMCE.getLang("template_day_short").split(',')[d.getDay()]);
148 fmt = fmt.replace("%%", "%");
149
150 return fmt;
151 }
152 });
153
154 // Register plugin
155 tinymce.PluginManager.add('template', tinymce.plugins.TemplatePlugin);
156})(); \ No newline at end of file
diff --git a/public/javascripts/tiny_mce/plugins/template/js/template.js b/public/javascripts/tiny_mce/plugins/template/js/template.js
new file mode 100755
index 0000000..24045d7
--- /dev/null
+++ b/public/javascripts/tiny_mce/plugins/template/js/template.js
@@ -0,0 +1,106 @@
1tinyMCEPopup.requireLangPack();
2
3var TemplateDialog = {
4 preInit : function() {
5 var url = tinyMCEPopup.getParam("template_external_list_url");
6
7 if (url != null)
8 document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></sc'+'ript>');
9 },
10
11 init : function() {
12 var ed = tinyMCEPopup.editor, tsrc, sel, x, u;
13
14 tsrc = ed.getParam("template_templates", false);
15 sel = document.getElementById('tpath');
16
17 // Setup external template list
18 if (!tsrc && typeof(tinyMCETemplateList) != 'undefined') {
19 for (x=0, tsrc = []; x<tinyMCETemplateList.length; x++)
20 tsrc.push({title : tinyMCETemplateList[x][0], src : tinyMCETemplateList[x][1], description : tinyMCETemplateList[x][2]});
21 }
22
23 for (x=0; x<tsrc.length; x++)
24 sel.options[sel.options.length] = new Option(tsrc[x].title, tinyMCEPopup.editor.documentBaseURI.toAbsolute(tsrc[x].src));
25
26 this.resize();
27 this.tsrc = tsrc;
28 },
29
30 resize : function() {
31 var w, h, e;
32
33 if (!self.innerWidth) {
34 w = document.body.clientWidth - 50;
35 h = document.body.clientHeight - 160;
36 } else {
37 w = self.innerWidth - 50;
38 h = self.innerHeight - 170;
39 }
40
41 e = document.getElementById('templatesrc');
42
43 if (e) {
44 e.style.height = Math.abs(h) + 'px';
45 e.style.width = Math.abs(w - 5) + 'px';
46 }
47 },
48
49 loadCSSFiles : function(d) {
50 var ed = tinyMCEPopup.editor;
51
52 tinymce.each(ed.getParam("content_css", '').split(','), function(u) {
53 d.write('<link href="' + ed.documentBaseURI.toAbsolute(u) + '" rel="stylesheet" type="text/css" />');
54 });
55 },
56
57 selectTemplate : function(u, ti) {
58 var d = window.frames['templatesrc'].document, x, tsrc = this.tsrc;
59
60 if (!u)
61 return;
62
63 d.body.innerHTML = this.templateHTML = this.getFileContents(u);
64
65 for (x=0; x<tsrc.length; x++) {
66 if (tsrc[x].title == ti)
67 document.getElementById('tmpldesc').innerHTML = tsrc[x].description || '';
68 }
69 },
70
71 insert : function() {
72 tinyMCEPopup.execCommand('mceInsertTemplate', false, {
73 content : this.templateHTML,
74 selection : tinyMCEPopup.editor.selection.getContent()
75 });
76
77 tinyMCEPopup.close();
78 },
79
80 getFileContents : function(u) {
81 var x, d, t = 'text/plain';
82
83 function g(s) {
84 x = 0;
85
86 try {
87 x = new ActiveXObject(s);
88 } catch (s) {
89 }
90
91 return x;
92 };
93
94 x = window.ActiveXObject ? g('Msxml2.XMLHTTP') || g('Microsoft.XMLHTTP') : new XMLHttpRequest();
95
96 // Synchronous AJAX load file
97 x.overrideMimeType && x.overrideMimeType(t);
98 x.open("GET", u, false);
99 x.send(null);
100
101 return x.responseText;
102 }
103};
104
105TemplateDialog.preInit();
106tinyMCEPopup.onInit.add(TemplateDialog.init, TemplateDialog);
diff --git a/public/javascripts/tiny_mce/plugins/template/langs/en_dlg.js b/public/javascripts/tiny_mce/plugins/template/langs/en_dlg.js
new file mode 100755
index 0000000..2471c3f
--- /dev/null
+++ b/public/javascripts/tiny_mce/plugins/template/langs/en_dlg.js
@@ -0,0 +1,15 @@
1tinyMCE.addI18n('en.template_dlg',{
2title:"Templates",
3label:"Template",
4desc_label:"Description",
5desc:"Insert predefined template content",
6select:"Select a template",
7preview:"Preview",
8warning:"Warning: Updating a template with a different one may cause data loss.",
9mdate_format:"%Y-%m-%d %H:%M:%S",
10cdate_format:"%Y-%m-%d %H:%M:%S",
11months_long:"January,February,March,April,May,June,July,August,September,October,November,December",
12months_short:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",
13day_long:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday",
14day_short:"Sun,Mon,Tue,Wed,Thu,Fri,Sat,Sun"
15}); \ No newline at end of file
diff --git a/public/javascripts/tiny_mce/plugins/template/template.htm b/public/javascripts/tiny_mce/plugins/template/template.htm
new file mode 100755
index 0000000..2b71c6e
--- /dev/null
+++ b/public/javascripts/tiny_mce/plugins/template/template.htm
@@ -0,0 +1,39 @@
1<html xmlns="http://www.w3.org/1999/xhtml">
2<head>
3 <title>{#template_dlg.title}</title>
4 <script type="text/javascript" src="../../tiny_mce_popup.js"></script>
5 <script type="text/javascript" src="js/template.js"></script>
6 <link href="css/template.css" rel="stylesheet" type="text/css" />
7 <base target="_self" />
8</head>
9<body onresize="TemplateDialog.resize();">
10 <form onsubmit="TemplateDialog.insert();return false;">
11 <div id="frmbody">
12 <div class="title">{#template_dlg.desc}</div>
13 <div class="frmRow"><label for="tpath" title="{#template_dlg.select}">{#template_dlg.label}:</label>
14 <select id="tpath" name="tpath" onchange="TemplateDialog.selectTemplate(this.options[this.selectedIndex].value, this.options[this.selectedIndex].text);" class="mceFocus">
15 <option value="">{#template_dlg.select}...</option>
16 </select>
17 <span id="warning"></span></div>
18 <div class="frmRow"><label for="tdesc">{#template_dlg.desc_label}:</label>
19 <span id="tmpldesc"></span></div>
20 <fieldset>
21 <legend>{#template_dlg.preview}</legend>
22 <iframe id="templatesrc" name="templatesrc" src="blank.htm" width="690" height="400" frameborder="0"></iframe>
23 </fieldset>
24 </div>
25
26 <div class="mceActionPanel">
27 <div style="float: left">
28 <input type="submit" id="insert" name="insert" value="{#insert}" />
29 </div>
30
31 <div style="float: right">
32 <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
33 </div>
34
35 <br style="clear:both" />
36 </div>
37 </form>
38</body>
39</html>