User:Cap123/iInput.int.js

/*  iInput By Cap123 (c) 2013 Copyright. All Rights Reserved.

function msg(message) { alert(message); } function input(input) { prompt(input); } function ask(question) { confirm(question); } function geolocation(geoloc) { document.write('		if(geo_position_js.init){			geo_position_js.getCurrentPosition(success_callback,error_callback,{enableHighAccuracy:true});		}		else{			alert("Unkown Error");		}

function success_callback(p) {			alert(geoloc); }		function error_callback(p) {			alert("Unkown Error"); }		} '); function pi { alert(math.pi); } function appDownloads(plistfile, codesignProtocol, appManifest, installName){ document.write('' + installName + ''); } function _(element) { var e = element.charAt(0); var el = element.substring(1);

if (e = '#') { return document.getElementById(el); } else if (e = '.') { return document.getElementByClassName(el); } else { return document.getElementByTagName(element); } } function $(element) { if (arguments.length > 1) { for (var i = 0, elements = [], length = arguments.length; i < length; i++) elements.push($(arguments[i])); return elements; } if (Object.isString(element)) element = document.getElementById(element); return Element.extend(element); } function insert(element, insertions) { element = $(element);

if (isContent(insertions)) insertions = { bottom: insertions };

for (var position in insertions) insertContentAt(element, insertions[position], position);

return element; }

function hide(element) { element = $(element); element.style.display = 'none'; return element; }

function show(element) { element = $(element); element.style.display = ''; return element; } function remove(element) { element = $(element); element.parentNode.removeChild(element); return element; } var iInput = { ajax: function(url, options) { return new ajax.request(url, options); } } var ajax = { load: function(url, callback) { var xhr; if(typeof XMLHttpRequest !== 'undefined') xhr = new XMLHttpRequest; else { var versions = ["MSXML2.XmlHttp.5.0", "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.2.0", "Microsoft.XmlHttp"] for(var i = 0, len = versions.length; i < len; i++) { try { xhr = new ActiveXObject(versions[i]); break; }                 catch(e){} }        }          xhr.onreadystatechange = ensureReadiness; function ensureReadiness { if(xhr.readyState < 4) { return; }             if(xhr.status !== 200) { return; }                if(xhr.readyState === 4) { callback(xhr); }                    }          xhr.open('GET', url, true); xhr.send(''); } /* * From here below this code was taken from: * https://github.com/sstephenson/prototype/tree/master/src/prototype/ajax * I give all the credit to Sam Stephen -- The maker of PrototypeJS */ getTransport: function { return Try.these(     function {return new XMLHttpRequest},      function {return new ActiveXObject('Msxml2.XMLHTTP')},      function {return new ActiveXObject('Microsoft.XMLHTTP')}    ) || false; },  activeRequestCount: 0 }; base: Class.create({ initialize: function(options) {    this.options = {      method:       'post',      asynchronous: true,      contentType:  'application/x-www-form-urlencoded',      encoding:     'UTF-8',      parameters:   '',      evalJSON:     true,      evalJS:       true    };    Object.extend(this.options, options || { });

this.options.method = this.options.method.toLowerCase;

if (Object.isHash(this.options.parameters)) this.options.parameters = this.options.parameters.toObject; } PeriodicalUpdater : Class.create(Ajax.Base, { initialize: function($super, container, url, options) {   $super(options);    this.onComplete = this.options.onComplete;

this.frequency = (this.options.frequency || 2); this.decay = (this.options.decay || 1);

this.updater = { }; this.container = container; this.url = url;

this.start; }, start: function { this.options.onComplete = this.updateComplete.bind(this); this.onTimerEvent; }, stop: function { this.updater.options.onComplete = undefined; clearTimeout(this.timer); (this.onComplete || Prototype.emptyFunction).apply(this, arguments); },

updateComplete: function(response) { if (this.options.decay) { this.decay = (response.responseText == this.lastText ?       this.decay * this.options.decay : 1);

this.lastText = response.responseText; }   this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency); },

onTimerEvent: function { this.updater = new Updater(this.container, this.url, this.options); } }); Request : Class.create(base, { _complete: false, initialize: function($super, url, options) { $super(options); this.transport = getTransport; this.request(url); },

request: function(url) { this.url = url; this.method = this.options.method; var params = Object.isString(this.options.parameters) ? this.options.parameters : Object.toQueryString(this.options.parameters);

if (!['get', 'post'].include(this.method)) { params += (params ? '&' : '') + "_method=" + this.method; this.method = 'post'; }

if (params && this.method === 'get') { this.url += (this.url.include('?') ? '&' : '?') + params; }

this.parameters = params.toQueryParams;

try { var response = new Response(this); if (this.options.onCreate) this.options.onCreate(response); Responders.dispatch('onCreate', this, response);

this.transport.open(this.method.toUpperCase, this.url,       this.options.asynchronous);

if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);

this.transport.onreadystatechange = this.onStateChange.bind(this); this.setRequestHeaders;

this.body = this.method == 'post' ? (this.options.postBody || params) : null; this.transport.send(this.body);

if (!this.options.asynchronous && this.transport.overrideMimeType) this.onStateChange;

}   catch (e) { this.dispatchException(e); } },

onStateChange: function { var readyState = this.transport.readyState; if (readyState > 1 && !((readyState == 4) && this._complete)) this.respondToReadyState(this.transport.readyState); },

setRequestHeaders: function { var headers = { 'X-Requested-With': 'XMLHttpRequest', 'X-Prototype-Version': Prototype.Version, 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*' };

if (this.method == 'post') { headers['Content-type'] = this.options.contentType + (this.options.encoding ? '; charset=' + this.options.encoding : ''); if (this.transport.overrideMimeType &&         (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) headers['Connection'] = 'close'; }   if (typeof this.options.requestHeaders == 'object') { var extras = this.options.requestHeaders;

if (Object.isFunction(extras.push)) for (var i = 0, length = extras.length; i < length; i += 2) headers[extras[i]] = extras[i+1]; else $H(extras).each(function(pair) { headers[pair.key] = pair.value }); }

for (var name in headers) if (headers[name] != null) this.transport.setRequestHeader(name, headers[name]); },

success: function { var status = this.getStatus; return !status || (status >= 200 && status < 300) || status == 304; },

getStatus: function { try { if (this.transport.status === 1223) return 204; return this.transport.status || 0; } catch (e) { return 0 } },

respondToReadyState: function(readyState) { var state = Ajax.Request.Events[readyState], response = new Response(this);

if (state == 'Complete') { try { this._complete = true; (this.options['on' + response.status]        || this.options['on' + (this.success ? 'Success' : 'Failure')]        || Prototype.emptyFunction)(response, response.headerJSON); } catch (e) { this.dispatchException(e); }

var contentType = response.getHeader('Content-type'); if (this.options.evalJS == 'force'         || (this.options.evalJS && this.isSameOrigin && contentType && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(.*)?\s*$/i))) this.evalResponse; }

try { (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON); Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON); } catch (e) { this.dispatchException(e); }

if (state == 'Complete') { this.transport.onreadystatechange = Prototype.emptyFunction; } },

isSameOrigin: function { var m = this.url.match(/^\s*https?:\/\/[^\/]*/); return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({ protocol: location.protocol, domain: document.domain, port: location.port ? ':' + location.port : '' })); },  getHeader: function(name) { try { return this.transport.getResponseHeader(name) || null; } catch (e) { return null; } },

evalResponse: function { try { return eval((this.transport.responseText || '').unfilterJSON); } catch (e) { this.dispatchException(e); } },

dispatchException: function(exception) { (this.options.onException || Prototype.emptyFunction)(this, exception); Ajax.Responders.dispatch('onException', this, exception); } });

Ajax.Request.Events = ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']; Responders : function { responders: [],

_each: function(iterator, context) { this.responders._each(iterator, context); },

register: function(responder) { if (!this.include(responder)) this.responders.push(responder); }, unregister: function(responder) { this.responders = this.responders.without(responder); },

dispatch: function(callback, request, transport, json) { this.each(function(responder) {     if (Object.isFunction(responder[callback])) {        try {          responder[callback].apply(responder, [request, transport, json]);        } catch (e) { }      }    }); } };

Object.extend(Ajax.Responders, Enumerable);

Ajax.Responders.register({ onCreate:   function { Ajax.activeRequestCount++ },  onComplete: function { Ajax.activeRequestCount-- } }); Response : Class.create({ initialize: function(request){    this.request = request;    var transport  = this.transport  = request.transport,        readyState = this.readyState = transport.readyState;

if ((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) { this.status      = this.getStatus; this.statusText  = this.getStatusText; this.responseText = String.interpret(transport.responseText); this.headerJSON  = this._getHeaderJSON; }

if (readyState == 4) { var xml = transport.responseXML; this.responseXML = Object.isUndefined(xml) ? null : xml; this.responseJSON = this._getResponseJSON; } },

status:     0,

statusText: '',

getStatus: Ajax.Request.prototype.getStatus,

getStatusText: function { try { return this.transport.statusText || ''; } catch (e) { return '' } }, getHeader: Ajax.Request.prototype.getHeader, getAllHeaders: function { try { return this.getAllResponseHeaders; } catch (e) { return null } }, getResponseHeader: function(name) { return this.transport.getResponseHeader(name); }, getAllResponseHeaders: function { return this.transport.getAllResponseHeaders; },

_getHeaderJSON: function { var json = this.getHeader('X-JSON'); if (!json) return null;

try { json = decodeURIComponent(escape(json)); } catch(e) { }   try { return json.evalJSON(this.request.options.sanitizeJSON ||       !this.request.isSameOrigin); } catch (e) { this.request.dispatchException(e); } },

_getResponseJSON: function { var options = this.request.options; if (!options.evalJSON || (options.evalJSON != 'force' && !(this.getHeader('Content-type') || '').include('application/json')) ||       this.responseText.blank) return null; try { return this.responseText.evalJSON(options.sanitizeJSON ||       !this.request.isSameOrigin); } catch (e) { this.request.dispatchException(e); } } }); Updater : Class.create(Ajax.Request, { initialize: function($super, container, url, options) { this.container = { success: (container.success || container), failure: (container.failure || (container.success ? null : container)) };

options = Object.clone(options); var onComplete = options.onComplete; options.onComplete = (function(response, json) {     this.updateContent(response.responseText);      if (Object.isFunction(onComplete)) onComplete(response, json);    }).bind(this);

$super(url, options); },

updateContent: function(responseText) { var receiver = this.container[this.success ? 'success' : 'failure'], options = this.options;

if (!options.evalScripts) responseText = responseText.stripScripts;

if (receiver = $(receiver)) { if (options.insertion) { if (Object.isString(options.insertion)) { var insertion = { }; insertion[options.insertion] = responseText; receiver.insert(insertion); }       else options.insertion(receiver, responseText); }     else receiver.update(responseText); } } }); } var Class = (function { var IS_DONTENUM_BUGGY = (function{                                     for (var p in { toString: 1 }) {                                      if (p === 'toString') return false;                                      }                                      return true;                                      }); function subclass {}; function create { var parent = null, properties = $A(arguments); if (Object.isFunction(properties[0])) parent = properties.shift; function klass { this.initialize.apply(this, arguments); }            Object.extend(klass, Class.Methods); klass.superclass = parent; klass.subclasses = []; if (parent) { subclass.prototype = parent.prototype; klass.prototype = new subclass; parent.subclasses.push(klass); }            for (var i = 0, length = properties.length; i < length; i++) klass.addMethods(properties[i]); if (!klass.prototype.initialize) klass.prototype.initialize = Prototype.emptyFunction; klass.prototype.constructor = klass; return klass; }            function addMethods(source) { var ancestor  = this.superclass && this.superclass.prototype, properties = Object.keys(source); if (IS_DONTENUM_BUGGY) { if (source.toString != Object.prototype.toString) properties.push("toString"); if (source.valueOf != Object.prototype.valueOf) properties.push("valueOf"); }            for (var i = 0, length = properties.length; i < length; i++) { var property = properties[i], value = source[property]; if (ancestor && Object.isFunction(value) &&                value.argumentNames[0] == "$super") { var method = value; value = (function(m) {                     return function { return ancestor[m].apply(this, arguments); };                      })(property).wrap(method); value.valueOf = (function(method) {                             return function { return method.valueOf.call(method); };                              })(method); value.toString = (function(method) {                              return function { return method.toString.call(method); };                               })(method); }            this.prototype[property] = value; }            return this; }            return { create: create, Methods: { addMethods: addMethods }            };             });

/* * Feel free to take some ajax code. * Make sure you add: var class = function { * It ends just above this message where there is: }); * Be a script bunny (Some one who steels code) from: var ajax = function { * Until the end of the class making */