annotate media/js/tiny_mce/plugins/pagebreak/editor_plugin_src.js @ 201:bc958bc3c6eb

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