/[drupal]/contributions/modules/wymeditor/wymeditor/jquery.wymeditor.js
ViewVC logotype

Diff of /contributions/modules/wymeditor/wymeditor/jquery.wymeditor.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.1.4.2, Sun Sep 21 14:14:36 2008 UTC revision 1.1.2.1.4.3, Sat Nov 22 00:43:02 2008 UTC
# Line 28  Line 28 
28  */  */
29  if(!WYMeditor) var WYMeditor = {};  if(!WYMeditor) var WYMeditor = {};
30    
31    //Wrap the Firebug console in WYMeditor.console
32    (function() {
33        if ( !window.console || !console.firebug ) {
34            var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
35            "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
36    
37            WYMeditor.console = {};
38            for (var i = 0; i < names.length; ++i)
39                WYMeditor.console[names[i]] = function() {}
40    
41        } else WYMeditor.console = window.console;
42    })();
43    
44  jQuery.extend(WYMeditor, {  jQuery.extend(WYMeditor, {
45    
46  /*  /*
# Line 105  jQuery.extend(WYMeditor, { Line 118  jQuery.extend(WYMeditor, {
118    
119  */  */
120    
121      VERSION             : "0.5-a2",      VERSION             : "0.5-b2",
122      INSTANCES           : [],      INSTANCES           : [],
123      STRINGS             : [],      STRINGS             : [],
124      SKINS               : [],      SKINS               : [],
# Line 724  WYMeditor.editor.prototype.init = functi Line 737  WYMeditor.editor.prototype.init = functi
737        this._box = jQuery(this._element).hide().after(this._options.boxHtml).next();        this._box = jQuery(this._element).hide().after(this._options.boxHtml).next();
738    
739        //store the instance index in the wymbox element        //store the instance index in the wymbox element
740        jQuery(this._box).data(WYMeditor.WYM_INDEX, this._index);        //but keep it compatible with jQuery < 1.2.3, see #122
741          if( jQuery.isFunction( jQuery.fn.data ) )
742            jQuery.data(this._box.get(0), WYMeditor.WYM_INDEX, this._index);
743    
744        var h = WYMeditor.Helper;        var h = WYMeditor.Helper;
745    
# Line 913  WYMeditor.editor.prototype.exec = functi Line 928  WYMeditor.editor.prototype.exec = functi
928      case WYMeditor.TOGGLE_HTML:      case WYMeditor.TOGGLE_HTML:
929        this.update();        this.update();
930        this.toggleHtml();        this.toggleHtml();
931    
932          //partially fixes #121 when the user manually inserts an image
933          if(!jQuery(this._box).find(this._options.htmlSelector).is(':visible'))
934            this.listen();
935      break;      break;
936    
937      case WYMeditor.PREVIEW:      case WYMeditor.PREVIEW:
# Line 1076  WYMeditor.editor.prototype.switchTo = fu Line 1095  WYMeditor.editor.prototype.switchTo = fu
1095  WYMeditor.editor.prototype.replaceStrings = function(sVal) {  WYMeditor.editor.prototype.replaceStrings = function(sVal) {
1096    //check if the language file has already been loaded    //check if the language file has already been loaded
1097    //if not, get it via a synchronous ajax call    //if not, get it via a synchronous ajax call
1098    if(!WYMeditor.STRINGS[this._options.lang])    if(!WYMeditor.STRINGS[this._options.lang]) {
1099      eval(jQuery.ajax({url:this._options.langPath      try {
1100        + this._options.lang + '.js', async:false}).responseText);        eval(jQuery.ajax({url:this._options.langPath
1101            + this._options.lang + '.js', async:false}).responseText);
1102        } catch(e) {
1103            WYMeditor.console.error("WYMeditor: error while parsing language file.");
1104            return sVal;
1105        }
1106      }
1107    
1108    //replace all the strings in sVal and return it    //replace all the strings in sVal and return it
1109    for (var key in WYMeditor.STRINGS[this._options.lang]) {    for (var key in WYMeditor.STRINGS[this._options.lang]) {
# Line 1118  WYMeditor.editor.prototype.update = func Line 1143  WYMeditor.editor.prototype.update = func
1143  /* @name dialog  /* @name dialog
1144   * @description Opens a dialog box   * @description Opens a dialog box
1145   */   */
1146  WYMeditor.editor.prototype.dialog = function(sType) {  WYMeditor.editor.prototype.dialog = function( dialogType, bodyHtml ) {
1147    
1148    var wDialog = window.open(    var wDialog = window.open(
1149      '',      '',
# Line 1129  WYMeditor.editor.prototype.dialog = func Line 1154  WYMeditor.editor.prototype.dialog = func
1154    
1155      var sBodyHtml = "";      var sBodyHtml = "";
1156    
1157      switch(sType) {      switch( dialogType ) {
1158    
1159        case(WYMeditor.DIALOG_LINK):        case(WYMeditor.DIALOG_LINK):
1160          sBodyHtml = this._options.dialogLinkHtml;          sBodyHtml = this._options.dialogLinkHtml;
# Line 1146  WYMeditor.editor.prototype.dialog = func Line 1171  WYMeditor.editor.prototype.dialog = func
1171        case(WYMeditor.PREVIEW):        case(WYMeditor.PREVIEW):
1172          sBodyHtml = this._options.dialogPreviewHtml;          sBodyHtml = this._options.dialogPreviewHtml;
1173        break;        break;
1174    
1175          default:
1176            sBodyHtml = bodyHtml;
1177      }      }
1178    
1179      var h = WYMeditor.Helper;      var h = WYMeditor.Helper;
# Line 1157  WYMeditor.editor.prototype.dialog = func Line 1185  WYMeditor.editor.prototype.dialog = func
1185      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.CSS_PATH, this._options.skinPath + WYMeditor.SKINS_DEFAULT_CSS);      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.CSS_PATH, this._options.skinPath + WYMeditor.SKINS_DEFAULT_CSS);
1186      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.WYM_PATH, this._options.wymPath);      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.WYM_PATH, this._options.wymPath);
1187      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.JQUERY_PATH, this._options.jQueryPath);      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.JQUERY_PATH, this._options.jQueryPath);
1188      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.DIALOG_TITLE, this.encloseString(sType));      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.DIALOG_TITLE, this.encloseString( dialogType ));
1189      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.DIALOG_BODY, sBodyHtml);      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.DIALOG_BODY, sBodyHtml);
1190      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.INDEX, this._index);      dialogHtml = h.replaceAll(dialogHtml, WYMeditor.INDEX, this._index);
1191    
# Line 1220  WYMeditor.editor.prototype.insert = func Line 1248  WYMeditor.editor.prototype.insert = func
1248      }      }
1249  };  };
1250    
1251    WYMeditor.editor.prototype.wrap = function(left, right) {
1252        // Do we have a selection?
1253        if (this._iframe.contentWindow.getSelection().focusNode != null) {
1254            // Wrap selection with provided html
1255            this._exec( WYMeditor.INSERT_HTML, left + this._iframe.contentWindow.getSelection().toString() + right);
1256        }
1257    };
1258    
1259    WYMeditor.editor.prototype.unwrap = function() {
1260        // Do we have a selection?
1261        if (this._iframe.contentWindow.getSelection().focusNode != null) {
1262            // Unwrap selection
1263            this._exec( WYMeditor.INSERT_HTML, this._iframe.contentWindow.getSelection().toString() );
1264        }
1265    };
1266    
1267  WYMeditor.editor.prototype.addCssRules = function(doc, aCss) {  WYMeditor.editor.prototype.addCssRules = function(doc, aCss) {
1268    var styles = doc.styleSheets[0];    var styles = doc.styleSheets[0];
1269    if(styles) {    if(styles) {
# Line 3378  WYMeditor.XhtmlSaxListener.prototype.rep Line 3422  WYMeditor.XhtmlSaxListener.prototype.rep
3422    
3423  WYMeditor.XhtmlSaxListener.prototype.joinRepeatedEntities = function(xhtml)  WYMeditor.XhtmlSaxListener.prototype.joinRepeatedEntities = function(xhtml)
3424  {  {
3425    var tags = 'em|strong|sub|sup|acronym|pre|del|blockquote|address';    var tags = 'em|strong|sub|sup|acronym|pre|del|address';
3426    return xhtml.replace(new RegExp('<\/('+tags+')><\\1>' ,''),'').    return xhtml.replace(new RegExp('<\/('+tags+')><\\1>' ,''),'').
3427    replace(new RegExp('(\s*<('+tags+')>\s*){2}(.*)(\s*<\/\\2>\s*){2}' ,''),'<\$2>\$3<\$2>');    replace(new RegExp('(\s*<('+tags+')>\s*){2}(.*)(\s*<\/\\2>\s*){2}' ,''),'<\$2>\$3<\$2>');
3428  };  };
3429    
3430  WYMeditor.XhtmlSaxListener.prototype.removeEmptyTags = function(xhtml)  WYMeditor.XhtmlSaxListener.prototype.removeEmptyTags = function(xhtml)
3431  {  {
3432    return xhtml.replace(new RegExp('<('+this.block_tags.join("|")+')>(<br \/>|&#160;|&nbsp;|\\s)*<\/\\1>' ,'g'),'');    return xhtml.replace(new RegExp('<('+this.block_tags.join("|").replace(/\|td/,'')+')>(<br \/>|&#160;|&nbsp;|\\s)*<\/\\1>' ,'g'),'');
3433  };  };
3434    
3435  WYMeditor.XhtmlSaxListener.prototype.getResult = function()  WYMeditor.XhtmlSaxListener.prototype.getResult = function()
# Line 3536  WYMeditor.WymCssLexer = function(parser, Line 3580  WYMeditor.WymCssLexer = function(parser,
3580      this.addExitPattern("/\\\x2a[<\/\\s]*WYMeditor[>\\s]*\\\x2a/", 'WymCss');      this.addExitPattern("/\\\x2a[<\/\\s]*WYMeditor[>\\s]*\\\x2a/", 'WymCss');
3581    }    }
3582    
3583    this.addSpecialPattern("\\\x2e[a-z-_0-9]+[\\sa-z]*", 'WymCss', 'WymCssStyleDeclaration');    this.addSpecialPattern("\\\x2e[a-z-_0-9]+[\\sa-z1-6]*", 'WymCss', 'WymCssStyleDeclaration');
3584    
3585    this.addEntryPattern("/\\\x2a", 'WymCss', 'WymCssComment');    this.addEntryPattern("/\\\x2a", 'WymCss', 'WymCssComment');
3586    this.addExitPattern("\\\x2a/", 'WymCssComment');    this.addExitPattern("\\\x2a/", 'WymCssComment');
# Line 3914  WYMeditor.WymClassExplorer.prototype.ins Line 3958  WYMeditor.WymClassExplorer.prototype.ins
3958          // Fall back to the internal paste function if there's no selection          // Fall back to the internal paste function if there's no selection
3959          this.paste(html);          this.paste(html);
3960      }      }
3961    };
3962    
3963    WYMeditor.WymClassExplorer.prototype.wrap = function(left, right) {
3964    
3965        // Get the current selection
3966        var range = this._doc.selection.createRange();
3967    
3968        // Check if the current selection is inside the editor
3969        if ( jQuery(range.parentElement()).parents( this._options.iframeBodySelector ).is('*') ) {
3970            try {
3971                // Overwrite selection with provided html
3972                range.pasteHTML(left + range.text + right);
3973            } catch (e) { }
3974        }
3975    };
3976    
3977    WYMeditor.WymClassExplorer.prototype.unwrap = function() {
3978    
3979        // Get the current selection
3980        var range = this._doc.selection.createRange();
3981    
3982        // Check if the current selection is inside the editor
3983        if ( jQuery(range.parentElement()).parents( this._options.iframeBodySelector ).is('*') ) {
3984            try {
3985                // Unwrap selection
3986                var text = range.text;
3987                this._exec( 'Cut' );
3988                range.pasteHTML( text );
3989            } catch (e) { }
3990        }
3991  };  };
3992    
3993  //keyup handler  //keyup handler
# Line 4579  WYMeditor.WymClassSafari.prototype.openB Line 4653  WYMeditor.WymClassSafari.prototype.openB
4653        var tag = new_tag;        var tag = new_tag;
4654        this._tag_stack.push(new_tag);        this._tag_stack.push(new_tag);
4655        attributes.style = '';        attributes.style = '';
4656    
4657          //should fix #125 - also removed the xhtml() override
4658          if(typeof attributes['class'] == 'string')
4659            attributes['class'] = attributes['class'].replace(/apple-style-span/gi, '');
4660    
4661      } else {      } else {
4662        return;        return;
4663      }      }
# Line 4595  WYMeditor.WymClassSafari.prototype.getTa Line 4674  WYMeditor.WymClassSafari.prototype.getTa
4674    if(/super/.test(style)) return 'sup';    if(/super/.test(style)) return 'sup';
4675    return false;    return false;
4676  };  };
   
 /* @name xhtml  
  * @description Cleans up the HTML  
  */  
 WYMeditor.editor.prototype.xhtml = function() {  
     jQuery('.Apple-style-span', this._doc.body).removeClass('Apple-style-span');  
     return this.parser.parse(this.html());  
 };  
   

Legend:
Removed from v.1.1.2.1.4.2  
changed lines
  Added in v.1.1.2.1.4.3

  ViewVC Help
Powered by ViewVC 1.1.2