Home » Source Code » » prototype.js

prototype.js ( File view )

From:
  • By 2010-08-11
  • View(s):5
  • Download(s):0
  • Point(s): 1
			/*  Prototype JavaScript framework, version 1.5.0_rc0
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
/*--------------------------------------------------------------------------*/

var Prototype = {

  Version: '1.5.0_rc0',
  ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',

  emptyFunction: function() {

},
  K: function(x) {
return x
}

}

var Class = {

  create: function() {

    return function() {

      this.initialize.apply(this, arguments);
    
}
  
}

}

var Abstract = new Object();

Object.extend = function(destination, source) {

  for (var property in source) {

    destination[property] = source[property];
  
}
  return destination;

}

Object.inspect = function(object) {

  try {

    if (object == undefined) return 'undefined';
    if (object == null) return 'null';
    return object.inspect ? object.inspect() : object.toString();
  
} catch (e) {

    if (e instanceof RangeError) return '...';
    throw e;
  
}

}

Function.prototype.bind = function() {

  var __method = this, args = $A(arguments), object = args.shift();
  return function() {

    return __method.apply(object, args.concat($A(arguments)));
  
}

}

Function.prototype.bindAsEventListener = function(object) {

  var __method = this;
  return function(event) {

    return __method.call(object, event || window.event);
  
}

}

Object.extend(Number.prototype, {

  toColorPart: function() {

    var digits = this.toString(16);
    if (this < 16) return '0' + digits;
    return digits;
  
},

  succ: function() {

    return this + 1;
  
},

  times: function(iterator) {

    $R(0, this, true).each(iterator);
    return this;
  
}

});

var Try = {

  these: function() {

    var returnValue;

    for (var i = 0; i < arguments.length; i++) {

      var lambda = arguments[i];
      try {

        returnValue = lambda();
        break;
      
} catch (e) {

}
    
}

    return returnValue;
  
}

}

/*--------------------------------------------------------------------------*/

var PeriodicalExecuter = Class.create();
PeriodicalExecuter.prototype = {

  initialize: function(callback, frequency) {

    this.callback = callback;
    this.frequency = frequency;
    this.currentlyExecuting = false;

    this.registerCallback();
  
},

  registerCallback: function() {

    setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
  
},

  onTimerEvent: function() {

    if (!this.currentlyExecuting) {

      try {

        this.currentlyExecuting = true;
        this.callback();
      
} finally {

        this.currentlyExecuting = false;
      
}
    
}
  
}

}
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 = '';
      
}
    
}
    return 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);
    
}

    return 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) 
};

}

String.prototype.parseQuery = String.prototype.toQueryParams;

var Template = Class.create();
Template.Pattern = /(^|.|\r|\n)(#\{
(.*?)\
})/;
Template.prototype = {

  initialize: function(template, pattern) {

    this.template = template.toString();
    this.pattern  = pattern || Template.Pattern;
  
},

  evaluate: function(object) {

    return this.template.gsub(this.pattern, function(match) {

      var before = match[1];
      if (before == '\\') return match[2];
      return before + (object[match[3]] || '').toString();
    
});
  
}

}

var $break    = new Object();
var $continue = new Object();

var Enumerable = {

  each: function(iterator) {

    var index = 0;
    try {

      this._each(function(value) {

        try {

          iterator(value, index++);
        
} catch (e) {

          if (e != $continue) throw e;
        
}
      
});
    
} catch (e) {

      if (e != $break) throw e;
    
}
  
},

  all: function(iterator) {

    var result = true;
    this.each(function(value, index) {

      result = result && !!(iterator || Prototype.K)(value, index);
      if (!result) throw $break;
    
});
    return result;
  
},

  any: function(iterator) {

    var result = true;
    this.each(function(value, index) {

      if (result = !!(iterator || Prototype.K)(value, index))
        throw $break;
    
});
    return result;
  
},

  collect: function(iterator) {

    var results = [];
    this.each(function(value, index) {

      results.push(iterator(value, index));
    
});
    return results;
  
},

  detect: function (iterator) {

    var result;
    this.each(function(value, index) {

      if (iterator(value, index)) {

        result = value;
        throw $break;
      
}
    
});
    return result;
  
},

  findAll: function(iterator) {

    var results = [];
    this.each(function(value, index) {

      if (iterator(value, index))
        results.push(value);
    
});
    return results;
  
},

  grep: function(pattern, iterator) {

    var results = [];
    this.each(function(value, index) {

      var stringValue = value.toString();
      if (stringValue.match(pattern))
        results.push((iterator || Prototype.K)(value, index));
    
})
    return results;
  
},

  include: function(object) {

    var found = false;
    this.each(function(value) {

      if (value == object) {

        found = true;
        throw $break;
      
}
    
});
    return found;
  
},

  inject: function(memo, iterator) {

    this.each(function(value, index) {

      memo = iterator(memo, value, index);
    
});
    return memo;
  
},

  invoke: function(method) {

    var args = $A(arguments).slice(1);
    return this.collect(function(value) {

      return value[method].apply(value, args);
    
});
  
},

  max: function(iterator) {

    var result;
    this.each(function(value, index) {

      value = (iterator || Prototype.K)(value, index);
      if (result == undefined || value >= result)
        result = value;
    
});
    return result;
  
},

  min: function(iterator) {

    var result;
    this.each(function(value, index) {

      value = (iterator || Prototype.K)(value, index);
      if (result == undefined || value < result)
        result = value;
    
});
    return result;
  
},

  partition: function(iterator) {

    var trues = [], falses = [];
    this.each(function(value, index) {

      ((iterator || Prototype.K)(value, index) ?
        trues : falses).push(value);
    
});
    return [trues, falses];
  
},

  pluck: function(property) {

    var results = [];
    this.each(function(value, index) {

      results.push(value[property]);
    
});
    return results;
  
},

  reject: function(iterator) {

    var results = [];
    this.each(function(value, index) {

      if (!iterator(value, index))
        results.push(value);
    
});
    return results;
  
},

  sortBy: function(iterator) {

    return this.collec
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
auto_suggest.html1.09 kB03-12-07 00:11
crud.html1.68 kB03-12-07 00:11
03.00 B
2col_leftNav.css6.28 kB03-12-07 00:11
autosuggest.css335.00 B03-12-07 00:11
debug.png399.00 B03-12-07 00:11
error.png289.00 B03-12-07 00:11
fatal.png309.00 B03-12-07 00:11
info.png271.00 B03-12-07 00:11
logger.css1.88 kB03-12-07 00:11
magnet.png430.00 B03-12-07 00:11
site.css1.43 kB03-12-07 00:11
warn.png257.00 B03-12-07 00:11
03.00 B
auto_suggest.html.txt1.09 kB03-12-07 00:11
auto_suggest.js.txt669.00 B03-12-07 00:11
CountryList.java.txt3.00 kB03-12-07 00:11
crud.html.txt1.68 kB03-12-07 00:11
crud.js.txt1.40 kB03-12-07 00:11
crud.jst.txt755.00 B03-12-07 00:11
index.html.txt3.24 kB03-12-07 00:11
jst_demo.html.txt1.68 kB03-12-07 00:11
LabelValueBean.java.txt4.72 kB03-12-07 00:11
mvcPic.html.txt1.05 kB03-12-07 00:11
rdf.jst.txt284.00 B03-12-07 00:11
rss.jst.txt272.00 B03-12-07 00:11
rss_reader.html.txt1.20 kB03-12-07 00:11
rss_reader.js.txt642.00 B03-12-07 00:11
services.properties.txt168.00 B03-12-07 00:11
services.xml.txt435.00 B03-12-07 00:11
Test.java.txt17.36 kB03-12-07 00:11
TestBean.java.txt1.41 kB03-12-07 00:11
unit_test.html.txt1.03 kB03-12-07 00:11
unit_test.js.txt15.89 kB03-12-07 00:11
unit_test.jst.txt493.00 B03-12-07 00:11
unit_test_js.jst.txt765.00 B03-12-07 00:11
User.java.txt2.49 kB03-12-07 00:11
UserManager.java.txt2.04 kB03-12-07 00:11
web.xml.txt1.58 kB03-12-07 00:11
web.xml_no_spring.txt1.58 kB03-12-07 00:11
03.00 B
check.gif604.00 B03-12-07 00:11
debug.png399.00 B03-12-07 00:11
error.gif633.00 B03-12-07 00:11
error.png289.00 B03-12-07 00:11
fatal.png309.00 B03-12-07 00:11
info.png271.00 B03-12-07 00:11
magnet.png430.00 B03-12-07 00:11
swato_01.png5.22 kB03-12-07 00:11
swato_02.png13.94 kB03-12-07 00:11
swato_04.png7.94 kB03-12-07 00:11
swato_05.png14.42 kB03-12-07 00:11
swato_Layer-5-over.png27.12 kB03-12-07 00:11
swato_Layer_5.png28.45 kB03-12-07 00:11
wait.gif1.52 kB03-12-07 00:11
warn.png257.00 B03-12-07 00:11
index.html3.70 kB03-12-07 00:11
03.00 B
effects.js33.07 kB03-12-07 00:11
jkl-floating.js7.22 kB03-12-07 00:11
jkl-parsexml.js14.11 kB03-12-07 00:11
jkl-resizable.js5.05 kB03-12-07 00:11
json.js10.34 kB03-12-07 00:11
logger.js6.77 kB03-12-07 00:11
pop-it-menu.js4.44 kB03-12-07 00:11
prototype.js55.81 kB03-12-07 00:11
swato-engine.js5.06 kB03-12-07 00:11
swato-form.js3.00 kB03-12-07 00:11
swato-jst.js3.91 kB03-12-07 00:11
swato-select.js1.18 kB03-12-07 00:11
swato-suggest.js11.62 kB03-12-07 00:11
swato.js939.00 B03-12-07 00:11
window.js40.77 kB03-12-07 00:11
03.00 B
crud.jst744.00 B03-12-07 00:11
rdf.jst284.00 B03-12-07 00:11
rss.jst272.00 B03-12-07 00:11
unit_test.jst493.00 B03-12-07 00:11
unit_test_js.jst765.00 B03-12-07 00:11
jst_demo.html1.68 kB03-12-07 00:11
03.00 B
MANIFEST.MF106.00 B03-12-07 00:11
mvcPic.html1.05 kB03-12-07 00:11
rss_reader.html1.20 kB03-12-07 00:11
03.00 B
auto_suggest.js665.00 B03-12-07 00:11
crud.js1.41 kB03-12-07 00:11
portal.js4.66 kB03-12-07 00:11
rss_reader.js642.00 B03-12-07 00:11
unit_test.js15.89 kB03-12-07 00:11
swato.jar56.50 kB08-04-08 10:57
test.html18.36 kB03-12-07 00:11
unit_test.html1.03 kB03-12-07 00:11
03.00 B
03.00 B
03.00 B
03.00 B
JSONArray.class8.16 kB03-12-07 00:11
JSONObject$1.class199.00 B03-12-07 00:11
JSONObject$Null.class860.00 B03-12-07 00:11
JSONObject.class10.41 kB03-12-07 00:11
JSONTokener.class5.17 kB03-12-07 00:11
03.00 B
03.00 B
03.00 B
CountryList.class2.52 kB03-12-07 00:11
LabelValueBean$1.class825.00 B03-12-07 00:11
LabelValueBean.class2.15 kB03-12-07 00:11
LabelValueBeanTest.class1.88 kB03-12-07 00:11
ObjA.class571.00 B03-12-07 00:11
ObjB.class571.00 B03-12-07 00:11
Test$1.class565.00 B03-12-07 00:11
Test$2.class714.00 B03-12-07 00:11
Test$Foo.class231.00 B03-12-07 00:11
Test$InnerFoo.class643.00 B03-12-07 00:11
Test$InnerSubTestBean.class520.00 B03-12-07 00:11
Test$StaticInnerSubTestBean.class437.00 B03-12-07 00:11
Test$TestBeanInvocationHandler.class1.56 kB03-12-07 00:11
Test.class13.72 kB03-12-07 00:11
TestBean.class1.27 kB03-12-07 00:11
User.class1.65 kB03-12-07 00:11
UserManager.class2.27 kB03-12-07 00:11
JSONConverter.class8.00 kB03-12-07 00:11
JSONConverterTest$1.class240.00 B03-12-07 00:11
JSONConverterTest$TestBean.class1.73 kB03-12-07 00:11
JSONConverterTest.class6.13 kB03-12-07 00:11
03.00 B
JSONRequest.class2.96 kB03-12-07 00:11
JSONResponse.class2.41 kB03-12-07 00:11
JSONServlet.class4.00 kB03-12-07 00:11
PropsFileContext.class3.48 kB03-12-07 00:11
RequestAware.class198.00 B03-12-07 00:11
RequestParameterHolder.class2.36 kB03-12-07 00:11
RequestParameterRecorder.class2.17 kB03-12-07 00:11
RequestRedirector.class2.78 kB03-12-07 00:11
ServiceContext.class243.00 B03-12-07 00:11
SessionAware.class191.00 B03-12-07 00:11
SpringContext.class1.39 kB03-12-07 00:11
SwatoActionProxy.class4.86 kB03-12-07 00:11
SwatoVisible.class396.00 B03-12-07 00:11
03.00 B
Pipe.class2.02 kB03-12-07 00:11
Utils.class632.00 B03-12-07 00:11
services.properties168.00 B03-12-07 00:11
services.xml881.00 B03-12-07 00:11
03.00 B
commons-httpclient-2.0.2.jar220.09 kB03-12-07 00:11
commons-logging.jar37.12 kB03-12-07 00:11
spring-beans.jar213.99 kB03-12-07 00:11
spring-context.jar100.22 kB03-12-07 00:11
spring-core.jar71.98 kB03-12-07 00:11
web.xml1.58 kB03-12-07 00:11
...
Sponsored links

prototype.js (884.61 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D