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