Changeset 524

Show
Ignore:
Timestamp:
08/15/08 13:00:25 (3 months ago)
Author:
jf.hovinne
Message:

Moved remaining string and array helpers to WYMeditor.Helper.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/wymeditor/jquery.wymeditor.js

    r523 r524  
    844844    var sName = jQuery(this).attr(WYMeditor.NAME); 
    845845     
    846     var oClass = aClasses.findByName(sName); 
     846    var oClass = WYMeditor.Helper.findByName(aClasses, sName); 
    847847     
    848848    if(oClass) { 
     
    24362436    for(var attribute in attributes) { 
    24372437      var value = attributes[attribute]; 
    2438       if(!this.skiped_attributes.contains(attribute) && !this.skiped_attribute_values.contains(value)){ 
    2439         if (typeof value != 'function' && possible_attributes.contains(attribute)) { 
     2438      var h = WYMeditor.Helper; 
     2439      if(!h.contains(this.skiped_attributes, attribute) && !h.contains(this.skiped_attribute_values, value)){ 
     2440        if (typeof value != 'function' && h.contains(possible_attributes, attribute)) { 
    24402441          if (this.doesAttributeNeedsValidation(tag, attribute)) { 
    24412442            if(this.validateAttribute(tag, attribute, value)){ 
     
    24932494        var defaults = default_attributes_and_events[key]; 
    24942495        if(typeof defaults == 'object'){ 
    2495  
    2496           if ((defaults['except'] && defaults['except'].contains(tag)) || (defaults['only'] && !defaults['only'].contains(tag))) { 
     2496          var h = WYMeditor.Helper; 
     2497          if ((defaults['except'] && h.contains(defaults['except'], tag)) || (defaults['only'] && !h.contains(defaults['only'], tag))) { 
    24972498            continue; 
    24982499          } 
     
    25092510  doesAttributeNeedsValidation: function(tag, attribute) 
    25102511  { 
    2511     return this._tags[tag] && ((this._tags[tag]['attributes'] && this._tags[tag]['attributes'][attribute]) || (this._tags[tag]['required'] && this._tags[tag]['required'].contains(attribute))); 
     2512    return this._tags[tag] && ((this._tags[tag]['attributes'] && this._tags[tag]['attributes'][attribute]) || (this._tags[tag]['required'] && 
     2513     WYMeditor.Helper.contains(this._tags[tag]['required'], attribute))); 
    25122514  }, 
    25132515  validateAttribute : function(tag, attribute, value) 
     
    25152517    if ( this._tags[tag] && 
    25162518      (this._tags[tag]['attributes'] && this._tags[tag]['attributes'][attribute] && value.length > 0 && !value.match(this._tags[tag]['attributes'][attribute])) || // invalid format 
    2517       (this._tags[tag] && this._tags[tag]['required'] && this._tags[tag]['required'].contains(attribute) && value.length == 0) // required attribute 
     2519      (this._tags[tag] && this._tags[tag]['required'] && WYMeditor.Helper.contains(this._tags[tag]['required'], attribute) && value.length == 0) // required attribute 
    25182520    ) { 
    25192521      return false; 
     
    36163618WYMeditor.XhtmlSaxListener.prototype.isBlockTag = function(tag) 
    36173619{ 
    3618   return !this.avoided_tags.contains(tag) && this.block_tags.contains(tag); 
     3620  return !WYMeditor.Helper.contains(this.avoided_tags, tag) && WYMeditor.Helper.contains(this.block_tags, tag); 
    36193621}; 
    36203622 
    36213623WYMeditor.XhtmlSaxListener.prototype.isInlineTag = function(tag) 
    36223624{ 
    3623   return !this.avoided_tags.contains(tag) && this.inline_tags.contains(tag); 
     3625  return !WYMeditor.Helper.contains(this.avoided_tags, tag) && WYMeditor.Helper.contains(this.inline_tags, tag); 
    36243626}; 
    36253627 
     
    38553857}; 
    38563858 
    3857 // String helpers 
    3858 if(!String.prototype.insertAt) { 
    3859     String.prototype.insertAt = function(inserted, pos) { 
    3860         return(this.substr(0,pos) + inserted + this.substring(pos)); 
    3861     }; 
    3862 }; 
     3859// String & array helpers 
    38633860 
    38643861WYMeditor.Helper = { 
    38653862 
     3863    //replace all instances of 'old' by 'rep' in 'str' string 
    38663864    replaceAll: function(str, old, rep) { 
    38673865        var rExp = new RegExp(old, "g"); 
     
    38693867    }, 
    38703868 
     3869    //insert 'inserted' at position 'pos' in 'str' string 
     3870    insertAt: function(str, inserted, pos) { 
     3871        return(str.substr(0,pos) + inserted + str.substring(pos)); 
     3872    }, 
     3873 
     3874    //trim 'str' string 
    38713875    trim: function(str) { 
    38723876        return str.replace(/^(\s*)|(\s*)$/gm,''); 
    3873     } 
    3874 }; 
    3875  
    3876 // Array helpers 
    3877  
    3878 // from http://forum.de.selfhtml.org/archiv/2004/3/t76079/#m438193 (2007-02-06) 
    3879 if(!Array.prototype.contains) { 
    3880     Array.prototype.contains = function (elem) { 
    3881         for (var i = 0; i < this.length; i++) { 
    3882             if (this[i] === elem) return true; 
     3877    }, 
     3878 
     3879    //return true if 'arr' array contains 'elem', or false 
     3880    contains: function(arr, elem) { 
     3881        for (var i = 0; i < arr.length; i++) { 
     3882            if (arr[i] === elem) return true; 
    38833883        } 
    38843884        return false; 
    3885     }; 
    3886 }; 
    3887  
    3888 if(!Array.prototype.indexof) { 
    3889     Array.prototype.indexOf = function (item) { 
    3890             var ret=-1; 
    3891         for(var i = 0; i < this.length; i++) { 
    3892             if (this[i] == item) { 
    3893                 ret=i; 
     3885    }, 
     3886 
     3887    //return 'item' position in 'arr' array, or -1 
     3888    indexOf: function(arr, item) { 
     3889        var ret=-1; 
     3890        for(var i = 0; i < arr.length; i++) { 
     3891            if (arr[i] == item) { 
     3892                ret = i; 
    38943893                break; 
    38953894            } 
    38963895        } 
    38973896            return(ret); 
    3898     }; 
    3899 }; 
    3900  
    3901 if(!Array.prototype.findByName) { 
    3902     Array.prototype.findByName = function (name) { 
    3903         for(var i = 0; i < this.length; i++) { 
    3904             var item = this[i]; 
     3897    }, 
     3898 
     3899    //return 'item' object in 'arr' array, checking its 'name' property, or null 
     3900    findByName: function(arr, name) { 
     3901        for(var i = 0; i < arr.length; i++) { 
     3902            var item = arr[i]; 
    39053903            if(item.name == name) return(item); 
    39063904        } 
    39073905        return(null); 
    3908     }; 
    3909 }; 
     3906    } 
     3907}; 
     3908 
     3909 
  • trunk/src/wymeditor/plugins/hovertools/jquery.wymeditor.hovertools.js

    r485 r524  
    3737      var aClasses = eval(wym._options.classesItems); 
    3838      var sName = jQuery(this).attr(WYMeditor.NAME); 
    39       var oClass = aClasses.findByName(sName); 
     39      var oClass = WYMeditor.Helper.findByName(aClasses, sName); 
    4040 
    4141      if(oClass){