bgneal@312: /** bgneal@312: * editor_plugin_src.js bgneal@312: * bgneal@312: * Copyright 2009, Moxiecode Systems AB bgneal@312: * Released under LGPL License. bgneal@312: * bgneal@312: * License: http://tinymce.moxiecode.com/license bgneal@312: * Contributing: http://tinymce.moxiecode.com/contributing bgneal@312: */ bgneal@312: bgneal@312: (function() { bgneal@312: tinymce.create('tinymce.plugins.FullPagePlugin', { bgneal@312: init : function(ed, url) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.editor = ed; bgneal@312: bgneal@312: // Register commands bgneal@312: ed.addCommand('mceFullPageProperties', function() { bgneal@312: ed.windowManager.open({ bgneal@312: file : url + '/fullpage.htm', bgneal@312: width : 430 + parseInt(ed.getLang('fullpage.delta_width', 0)), bgneal@312: height : 495 + parseInt(ed.getLang('fullpage.delta_height', 0)), bgneal@312: inline : 1 bgneal@312: }, { bgneal@312: plugin_url : url, bgneal@312: head_html : t.head bgneal@312: }); bgneal@312: }); bgneal@312: bgneal@312: // Register buttons bgneal@312: ed.addButton('fullpage', {title : 'fullpage.desc', cmd : 'mceFullPageProperties'}); bgneal@312: bgneal@312: ed.onBeforeSetContent.add(t._setContent, t); bgneal@312: ed.onSetContent.add(t._setBodyAttribs, t); bgneal@312: ed.onGetContent.add(t._getContent, t); bgneal@312: }, bgneal@312: bgneal@312: getInfo : function() { bgneal@312: return { bgneal@312: longname : 'Fullpage', bgneal@312: author : 'Moxiecode Systems AB', bgneal@312: authorurl : 'http://tinymce.moxiecode.com', bgneal@312: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullpage', bgneal@312: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: // Private plugin internal methods bgneal@312: bgneal@312: _setBodyAttribs : function(ed, o) { bgneal@312: var bdattr, i, len, kv, k, v, t, attr = this.head.match(/body(.*?)>/i); bgneal@312: bgneal@312: if (attr && attr[1]) { bgneal@312: bdattr = attr[1].match(/\s*(\w+\s*=\s*".*?"|\w+\s*=\s*'.*?'|\w+\s*=\s*\w+|\w+)\s*/g); bgneal@312: bgneal@312: if (bdattr) { bgneal@312: for(i = 0, len = bdattr.length; i < len; i++) { bgneal@312: kv = bdattr[i].split('='); bgneal@312: k = kv[0].replace(/\s/,''); bgneal@312: v = kv[1]; bgneal@312: bgneal@312: if (v) { bgneal@312: v = v.replace(/^\s+/,'').replace(/\s+$/,''); bgneal@312: t = v.match(/^["'](.*)["']$/); bgneal@312: bgneal@312: if (t) bgneal@312: v = t[1]; bgneal@312: } else bgneal@312: v = k; bgneal@312: bgneal@312: ed.dom.setAttrib(ed.getBody(), 'style', v); bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: _createSerializer : function() { bgneal@312: return new tinymce.dom.Serializer({ bgneal@312: dom : this.editor.dom, bgneal@312: apply_source_formatting : true bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: _setContent : function(ed, o) { bgneal@312: var t = this, sp, ep, c = o.content, v, st = ''; bgneal@312: bgneal@312: // Ignore raw updated if we already have a head, this will fix issues with undo/redo keeping the head/foot separate bgneal@312: if (o.format == 'raw' && t.head) bgneal@312: return; bgneal@312: bgneal@312: if (o.source_view && ed.getParam('fullpage_hide_in_source_view')) bgneal@312: return; bgneal@312: bgneal@312: // Parse out head, body and footer bgneal@312: c = c.replace(/<(\/?)BODY/gi, '<$1body'); bgneal@312: sp = c.indexOf('', sp); bgneal@312: t.head = c.substring(0, sp + 1); bgneal@312: bgneal@312: ep = c.indexOf('\n'; bgneal@312: bgneal@312: t.head += ed.getParam('fullpage_default_doctype', ''); bgneal@312: t.head += '\n\n\n' + ed.getParam('fullpage_default_title', 'Untitled document') + '\n'; bgneal@312: bgneal@312: if (v = ed.getParam('fullpage_default_encoding')) bgneal@312: t.head += '\n'; bgneal@312: bgneal@312: if (v = ed.getParam('fullpage_default_font_family')) bgneal@312: st += 'font-family: ' + v + ';'; bgneal@312: bgneal@312: if (v = ed.getParam('fullpage_default_font_size')) bgneal@312: st += 'font-size: ' + v + ';'; bgneal@312: bgneal@312: if (v = ed.getParam('fullpage_default_text_color')) bgneal@312: st += 'color: ' + v + ';'; bgneal@312: bgneal@312: t.head += '\n\n'; bgneal@312: t.foot = '\n\n'; bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: _getContent : function(ed, o) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (!o.source_view || !ed.getParam('fullpage_hide_in_source_view')) bgneal@312: o.content = tinymce.trim(t.head) + '\n' + tinymce.trim(o.content) + '\n' + tinymce.trim(t.foot); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Register plugin bgneal@312: tinymce.PluginManager.add('fullpage', tinymce.plugins.FullPagePlugin); bgneal@312: })();