// MooTools: the javascript framework. // Load this file's selection again by visiting: http://mootools.net/more/4da9e3082bf0d4194b76d7e5b3874113 // Or build this file again with packager using: packager build More/Element.Forms More/Element.Delegation More/Element.Shortcuts /* --- script: String.Extras.js name: String.Extras description: Extends the String native object to include methods useful in managing various kinds of strings (query strings, urls, html, etc). license: MIT-style license authors: - Aaron Newton - Guillermo Rauch - Christopher Pitt requires: - Core/String - Core/Array provides: [String.Extras] ... */ (function(){ var special = { 'a': /[àáâãäåăą]/g, 'A': /[ÀÁÂÃÄÅĂĄ]/g, 'c': /[ćčç]/g, 'C': /[ĆČÇ]/g, 'd': /[ďđ]/g, 'D': /[ĎÐ]/g, 'e': /[èéêëěę]/g, 'E': /[ÈÉÊËĚĘ]/g, 'g': /[ğ]/g, 'G': /[Ğ]/g, 'i': /[ìíîï]/g, 'I': /[ÌÍÎÏ]/g, 'l': /[ĺľł]/g, 'L': /[ĹĽŁ]/g, 'n': /[ñňń]/g, 'N': /[ÑŇŃ]/g, 'o': /[òóôõöøő]/g, 'O': /[ÒÓÔÕÖØ]/g, 'r': /[řŕ]/g, 'R': /[ŘŔ]/g, 's': /[ššş]/g, 'S': /[ŠŞŚ]/g, 't': /[ťţ]/g, 'T': /[ŤŢ]/g, 'ue': /[ü]/g, 'UE': /[Ü]/g, 'u': /[ùúûůµ]/g, 'U': /[ÙÚÛŮ]/g, 'y': /[ÿý]/g, 'Y': /[ŸÝ]/g, 'z': /[žźż]/g, 'Z': /[ŽŹŻ]/g, 'th': /[þ]/g, 'TH': /[Þ]/g, 'dh': /[ð]/g, 'DH': /[Ð]/g, 'ss': /[ß]/g, 'oe': /[œ]/g, 'OE': /[Œ]/g, 'ae': /[æ]/g, 'AE': /[Æ]/g }, tidy = { ' ': /[\xa0\u2002\u2003\u2009]/g, '*': /[\xb7]/g, '\'': /[\u2018\u2019]/g, '"': /[\u201c\u201d]/g, '...': /[\u2026]/g, '-': /[\u2013]/g, // '--': /[\u2014]/g, '»': /[\uFFFD]/g }; var walk = function(string, replacements){ var result = string; for (key in replacements) result = result.replace(replacements[key], key); return result; }; var getRegexForTag = function(tag, contents){ tag = tag || ''; var regstr = contents ? "<" + tag + "(?!\\w)[^>]*>([\\s\\S]*?)<\/" + tag + "(?!\\w)>" : "<\/?" + tag + "([^>]+)?>"; reg = new RegExp(regstr, "gi"); return reg; }; String.implement({ standardize: function(){ return walk(this, special); }, repeat: function(times){ return new Array(times + 1).join(this); }, pad: function(length, str, direction){ if (this.length >= length) return this; var pad = (str == null ? ' ' : '' + str) .repeat(length - this.length) .substr(0, length - this.length); if (!direction || direction == 'right') return this + pad; if (direction == 'left') return pad + this; return pad.substr(0, (pad.length / 2).floor()) + this + pad.substr(0, (pad.length / 2).ceil()); }, getTags: function(tag, contents){ return this.match(getRegexForTag(tag, contents)) || []; }, stripTags: function(tag, contents){ return this.replace(getRegexForTag(tag, contents), ''); }, tidy: function(){ return walk(this, tidy); } }); })(); /* --- script: More.js name: More description: MooTools More license: MIT-style license authors: - Guillermo Rauch - Thomas Aylott - Scott Kyle - Arian Stolwijk - Tim Wienk - Christoph Pojer - Aaron Newton requires: - Core/MooTools provides: [MooTools.More] ... */ MooTools.More = { 'version': '1.3.0.1', 'build': '6dce99bed2792dffcbbbb4ddc15a1fb9a41994b5' }; /* --- script: Element.Forms.js name: Element.Forms description: Extends the Element native object to include methods useful in managing inputs. license: MIT-style license authors: - Aaron Newton requires: - Core/Element - /String.Extras - /MooTools.More provides: [Element.Forms] ... */ Element.implement({ tidy: function(){ this.set('value', this.get('value').tidy()); }, getTextInRange: function(start, end){ return this.get('value').substring(start, end); }, getSelectedText: function(){ if (this.setSelectionRange) return this.getTextInRange(this.getSelectionStart(), this.getSelectionEnd()); return document.selection.createRange().text; }, getSelectedRange: function(){ if (this.selectionStart != null){ return { start: this.selectionStart, end: this.selectionEnd }; } var pos = { start: 0, end: 0 }; var range = this.getDocument().selection.createRange(); if (!range || range.parentElement() != this) return pos; var duplicate = range.duplicate(); if (this.type == 'text'){ pos.start = 0 - duplicate.moveStart('character', -100000); pos.end = pos.start + range.text.length; } else { var value = this.get('value'); var offset = value.length; duplicate.moveToElementText(this); duplicate.setEndPoint('StartToEnd', range); if (duplicate.text.length) offset -= value.match(/[\n\r]*$/)[0].length; pos.end = offset - duplicate.text.length; duplicate.setEndPoint('StartToStart', range); pos.start = offset - duplicate.text.length; } return pos; }, getSelectionStart: function(){ return this.getSelectedRange().start; }, getSelectionEnd: function(){ return this.getSelectedRange().end; }, setCaretPosition: function(pos){ if (pos == 'end') pos = this.get('value').length; this.selectRange(pos, pos); return this; }, getCaretPosition: function(){ return this.getSelectedRange().start; }, selectRange: function(start, end){ if (this.setSelectionRange){ this.focus(); this.setSelectionRange(start, end); } else { var value = this.get('value'); var diff = value.substr(start, end - start).replace(/\r/g, '').length; start = value.substr(0, start).replace(/\r/g, '').length; var range = this.createTextRange(); range.collapse(true); range.moveEnd('character', start + diff); range.moveStart('character', start); range.select(); } return this; }, insertAtCursor: function(value, select){ var pos = this.getSelectedRange(); var text = this.get('value'); this.set('value', text.substring(0, pos.start) + value + text.substring(pos.end, text.length)); if (select !== false) this.selectRange(pos.start, pos.start + value.length); else this.setCaretPosition(pos.start + value.length); return this; }, insertAroundCursor: function(options, select){ options = Object.append({ before: '', defaultMiddle: '', after: '' }, options); var value = this.getSelectedText() || options.defaultMiddle; var pos = this.getSelectedRange(); var text = this.get('value'); if (pos.start == pos.end){ this.set('value', text.substring(0, pos.start) + options.before + value + options.after + text.substring(pos.end, text.length)); this.selectRange(pos.start + options.before.length, pos.end + options.before.length + value.length); } else { var current = text.substring(pos.start, pos.end); this.set('value', text.substring(0, pos.start) + options.before + current + options.after + text.substring(pos.end, text.length)); var selStart = pos.start + options.before.length; if (select !== false) this.selectRange(selStart, selStart + current.length); else this.setCaretPosition(selStart + text.length); } return this; } }); /* --- name: Events.Pseudos description: Adds the functionallity to add pseudo events license: MIT-style license authors: - Arian Stolwijk requires: [Core/Class.Extras, Core/Slick.Parser, More/MooTools.More] provides: [Events.Pseudos] ... */ Events.Pseudos = function(pseudos, addEvent, removeEvent){ var storeKey = 'monitorEvents:'; var storageOf = function(object){ return { store: object.store ? function(key, value){ object.store(storeKey + key, value); } : function(key, value){ (object.$monitorEvents || (object.$monitorEvents = {}))[key] = value; }, retrieve: object.retrieve ? function(key, dflt){ return object.retrieve(storeKey + key, dflt); } : function(key, dflt){ if (!object.$monitorEvents) return dflt; return object.$monitorEvents[key] || dflt; } }; }; var splitType = function(type){ if (type.indexOf(':') == -1) return null; var parsed = Slick.parse(type).expressions[0][0], parsedPseudos = parsed.pseudos; return (pseudos && pseudos[parsedPseudos[0].key]) ? { event: parsed.tag, value: parsedPseudos[0].value, pseudo: parsedPseudos[0].key, original: type } : null; }; return { addEvent: function(type, fn, internal){ var split = splitType(type); if (!split) return addEvent.call(this, type, fn, internal); var storage = storageOf(this), events = storage.retrieve(type, []), pseudoArgs = Array.from(pseudos[split.pseudo]), proxy = pseudoArgs[1]; var self = this; var monitor = function(){ pseudoArgs[0].call(self, split, fn, arguments, proxy); }; events.include({event: fn, monitor: monitor}); storage.store(type, events); var eventType = split.event; if (proxy && proxy[eventType]) eventType = proxy[eventType].base; addEvent.call(this, type, fn, internal); return addEvent.call(this, eventType, monitor, internal); }, removeEvent: function(type, fn){ var split = splitType(type); if (!split) return removeEvent.call(this, type, fn); var storage = storageOf(this), events = storage.retrieve(type), pseudoArgs = Array.from(pseudos[split.pseudo]), proxy = pseudoArgs[1]; if (!events) return this; var eventType = split.event; if (proxy && proxy[eventType]) eventType = proxy[eventType].base; removeEvent.call(this, type, fn); events.each(function(monitor, i){ if (!fn || monitor.event == fn) removeEvent.call(this, eventType, monitor.monitor); delete events[i]; }, this); storage.store(type, events); return this; } }; }; (function(){ var pseudos = { once: function(split, fn, args){ fn.apply(this, args); this.removeEvent(split.original, fn); } }; Events.definePseudo = function(key, fn){ pseudos[key] = fn; }; var proto = Events.prototype; Events.implement(Events.Pseudos(pseudos, proto.addEvent, proto.removeEvent)); })(); /* --- name: Element.Event.Pseudos description: Adds the functionality to add pseudo events for Elements license: MIT-style license authors: - Arian Stolwijk requires: [Core/Element.Event, Events.Pseudos] provides: [Element.Event.Pseudos] ... */ (function(){ var pseudos = { once: function(split, fn, args){ fn.apply(this, args); this.removeEvent(split.original, fn); } }; Event.definePseudo = function(key, fn, proxy){ pseudos[key] = [fn, proxy]; }; var proto = Element.prototype; [Element, Window, Document].invoke('implement', Events.Pseudos(pseudos, proto.addEvent, proto.removeEvent)); })(); /* --- script: Element.Delegation.js name: Element.Delegation description: Extends the Element native object to include the delegate method for more efficient event management. credits: - "Event checking based on the work of Daniel Steigerwald. License: MIT-style license. Copyright: Copyright (c) 2008 Daniel Steigerwald, daniel.steigerwald.cz" license: MIT-style license authors: - Aaron Newton - Daniel Steigerwald requires: [/MooTools.More, Element.Event.Pseudos] provides: [Element.Delegation] ... */ Event.definePseudo('relay', function(split, fn, args, proxy){ var event = args[0]; var check = proxy ? proxy.condition : null; for (var target = event.target; target && target != this; target = target.parentNode){ var finalTarget = document.id(target); if (Slick.match(target, split.value) && (!check || check.call(finalTarget, event))){ if (finalTarget) fn.call(finalTarget, event, finalTarget); return; } } }, { mouseenter: { base: 'mouseover', condition: Element.Events.mouseenter.condition }, mouseleave: { base: 'mouseout', condition: Element.Events.mouseleave.condition } }); /* --- script: Element.Shortcuts.js name: Element.Shortcuts description: Extends the Element native object to include some shortcut methods. license: MIT-style license authors: - Aaron Newton requires: - Core/Element.Style - /MooTools.More provides: [Element.Shortcuts] ... */ Element.implement({ isDisplayed: function(){ return this.getStyle('display') != 'none'; }, isVisible: function(){ var w = this.offsetWidth, h = this.offsetHeight; return (w == 0 && h == 0) ? false : (w > 0 && h > 0) ? true : this.style.display != 'none'; }, toggle: function(){ return this[this.isDisplayed() ? 'hide' : 'show'](); }, hide: function(){ var d; try { //IE fails here if the element is not in the dom d = this.getStyle('display'); } catch(e){} if (d == 'none') return this; return this.store('element:_originalDisplay', d || '').setStyle('display', 'none'); }, show: function(display){ if (!display && this.isDisplayed()) return this; display = display || this.retrieve('element:_originalDisplay') || 'block'; return this.setStyle('display', (display == 'none') ? 'block' : display); }, swapClass: function(remove, add){ return this.removeClass(remove).addClass(add); } }); Document.implement({ clearSelection: function(){ if (document.selection && document.selection.empty){ document.selection.empty(); } else if (window.getSelection){ var selection = window.getSelection(); if (selection && selection.removeAllRanges) selection.removeAllRanges(); } } });