Changeset 1655 for branches/3.0

Show
Ignore:
Timestamp:
01/25/2007 06:02:53 AM (23 months ago)
Author:
wei
Message:

add Base js.

Location:
branches/3.0/framework/Web/Javascripts
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/3.0/framework/Web/Javascripts/extended/base.js

    r1397 r1655  
    33 * Similar to bindAsEventLister, but takes additional arguments. 
    44 */ 
    5 Function.prototype.bindEvent = function()  
     5Function.prototype.bindEvent = function() 
    66{ 
    77        var __method = this, args = $A(arguments), object = args.shift(); 
    8         return function(event)  
     8        return function(event) 
    99        { 
    1010                return __method.apply(object, [event || window.event].concat(args)); 
     
    2424                var component = Class.create(); 
    2525                Object.extend(component.prototype, base.prototype); 
    26                 if(definition)  
     26                if(definition) 
    2727                        Object.extend(component.prototype, definition); 
    2828                return component; 
    2929} 
     30 
     31/* 
     32        Base, version 1.0.2 
     33        Copyright 2006, Dean Edwards 
     34        License: http://creativecommons.org/licenses/LGPL/2.1/ 
     35*/ 
     36 
     37var Base = function() { 
     38        if (arguments.length) { 
     39                if (this == window) { // cast an object to this class 
     40                        Base.prototype.extend.call(arguments[0], arguments.callee.prototype); 
     41                } else { 
     42                        this.extend(arguments[0]); 
     43                } 
     44        } 
     45}; 
     46 
     47Base.version = "1.0.2"; 
     48 
     49Base.prototype = { 
     50        extend: function(source, value) { 
     51                var extend = Base.prototype.extend; 
     52                if (arguments.length == 2) { 
     53                        var ancestor = this[source]; 
     54                        // overriding? 
     55                        if ((ancestor instanceof Function) && (value instanceof Function) && 
     56                                ancestor.valueOf() != value.valueOf() && /\bbase\b/.test(value)) { 
     57                                var method = value; 
     58                        //      var _prototype = this.constructor.prototype; 
     59                        //      var fromPrototype = !Base._prototyping && _prototype[source] == ancestor; 
     60                                value = function() { 
     61                                        var previous = this.base; 
     62                                //      this.base = fromPrototype ? _prototype[source] : ancestor; 
     63                                        this.base = ancestor; 
     64                                        var returnValue = method.apply(this, arguments); 
     65                                        this.base = previous; 
     66                                        return returnValue; 
     67                                }; 
     68                                // point to the underlying method 
     69                                value.valueOf = function() { 
     70                                        return method; 
     71                                }; 
     72                                value.toString = function() { 
     73                                        return String(method); 
     74                                }; 
     75                        } 
     76                        return this[source] = value; 
     77                } else if (source) { 
     78                        var _prototype = {toSource: null}; 
     79                        // do the "toString" and other methods manually 
     80                        var _protected = ["toString", "valueOf"]; 
     81                        // if we are prototyping then include the constructor 
     82                        if (Base._prototyping) _protected[2] = "constructor"; 
     83                        for (var i = 0; (name = _protected[i]); i++) { 
     84                                if (source[name] != _prototype[name]) { 
     85                                        extend.call(this, name, source[name]); 
     86                                } 
     87                        } 
     88                        // copy each of the source object's properties to this object 
     89                        for (var name in source) { 
     90                                if (!_prototype[name]) { 
     91                                        extend.call(this, name, source[name]); 
     92                                } 
     93                        } 
     94                } 
     95                return this; 
     96        }, 
     97 
     98        base: function() { 
     99                // call this method from any other method to invoke that method's ancestor 
     100        } 
     101}; 
     102 
     103Base.extend = function(_instance, _static) { 
     104        var extend = Base.prototype.extend; 
     105        if (!_instance) _instance = {}; 
     106        // build the prototype 
     107        Base._prototyping = true; 
     108        var _prototype = new this; 
     109        extend.call(_prototype, _instance); 
     110        var constructor = _prototype.constructor; 
     111        _prototype.constructor = this; 
     112        delete Base._prototyping; 
     113        // create the wrapper for the constructor function 
     114        var klass = function() { 
     115                if (!Base._prototyping) constructor.apply(this, arguments); 
     116                this.constructor = klass; 
     117        }; 
     118        klass.prototype = _prototype; 
     119        // build the class interface 
     120        klass.extend = this.extend; 
     121        klass.implement = this.implement; 
     122        klass.toString = function() { 
     123                return String(constructor); 
     124        }; 
     125        extend.call(klass, _static); 
     126        // single instance 
     127        var object = constructor ? klass : _prototype; 
     128        // class initialisation 
     129        if (object.init instanceof Function) object.init(); 
     130        return object; 
     131}; 
     132 
     133Base.implement = function(_interface) { 
     134        if (_interface instanceof Function) _interface = _interface.prototype; 
     135        this.prototype.extend(_interface); 
     136}; 
  • branches/3.0/framework/Web/Javascripts/js/compressed/prado.js

    r1397 r1655  
    1616{var component=Class.create();Object.extend(component.prototype,base.prototype);if(definition) 
    1717Object.extend(component.prototype,definition);return component;} 
    18 Object.extend(String.prototype,{gsub:function(pattern,replacement){var result='',source=this,match;replacement=arguments.callee.prepareReplacement(replacement);while(source.length>0){if(match=source.match(pattern)){result+=source.slice(0,match.index);result+=(replacement(match)||'').toString();source=source.slice(match.index+match[0].length);}else{result+=source,source='';}} 
     18var Base=function(){if(arguments.length){if(this==window){Base.prototype.extend.call(arguments[0],arguments.callee.prototype);}else{this.extend(arguments[0]);}}};Base.version="1.0.2";Base.prototype={extend:function(source,value){var extend=Base.prototype.extend;if(arguments.length==2){var ancestor=this[source];if((ancestor instanceof Function)&&(value instanceof Function)&&ancestor.valueOf()!=value.valueOf()&&/\bbase\b/.test(value)){var method=value;value=function(){var previous=this.base;this.base=ancestor;var returnValue=method.apply(this,arguments);this.base=previous;return returnValue;};value.valueOf=function(){return method;};value.toString=function(){return String(method);};} 
     19return this[source]=value;}else if(source){var _prototype={toSource:null};var _protected=["toString","valueOf"];if(Base._prototyping)_protected[2]="constructor";for(var i=0;(name=_protected[i]);i++){if(source[name]!=_prototype[name]){extend.call(this,name,source[name]);}} 
     20for(var name in source){if(!_prototype[name]){extend.call(this,name,source[name]);}}} 
     21return this;},base:function(){}};Base.extend=function(_instance,_static){var extend=Base.prototype.extend;if(!_instance)_instance={};Base._prototyping=true;var _prototype=new this;extend.call(_prototype,_instance);var constructor=_prototype.constructor;_prototype.constructor=this;delete Base._prototyping;var klass=function(){if(!Base._prototyping)constructor.apply(this,arguments);this.constructor=klass;};klass.prototype=_prototype;klass.extend=this.extend;klass.implement=this.implement;klass.toString=function(){return String(constructor);};extend.call(klass,_static);var object=constructor?klass:_prototype;if(object.init instanceof Function)object.init();return object;};Base.implement=function(_interface){if(_interface instanceof Function)_interface=_interface.prototype;this.prototype.extend(_interface);};Object.extend(String.prototype,{gsub:function(pattern,replacement){var result='',source=this,match;replacement=arguments.callee.prepareReplacement(replacement);while(source.length>0){if(match=source.match(pattern)){result+=source.slice(0,match.index);result+=(replacement(match)||'').toString();source=source.slice(match.index+match[0].length);}else{result+=source,source='';}} 
    1922return result;},sub:function(pattern,replacement,count){replacement=this.gsub.prepareReplacement(replacement);count=count===undefined?1:count;return this.gsub(pattern,function(match){if(--count<0)return match[0];return replacement(match);});},scan:function(pattern,iterator){this.gsub(pattern,iterator);return this;},truncate:function(length,truncation){length=length||30;truncation=truncation===undefined?'...':truncation;return this.length>length?this.slice(0,length-truncation.length)+truncation:this;},strip:function(){return this.replace(/^\s+/,'').replace(/\s+$/,'');},stripTags:function(){return this.replace(/<\/?[^>]+>/gi,'');},stripScripts:function(){return this.replace(new RegExp(Prototype.ScriptFragment,'img'),'');},extractScripts:function(){var matchAll=new RegExp(Prototype.ScriptFragment,'img');var matchOne=new RegExp(Prototype.ScriptFragment,'im');return(this.match(matchAll)||[]).map(function(scriptTag){return(scriptTag.match(matchOne)||['',''])[1];});},evalScripts:function(){return this.extractScripts().map(function(script){return eval(script)});},escapeHTML:function(){var div=document.createElement('div');var text=document.createTextNode(this);div.appendChild(text);return div.innerHTML;},unescapeHTML:function(){var div=document.createElement('div');div.innerHTML=this.stripTags();return div.childNodes[0]?div.childNodes[0].nodeValue:'';},toQueryParams:function(){var pairs=this.match(/^\??(.*)$/)[1].split('&');return pairs.inject({},function(params,pairString){var pair=pairString.split('=');params[pair[0]]=pair[1];return params;});},toArray:function(){return this.split('');},camelize:function(){var oStringList=this.split('-');if(oStringList.length==1)return oStringList[0];var camelizedString=this.indexOf('-')==0?oStringList[0].charAt(0).toUpperCase()+oStringList[0].substring(1):oStringList[0];for(var i=1,len=oStringList.length;i<len;i++){var s=oStringList[i];camelizedString+=s.charAt(0).toUpperCase()+s.substring(1);} 
    2023return camelizedString;},inspect:function(){return"'"+this.replace(/\\/g,'\\\\').replace(/'/g,'\\\'')+"'";}});String.prototype.gsub.prepareReplacement=function(replacement){if(typeof replacement=='function')return replacement;var template=new Template(replacement);return function(match){return template.evaluate(match)};} 
  • branches/3.0/framework/Web/Javascripts/js/debug/prado.js

    r1397 r1655  
    132132 * Similar to bindAsEventLister, but takes additional arguments. 
    133133 */ 
    134 Function.prototype.bindEvent = function()  
     134Function.prototype.bindEvent = function() 
    135135{ 
    136136        var __method = this, args = $A(arguments), object = args.shift(); 
    137         return function(event)  
     137        return function(event) 
    138138        { 
    139139                return __method.apply(object, [event || window.event].concat(args)); 
     
    153153                var component = Class.create(); 
    154154                Object.extend(component.prototype, base.prototype); 
    155                 if(definition)  
     155                if(definition) 
    156156                        Object.extend(component.prototype, definition); 
    157157                return component; 
    158158} 
     159 
     160/* 
     161        Base, version 1.0.2 
     162        Copyright 2006, Dean Edwards 
     163        License: http://creativecommons.org/licenses/LGPL/2.1/ 
     164*/ 
     165 
     166var Base = function() { 
     167        if (arguments.length) { 
     168                if (this == window) { // cast an object to this class 
     169                        Base.prototype.extend.call(arguments[0], arguments.callee.prototype); 
     170                } else { 
     171                        this.extend(arguments[0]); 
     172                } 
     173        } 
     174}; 
     175 
     176Base.version = "1.0.2"; 
     177 
     178Base.prototype = { 
     179        extend: function(source, value) { 
     180                var extend = Base.prototype.extend; 
     181                if (arguments.length == 2) { 
     182                        var ancestor = this[source]; 
     183                        // overriding? 
     184                        if ((ancestor instanceof Function) && (value instanceof Function) && 
     185                                ancestor.valueOf() != value.valueOf() && /\bbase\b/.test(value)) { 
     186                                var method = value; 
     187                        //      var _prototype = this.constructor.prototype; 
     188                        //      var fromPrototype = !Base._prototyping && _prototype[source] == ancestor; 
     189                                value = function() { 
     190                                        var previous = this.base; 
     191                                //      this.base = fromPrototype ? _prototype[source] : ancestor; 
     192                                        this.base = ancestor; 
     193                                        var returnValue = method.apply(this, arguments); 
     194                                        this.base = previous; 
     195                                        return returnValue; 
     196                                }; 
     197                                // point to the underlying method 
     198                                value.valueOf = function() { 
     199                                        return method; 
     200                                }; 
     201                                value.toString = function() { 
     202                                        return String(method); 
     203                                }; 
     204                        } 
     205                        return this[source] = value; 
     206                } else if (source) { 
     207                        var _prototype = {toSource: null}; 
     208                        // do the "toString" and other methods manually 
     209                        var _protected = ["toString", "valueOf"]; 
     210                        // if we are prototyping then include the constructor 
     211                        if (Base._prototyping) _protected[2] = "constructor"; 
     212                        for (var i = 0; (name = _protected[i]); i++) { 
     213                                if (source[name] != _prototype[name]) { 
     214                                        extend.call(this, name, source[name]); 
     215                                } 
     216                        } 
     217                        // copy each of the source object's properties to this object 
     218                        for (var name in source) { 
     219                                if (!_prototype[name]) { 
     220                                        extend.call(this, name, source[name]); 
     221                                } 
     222                        } 
     223                } 
     224                return this; 
     225        }, 
     226 
     227        base: function() { 
     228                // call this method from any other method to invoke that method's ancestor 
     229        } 
     230}; 
     231 
     232Base.extend = function(_instance, _static) { 
     233        var extend = Base.prototype.extend; 
     234        if (!_instance) _instance = {}; 
     235        // build the prototype 
     236        Base._prototyping = true; 
     237        var _prototype = new this; 
     238        extend.call(_prototype, _instance); 
     239        var constructor = _prototype.constructor; 
     240        _prototype.constructor = this; 
     241        delete Base._prototyping; 
     242        // create the wrapper for the constructor function 
     243        var klass = function() { 
     244                if (!Base._prototyping) constructor.apply(this, arguments); 
     245                this.constructor = klass; 
     246        }; 
     247        klass.prototype = _prototype; 
     248        // build the class interface 
     249        klass.extend = this.extend; 
     250        klass.implement = this.implement; 
     251        klass.toString = function() { 
     252                return String(constructor); 
     253        }; 
     254        extend.call(klass, _static); 
     255        // single instance 
     256        var object = constructor ? klass : _prototype; 
     257        // class initialisation 
     258        if (object.init instanceof Function) object.init(); 
     259        return object; 
     260}; 
     261 
     262Base.implement = function(_interface) { 
     263        if (_interface instanceof Function) _interface = _interface.prototype; 
     264        this.prototype.extend(_interface); 
     265}; 
     266 
    159267 
    160268Object.extend(String.prototype, {