//MooTools More, . Copyright (c) 2006-2009 Aaron Newton , Valerio Proietti & the MooTools team , MIT Style License. /* --- script: More.js description: MooTools More license: MIT-style license authors: - Guillermo Rauch - Thomas Aylott - Scott Kyle requires: - core:1.2.4/MooTools provides: [MooTools.More] ... */ MooTools.More = { 'version': '1.2.4.3', 'build': '6c664838ffa145382c063893d35455a624c13a50' }; /* --- script: Log.js description: Provides basic logging functionality for plugins to implement. license: MIT-style license authors: - Guillermo Rauch - Thomas Aylott - Scott Kyle requires: - core:1.2.4/Class - /MooTools.More provides: [Log] ... */ (function(){ var global = this; var log = function(){ if (global.console && console.log){ try { console.log.apply(console, arguments); } catch(e) { console.log(Array.slice(arguments)); } } else { Log.logged.push(arguments); } return this; }; var disabled = function(){ this.logged.push(arguments); return this; }; this.Log = new Class({ logged: [], log: disabled, resetLog: function(){ this.logged.empty(); return this; }, enableLog: function(){ this.log = log; this.logged.each(function(args){ this.log.apply(this, args); }, this); return this.resetLog(); }, disableLog: function(){ this.log = disabled; return this; } }); Log.extend(new Log).enableLog(); // legacy Log.logger = function(){ return this.log.apply(this, arguments); }; })(); /* --- script: Request.JSONP.js description: Defines Request.JSONP, a class for cross domain javascript via script injection. license: MIT-style license authors: - Aaron Newton - Guillermo Rauch requires: - core:1.2.4/Element - core:1.2.4/Request - /Log provides: [Request.JSONP] ... */ Request.JSONP = new Class({ Implements: [Chain, Events, Options, Log], options: {/* onRetry: $empty(intRetries), onRequest: $empty(scriptElement), onComplete: $empty(data), onSuccess: $empty(data), onCancel: $empty(), log: false, */ url: '', data: {}, retries: 0, timeout: 0, link: 'ignore', callbackKey: 'callback', injectScript: document.head }, initialize: function(options){ this.setOptions(options); if (this.options.log) this.enableLog(); this.running = false; this.requests = 0; this.triesRemaining = []; }, check: function(){ if (!this.running) return true; switch (this.options.link){ case 'cancel': this.cancel(); return true; case 'chain': this.chain(this.caller.bind(this, arguments)); return false; } return false; }, send: function(options){ if (!$chk(arguments[1]) && !this.check(options)) return this; var type = $type(options), old = this.options, index = $chk(arguments[1]) ? arguments[1] : this.requests++; if (type == 'string' || type == 'element') options = {data: options}; options = $extend({data: old.data, url: old.url}, options); if (!$chk(this.triesRemaining[index])) this.triesRemaining[index] = this.options.retries; var remaining = this.triesRemaining[index]; (function(){ var script = this.getScript(options); this.log('JSONP retrieving script with url: ' + script.get('src')); this.fireEvent('request', script); this.running = true; (function(){ if (remaining){ this.triesRemaining[index] = remaining - 1; if (script){ script.destroy(); this.send(options, index).fireEvent('retry', this.triesRemaining[index]); } } else if(script && this.options.timeout){ script.destroy(); this.cancel().fireEvent('failure'); } }).delay(this.options.timeout, this); }).delay(Browser.Engine.trident ? 50 : 0, this); return this; }, cancel: function(){ if (!this.running) return this; this.running = false; this.fireEvent('cancel'); return this; }, getScript: function(options){ var index = Request.JSONP.counter, data; Request.JSONP.counter++; switch ($type(options.data)){ case 'element': data = document.id(options.data).toQueryString(); break; case 'object': case 'hash': data = Hash.toQueryString(options.data); } var src = options.url + (options.url.test('\\?') ? '&' :'?') + (options.callbackKey || this.options.callbackKey) + '=Request.JSONP.request_map.request_'+ index + (data ? '&' + data : ''); if (src.length > 2083) this.log('JSONP '+ src +' will fail in Internet Explorer, which enforces a 2083 bytes length limit on URIs'); var script = new Element('script', {type: 'text/javascript', src: src}); Request.JSONP.request_map['request_' + index] = function(){ this.success(arguments, script); }.bind(this); return script.inject(this.options.injectScript); }, success: function(args, script){ if (script) script.destroy(); this.running = false; this.log('JSONP successfully retrieved: ', args); this.fireEvent('complete', args).fireEvent('success', args).callChain(); } }); Request.JSONP.counter = 0; Request.JSONP.request_map = {};