annotate media/js/tiny_mce/plugins/pagebreak/editor_plugin_src.js @ 45:a5b4c5ce0658

Breaking down and controlling all media files, including javascript libraries.
author Brian Neal <bgneal@gmail.com>
date Fri, 19 Jun 2009 03:16:03 +0000
parents
children 149c3567fec1
rev   line source
bgneal@45 1 /**
bgneal@45 2 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
bgneal@45 3 *
bgneal@45 4 * @author Moxiecode
bgneal@45 5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
bgneal@45 6 */
bgneal@45 7
bgneal@45 8 (function() {
bgneal@45 9 tinymce.create('tinymce.plugins.PageBreakPlugin', {
bgneal@45 10 init : function(ed, url) {
bgneal@45 11 var pb = '<img src="' + url + '/img/trans.gif" class="mcePageBreak mceItemNoResize" />', cls = 'mcePageBreak', sep = ed.getParam('pagebreak_separator', '<!-- pagebreak -->'), pbRE;
bgneal@45 12
bgneal@45 13 pbRE = new RegExp(sep.replace(/[\?\.\*\[\]\(\)\{\}\+\^\$\:]/g, function(a) {return '\\' + a;}), 'g');
bgneal@45 14
bgneal@45 15 // Register commands
bgneal@45 16 ed.addCommand('mcePageBreak', function() {
bgneal@45 17 ed.execCommand('mceInsertContent', 0, pb);
bgneal@45 18 });
bgneal@45 19
bgneal@45 20 // Register buttons
bgneal@45 21 ed.addButton('pagebreak', {title : 'pagebreak.desc', cmd : cls});
bgneal@45 22
bgneal@45 23 ed.onInit.add(function() {
bgneal@45 24 if (ed.settings.content_css !== false)
bgneal@45 25 ed.dom.loadCSS(url + "/css/content.css");
bgneal@45 26
bgneal@45 27 if (ed.theme.onResolveName) {
bgneal@45 28 ed.theme.onResolveName.add(function(th, o) {
bgneal@45 29 if (o.node.nodeName == 'IMG' && ed.dom.hasClass(o.node, cls))
bgneal@45 30 o.name = 'pagebreak';
bgneal@45 31 });
bgneal@45 32 }
bgneal@45 33 });
bgneal@45 34
bgneal@45 35 ed.onClick.add(function(ed, e) {
bgneal@45 36 e = e.target;
bgneal@45 37
bgneal@45 38 if (e.nodeName === 'IMG' && ed.dom.hasClass(e, cls))
bgneal@45 39 ed.selection.select(e);
bgneal@45 40 });
bgneal@45 41
bgneal@45 42 ed.onNodeChange.add(function(ed, cm, n) {
bgneal@45 43 cm.setActive('pagebreak', n.nodeName === 'IMG' && ed.dom.hasClass(n, cls));
bgneal@45 44 });
bgneal@45 45
bgneal@45 46 ed.onBeforeSetContent.add(function(ed, o) {
bgneal@45 47 o.content = o.content.replace(pbRE, pb);
bgneal@45 48 });
bgneal@45 49
bgneal@45 50 ed.onPostProcess.add(function(ed, o) {
bgneal@45 51 if (o.get)
bgneal@45 52 o.content = o.content.replace(/<img[^>]+>/g, function(im) {
bgneal@45 53 if (im.indexOf('class="mcePageBreak') !== -1)
bgneal@45 54 im = sep;
bgneal@45 55
bgneal@45 56 return im;
bgneal@45 57 });
bgneal@45 58 });
bgneal@45 59 },
bgneal@45 60
bgneal@45 61 getInfo : function() {
bgneal@45 62 return {
bgneal@45 63 longname : 'PageBreak',
bgneal@45 64 author : 'Moxiecode Systems AB',
bgneal@45 65 authorurl : 'http://tinymce.moxiecode.com',
bgneal@45 66 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/pagebreak',
bgneal@45 67 version : tinymce.majorVersion + "." + tinymce.minorVersion
bgneal@45 68 };
bgneal@45 69 }
bgneal@45 70 });
bgneal@45 71
bgneal@45 72 // Register plugin
bgneal@45 73 tinymce.PluginManager.add('pagebreak', tinymce.plugins.PageBreakPlugin);
bgneal@45 74 })();