halo-theme-hao/templates/assets/libs/link/protoclass.min.js
2024-04-12 14:35:37 +08:00

1 line
3.4 KiB
JavaScript

var Class={create:function(){var parent=null,properties=$A(arguments);function klass(){this.initialize.apply(this,arguments)}if(Object.isFunction(properties[0])&&(parent=properties.shift()),Object.extend(klass,Class.Methods),klass.superclass=parent,klass.subclasses=[],parent){var subclass=function(){};subclass.prototype=parent.prototype,klass.prototype=new subclass,parent.subclasses.push(klass)}for(var i=0;i<properties.length;i++)klass.addMethods(properties[i]);return klass.prototype.initialize||(klass.prototype.initialize=this.emptyFunction),klass.prototype.constructor=klass,klass},emptyFunction:function(){}};function $A(iterable){if(!iterable)return[];if(iterable.toArray)return iterable.toArray();for(var length=iterable.length||0,results=new Array(length);length--;)results[length]=iterable[length];return results}Class.Methods={addMethods:function(source){var ancestor=this.superclass&&this.superclass.prototype,properties=Object.keys(source);Object.keys({toString:!0}).length||properties.push("toString","valueOf");for(var i=0,length=properties.length;i<length;i++){var property=properties[i],value=source[property];if(ancestor&&Object.isFunction(value)&&"$super"==value.argumentNames().first()){var method=value;value=Object.extend(function(m){return function(){return ancestor[m].apply(this,arguments)}}(property).wrap(method),{valueOf:function(){return method},toString:function(){return method.toString()}})}this.prototype[property]=value}return this}},Object.extend=function(destination,source){for(var property in source)destination[property]=source[property];return destination},Object.extend(Object,{inspect:function(object){try{return Object.isUndefined(object)?"undefined":null===object?"null":object.inspect?object.inspect():String(object)}catch(e){if(e instanceof RangeError)return"...";throw e}},toJSON:function(object){switch(typeof object){case"undefined":case"function":case"unknown":return;case"boolean":return object.toString()}if(null===object)return"null";if(object.toJSON)return object.toJSON();if(!Object.isElement(object)){var results=[];for(var property in object){var value=Object.toJSON(object[property]);Object.isUndefined(value)||results.push(property.toJSON()+": "+value)}return"{"+results.join(", ")+"}"}},toQueryString:function(object){return $H(object).toQueryString()},toHTML:function(object){return object&&object.toHTML?object.toHTML():String.interpret(object)},keys:function(object){var keys=[];for(var property in object)keys.push(property);return keys},values:function(object){var values=[];for(var property in object)values.push(object[property]);return values},clone:function(object){return Object.extend({},object)},isElement:function(object){return object&&1==object.nodeType},isArray:function(object){return null!=object&&"object"==typeof object&&"splice"in object&&"join"in object},isHash:function(object){return object instanceof Hash},isFunction:function(object){return"function"==typeof object},isString:function(object){return"string"==typeof object},isNumber:function(object){return"number"==typeof object},isUndefined:function(object){return void 0===object}}),(WebKit=navigator.userAgent.indexOf("AppleWebKit/")>-1)&&($A=function(iterable){if(!iterable)return[];if((!Object.isFunction(iterable)||"[object NodeList]"!=iterable)&&iterable.toArray)return iterable.toArray();for(var length=iterable.length||0,results=new Array(length);length--;)results[length]=iterable[length];return results});