annotate static/js/tiny_mce/plugins/fullpage/editor_plugin_src.js @ 339:b871892264f2

Adding the sg101 IRC bot code to SVN. This code is pretty rough and needs love, but it gets the job done (one of my first Python apps). This fixes #150.
author Brian Neal <bgneal@gmail.com>
date Sat, 26 Feb 2011 21:27:49 +0000
parents 88b2b9cb8c1f
children 6c182ceb7147
rev   line source
bgneal@312 1 /**
bgneal@312 2 * editor_plugin_src.js
bgneal@312 3 *
bgneal@312 4 * Copyright 2009, Moxiecode Systems AB
bgneal@312 5 * Released under LGPL License.
bgneal@312 6 *
bgneal@312 7 * License: http://tinymce.moxiecode.com/license
bgneal@312 8 * Contributing: http://tinymce.moxiecode.com/contributing
bgneal@312 9 */
bgneal@312 10
bgneal@312 11 (function() {
bgneal@312 12 tinymce.create('tinymce.plugins.FullPagePlugin', {
bgneal@312 13 init : function(ed, url) {
bgneal@312 14 var t = this;
bgneal@312 15
bgneal@312 16 t.editor = ed;
bgneal@312 17
bgneal@312 18 // Register commands
bgneal@312 19 ed.addCommand('mceFullPageProperties', function() {
bgneal@312 20 ed.windowManager.open({
bgneal@312 21 file : url + '/fullpage.htm',
bgneal@312 22 width : 430 + parseInt(ed.getLang('fullpage.delta_width', 0)),
bgneal@312 23 height : 495 + parseInt(ed.getLang('fullpage.delta_height', 0)),
bgneal@312 24 inline : 1
bgneal@312 25 }, {
bgneal@312 26 plugin_url : url,
bgneal@312 27 head_html : t.head
bgneal@312 28 });
bgneal@312 29 });
bgneal@312 30
bgneal@312 31 // Register buttons
bgneal@312 32 ed.addButton('fullpage', {title : 'fullpage.desc', cmd : 'mceFullPageProperties'});
bgneal@312 33
bgneal@312 34 ed.onBeforeSetContent.add(t._setContent, t);
bgneal@312 35 ed.onSetContent.add(t._setBodyAttribs, t);
bgneal@312 36 ed.onGetContent.add(t._getContent, t);
bgneal@312 37 },
bgneal@312 38
bgneal@312 39 getInfo : function() {
bgneal@312 40 return {
bgneal@312 41 longname : 'Fullpage',
bgneal@312 42 author : 'Moxiecode Systems AB',
bgneal@312 43 authorurl : 'http://tinymce.moxiecode.com',
bgneal@312 44 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullpage',
bgneal@312 45 version : tinymce.majorVersion + "." + tinymce.minorVersion
bgneal@312 46 };
bgneal@312 47 },
bgneal@312 48
bgneal@312 49 // Private plugin internal methods
bgneal@312 50
bgneal@312 51 _setBodyAttribs : function(ed, o) {
bgneal@312 52 var bdattr, i, len, kv, k, v, t, attr = this.head.match(/body(.*?)>/i);
bgneal@312 53
bgneal@312 54 if (attr && attr[1]) {
bgneal@312 55 bdattr = attr[1].match(/\s*(\w+\s*=\s*".*?"|\w+\s*=\s*'.*?'|\w+\s*=\s*\w+|\w+)\s*/g);
bgneal@312 56
bgneal@312 57 if (bdattr) {
bgneal@312 58 for(i = 0, len = bdattr.length; i < len; i++) {
bgneal@312 59 kv = bdattr[i].split('=');
bgneal@312 60 k = kv[0].replace(/\s/,'');
bgneal@312 61 v = kv[1];
bgneal@312 62
bgneal@312 63 if (v) {
bgneal@312 64 v = v.replace(/^\s+/,'').replace(/\s+$/,'');
bgneal@312 65 t = v.match(/^["'](.*)["']$/);
bgneal@312 66
bgneal@312 67 if (t)
bgneal@312 68 v = t[1];
bgneal@312 69 } else
bgneal@312 70 v = k;
bgneal@312 71
bgneal@312 72 ed.dom.setAttrib(ed.getBody(), 'style', v);
bgneal@312 73 }
bgneal@312 74 }
bgneal@312 75 }
bgneal@312 76 },
bgneal@312 77
bgneal@312 78 _createSerializer : function() {
bgneal@312 79 return new tinymce.dom.Serializer({
bgneal@312 80 dom : this.editor.dom,
bgneal@312 81 apply_source_formatting : true
bgneal@312 82 });
bgneal@312 83 },
bgneal@312 84
bgneal@312 85 _setContent : function(ed, o) {
bgneal@312 86 var t = this, sp, ep, c = o.content, v, st = '';
bgneal@312 87
bgneal@312 88 // Ignore raw updated if we already have a head, this will fix issues with undo/redo keeping the head/foot separate
bgneal@312 89 if (o.format == 'raw' && t.head)
bgneal@312 90 return;
bgneal@312 91
bgneal@312 92 if (o.source_view && ed.getParam('fullpage_hide_in_source_view'))
bgneal@312 93 return;
bgneal@312 94
bgneal@312 95 // Parse out head, body and footer
bgneal@312 96 c = c.replace(/<(\/?)BODY/gi, '<$1body');
bgneal@312 97 sp = c.indexOf('<body');
bgneal@312 98
bgneal@312 99 if (sp != -1) {
bgneal@312 100 sp = c.indexOf('>', sp);
bgneal@312 101 t.head = c.substring(0, sp + 1);
bgneal@312 102
bgneal@312 103 ep = c.indexOf('</body', sp);
bgneal@312 104 if (ep == -1)
bgneal@312 105 ep = c.indexOf('</body', ep);
bgneal@312 106
bgneal@312 107 o.content = c.substring(sp + 1, ep);
bgneal@312 108 t.foot = c.substring(ep);
bgneal@312 109
bgneal@312 110 function low(s) {
bgneal@312 111 return s.replace(/<\/?[A-Z]+/g, function(a) {
bgneal@312 112 return a.toLowerCase();
bgneal@312 113 })
bgneal@312 114 };
bgneal@312 115
bgneal@312 116 t.head = low(t.head);
bgneal@312 117 t.foot = low(t.foot);
bgneal@312 118 } else {
bgneal@312 119 t.head = '';
bgneal@312 120 if (ed.getParam('fullpage_default_xml_pi'))
bgneal@312 121 t.head += '<?xml version="1.0" encoding="' + ed.getParam('fullpage_default_encoding', 'ISO-8859-1') + '" ?>\n';
bgneal@312 122
bgneal@312 123 t.head += ed.getParam('fullpage_default_doctype', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
bgneal@312 124 t.head += '\n<html>\n<head>\n<title>' + ed.getParam('fullpage_default_title', 'Untitled document') + '</title>\n';
bgneal@312 125
bgneal@312 126 if (v = ed.getParam('fullpage_default_encoding'))
bgneal@312 127 t.head += '<meta http-equiv="Content-Type" content="' + v + '" />\n';
bgneal@312 128
bgneal@312 129 if (v = ed.getParam('fullpage_default_font_family'))
bgneal@312 130 st += 'font-family: ' + v + ';';
bgneal@312 131
bgneal@312 132 if (v = ed.getParam('fullpage_default_font_size'))
bgneal@312 133 st += 'font-size: ' + v + ';';
bgneal@312 134
bgneal@312 135 if (v = ed.getParam('fullpage_default_text_color'))
bgneal@312 136 st += 'color: ' + v + ';';
bgneal@312 137
bgneal@312 138 t.head += '</head>\n<body' + (st ? ' style="' + st + '"' : '') + '>\n';
bgneal@312 139 t.foot = '\n</body>\n</html>';
bgneal@312 140 }
bgneal@312 141 },
bgneal@312 142
bgneal@312 143 _getContent : function(ed, o) {
bgneal@312 144 var t = this;
bgneal@312 145
bgneal@312 146 if (!o.source_view || !ed.getParam('fullpage_hide_in_source_view'))
bgneal@312 147 o.content = tinymce.trim(t.head) + '\n' + tinymce.trim(o.content) + '\n' + tinymce.trim(t.foot);
bgneal@312 148 }
bgneal@312 149 });
bgneal@312 150
bgneal@312 151 // Register plugin
bgneal@312 152 tinymce.PluginManager.add('fullpage', tinymce.plugins.FullPagePlugin);
bgneal@312 153 })();