From acb2a371e539beac251e9ea6f4405f5ef24cf9b7 Mon Sep 17 00:00:00 2001 From: Denis Shulyaka Date: Wed, 11 Mar 2015 23:09:25 +0300 Subject: [PATCH] Update mediaboxAdvanced and mootools to the latest upstream version Sources: https://github.com/iaian7/mediaboxAdvanced and http://mootools.net/ Signed-off-by: Denis Shulyaka --- src/images/50.gif | Bin 77 -> 0 bytes src/images/{loading.gif => loading-dark.gif} | Bin .../{loading3.gif => loading-light.gif} | Bin .../{loading2.gif => loading-minimal.gif} | Bin .../mediaboxAdv-Dark.css} | 62 +- .../mediaboxAdv-Light.css} | 82 +- src/images/mediaboxAdv-Minimal.css | 158 + src/images/mediaboxAdv-Smooth.css | 233 + .../{mediaboxAdv-1.3.4b.js => mediaboxAdv.js} | 593 +-- src/js/mootools.js | 4229 ++++++++++------- src/templates/exhibition.html | 4 +- src/templates/integrate.html | 4 +- src/templates/mano.html | 4 +- 13 files changed, 3299 insertions(+), 2070 deletions(-) delete mode 100644 src/images/50.gif rename src/images/{loading.gif => loading-dark.gif} (100%) rename src/images/{loading3.gif => loading-light.gif} (100%) rename src/images/{loading2.gif => loading-minimal.gif} (100%) rename src/{css/mediaboxAdvBlack21.css => images/mediaboxAdv-Dark.css} (80%) rename src/{css/mediaboxAdvWhite.css => images/mediaboxAdv-Light.css} (75%) create mode 100644 src/images/mediaboxAdv-Minimal.css create mode 100644 src/images/mediaboxAdv-Smooth.css rename src/js/{mediaboxAdv-1.3.4b.js => mediaboxAdv.js} (59%) diff --git a/src/images/50.gif b/src/images/50.gif deleted file mode 100644 index 580f9887ce5f7c62ae5cae0deabe61e707843986..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 77 zcmZ?wbhEHb6k!lyXkcUjg8%>jEB<5wG8q|kKzxu41CxqN&+?hC|179!^ebC?NwVZ@ b;eC-f< - based on Slimbox v1.64 - The ultimate lightweight Lightbox clone - (c) 2007-2008 Christophe Beyls - MIT-style license. +mediaboxAdvanced v1.5.4 - The ultimate extension of Slimbox and Mediabox; an all-media script +updated 2011.2.19 + (c) 2007-2011 John Einselen - http://iaian7.com +based on Slimbox v1.64 - The ultimate lightweight Lightbox clone + (c) 2007-2008 Christophe Beyls - http://www.digitalia.be + +description: The ultimate extension of Slimbox and Mediabox; an all-media script + +license: MIT-style + +authors: +- John Einselen +- Christophe Beyls +- Contributions from many others + +requires: +- core/1.3.2: [Core, Array, String, Number, Function, Object, Event, Browser, Class, Class.Extras, Slick.*, Element.*, FX.*, DOMReady, Swiff] +- Quickie/2.1: '*' + +provides: [Mediabox.open, Mediabox.close, Mediabox.recenter, Mediabox.scanPage] */ var Mediabox; (function() { // Global variables, accessible to Mediabox only - var options, images, activeImage, prevImage, nextImage, top, mTop, left, mLeft, winWidth, winHeight, fx, preload, preloadPrev = new Image(), preloadNext = new Image(), foxfix = false, iefix = false, + var options, mediaArray, activeMedia, prevMedia, nextMedia, top, mTop, left, mLeft, winWidth, winHeight, fx, preload, preloadPrev = new Image(), preloadNext = new Image(), // DOM elements - overlay, center, image, bottom, captionSplit, title, caption, prevLink, number, nextLink, + overlay, center, media, bottom, captionSplit, title, caption, number, prevLink, nextLink, // Mediabox specific vars - URL, WH, WHL, elrel, mediaWidth, mediaHeight, mediaType = "none", mediaSplit, mediaId = "mediaBox", mediaFmt, margin; + URL, WH, WHL, elrel, mediaWidth, mediaHeight, mediaType = "none", mediaSplit, mediaId = "mediaBox", margin, marginBottom; /* Initialization */ @@ -28,19 +42,20 @@ var Mediabox; ]).setStyle("display", "none") ); - image = new Element("div", {id: "mbImage"}).injectInside(center); - bottom = new Element("div", {id: "mbBottom"}).injectInside(center).adopt( + container = new Element("div", {id: "mbContainer"}).inject(center, "inside"); + media = new Element("div", {id: "mbMedia"}).inject(container, "inside"); + bottom = new Element("div", {id: "mbBottom"}).inject(center, "inside").adopt( closeLink = new Element("a", {id: "mbCloseLink", href: "#"}).addEvent("click", close), nextLink = new Element("a", {id: "mbNextLink", href: "#"}).addEvent("click", next), prevLink = new Element("a", {id: "mbPrevLink", href: "#"}).addEvent("click", previous), title = new Element("div", {id: "mbTitle"}), number = new Element("div", {id: "mbNumber"}), caption = new Element("div", {id: "mbCaption"}) - ); + ); fx = { overlay: new Fx.Tween(overlay, {property: "opacity", duration: 360}).set(0), - image: new Fx.Tween(image, {property: "opacity", duration: 360, onComplete: captionAnimate}), + media: new Fx.Tween(media, {property: "opacity", duration: 360, onComplete: captionAnimate}), bottom: new Fx.Tween(bottom, {property: "opacity", duration: 240}).set(0) }; }); @@ -52,27 +67,49 @@ var Mediabox; close(); // Thanks to Yosha on the google group for fixing the close function API! }, - open: function(_images, startImage, _options) { - options = $extend({ - text: ['«','»','×'], // Set "previous", "next", and "close" button content (HTML code should be written as entity codes or properly escaped) -// text: ['«','»','×'], // Set "previous", "next", and "close" button content (HTML code should be written as entity codes or properly escaped) -// example text: ['Prev','Next','Close'], - loop: true, // Allows to navigate between first and last images + recenter: function(){ // Thanks to Garo Hussenjian (Xapnet Productions http://www.xapnet.com) for suggesting this addition + if (center && !Browser.Platform.ios) { + left = window.getScrollLeft() + (window.getWidth()/2); + center.setStyles({left: left, marginLeft: -(mediaWidth/2)-margin}); +// top = window.getScrollTop() + (window.getHeight()/2); +// margin = center.getStyle('padding-left').toInt()+media.getStyle('margin-left').toInt()+media.getStyle('padding-left').toInt(); +// center.setStyles({top: top, left: left, marginTop: -(mediaHeight/2)-margin, marginLeft: -(mediaWidth/2)-margin}); + } + }, + + open: function(_mediaArray, startMedia, _options) { + options = { +// Text options (translate as needed) + buttonText: ['«','»','×'], // Array defines "previous", "next", and "close" button content (HTML code should be written as entity codes or properly escaped) +// buttonText: ['«','»','×'], +// buttonText: ['Prev','Next','Close'], + counterText: '({x} / {y})', // Counter text, {x} = current item number, {y} = total gallery length + linkText: '{x}
open in a new tab', // Text shown on iOS devices for non-image links + flashText: 'Error
Adobe Flash is either not installed or not up to date, please visit Adobe.com to download the free player.', // Text shown if Flash is not installed. +// General overlay options + center: true, // Set to false for use with custom CSS layouts + loop: true, // Navigate from last to first elements in a gallery keyboard: true, // Enables keyboard control; escape key, left arrow, and right arrow - alpha: true, // Adds 'x', 'c', 'p', and 'n' when keyboard control is also set to true - stopKey: false, // Stops all default keyboard actions while overlay is open (such as up/down arrows) - // Does not apply to iFrame content, does not affect mouse scrolling - overlayOpacity: 0.7, // 1 is opaque, 0 is completely transparent (change the color in the CSS file) + keyboardAlpha: false, // Adds 'x', 'c', 'p', and 'n' when keyboard control is also set to true + keyboardStop: false, // Stops all default keyboard actions while overlay is open (such as up/down arrows) + // Does not apply to iFrame content, does not affect mouse scrolling + overlayOpacity: 0.8, // 1 is opaque, 0 is completely transparent (change the color in the CSS file) resizeOpening: true, // Determines if box opens small and grows (true) or starts at larger size (false) resizeDuration: 240, // Duration of each of the box resize animations (in milliseconds) - resizeTransition: false, // Mootools transition effect (false leaves it at the default) initialWidth: 320, // Initial width of the box (in pixels) initialHeight: 180, // Initial height of the box (in pixels) defaultWidth: 640, // Default width of the box (in pixels) for undefined media (MP4, FLV, etc.) defaultHeight: 360, // Default height of the box (in pixels) for undefined media (MP4, FLV, etc.) showCaption: true, // Display the title and caption, true / false showCounter: true, // If true, a counter will only be shown if there is more than 1 image to display - counterText: '({x} / {y})', // Translate or change as you wish + countBack: false, // Inverts the displayed number (so instead of the first element being labeled 1/10, it's 10/10) + clickBlock: true, // Adds an event on right-click to block saving of images from the context menu in most browsers (this can't prevent other ways of downloading, but works as a casual deterent) + // due to less than ideal code ordering, clickBlock on links must be removed manually around line 250 +// iOS device options +// iOSenable: false, // When set to false, disables overlay entirely (links open in new tab) + // IMAGES and INLINE content will display normally, + // while ALL OTHER content will display a direct link (this is required so as to not break mixed-media galleries) + iOShtml: true, // If set to true, HTML content is displayed normally as well (useful if your HTML content is minimal and UI oriented instead of external sites) // Image options imgBackground: false, // Embed images as CSS background (true) or tag (false) // CSS background is naturally non-clickable, preventing downloads @@ -81,7 +118,8 @@ var Mediabox; imgPadding: 100, // Clearance necessary for images larger than the window size (only used when imgBackground is false) // Change this number only if the CSS style is significantly divergent from the original, and requires different sizes // Inline options -// overflow: 'auto', // If set, overides CSS settings for inline content only + overflow: 'auto', // If set, overides CSS settings for inline content only, set to "false" to leave CSS settings intact. + inlineClone: false, // Clones the inline element instead of moving it from the page to the overlay // Global media options html5: 'true', // HTML5 settings for YouTube and Vimeo, false = off, true = on scriptaccess: 'true', // Allow script access to flash files @@ -93,20 +131,16 @@ var Mediabox; volume: '100', // 0-100, used for NonverBlaster and Quicktime players medialoop: 'true', // Loop video playback, true / false, used for NonverBlaster and Quicktime players bgcolor: '#000000', // Background color, used for flash and QT media - wmode: 'opaque', // Background setting for Adobe Flash ('opaque' and 'transparent' are most common) + wmode: 'transparent', // Background setting for Adobe Flash ('opaque' and 'transparent' are most common) // NonverBlaster - useNB: false, // use NonverBlaster (true) or JW Media Player (false) for .flv and .mp4 files - playerpath: 'NonverBlaster.swf', // Path to NonverBlaster.swf - controlColor: '0xFFFFFF', // set the controlbar color - controlBackColor: '0x000000', // set the controlbar color - showTimecode: 'false', // turn timecode display off or on -// JW Media Player settings and options - JWplayerpath: 'player.swf', // Path to the mediaplayer.swf or flvplayer.swf file - backcolor: '000000', // Base color for the controller, color name / hex value (0x000000) - frontcolor: '999999', // Text and button color for the controller, color name / hex value (0x000000) - lightcolor: '000000', // Rollover color for the controller, color name / hex value (0x000000) - screencolor: '000000', // Rollover color for the controller, color name / hex value (0x000000) - controlbar: 'over', // bottom, over, none (this setting is ignored when playing audio files) + playerpath: 'files/NonverBlaster.swf', // Path to NonverBlaster.swf + showTimecode: 'false', // turn timecode display off or on (true, false) + controlColor: '0xFFFFFF', // set the control color + controlBackColor: '0x0000000', // set the bakcground color (video only) +// playerBackColor: '0x0000FF', // set the player background color (leave blank to allow CSS styles to show through for audio) + playerBackColor: '', // set the player background color (leave blank to allow CSS styles to show through) + wmodeNB: 'transparent', // Background setting for Adobe Flash (set to 'transparent' for a blank background, 'opaque' in other situations) +// autoAdvance: 'false', // placeholder setting only - not currently implemented (intending to add auto gallery list navigation on play-end) // Quicktime options controller: 'true', // Show controller, true / false // Flickr options @@ -118,12 +152,11 @@ var Mediabox; revverFront: 'ffffff', // Foreground color revverGrad: '000000', // Gradation color // Ustream options - usViewers: 'true', // Show online viewer count (true/false) + usViewers: 'true', // Show online viewer count (true, false) // Youtube options ytBorder: '0', // Outline (1=true, 0=false) ytColor1: '000000', // Outline color ytColor2: '333333', // Base interface color (highlight colors stay consistent) - ytQuality: '&ap=%2526fmt%3D18', // Leave empty for standard quality, use '&ap=%2526fmt%3D18' for high quality, and '&ap=%2526fmt%3D22' for HD (note that not all videos are availible in high quality, and very few in HD) ytRel: '0', // Show related videos (1=true, 0=false) ytInfo: '1', // Show video info (1=true, 0=false) ytSearch: '0', // Show search field (1=true, 0=false) @@ -134,43 +167,51 @@ var Mediabox; vmByline: '1', // Show byline vmPortrait: '1', // Show author portrait vmColor: 'ffffff' // Custom controller colors, hex value minus the # sign, defult is 5ca0b5 - }, _options || {}); - - prevLink.set('html', options.text[0]); - nextLink.set('html', options.text[1]); - closeLink.set('html', options.text[2]); + }; - margin = center.getStyle('padding-left').toInt()+image.getStyle('margin-left').toInt()+image.getStyle('padding-left').toInt(); + prevLink.set('html', options.buttonText[0]); + nextLink.set('html', options.buttonText[1]); + closeLink.set('html', options.buttonText[2]); - if ((Browser.Engine.gecko) && (Browser.Engine.version<19)) { // Fixes Firefox 2 and Camino 1.6 incompatibility with opacity + flash - foxfix = true; + if (Browser.firefox2) { // Fixes Firefox 2 and Camino 1.6 incompatibility with opacity + flash options.overlayOpacity = 1; - overlay.className = 'mbOverlayFF'; + overlay.className = 'mbOverlayOpaque'; } - if ((Browser.Engine.trident) && (Browser.Engine.version<5)) { // Fixes IE 6 and earlier incompatibilities with CSS position: fixed; - iefix = true; - overlay.className = 'mbOverlayIE'; - overlay.setStyle("position", "absolute"); + if (Browser.Platform.ios) { + options.keyboard = false; + options.resizeOpening = false; // Speeds up interaction on small devices (mobile) or older computers (IE6) + overlay.className = 'mbMobile'; + bottom.className = 'mbMobile'; +// options.overlayOpacity = 0.001; // Helps ameliorate the issues with CSS overlays in iOS, leaving a clickable background, but avoiding the visible issues position(); } - if (typeof _images == "string") { // Used for single images only, with URL and Title as first two arguments - _images = [[_images,startImage,_options]]; - startImage = 0; + if (Browser.ie6) { + options.resizeOpening = false; // Speeds up interaction on small devices (mobile) or older computers (IE6) + overlay.className = 'mbOverlayAbsolute'; + position(); + } + + if (typeof _mediaArray == "string") { // Used for single mediaArray only, with URL and Title as first two arguments + _mediaArray = [[_mediaArray,startMedia,_options]]; + startMedia = 0; } - images = _images; - options.loop = options.loop && (images.length > 1); + mediaArray = _mediaArray; + options.loop = options.loop && (mediaArray.length > 1); size(); setup(true); top = window.getScrollTop() + (window.getHeight()/2); left = window.getScrollLeft() + (window.getWidth()/2); - fx.resize = new Fx.Morph(center, $extend({duration: options.resizeDuration, onComplete: imageAnimate}, options.resizeTransition ? {transition: options.resizeTransition} : {})); - center.setStyles({top: top, left: left, width: options.initialWidth, height: options.initialHeight, marginTop: -(options.initialHeight/2)-margin, marginLeft: -(options.initialWidth/2)-margin, display: ""}); + margin = center.getStyle('padding-left').toInt()+media.getStyle('margin-left').toInt()+media.getStyle('padding-left').toInt(); + marginBottom = bottom.getStyle('margin-left').toInt()+bottom.getStyle('padding-left').toInt()+bottom.getStyle('margin-right').toInt()+bottom.getStyle('padding-right').toInt(); + +/****/ center.setStyles({top: top, left: left, width: options.initialWidth, height: options.initialHeight, marginTop: -(options.initialHeight/2)-margin, marginLeft: -(options.initialWidth/2)-margin, display: ""}); + fx.resize = new Fx.Morph(center, {duration: options.resizeDuration, onComplete: mediaAnimate}); fx.overlay.start(options.overlayOpacity); - return changeImage(startImage); + return changeMedia(startMedia); } }; @@ -195,7 +236,7 @@ var Mediabox; linkMapper = linkMapper || function(el) { elrel = el.rel.split(/[\[\]]/); elrel = elrel[1]; - return [el.href, el.title, elrel]; + return [el.get('href'), el.title, elrel]; // thanks to Dušan Medlín for figuring out the URL bug! }; linksFilter = linksFilter || function() { @@ -204,12 +245,13 @@ var Mediabox; var links = this; +/* clickBlock code - remove the following three lines to enable right-clicking on links to images */ links.addEvent('contextmenu', function(e){ if (this.toString().match(/\.gif|\.jpg|\.jpeg|\.png/i)) e.stop(); }); links.removeEvents("click").addEvent("click", function() { - // Build the list of images that will be displayed + // Build the list of media that will be displayed var filteredArray = links.filter(linksFilter, this); var filteredLinks = []; var filteredHrefs = []; @@ -218,7 +260,7 @@ var Mediabox; if(filteredHrefs.indexOf(item.toString()) < 0) { filteredLinks.include(filteredArray[index]); filteredHrefs.include(filteredArray[index].toString()); - }; + } }); return Mediabox.open(filteredLinks.map(linkMapper), filteredHrefs.indexOf(this.toString()), _options); @@ -242,9 +284,9 @@ var Mediabox; function setup(open) { // Hides on-page objects and embeds while the overlay is open, nessesary to counteract Firefox stupidity - if (Browser.Engine.gecko) { + if (Browser.firefox) { ["object", window.ie ? "select" : "embed"].forEach(function(tag) { - Array.forEach(document.getElementsByTagName(tag), function(el) { + Array.forEach($$(tag), function(el) { if (open) el._mediabox = el.style.visibility; el.style.visibility = open ? "hidden" : el._mediabox; }); @@ -254,13 +296,13 @@ var Mediabox; overlay.style.display = open ? "" : "none"; var fn = open ? "addEvent" : "removeEvent"; - if (iefix) window[fn]("scroll", position); + if (Browser.Platform.ios || Browser.ie6) window[fn]("scroll", position); // scroll position is updated only after movement has stopped window[fn]("resize", size); if (options.keyboard) document[fn]("keydown", keyDown); } function keyDown(event) { - if (options.alpha) { + if (options.keyboardAlpha) { switch(event.code) { case 27: // Esc case 88: // 'x' @@ -287,42 +329,51 @@ var Mediabox; next(); } } - if (options.stopKey) { return false; }; + if (options.keyboardStop) { return false; } } function previous() { - return changeImage(prevImage); + return changeMedia(prevMedia); } function next() { - return changeImage(nextImage); + return changeMedia(nextMedia); } - function changeImage(imageIndex) { - if (imageIndex >= 0) { - image.set('html', ''); - activeImage = imageIndex; - prevImage = ((activeImage || !options.loop) ? activeImage : images.length) - 1; - nextImage = activeImage + 1; - if (nextImage == images.length) nextImage = options.loop ? 0 : -1; + function changeMedia(mediaIndex) { + if (mediaIndex >= 0) { +// if (Browser.Platform.ios && !options.iOSenable) { +// window.open(mediaArray[mediaIndex][0], "_blank"); +// close(); +// return false; +// } + media.set('html', ''); + activeMedia = mediaIndex; + prevMedia = ((activeMedia || !options.loop) ? activeMedia : mediaArray.length) - 1; + nextMedia = activeMedia + 1; + if (nextMedia == mediaArray.length) nextMedia = options.loop ? 0 : -1; stop(); center.className = "mbLoading"; + if (preload && mediaType == "inline" && !options.inlineClone) preload.adopt(media.getChildren()); // prevents loss of adopted data /* mediaboxAdvanced link formatting and media support */ - if (!images[imageIndex][2]) images[imageIndex][2] = ''; // Thanks to Leo Feyer for offering this fix - WH = images[imageIndex][2].split(' '); + if (!mediaArray[mediaIndex][2]) mediaArray[mediaIndex][2] = ''; // Thanks to Leo Feyer for offering this fix + WH = mediaArray[mediaIndex][2].split(' '); WHL = WH.length; if (WHL>1) { - mediaWidth = (WH[WHL-2].match("%")) ? (window.getWidth()*((WH[WHL-2].replace("%", ""))*0.01))+"px" : WH[WHL-2]+"px"; - mediaHeight = (WH[WHL-1].match("%")) ? (window.getHeight()*((WH[WHL-1].replace("%", ""))*0.01))+"px" : WH[WHL-1]+"px"; +// mediaWidth = (WH[WHL-2].match("%")) ? (window.getWidth()*((WH[WHL-2].replace("%", ""))*0.01))+"px" : WH[WHL-2]+"px"; + mediaWidth = (WH[WHL-2].match("%")) ? (window.getWidth()*((WH[WHL-2].replace("%", ""))*0.01)) : WH[WHL-2]; +// mediaHeight = (WH[WHL-1].match("%")) ? (window.getHeight()*((WH[WHL-1].replace("%", ""))*0.01))+"px" : WH[WHL-1]+"px"; + mediaHeight = (WH[WHL-1].match("%")) ? (window.getHeight()*((WH[WHL-1].replace("%", ""))*0.01)) : WH[WHL-1]; } else { mediaWidth = ""; mediaHeight = ""; } - URL = images[imageIndex][0]; + URL = mediaArray[mediaIndex][0]; // URL = encodeURI(URL).replace("(","%28").replace(")","%29"); - captionSplit = images[activeImage][1].split('::'); +// URL = encodeURI(URL).replace("(","%28").replace(")","%29").replace("%20"," "); + captionSplit = mediaArray[activeMedia][1].split('::'); // Quietube and yFrog support if (URL.match(/quietube\.com/i)) { @@ -365,48 +416,29 @@ var Mediabox; mediaType = 'obj'; mediaWidth = mediaWidth || options.defaultWidth; mediaHeight = mediaHeight || options.defaultHeight; - if (options.useNB) { - preload = new Swiff(''+options.playerpath+'?mediaURL='+URL+'&allowSmoothing=true&autoPlay='+options.autoplay+'&buffer=6&showTimecode='+options.showTimecode+'&loop='+options.medialoop+'&controlColor='+options.controlColor+'&controlBackColor='+options.controlBackColor+'&defaultVolume='+options.volume+'&scaleIfFullScreen=true&showScalingButton=true&crop=false', { - id: 'MediaboxSWF', - width: mediaWidth, - height: mediaHeight, - params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} - }); - } else { - preload = new Swiff(''+options.JWplayerpath+'?v1.3.5&skin=mySkin.swf&video='+encodeURI(URL), { - id: 'MediaboxSWF', + preload = new Swiff(''+options.playerpath+'?mediaURL='+URL+'&allowSmoothing=true&autoPlay='+options.autoplay+'&buffer=6&showTimecode='+options.showTimecode+'&loop='+options.medialoop+'&controlColor='+options.controlColor+'&controlBackColor='+options.controlBackColor+'&playerBackColor='+options.playerBackColor+'&defaultVolume='+options.volume+'&scaleIfFullScreen=true&showScalingButton=true&crop=false', { + id: 'mbVideo', width: mediaWidth, height: mediaHeight, - params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} + params: {wmode: options.wmodeNB, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} }); - } startEffect(); // MP3, AAC } else if (URL.match(/\.mp3|\.aac|tweetmic\.com|tmic\.fm/i) || mediaType == 'audio') { mediaType = 'obj'; mediaWidth = mediaWidth || options.defaultWidth; - mediaHeight = mediaHeight || "20px"; + mediaHeight = mediaHeight || "17"; if (URL.match(/tweetmic\.com|tmic\.fm/i)) { URL = URL.split('/'); URL[4] = URL[4] || URL[3]; URL = "http://media4.fjarnet.net/tweet/tweetmicapp-"+URL[4]+'.mp3'; } - if (options.useNB) { preload = new Swiff(''+options.playerpath+'?mediaURL='+URL+'&allowSmoothing=true&autoPlay='+options.autoplay+'&buffer=6&showTimecode='+options.showTimecode+'&loop='+options.medialoop+'&controlColor='+options.controlColor+'&controlBackColor='+options.controlBackColor+'&defaultVolume='+options.volume+'&scaleIfFullScreen=true&showScalingButton=true&crop=false', { - id: 'MediaboxSWF', + id: 'mbAudio', width: mediaWidth, height: mediaHeight, params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} }); - } else { -// preload = new Swiff(''+options.JWplayerpath+'?file='+URL+'&backcolor='+options.backcolor+'&frontcolor='+options.frontcolor+'&lightcolor='+options.lightcolor+'&screencolor='+options.screencolor+'&autostart='+options.autoplay, { - preload = new Swiff(''+options.JWplayerpath+'?v1.3.5&skin=mySkin.swf&video='+encodeURI(URL), { - id: 'MediaboxSWF', - width: mediaWidth, - height: mediaHeight, - params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} - }); - } startEffect(); // SWF } else if (URL.match(/\.swf/i) || mediaType == 'flash') { @@ -414,7 +446,7 @@ var Mediabox; mediaWidth = mediaWidth || options.defaultWidth; mediaHeight = mediaHeight || options.defaultHeight; preload = new Swiff(URL, { - id: 'MediaboxSWF', + id: 'mbFlash', width: mediaWidth, height: mediaHeight, params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} @@ -424,12 +456,12 @@ var Mediabox; } else if (URL.match(/\.mov|\.m4v|\.m4a|\.aiff|\.avi|\.caf|\.dv|\.mid|\.m3u|\.mp3|\.mp2|\.mp4|\.qtz/i) || mediaType == 'qt') { mediaType = 'qt'; mediaWidth = mediaWidth || options.defaultWidth; - mediaHeight = (parseInt(mediaHeight)+16)+"px" || options.defaultHeight; +// mediaHeight = (parseInt(mediaHeight, 10)+16)+"px" || options.defaultHeight; + mediaHeight = (parseInt(mediaHeight, 10)+16) || options.defaultHeight; preload = new Quickie(URL, { id: 'MediaboxQT', width: mediaWidth, height: mediaHeight, - container: 'mbImage', attributes: {controller: options.controller, autoplay: options.autoplay, volume: options.volume, loop: options.medialoop, bgcolor: options.bgcolor} }); startEffect(); @@ -439,8 +471,8 @@ var Mediabox; // Blip.tv } else if (URL.match(/blip\.tv/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "640px"; - mediaHeight = mediaHeight || "390px"; + mediaWidth = mediaWidth || "640"; + mediaHeight = mediaHeight || "390"; preload = new Swiff(URL, { src: URL, width: mediaWidth, @@ -451,8 +483,8 @@ var Mediabox; // Break.com } else if (URL.match(/break\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "464px"; - mediaHeight = mediaHeight || "376px"; + mediaWidth = mediaWidth || "464"; + mediaHeight = mediaHeight || "376"; mediaId = URL.match(/\d{6}/g); preload = new Swiff('http://embed.break.com/'+mediaId, { width: mediaWidth, @@ -463,8 +495,8 @@ var Mediabox; // DailyMotion } else if (URL.match(/dailymotion\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "480px"; - mediaHeight = mediaHeight || "381px"; + mediaWidth = mediaWidth || "480"; + mediaHeight = mediaHeight || "381"; preload = new Swiff(URL, { id: mediaId, width: mediaWidth, @@ -475,8 +507,8 @@ var Mediabox; // Facebook } else if (URL.match(/facebook\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "320px"; - mediaHeight = mediaHeight || "240px"; + mediaWidth = mediaWidth || "320"; + mediaHeight = mediaHeight || "240"; mediaSplit = URL.split('v='); mediaSplit = mediaSplit[1].split('&'); mediaId = mediaSplit[0]; @@ -489,10 +521,10 @@ var Mediabox; }); startEffect(); // Flickr - } else if (URL.match(/flickr\.com/i)) { + } else if (URL.match(/flickr\.com(?!.+\/show\/)/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "500px"; - mediaHeight = mediaHeight || "375px"; + mediaWidth = mediaWidth || "500"; + mediaHeight = mediaHeight || "375"; mediaSplit = URL.split('/'); mediaId = mediaSplit[5]; preload = new Swiff('http://www.flickr.com/apps/video/stewart.swf', { @@ -506,8 +538,8 @@ var Mediabox; // GameTrailers Video } else if (URL.match(/gametrailers\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "480px"; - mediaHeight = mediaHeight || "392px"; + mediaWidth = mediaWidth || "480"; + mediaHeight = mediaHeight || "392"; mediaId = URL.match(/\d{5}/g); preload = new Swiff('http://www.gametrailers.com/remote_wrap.php?mid='+mediaId, { id: mediaId, @@ -519,8 +551,8 @@ var Mediabox; // Google Video } else if (URL.match(/google\.com\/videoplay/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "400px"; - mediaHeight = mediaHeight || "326px"; + mediaWidth = mediaWidth || "400"; + mediaHeight = mediaHeight || "326"; mediaSplit = URL.split('='); mediaId = mediaSplit[1]; preload = new Swiff('http://video.google.com/googleplayer.swf?docId='+mediaId+'&autoplay='+options.autoplayNum, { @@ -533,8 +565,8 @@ var Mediabox; // Megavideo - Thanks to Robert Jandreu for suggesting this code! } else if (URL.match(/megavideo\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "640px"; - mediaHeight = mediaHeight || "360px"; + mediaWidth = mediaWidth || "640"; + mediaHeight = mediaHeight || "360"; mediaSplit = URL.split('='); mediaId = mediaSplit[1]; preload = new Swiff('http://wwwstatic.megavideo.com/mv_player.swf?v='+mediaId, { @@ -547,8 +579,8 @@ var Mediabox; // Metacafe } else if (URL.match(/metacafe\.com\/watch/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "400px"; - mediaHeight = mediaHeight || "345px"; + mediaWidth = mediaWidth || "400"; + mediaHeight = mediaHeight || "345"; mediaSplit = URL.split('/'); mediaId = mediaSplit[4]; preload = new Swiff('http://www.metacafe.com/fplayer/'+mediaId+'/.swf?playerVars=autoPlay='+options.autoplayYes, { @@ -561,8 +593,8 @@ var Mediabox; // Myspace } else if (URL.match(/vids\.myspace\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "425px"; - mediaHeight = mediaHeight || "360px"; + mediaWidth = mediaWidth || "425"; + mediaHeight = mediaHeight || "360"; preload = new Swiff(URL, { id: mediaId, width: mediaWidth, @@ -573,8 +605,8 @@ var Mediabox; // Revver } else if (URL.match(/revver\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "480px"; - mediaHeight = mediaHeight || "392px"; + mediaWidth = mediaWidth || "480"; + mediaHeight = mediaHeight || "392"; mediaSplit = URL.split('/'); mediaId = mediaSplit[4]; preload = new Swiff('http://flash.revver.com/player/1.0/player.swf?mediaId='+mediaId+'&affiliateId='+options.revverID+'&allowFullScreen='+options.revverFullscreen+'&autoStart='+options.autoplay+'&backColor=#'+options.revverBack+'&frontColor=#'+options.revverFront+'&gradColor=#'+options.revverGrad+'&shareUrl=revver', { @@ -587,8 +619,8 @@ var Mediabox; // Rutube } else if (URL.match(/rutube\.ru/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "470px"; - mediaHeight = mediaHeight || "353px"; + mediaWidth = mediaWidth || "470"; + mediaHeight = mediaHeight || "353"; mediaSplit = URL.split('='); mediaId = mediaSplit[1]; preload = new Swiff('http://video.rutube.ru/'+mediaId, { @@ -598,25 +630,11 @@ var Mediabox; params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} }); startEffect(); -// Seesmic - } else if (URL.match(/seesmic\.com/i)) { - mediaType = 'obj'; - mediaWidth = mediaWidth || "435px"; - mediaHeight = mediaHeight || "355px"; - mediaSplit = URL.split('/'); - mediaId = mediaSplit[5]; - preload = new Swiff('http://seesmic.com/Standalone.swf?video='+mediaId, { - id: mediaId, - width: mediaWidth, - height: mediaHeight, - params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} - }); - startEffect(); // Tudou } else if (URL.match(/tudou\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "400px"; - mediaHeight = mediaHeight || "340px"; + mediaWidth = mediaWidth || "400"; + mediaHeight = mediaHeight || "340"; mediaSplit = URL.split('/'); mediaId = mediaSplit[5]; preload = new Swiff('http://www.tudou.com/v/'+mediaId, { @@ -625,11 +643,11 @@ var Mediabox; params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} }); startEffect(); -// Twitvcam +// Twitcam } else if (URL.match(/twitcam\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "320px"; - mediaHeight = mediaHeight || "265px"; + mediaWidth = mediaWidth || "320"; + mediaHeight = mediaHeight || "265"; mediaSplit = URL.split('/'); mediaId = mediaSplit[3]; preload = new Swiff('http://static.livestream.com/chromelessPlayer/wrappers/TwitcamPlayer.swf?hash='+mediaId, { @@ -638,24 +656,11 @@ var Mediabox; params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} }); startEffect(); -// Twiturm - } else if (URL.match(/twiturm\.com/i)) { - mediaType = 'obj'; - mediaWidth = mediaWidth || "402px"; - mediaHeight = mediaHeight || "48px"; - mediaSplit = URL.split('/'); - mediaId = mediaSplit[3]; - preload = new Swiff('http://twiturm.com/flash/twiturm_mp3.swf?playerID=0&sf='+mediaId, { - width: mediaWidth, - height: mediaHeight, - params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} - }); - startEffect(); // Twitvid } else if (URL.match(/twitvid\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "600px"; - mediaHeight = mediaHeight || "338px"; + mediaWidth = mediaWidth || "600"; + mediaHeight = mediaHeight || "338"; mediaSplit = URL.split('/'); mediaId = mediaSplit[3]; preload = new Swiff('http://www.twitvid.com/player/'+mediaId, { @@ -667,8 +672,8 @@ var Mediabox; // Ustream.tv } else if (URL.match(/ustream\.tv/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "400px"; - mediaHeight = mediaHeight || "326px"; + mediaWidth = mediaWidth || "400"; + mediaHeight = mediaHeight || "326"; preload = new Swiff(URL+'&viewcount='+options.usViewers+'&autoplay='+options.autoplay, { width: mediaWidth, height: mediaHeight, @@ -678,8 +683,8 @@ var Mediabox; // YouKu } else if (URL.match(/youku\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "480px"; - mediaHeight = mediaHeight || "400px"; + mediaWidth = mediaWidth || "480"; + mediaHeight = mediaHeight || "400"; mediaSplit = URL.split('id_'); mediaId = mediaSplit[1]; preload = new Swiff('http://player.youku.com/player.php/sid/'+mediaId+'=/v.swf', { @@ -693,8 +698,8 @@ var Mediabox; mediaSplit = URL.split('v='); if (options.html5) { mediaType = 'url'; - mediaWidth = mediaWidth || "640px"; - mediaHeight = mediaHeight || "385px"; + mediaWidth = mediaWidth || "640"; + mediaHeight = mediaHeight || "385"; mediaId = "mediaId_"+new Date().getTime(); // Safari may not update iframe content with a static id. preload = new Element('iframe', { 'src': 'http://www.youtube.com/embed/'+mediaSplit[1], @@ -707,20 +712,9 @@ var Mediabox; } else { mediaType = 'obj'; mediaId = mediaSplit[1]; - if (mediaId.match(/fmt=22/i)) { - mediaFmt = '&ap=%2526fmt%3D22'; - mediaWidth = mediaWidth || "640px"; - mediaHeight = mediaHeight || "385px"; - } else if (mediaId.match(/fmt=18/i)) { - mediaFmt = '&ap=%2526fmt%3D18'; - mediaWidth = mediaWidth || "560px"; - mediaHeight = mediaHeight || "345px"; - } else { - mediaFmt = options.ytQuality; - mediaWidth = mediaWidth || "480px"; - mediaHeight = mediaHeight || "295px"; - } - preload = new Swiff('http://www.youtube.com/v/'+mediaId+'&autoplay='+options.autoplayNum+'&fs='+options.fullscreenNum+mediaFmt+'&border='+options.ytBorder+'&color1=0x'+options.ytColor1+'&color2=0x'+options.ytColor2+'&rel='+options.ytRel+'&showinfo='+options.ytInfo+'&showsearch='+options.ytSearch, { + mediaWidth = mediaWidth || "480"; + mediaHeight = mediaHeight || "385"; + preload = new Swiff('http://www.youtube.com/v/'+mediaId+'&autoplay='+options.autoplayNum+'&fs='+options.fullscreenNum+'&border='+options.ytBorder+'&color1=0x'+options.ytColor1+'&color2=0x'+options.ytColor2+'&rel='+options.ytRel+'&showinfo='+options.ytInfo+'&showsearch='+options.ytSearch, { id: mediaId, width: mediaWidth, height: mediaHeight, @@ -733,9 +727,9 @@ var Mediabox; mediaType = 'obj'; mediaSplit = URL.split('p='); mediaId = mediaSplit[1]; - mediaWidth = mediaWidth || "480px"; - mediaHeight = mediaHeight || "385px"; - preload = new Swiff('http://www.youtube.com/p/'+mediaId+'&autoplay='+options.autoplayNum+'&fs='+options.fullscreenNum+mediaFmt+'&border='+options.ytBorder+'&color1=0x'+options.ytColor1+'&color2=0x'+options.ytColor2+'&rel='+options.ytRel+'&showinfo='+options.ytInfo+'&showsearch='+options.ytSearch, { + mediaWidth = mediaWidth || "480"; + mediaHeight = mediaHeight || "385"; + preload = new Swiff('http://www.youtube.com/p/'+mediaId+'&autoplay='+options.autoplayNum+'&fs='+options.fullscreenNum+'&border='+options.ytBorder+'&color1=0x'+options.ytColor1+'&color2=0x'+options.ytColor2+'&rel='+options.ytRel+'&showinfo='+options.ytInfo+'&showsearch='+options.ytSearch, { id: mediaId, width: mediaWidth, height: mediaHeight, @@ -745,8 +739,8 @@ var Mediabox; // Veoh } else if (URL.match(/veoh\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "410px"; - mediaHeight = mediaHeight || "341px"; + mediaWidth = mediaWidth || "410"; + mediaHeight = mediaHeight || "341"; URL = URL.replace('%3D','/'); mediaSplit = URL.split('watch/'); mediaId = mediaSplit[1]; @@ -760,8 +754,8 @@ var Mediabox; // Viddler } else if (URL.match(/viddler\.com/i)) { mediaType = 'obj'; - mediaWidth = mediaWidth || "437px"; - mediaHeight = mediaHeight || "370px"; + mediaWidth = mediaWidth || "437"; + mediaHeight = mediaHeight || "370"; mediaSplit = URL.split('/'); mediaId = mediaSplit[4]; preload = new Swiff(URL, { @@ -773,25 +767,10 @@ var Mediabox; params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen, id: 'viddler_'+mediaId, movie: URL} }); startEffect(); -// Viddyou - } else if (URL.match(/viddyou\.com/i)) { - mediaType = 'obj'; - mediaWidth = mediaWidth || "416px"; - mediaHeight = mediaHeight || "312px"; - mediaSplit = URL.split('='); - mediaId = mediaSplit[1]; - preload = new Swiff('http://www.viddyou.com/get/v2_'+options.vuPlayer+'/'+mediaId+'.swf', { - id: mediaId, - movie: 'http://www.viddyou.com/get/v2_'+options.vuPlayer+'/'+mediaId+'.swf', - width: mediaWidth, - height: mediaHeight, - params: {wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} - }); - startEffect(); // Vimeo (now includes HTML5 option) } else if (URL.match(/vimeo\.com/i)) { - mediaWidth = mediaWidth || "640px"; // site defualt: 400px - mediaHeight = mediaHeight || "360px"; // site defualt: 225px + mediaWidth = mediaWidth || "640"; // site defualt: 400px + mediaHeight = mediaHeight || "360"; // site defualt: 225px mediaSplit = URL.split('/'); mediaId = mediaSplit[3]; @@ -816,32 +795,16 @@ var Mediabox; }); startEffect(); } -// 12seconds - } else if (URL.match(/12seconds\.tv/i)) { - mediaType = 'obj'; - mediaWidth = mediaWidth || "430px"; - mediaHeight = mediaHeight || "360px"; - mediaSplit = URL.split('/'); - mediaId = mediaSplit[5]; - preload = new Swiff('http://embed.12seconds.tv/players/remotePlayer.swf', { - id: mediaId, - width: mediaWidth, - height: mediaHeight, - params: {flashvars: 'vid='+mediaId+'', wmode: options.wmode, bgcolor: options.bgcolor, allowscriptaccess: options.scriptaccess, allowfullscreen: options.fullscreen} - }); - startEffect(); - - /* Specific Content Types */ - // INLINE } else if (URL.match(/\#mb_/i)) { mediaType = 'inline'; mediaWidth = mediaWidth || options.defaultWidth; mediaHeight = mediaHeight || options.defaultHeight; URLsplit = URL.split('#'); - preload = document.id(URLsplit[1]).get('html'); +// preload = new Element("div", {id: "mbMediaInline"}).adopt(document.id(URLsplit[1]).getChildren().clone([true,true])); + preload = document.id(URLsplit[1]); startEffect(); -// HTML +// HTML (applies to ALL links not recognised as a specific media type) } else { mediaType = 'url'; mediaWidth = mediaWidth || options.defaultWidth; @@ -861,96 +824,126 @@ var Mediabox; } function startEffect() { +// if (Browser.Platform.ios && (mediaType == "obj" || mediaType == "qt" || mediaType == "html")) alert("this isn't gonna work"); +// if (Browser.Platform.ios && (mediaType == "obj" || mediaType == "qt" || mediaType == "html")) mediaType = "ios"; + (mediaType == "img")?media.addEvent("click", next):media.removeEvent("click", next); if (mediaType == "img"){ mediaWidth = preload.width; mediaHeight = preload.height; if (options.imgBackground) { - image.setStyles({backgroundImage: "url("+URL+")", display: ""}); + media.setStyles({backgroundImage: "url("+URL+")", display: ""}); } else { // Thanks to Dusan Medlin for fixing large 16x9 image errors in a 4x3 browser if (mediaHeight >= winHeight-options.imgPadding && (mediaHeight / winHeight) >= (mediaWidth / winWidth)) { mediaHeight = winHeight-options.imgPadding; - mediaWidth = preload.width = parseInt((mediaHeight/preload.height)*mediaWidth); + mediaWidth = preload.width = parseInt((mediaHeight/preload.height)*mediaWidth, 10); preload.height = mediaHeight; } else if (mediaWidth >= winWidth-options.imgPadding && (mediaHeight / winHeight) < (mediaWidth / winWidth)) { mediaWidth = winWidth-options.imgPadding; - mediaHeight = preload.height = parseInt((mediaWidth/preload.width)*mediaHeight); + mediaHeight = preload.height = parseInt((mediaWidth/preload.width)*mediaHeight, 10); preload.width = mediaWidth; } - if (Browser.Engine.trident) preload = document.id(preload); - preload.addEvent('mousedown', function(e){ e.stop(); }).addEvent('contextmenu', function(e){ e.stop(); }); - image.setStyles({backgroundImage: "none", display: ""}); - preload.inject(image); + if (Browser.ie) preload = document.id(preload); + if (options.clickBlock) preload.addEvent('mousedown', function(e){ e.stop(); }).addEvent('contextmenu', function(e){ e.stop(); }); + media.setStyles({backgroundImage: "none", display: ""}); + preload.inject(media); } +// mediaWidth += "px"; +// mediaHeight += "px"; + } else if (mediaType == "inline") { +// if (options.overflow) media.setStyles({overflow: options.overflow}); + media.setStyles({backgroundImage: "none", display: ""}); +// preload.inject(media); +// media.grab(preload.get('html')); + (options.inlineClone)?media.grab(preload.get('html')):media.adopt(preload.getChildren()); + } else if (mediaType == "qt") { + media.setStyles({backgroundImage: "none", display: ""}); + preload.inject(media); +// preload; + } else if (mediaType == "ios" || Browser.Platform.ios) { + media.setStyles({backgroundImage: "none", display: ""}); + media.set('html', options.linkText.replace(/\{x\}/gi, URL)); + mediaWidth = options.DefaultWidth; + mediaHeight = options.DefaultHeight; + } else if (mediaType == "url") { + media.setStyles({backgroundImage: "none", display: ""}); + preload.inject(media); +// if (Browser.safari) options.resizeOpening = false; // Prevents occasional blank video display errors in Safari, thanks to Kris Gale for the solution + } else if (mediaType == "video") { + media.setStyles({backgroundImage: "none", display: ""}); + preload.inject(media); } else if (mediaType == "obj") { - if (Browser.Plugins.Flash.version<8) { - image.setStyles({backgroundImage: "none", display: ""}); - image.set('html', '
Error
Adobe Flash is either not installed or not up to date, please visit Adobe.com to download the free player.
'); + if (Browser.Plugins.Flash.version < "8") { + media.setStyles({backgroundImage: "none", display: ""}); + media.set('html', '
Error
Adobe Flash is either not installed or not up to date, please visit Adobe.com to download the free player.
'); mediaWidth = options.DefaultWidth; mediaHeight = options.DefaultHeight; } else { - image.setStyles({backgroundImage: "none", display: ""}); - preload.inject(image); + media.setStyles({backgroundImage: "none", display: ""}); + preload.inject(media); +// if (Browser.safari) options.resizeOpening = false; // Prevents occasional blank video display errors in Safari, thanks to Kris Gale for the solution } - } else if (mediaType == "qt") { - image.setStyles({backgroundImage: "none", display: ""}); - preload; - } else if (mediaType == "inline") { -// if (options.overflow) image.setStyles({overflow: options.overflow}); - image.setStyles({backgroundImage: "none", display: ""}); - image.set('html', preload); - } else if (mediaType == "url") { - image.setStyles({backgroundImage: "none", display: ""}); - preload.inject(image); - } else if (mediaType == "video") { - image.setStyles({backgroundImage: "none", display: ""}); - preload.inject(image); } else { - image.setStyles({backgroundImage: "none", display: ""}); - image.set('html', '
Error
A file type error has occoured, please visit iaian7.com or contact the website author for more information.
'); + media.setStyles({backgroundImage: "none", display: ""}); + media.set('html', options.flashText); mediaWidth = options.defaultWidth; mediaHeight = options.defaultHeight; } - image.setStyles({width: mediaWidth, height: mediaHeight}); - caption.setStyles({width: mediaWidth}); title.set('html', (options.showCaption) ? captionSplit[0] : ""); caption.set('html', (options.showCaption && (captionSplit.length > 1)) ? captionSplit[1] : ""); - number.set('html', (options.showCounter && (images.length > 1)) ? options.counterText.replace(/{x}/, activeImage + 1).replace(/{y}/, images.length) : ""); - - if ((prevImage >= 0) && (images[prevImage][0].match(/\.gif|\.jpg|\.jpeg|\.png|twitpic\.com/i))) preloadPrev.src = images[prevImage][0].replace(/twitpic\.com/i, "twitpic.com/show/full"); - if ((nextImage >= 0) && (images[nextImage][0].match(/\.gif|\.jpg|\.jpeg|\.png|twitpic\.com/i))) preloadNext.src = images[nextImage][0].replace(/twitpic\.com/i, "twitpic.com/show/full"); - - mediaWidth = image.offsetWidth; - mediaHeight = image.offsetHeight+bottom.offsetHeight; - if (mediaHeight >= top+top) { mTop = -top } else { mTop = -(mediaHeight/2) }; - if (mediaWidth >= left+left) { mLeft = -left } else { mLeft = -(mediaWidth/2) }; - if (options.resizeOpening) { fx.resize.start({width: mediaWidth, height: mediaHeight, marginTop: mTop-margin, marginLeft: mLeft-margin}); - } else { center.setStyles({width: mediaWidth, height: mediaHeight, marginTop: mTop-margin, marginLeft: mLeft-margin}); imageAnimate(); } + number.set('html', (options.showCounter && (mediaArray.length > 1)) ? options.counterText.replace(/\{x\}/, (options.countBack)?mediaArray.length-activeMedia:activeMedia+1).replace(/\{y\}/, mediaArray.length) : ""); + +// if (options.countBack) { +// number.set('html', (options.showCounter && (mediaArray.length > 1)) ? options.counterText.replace(/{x}/, activeMedia + 1).replace(/{y}/, mediaArray.length) : ""); +// } else { +// number.set('html', (options.showCounter && (mediaArray.length > 1)) ? options.counterText.replace(/{x}/, mediaArray.length - activeMedia).replace(/{y}/, mediaArray.length) : ""); +// } + + if ((prevMedia >= 0) && (mediaArray[prevMedia][0].match(/\.gif|\.jpg|\.jpeg|\.png|twitpic\.com/i))) preloadPrev.src = mediaArray[prevMedia][0].replace(/twitpic\.com/i, "twitpic.com/show/full"); + if ((nextMedia >= 0) && (mediaArray[nextMedia][0].match(/\.gif|\.jpg|\.jpeg|\.png|twitpic\.com/i))) preloadNext.src = mediaArray[nextMedia][0].replace(/twitpic\.com/i, "twitpic.com/show/full"); + if (prevMedia >= 0) prevLink.style.display = ""; + if (nextMedia >= 0) nextLink.style.display = ""; + media.setStyles({width: mediaWidth+"px", height: mediaHeight+"px"}); + bottom.setStyles({width: mediaWidth-marginBottom+"px"}); + caption.setStyles({width: mediaWidth-marginBottom+"px"}); + + mediaWidth = media.offsetWidth; + mediaHeight = media.offsetHeight+bottom.offsetHeight; + if (mediaHeight >= top+top) { mTop = -top; } else { mTop = -(mediaHeight/2); } + if (mediaWidth >= left+left) { mLeft = -left; } else { mLeft = -(mediaWidth/2); } +/****/ if (options.resizeOpening) { fx.resize.start({width: mediaWidth, height: mediaHeight, marginTop: mTop-margin, marginLeft: mLeft-margin}); +/****/ } else { center.setStyles({width: mediaWidth, height: mediaHeight, marginTop: mTop-margin, marginLeft: mLeft-margin}); mediaAnimate(); } +// center.setStyles({width: mediaWidth, height: mediaHeight, marginTop: mTop-margin, marginLeft: mLeft-margin}); +// mediaAnimate(); } - function imageAnimate() { - fx.image.start(1); + function mediaAnimate() { + fx.media.start(1); } function captionAnimate() { center.className = ""; - if (prevImage >= 0) prevLink.style.display = ""; - if (nextImage >= 0) nextLink.style.display = ""; +// if (prevMedia >= 0) prevLink.style.display = ""; +// if (nextMedia >= 0) nextLink.style.display = ""; fx.bottom.start(1); } function stop() { - if (preload) preload.onload = $empty; + if (preload) { + if (mediaType == "inline" && !options.inlineClone) preload.adopt(media.getChildren()); // prevents loss of adopted data + preload.onload = function(){}; // $empty replacement + } fx.resize.cancel(); - fx.image.cancel().set(0); + fx.media.cancel().set(0); fx.bottom.cancel().set(0); $$(prevLink, nextLink).setStyle("display", "none"); } function close() { - if (activeImage >= 0) { - preload.onload = $empty; - image.set('html', ''); + if (activeMedia >= 0) { + if (mediaType == "inline" && !options.inlineClone) preload.adopt(media.getChildren()); // prevents loss of adopted data + preload.onload = function(){}; // $empty replacement + media.empty(); for (var f in fx) fx[f].cancel(); center.setStyle("display", "none"); fx.overlay.chain(setup).start(0); @@ -959,17 +952,43 @@ var Mediabox; } })(); + /* Quicktime detection from Quickie.js */ + +Browser.Plugins.QuickTime = (function(){ + if (navigator.plugins) { + for (var i = 0, l = navigator.plugins.length; i < l; i++) { + if (navigator.plugins[i].name.indexOf('QuickTime') >= 0) { + return true; + } + } + } else { + var test; + try { test = new ActiveXObject('QuickTime.QuickTime'); } + catch(e) {} + + if (test) { return true; } + } + return false; +})(); + /* Autoload code block */ Mediabox.scanPage = function() { +// if (Browser.Platform.ios && !(navigator.userAgent.match(/iPad/i))) return; // this quits the process if the visitor is using a non-iPad iOS device (iPhone or iPod Touch) // $$('#mb_').each(function(hide) { hide.set('display', 'none'); }); var links = $$("a").filter(function(el) { return el.rel && el.rel.test(/^lightbox/i); }); - $$(links).mediabox({/* Put custom options here */}, null, function(el) { - var rel0 = this.rel.replace(/[[]|]/gi," "); +// $$(links).mediabox({/* Put custom options here */}, null, function(el) { + links.mediabox({/* Put custom options here */}, null, function(el) { + var rel0 = this.rel.replace(/[\[\]|]/gi," "); var relsize = rel0.split(" "); - return (this == el) || ((this.rel.length > 8) && el.rel.match(relsize[1])); +// return (this == el) || ((this.rel.length > 8) && el.rel.match(relsize[1])); + + var relsearch = "\\["+relsize[1]+"[ \\]]"; + var relregexp = new RegExp(relsearch); + return (this == el) || ((this.rel.length > 8) && el.rel.match(relregexp)); }); }; -window.addEvent("domready", Mediabox.scanPage); + +window.addEvents({domready: Mediabox.scanPage, resize: Mediabox.recenter}); // to recenter the overlay while scrolling, add "scroll: Mediabox.recenter" to the object diff --git a/src/js/mootools.js b/src/js/mootools.js index 88ae5b5..14c176b 100644 --- a/src/js/mootools.js +++ b/src/js/mootools.js @@ -1,13 +1,7 @@ +/* MooTools: the javascript framework. license: MIT-style license. copyright: Copyright (c) 2006-2015 [Valerio Proietti](http://mad4milk.net/).*/ /* ---- -MooTools: the javascript framework - -web build: - - http://mootools.net/core/7c56cfef9dddcf170a5d68e3fb61cfd7 - -packager build: - - packager build Core/Core Core/Array Core/String Core/Number Core/Function Core/Object Core/Event Core/Browser Core/Class Core/Class.Extras Core/Slick.Parser Core/Slick.Finder Core/Element Core/Element.Style Core/Element.Event Core/Element.Dimensions Core/Fx Core/Fx.CSS Core/Fx.Tween Core/Fx.Morph Core/Fx.Transitions Core/Request Core/Request.HTML Core/Request.JSON Core/Cookie Core/JSON Core/DOMReady Core/Swiff - +Web Build: http://mootools.net/core/builder/e426a9ae7167c5807b173d5deff673fc +*/ /* --- @@ -17,7 +11,7 @@ description: The heart of MooTools. license: MIT-style license. -copyright: Copyright (c) 2006-2010 [Valerio Proietti](http://mad4milk.net/). +copyright: Copyright (c) 2006-2014 [Valerio Proietti](http://mad4milk.net/). authors: The MooTools production team (http://mootools.net/developers/) @@ -29,25 +23,25 @@ provides: [Core, MooTools, Type, typeOf, instanceOf, Native] ... */ - +/*! MooTools: the javascript framework. license: MIT-style license. copyright: Copyright (c) 2006-2014 [Valerio Proietti](http://mad4milk.net/).*/ (function(){ this.MooTools = { - version: '1.3', - build: 'a3eed692dd85050d80168ec2c708efe901bb7db3' + version: '1.5.1', + build: '0542c135fdeb7feed7d9917e01447a408f22c876' }; // typeOf, instanceOf var typeOf = this.typeOf = function(item){ if (item == null) return 'null'; - if (item.$family) return item.$family(); + if (item.$family != null) return item.$family(); if (item.nodeName){ if (item.nodeType == 1) return 'element'; if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace'; } else if (typeof item.length == 'number'){ - if (item.callee) return 'arguments'; + if ('callee' in item) return 'arguments'; if ('item' in item) return 'collection'; } @@ -61,6 +55,9 @@ var instanceOf = this.instanceOf = function(item, object){ if (constructor === object) return true; constructor = constructor.parent; } + /**/ + if (!item.hasOwnProperty) return false; + /**/ return item instanceof object; }; @@ -93,8 +90,9 @@ Function.prototype.overloadGetter = function(usePlural){ var self = this; return function(a){ var args, result; - if (usePlural || typeof a != 'string') args = a; + if (typeof a != 'string') args = a; else if (arguments.length > 1) args = arguments; + else if (usePlural) args = [a]; if (args){ result = {}; for (var i = 0; i < args.length; i++) result[args[i]] = self.call(this, args[i]); @@ -196,7 +194,7 @@ var hooksOf = function(object){ }; var implement = function(name, method){ - if (method && method.$hidden) return this; + if (method && method.$hidden) return; var hooks = hooksOf(this); @@ -205,22 +203,19 @@ var implement = function(name, method){ if (typeOf(hook) == 'type') implement.call(hook, name, method); else hook.call(this, name, method); } - + var previous = this.prototype[name]; if (previous == null || !previous.$protected) this.prototype[name] = method; if (this[name] == null && typeOf(method) == 'function') extend.call(this, name, function(item){ return method.apply(item, slice.call(arguments, 1)); }); - - return this; }; var extend = function(name, method){ - if (method && method.$hidden) return this; + if (method && method.$hidden) return; var previous = this[name]; if (previous == null || !previous.$protected) this[name] = method; - return this; }; Type.implement({ @@ -256,21 +251,25 @@ var force = function(name, object, methods){ proto = prototype[key]; if (generic) generic.protect(); - - if (isType && proto){ - delete prototype[key]; - prototype[key] = proto.protect(); - } + if (isType && proto) object.implement(key, proto.protect()); } - if (isType) object.implement(prototype); + if (isType){ + var methodsEnumerable = prototype.propertyIsEnumerable(methods[0]); + object.forEachMethod = function(fn){ + if (!methodsEnumerable) for (var i = 0, l = methods.length; i < l; i++){ + fn.call(prototype, prototype[methods[i]], methods[i]); + } + for (var key in prototype) fn.call(prototype, prototype[key], key); + }; + } return force; }; force('String', String, [ - 'charAt', 'charCodeAt', 'concat', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search', - 'slice', 'split', 'substr', 'substring', 'toLowerCase', 'toUpperCase' + 'charAt', 'charCodeAt', 'concat', 'contains', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search', + 'slice', 'split', 'substr', 'substring', 'trim', 'toLowerCase', 'toUpperCase' ])('Array', Array, [ 'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice', 'indexOf', 'lastIndexOf', 'filter', 'forEach', 'every', 'map', 'some', 'reduce', 'reduceRight' @@ -308,9 +307,10 @@ Number.extend('random', function(min, max){ // forEach, each +var hasOwnProperty = Object.prototype.hasOwnProperty; Object.extend('forEach', function(object, fn, bind){ for (var key in object){ - if (object.hasOwnProperty(key)) fn.call(bind, object[key], key, object); + if (hasOwnProperty.call(object, key)) fn.call(bind, object[key], key, object); } }); @@ -318,11 +318,13 @@ Object.each = Object.forEach; Array.implement({ + /**/ forEach: function(fn, bind){ for (var i = 0, l = this.length; i < l; i++){ if (i in this) fn.call(bind, this[i], i, this); } }, + /**/ each: function(fn, bind){ Array.forEach(this, fn, bind); @@ -522,7 +524,6 @@ this.$unlink = function(object){ })(); - /* --- @@ -532,7 +533,7 @@ description: Contains Array Prototypes like each, contains, and erase. license: MIT-style license. -requires: Type +requires: [Type] provides: Array @@ -541,15 +542,9 @@ provides: Array Array.implement({ - invoke: function(methodName){ - var args = Array.slice(arguments, 1); - return this.map(function(item){ - return item[methodName].apply(item, args); - }); - }, - + /**/ every: function(fn, bind){ - for (var i = 0, l = this.length; i < l; i++){ + for (var i = 0, l = this.length >>> 0; i < l; i++){ if ((i in this) && !fn.call(bind, this[i], i, this)) return false; } return true; @@ -557,40 +552,49 @@ Array.implement({ filter: function(fn, bind){ var results = []; - for (var i = 0, l = this.length; i < l; i++){ - if ((i in this) && fn.call(bind, this[i], i, this)) results.push(this[i]); + for (var value, i = 0, l = this.length >>> 0; i < l; i++) if (i in this){ + value = this[i]; + if (fn.call(bind, value, i, this)) results.push(value); } return results; }, - clean: function(){ - return this.filter(function(item){ - return item != null; - }); - }, - indexOf: function(item, from){ - var len = this.length; - for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){ + var length = this.length >>> 0; + for (var i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++){ if (this[i] === item) return i; } return -1; }, map: function(fn, bind){ - var results = []; - for (var i = 0, l = this.length; i < l; i++){ + var length = this.length >>> 0, results = Array(length); + for (var i = 0; i < length; i++){ if (i in this) results[i] = fn.call(bind, this[i], i, this); } return results; }, some: function(fn, bind){ - for (var i = 0, l = this.length; i < l; i++){ + for (var i = 0, l = this.length >>> 0; i < l; i++){ if ((i in this) && fn.call(bind, this[i], i, this)) return true; } return false; }, + /**/ + + clean: function(){ + return this.filter(function(item){ + return item != null; + }); + }, + + invoke: function(methodName){ + var args = Array.slice(arguments, 1); + return this.map(function(item){ + return item[methodName].apply(item, args); + }); + }, associate: function(keys){ var obj = {}, length = Math.min(this.length, keys.length); @@ -672,7 +676,7 @@ Array.implement({ if (this.length != 3) return null; var rgb = this.map(function(value){ if (value.length == 1) value += value; - return value.toInt(16); + return parseInt(value, 16); }); return (array) ? rgb : 'rgb(' + rgb + ')'; }, @@ -700,145 +704,6 @@ var $pick = function(){ // - -/* ---- - -name: String - -description: Contains String Prototypes like camelCase, capitalize, test, and toInt. - -license: MIT-style license. - -requires: Type - -provides: String - -... -*/ - -String.implement({ - - test: function(regex, params){ - return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this); - }, - - contains: function(string, separator){ - return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1; - }, - - trim: function(){ - return this.replace(/^\s+|\s+$/g, ''); - }, - - clean: function(){ - return this.replace(/\s+/g, ' ').trim(); - }, - - camelCase: function(){ - return this.replace(/-\D/g, function(match){ - return match.charAt(1).toUpperCase(); - }); - }, - - hyphenate: function(){ - return this.replace(/[A-Z]/g, function(match){ - return ('-' + match.charAt(0).toLowerCase()); - }); - }, - - capitalize: function(){ - return this.replace(/\b[a-z]/g, function(match){ - return match.toUpperCase(); - }); - }, - - escapeRegExp: function(){ - return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1'); - }, - - toInt: function(base){ - return parseInt(this, base || 10); - }, - - toFloat: function(){ - return parseFloat(this); - }, - - hexToRgb: function(array){ - var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/); - return (hex) ? hex.slice(1).hexToRgb(array) : null; - }, - - rgbToHex: function(array){ - var rgb = this.match(/\d{1,3}/g); - return (rgb) ? rgb.rgbToHex(array) : null; - }, - - substitute: function(object, regexp){ - return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){ - if (match.charAt(0) == '\\') return match.slice(1); - return (object[name] != null) ? object[name] : ''; - }); - } - -}); - - -/* ---- - -name: Number - -description: Contains Number Prototypes like limit, round, times, and ceil. - -license: MIT-style license. - -requires: Type - -provides: Number - -... -*/ - -Number.implement({ - - limit: function(min, max){ - return Math.min(max, Math.max(min, this)); - }, - - round: function(precision){ - precision = Math.pow(10, precision || 0).toFixed(precision < 0 ? -precision : 0); - return Math.round(this * precision) / precision; - }, - - times: function(fn, bind){ - for (var i = 0; i < this; i++) fn.call(bind, i, this); - }, - - toFloat: function(){ - return parseFloat(this); - }, - - toInt: function(base){ - return parseInt(this, base || 10); - } - -}); - -Number.alias('each', 'times'); - -(function(math){ - var methods = {}; - math.each(function(name){ - if (!Number[name]) methods[name] = function(){ - return Math[name].apply(null, [this].concat(Array.from(arguments))); - }; - }); - Number.implement(methods); -})(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']); - - /* --- @@ -874,20 +739,30 @@ Function.implement({ try { return this.apply(bind, Array.from(args)); } catch (e){} - + return null; }, - bind: function(bind){ + /**/ + bind: function(that){ var self = this, - args = (arguments.length > 1) ? Array.slice(arguments, 1) : null; - - return function(){ - if (!args && !arguments.length) return self.call(bind); - if (args && arguments.length) return self.apply(bind, args.concat(Array.from(arguments))); - return self.apply(bind, args || arguments); + args = arguments.length > 1 ? Array.slice(arguments, 1) : null, + F = function(){}; + + var bound = function(){ + var context = that, length = arguments.length; + if (this instanceof bound){ + F.prototype = self.prototype; + context = new F; + } + var result = (!args && !length) + ? self.call(context) + : self.apply(context, args && length ? args.concat(Array.slice(arguments)) : args || arguments); + return context == that ? result : context; }; + return bound; }, + /**/ pass: function(args, bind){ var self = this; @@ -898,11 +773,11 @@ Function.implement({ }, delay: function(delay, bind, args){ - return setTimeout(this.pass(args, bind), delay); + return setTimeout(this.pass((args == null ? [] : args), bind), delay); }, periodical: function(periodical, bind, args){ - return setInterval(this.pass(args, bind), periodical); + return setInterval(this.pass((args == null ? [] : args), bind), periodical); } }); @@ -952,216 +827,155 @@ Function.implement({ }); +if (Object.create == Function.prototype.create) Object.create = null; + var $try = Function.attempt; // - /* --- -name: Object +name: Number -description: Object generic methods +description: Contains Number Prototypes like limit, round, times, and ceil. license: MIT-style license. requires: Type -provides: [Object, Hash] +provides: Number ... */ +Number.implement({ -Object.extend({ - - subset: function(object, keys){ - var results = {}; - for (var i = 0, l = keys.length; i < l; i++){ - var k = keys[i]; - results[k] = object[k]; - } - return results; - }, - - map: function(object, fn, bind){ - var results = {}; - for (var key in object){ - if (object.hasOwnProperty(key)) results[key] = fn.call(bind, object[key], key, object); - } - return results; - }, - - filter: function(object, fn, bind){ - var results = {}; - Object.each(object, function(value, key){ - if (fn.call(bind, value, key, object)) results[key] = value; - }); - return results; + limit: function(min, max){ + return Math.min(max, Math.max(min, this)); }, - every: function(object, fn, bind){ - for (var key in object){ - if (object.hasOwnProperty(key) && !fn.call(bind, object[key], key)) return false; - } - return true; + round: function(precision){ + precision = Math.pow(10, precision || 0).toFixed(precision < 0 ? -precision : 0); + return Math.round(this * precision) / precision; }, - some: function(object, fn, bind){ - for (var key in object){ - if (object.hasOwnProperty(key) && fn.call(bind, object[key], key)) return true; - } - return false; + times: function(fn, bind){ + for (var i = 0; i < this; i++) fn.call(bind, i, this); }, - keys: function(object){ - var keys = []; - for (var key in object){ - if (object.hasOwnProperty(key)) keys.push(key); - } - return keys; + toFloat: function(){ + return parseFloat(this); }, - values: function(object){ - var values = []; - for (var key in object){ - if (object.hasOwnProperty(key)) values.push(object[key]); - } - return values; - }, + toInt: function(base){ + return parseInt(this, base || 10); + } - getLength: function(object){ - return Object.keys(object).length; - }, +}); - keyOf: function(object, value){ - for (var key in object){ - if (object.hasOwnProperty(key) && object[key] === value) return key; - } - return null; - }, +Number.alias('each', 'times'); - contains: function(object, value){ - return Object.keyOf(object, value) != null; - }, - - toQueryString: function(object, base){ - var queryString = []; - - Object.each(object, function(value, key){ - if (base) key = base + '[' + key + ']'; - var result; - switch (typeOf(value)){ - case 'object': result = Object.toQueryString(value, key); break; - case 'array': - var qs = {}; - value.each(function(val, i){ - qs[i] = val; - }); - result = Object.toQueryString(qs, key); - break; - default: result = key + '=' + encodeURIComponent(value); - } - if (value != null) queryString.push(result); - }); - - return queryString.join('&'); - } +(function(math){ + var methods = {}; + math.each(function(name){ + if (!Number[name]) methods[name] = function(){ + return Math[name].apply(null, [this].concat(Array.from(arguments))); + }; + }); + Number.implement(methods); +})(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']); -}); +/* +--- +name: String -//<1.2compat> +description: Contains String Prototypes like camelCase, capitalize, test, and toInt. -Hash.implement({ +license: MIT-style license. - has: Object.prototype.hasOwnProperty, +requires: [Type, Array] - keyOf: function(value){ - return Object.keyOf(this, value); - }, +provides: String - hasValue: function(value){ - return Object.contains(this, value); - }, +... +*/ - extend: function(properties){ - Hash.each(properties || {}, function(value, key){ - Hash.set(this, key, value); - }, this); - return this; - }, +String.implement({ - combine: function(properties){ - Hash.each(properties || {}, function(value, key){ - Hash.include(this, key, value); - }, this); - return this; + // + contains: function(string, index){ + return (index ? String(this).slice(index) : String(this)).indexOf(string) > -1; }, + // - erase: function(key){ - if (this.hasOwnProperty(key)) delete this[key]; - return this; + test: function(regex, params){ + return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this); }, - get: function(key){ - return (this.hasOwnProperty(key)) ? this[key] : null; + trim: function(){ + return String(this).replace(/^\s+|\s+$/g, ''); }, - set: function(key, value){ - if (!this[key] || this.hasOwnProperty(key)) this[key] = value; - return this; + clean: function(){ + return String(this).replace(/\s+/g, ' ').trim(); }, - empty: function(){ - Hash.each(this, function(value, key){ - delete this[key]; - }, this); - return this; + camelCase: function(){ + return String(this).replace(/-\D/g, function(match){ + return match.charAt(1).toUpperCase(); + }); }, - include: function(key, value){ - if (this[key] == null) this[key] = value; - return this; + hyphenate: function(){ + return String(this).replace(/[A-Z]/g, function(match){ + return ('-' + match.charAt(0).toLowerCase()); + }); }, - map: function(fn, bind){ - return new Hash(Object.map(this, fn, bind)); + capitalize: function(){ + return String(this).replace(/\b[a-z]/g, function(match){ + return match.toUpperCase(); + }); }, - filter: function(fn, bind){ - return new Hash(Object.filter(this, fn, bind)); + escapeRegExp: function(){ + return String(this).replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1'); }, - every: function(fn, bind){ - return Object.every(this, fn, bind); + toInt: function(base){ + return parseInt(this, base || 10); }, - some: function(fn, bind){ - return Object.some(this, fn, bind); + toFloat: function(){ + return parseFloat(this); }, - getKeys: function(){ - return Object.keys(this); + hexToRgb: function(array){ + var hex = String(this).match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/); + return (hex) ? hex.slice(1).hexToRgb(array) : null; }, - getValues: function(){ - return Object.values(this); + rgbToHex: function(array){ + var rgb = String(this).match(/\d{1,3}/g); + return (rgb) ? rgb.rgbToHex(array) : null; }, - toQueryString: function(base){ - return Object.toQueryString(this, base); + substitute: function(object, regexp){ + return String(this).replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){ + if (match.charAt(0) == '\\') return match.slice(1); + return (object[name] != null) ? object[name] : ''; + }); } }); -Hash.extend = Object.append; - -Hash.alias({indexOf: 'keyOf', contains: 'hasValue'}); - -// - +//<1.4compat> +String.prototype.contains = function(string, separator){ + return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : String(this).indexOf(string) > -1; +}; +// /* --- @@ -1184,48 +998,63 @@ provides: [Browser, Window, Document] var document = this.document; var window = document.window = this; -var UID = 1; - -this.$uid = (window.ActiveXObject) ? function(item){ - return (item.uid || (item.uid = [UID++]))[0]; -} : function(item){ - return item.uid || (item.uid = UID++); -}; - -$uid(window); -$uid(document); +var parse = function(ua, platform){ + ua = ua.toLowerCase(); + platform = (platform ? platform.toLowerCase() : ''); -var ua = navigator.userAgent.toLowerCase(), - platform = navigator.platform.toLowerCase(), - UA = ua.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, 'unknown', 0], - mode = UA[1] == 'ie' && document.documentMode; + var UA = ua.match(/(opera|ie|firefox|chrome|trident|crios|version)[\s\/:]([\w\d\.]+)?.*?(safari|(?:rv[\s\/:]|version[\s\/:])([\w\d\.]+)|$)/) || [null, 'unknown', 0]; -var Browser = this.Browser = { + if (UA[1] == 'trident'){ + UA[1] = 'ie'; + if (UA[4]) UA[2] = UA[4]; + } else if (UA[1] == 'crios'){ + UA[1] = 'chrome'; + } - extend: Function.prototype.extend, + platform = ua.match(/ip(?:ad|od|hone)/) ? 'ios' : (ua.match(/(?:webos|android)/) || platform.match(/mac|win|linux/) || ['other'])[0]; + if (platform == 'win') platform = 'windows'; - name: (UA[1] == 'version') ? UA[3] : UA[1], + return { + extend: Function.prototype.extend, + name: (UA[1] == 'version') ? UA[3] : UA[1], + version: parseFloat((UA[1] == 'opera' && UA[4]) ? UA[4] : UA[2]), + platform: platform + }; +}; - version: mode || parseFloat((UA[1] == 'opera' && UA[4]) ? UA[4] : UA[2]), +var Browser = this.Browser = parse(navigator.userAgent, navigator.platform); - Platform: { - name: ua.match(/ip(?:ad|od|hone)/) ? 'ios' : (ua.match(/(?:webos|android)/) || platform.match(/mac|win|linux/) || ['other'])[0] - }, +if (Browser.name == 'ie'){ + Browser.version = document.documentMode; +} +Browser.extend({ Features: { xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector), json: !!(window.JSON) }, + parseUA: parse +}); - Plugins: {} - -}; - +//<1.4compat> Browser[Browser.name] = true; Browser[Browser.name + parseInt(Browser.version, 10)] = true; -Browser.Platform[Browser.Platform.name] = true; + +if (Browser.name == 'ie' && Browser.version >= '11'){ + delete Browser.ie; +} + +var platform = Browser.platform; +if (platform == 'windows'){ + platform = 'win'; +} +Browser.Platform = { + name: platform +}; +Browser.Platform[platform] = true; +// // Request @@ -1258,6 +1087,8 @@ Browser.Request = (function(){ Browser.Features.xhr = !!(Browser.Request); +//<1.4compat> + // Flash detection var version = (Function.attempt(function(){ @@ -1266,11 +1097,15 @@ var version = (Function.attempt(function(){ return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version'); }) || '0 r0').match(/\d+/g); -Browser.Plugins.Flash = { - version: Number(version[0] || '0.' + version[1]) || 0, - build: Number(version[2]) || 0 +Browser.Plugins = { + Flash: { + version: Number(version[0] || '0.' + version[1]) || 0, + build: Number(version[2]) || 0 + } }; +// + // String scripts Browser.exec = function(text){ @@ -1324,16 +1159,18 @@ Document.mirror(function(name, method){ }); document.html = document.documentElement; -document.head = document.getElementsByTagName('head')[0]; +if (!document.head) document.head = document.getElementsByTagName('head')[0]; if (document.execCommand) try { document.execCommand("BackgroundImageCache", false, true); } catch (e){} +/**/ if (this.attachEvent && !this.addEventListener){ var unloadEvent = function(){ this.detachEvent('onunload', unloadEvent); document.head = document.html = document.window = null; + window = this.Window = document = null; }; this.attachEvent('onunload', unloadEvent); } @@ -1361,6 +1198,7 @@ try { }; }); } +/**/ //<1.2compat> @@ -1410,7 +1248,7 @@ if (Browser.opera){ } if (Browser.name == 'unknown'){ - switch ((ua.match(/(?:webkit|khtml|gecko)/) || [])[0]){ + switch ((navigator.userAgent.toLowerCase().match(/(?:webkit|khtml|gecko)/) || [])[0]){ case 'webkit': case 'khtml': Browser.Engine.webkit = true; @@ -1426,143 +1264,6 @@ this.$exec = Browser.exec; })(); - -/* ---- - -name: Event - -description: Contains the Event Class, to make the event object cross-browser. - -license: MIT-style license. - -requires: [Window, Document, Array, Function, String, Object] - -provides: Event - -... -*/ - -var Event = new Type('Event', function(event, win){ - if (!win) win = window; - var doc = win.document; - event = event || win.event; - if (event.$extended) return event; - this.$extended = true; - var type = event.type, - target = event.target || event.srcElement, - page = {}, - client = {}; - while (target && target.nodeType == 3) target = target.parentNode; - - if (type.indexOf('key') != -1){ - var code = event.which || event.keyCode; - var key = Object.keyOf(Event.Keys, code); - if (type == 'keydown'){ - var fKey = code - 111; - if (fKey > 0 && fKey < 13) key = 'f' + fKey; - } - if (!key) key = String.fromCharCode(code).toLowerCase(); - } else if (type.test(/click|mouse|menu/i)){ - doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body; - page = { - x: (event.pageX != null) ? event.pageX : event.clientX + doc.scrollLeft, - y: (event.pageY != null) ? event.pageY : event.clientY + doc.scrollTop - }; - client = { - x: (event.pageX != null) ? event.pageX - win.pageXOffset : event.clientX, - y: (event.pageY != null) ? event.pageY - win.pageYOffset : event.clientY - }; - if (type.test(/DOMMouseScroll|mousewheel/)){ - var wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3; - } - var rightClick = (event.which == 3) || (event.button == 2), - related = null; - if (type.test(/over|out/)){ - related = event.relatedTarget || event[(type == 'mouseover' ? 'from' : 'to') + 'Element']; - var testRelated = function(){ - while (related && related.nodeType == 3) related = related.parentNode; - return true; - }; - var hasRelated = (Browser.firefox2) ? testRelated.attempt() : testRelated(); - related = (hasRelated) ? related : null; - } - } else if (type.test(/gesture|touch/i)){ - this.rotation = event.rotation; - this.scale = event.scale; - this.targetTouches = event.targetTouches; - this.changedTouches = event.changedTouches; - var touches = this.touches = event.touches; - if (touches && touches[0]){ - var touch = touches[0]; - page = {x: touch.pageX, y: touch.pageY}; - client = {x: touch.clientX, y: touch.clientY}; - } - } - - return Object.append(this, { - event: event, - type: type, - - page: page, - client: client, - rightClick: rightClick, - - wheel: wheel, - - relatedTarget: document.id(related), - target: document.id(target), - - code: code, - key: key, - - shift: event.shiftKey, - control: event.ctrlKey, - alt: event.altKey, - meta: event.metaKey - }); -}); - -Event.Keys = { - 'enter': 13, - 'up': 38, - 'down': 40, - 'left': 37, - 'right': 39, - 'esc': 27, - 'space': 32, - 'backspace': 8, - 'tab': 9, - 'delete': 46 -}; - -//<1.2compat> - -Event.Keys = new Hash(Event.Keys); - -// - -Event.implement({ - - stop: function(){ - return this.stopPropagation().preventDefault(); - }, - - stopPropagation: function(){ - if (this.event.stopPropagation) this.event.stopPropagation(); - else this.event.cancelBubble = true; - return this; - }, - - preventDefault: function(){ - if (this.event.preventDefault) this.event.preventDefault(); - else this.event.returnValue = false; - return this; - } - -}); - - /* --- @@ -1679,7 +1380,6 @@ Class.Mutators = { })(); - /* --- @@ -1756,12 +1456,12 @@ this.Events = new Class({ }, this); return this; }, - + removeEvent: function(type, fn){ type = removeOn(type); var events = this.$events[type]; if (events && !fn.internal){ - var index = events.indexOf(fn); + var index = events.indexOf(fn); if (index != -1) delete events[index]; } return this; @@ -1777,7 +1477,9 @@ this.Events = new Class({ for (type in this.$events){ if (events && events != type) continue; var fns = this.$events[type]; - for (var i = fns.length; i--;) this.removeEvent(type, fns[i]); + for (var i = fns.length; i--;) if (i in fns){ + this.removeEvent(type, fns[i]); + } } return this; } @@ -1788,8 +1490,7 @@ this.Options = new Class({ setOptions: function(){ var options = this.options = Object.merge.apply(null, [{}, this.options].append(arguments)); - if (!this.addEvent) return this; - for (var option in options){ + if (this.addEvent) for (var option in options){ if (typeOf(options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue; this.addEvent(option, options[option]); delete options[option]; @@ -1801,39 +1502,253 @@ this.Options = new Class({ })(); - /* --- -name: Slick.Parser -description: Standalone CSS3 Selector parser -provides: Slick.Parser + +name: Object + +description: Object generic methods + +license: MIT-style license. + +requires: Type + +provides: [Object, Hash] + ... */ (function(){ -var parsed, - separatorIndex, - combinatorIndex, - reversed, - cache = {}, - reverseCache = {}, - reUnescape = /\\/g; +var hasOwnProperty = Object.prototype.hasOwnProperty; -var parse = function(expression, isReversed){ - if (expression == null) return null; - if (expression.Slick === true) return expression; - expression = ('' + expression).replace(/^\s+|\s+$/g, ''); - reversed = !!isReversed; - var currentCache = (reversed) ? reverseCache : cache; +Object.extend({ + + subset: function(object, keys){ + var results = {}; + for (var i = 0, l = keys.length; i < l; i++){ + var k = keys[i]; + if (k in object) results[k] = object[k]; + } + return results; + }, + + map: function(object, fn, bind){ + var results = {}; + for (var key in object){ + if (hasOwnProperty.call(object, key)) results[key] = fn.call(bind, object[key], key, object); + } + return results; + }, + + filter: function(object, fn, bind){ + var results = {}; + for (var key in object){ + var value = object[key]; + if (hasOwnProperty.call(object, key) && fn.call(bind, value, key, object)) results[key] = value; + } + return results; + }, + + every: function(object, fn, bind){ + for (var key in object){ + if (hasOwnProperty.call(object, key) && !fn.call(bind, object[key], key)) return false; + } + return true; + }, + + some: function(object, fn, bind){ + for (var key in object){ + if (hasOwnProperty.call(object, key) && fn.call(bind, object[key], key)) return true; + } + return false; + }, + + keys: function(object){ + var keys = []; + for (var key in object){ + if (hasOwnProperty.call(object, key)) keys.push(key); + } + return keys; + }, + + values: function(object){ + var values = []; + for (var key in object){ + if (hasOwnProperty.call(object, key)) values.push(object[key]); + } + return values; + }, + + getLength: function(object){ + return Object.keys(object).length; + }, + + keyOf: function(object, value){ + for (var key in object){ + if (hasOwnProperty.call(object, key) && object[key] === value) return key; + } + return null; + }, + + contains: function(object, value){ + return Object.keyOf(object, value) != null; + }, + + toQueryString: function(object, base){ + var queryString = []; + + Object.each(object, function(value, key){ + if (base) key = base + '[' + key + ']'; + var result; + switch (typeOf(value)){ + case 'object': result = Object.toQueryString(value, key); break; + case 'array': + var qs = {}; + value.each(function(val, i){ + qs[i] = val; + }); + result = Object.toQueryString(qs, key); + break; + default: result = key + '=' + encodeURIComponent(value); + } + if (value != null) queryString.push(result); + }); + + return queryString.join('&'); + } + +}); + +})(); + +//<1.2compat> + +Hash.implement({ + + has: Object.prototype.hasOwnProperty, + + keyOf: function(value){ + return Object.keyOf(this, value); + }, + + hasValue: function(value){ + return Object.contains(this, value); + }, + + extend: function(properties){ + Hash.each(properties || {}, function(value, key){ + Hash.set(this, key, value); + }, this); + return this; + }, + + combine: function(properties){ + Hash.each(properties || {}, function(value, key){ + Hash.include(this, key, value); + }, this); + return this; + }, + + erase: function(key){ + if (this.hasOwnProperty(key)) delete this[key]; + return this; + }, + + get: function(key){ + return (this.hasOwnProperty(key)) ? this[key] : null; + }, + + set: function(key, value){ + if (!this[key] || this.hasOwnProperty(key)) this[key] = value; + return this; + }, + + empty: function(){ + Hash.each(this, function(value, key){ + delete this[key]; + }, this); + return this; + }, + + include: function(key, value){ + if (this[key] == null) this[key] = value; + return this; + }, + + map: function(fn, bind){ + return new Hash(Object.map(this, fn, bind)); + }, + + filter: function(fn, bind){ + return new Hash(Object.filter(this, fn, bind)); + }, + + every: function(fn, bind){ + return Object.every(this, fn, bind); + }, + + some: function(fn, bind){ + return Object.some(this, fn, bind); + }, + + getKeys: function(){ + return Object.keys(this); + }, + + getValues: function(){ + return Object.values(this); + }, + + toQueryString: function(base){ + return Object.toQueryString(this, base); + } + +}); + +Hash.extend = Object.append; + +Hash.alias({indexOf: 'keyOf', contains: 'hasValue'}); + +// + +/* +--- +name: Slick.Parser +description: Standalone CSS3 Selector parser +provides: Slick.Parser +... +*/ + +;(function(){ + +var parsed, + separatorIndex, + combinatorIndex, + reversed, + cache = {}, + reverseCache = {}, + reUnescape = /\\/g; + +var parse = function(expression, isReversed){ + if (expression == null) return null; + if (expression.Slick === true) return expression; + expression = ('' + expression).replace(/^\s+|\s+$/g, ''); + reversed = !!isReversed; + var currentCache = (reversed) ? reverseCache : cache; if (currentCache[expression]) return currentCache[expression]; - parsed = {Slick: true, expressions: [], raw: expression, reverse: function(){ - return parse(this.raw, true); - }}; + parsed = { + Slick: true, + expressions: [], + raw: expression, + reverse: function(){ + return parse(this.raw, true); + } + }; separatorIndex = -1; while (expression != (expression = expression.replace(regexp, parser))); parsed.length = parsed.expressions.length; - return currentCache[expression] = (reversed) ? reverse(parsed) : parsed; + return currentCache[parsed.raw] = (reversed) ? reverse(parsed) : parsed; }; var reverseCombinator = function(combinator){ @@ -1862,7 +1777,9 @@ var reverse = function(expression){ }; var escapeRegExp = function(string){// Credit: XRegExp 0.6.1 (c) 2007-2008 Steven Levithan MIT License - return string.replace(/[-[\]{}()*+?.\\^$|,#\s]/g, "\\$&"); + return string.replace(/[-[\]{}()*+?.\\^$|,#\s]/g, function(match){ + return '\\' + match; + }); }; var regexp = new RegExp( @@ -1894,7 +1811,7 @@ __END__ )?\ )" */ - "^(?:\\s*(,)\\s*|\\s*(+)\\s*|(\\s+)|(+|\\*)|\\#(+)|\\.(+)|\\[\\s*(+)(?:\\s*([*^$!~|]?=)(?:\\s*(?:([\"']?)(.*?)\\9)))?\\s*\\](?!\\])|:+(+)(?:\\((?:(?:([\"'])([^\\12]*)\\12)|((?:\\([^)]+\\)|[^()]*)+))\\))?)" + "^(?:\\s*(,)\\s*|\\s*(+)\\s*|(\\s+)|(+|\\*)|\\#(+)|\\.(+)|\\[\\s*(+)(?:\\s*([*^$!~|]?=)(?:\\s*(?:([\"']?)(.*?)\\9)))?\\s*\\](?!\\])|(:+)(+)(?:\\((?:(?:([\"'])([^\\13]*)\\13)|((?:\\([^)]+\\)|[^()]*)+))\\))?)" .replace(//, '[' + escapeRegExp(">+~`!@$%^&={}\\;/g, '(?:[\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])') .replace(//g, '(?:[:\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])') @@ -1916,6 +1833,7 @@ function parser( attributeQuote, attributeValue, + pseudoMarker, pseudoClass, pseudoQuote, pseudoClassQuotedValue, @@ -1961,7 +1879,8 @@ function parser( if (!currentParsed.pseudos) currentParsed.pseudos = []; currentParsed.pseudos.push({ key: pseudoClass.replace(reUnescape, ''), - value: pseudoClassValue + value: pseudoClassValue, + type: pseudoMarker.length == 1 ? 'class' : 'element' }); } else if (attributeKey){ @@ -2024,7 +1943,6 @@ if (!this.Slick) this.Slick = Slick; }).apply(/**/(typeof exports != 'undefined') ? exports : /**/this); - /* --- name: Slick.Finder @@ -2034,9 +1952,11 @@ requires: Slick.Parser ... */ -(function(){ +;(function(){ -var local = {}; +var local = {}, + featuresCache = {}, + toString = Object.prototype.toString; // Feature / Bug detection @@ -2045,16 +1965,16 @@ local.isNativeCode = function(fn){ }; local.isXML = function(document){ - return (!!document.xmlVersion) || (!!document.xml) || (Object.prototype.toString.call(document) === '[object XMLDocument]') || - (document.nodeType === 9 && document.documentElement.nodeName !== 'HTML'); + return (!!document.xmlVersion) || (!!document.xml) || (toString.call(document) == '[object XMLDocument]') || + (document.nodeType == 9 && document.documentElement.nodeName != 'HTML'); }; local.setDocument = function(document){ // convert elements / window arguments to document. if document cannot be extrapolated, the function returns. - - if (document.nodeType === 9); // document - else if (document.ownerDocument) document = document.ownerDocument; // node + var nodeType = document.nodeType; + if (nodeType == 9); // document + else if (nodeType) document = document.ownerDocument; // node else if (document.navigator) document = document.document; // window else return; @@ -2062,116 +1982,182 @@ local.setDocument = function(document){ if (this.document === document) return; this.document = document; - var root = this.root = document.documentElement; - - this.isXMLDocument = this.isXML(document); - - this.brokenStarGEBTN - = this.starSelectsClosedQSA - = this.idGetsName - = this.brokenMixedCaseQSA - = this.brokenGEBCN - = this.brokenCheckedQSA - = this.brokenEmptyAttributeQSA - = this.isHTMLDocument + + // check if we have done feature detection on this document before + + var root = document.documentElement, + rootUid = this.getUIDXML(root), + features = featuresCache[rootUid], + feature; + + if (features){ + for (feature in features){ + this[feature] = features[feature]; + } + return; + } + + features = featuresCache[rootUid] = {}; + + features.root = root; + features.isXMLDocument = this.isXML(document); + + features.brokenStarGEBTN + = features.starSelectsClosedQSA + = features.idGetsName + = features.brokenMixedCaseQSA + = features.brokenGEBCN + = features.brokenCheckedQSA + = features.brokenEmptyAttributeQSA + = features.isHTMLDocument + = features.nativeMatchesSelector = false; var starSelectsClosed, starSelectsComments, - brokenSecondClassNameGEBCN, cachedGetElementsByClassName; + brokenSecondClassNameGEBCN, cachedGetElementsByClassName, + brokenFormAttributeGetter; - var selected, id; + var selected, id = 'slick_uniqueid'; var testNode = document.createElement('div'); - root.appendChild(testNode); + + var testRoot = document.body || document.getElementsByTagName('body')[0] || root; + testRoot.appendChild(testNode); // on non-HTML documents innerHTML and getElementsById doesnt work properly try { - id = 'slick_getbyid_test'; testNode.innerHTML = ''; - this.isHTMLDocument = !!document.getElementById(id); + features.isHTMLDocument = !!document.getElementById(id); } catch(e){}; - if (this.isHTMLDocument){ - + if (features.isHTMLDocument){ + testNode.style.display = 'none'; - + // IE returns comment nodes for getElementsByTagName('*') for some documents testNode.appendChild(document.createComment('')); - starSelectsComments = (testNode.getElementsByTagName('*').length > 0); + starSelectsComments = (testNode.getElementsByTagName('*').length > 1); // IE returns closed nodes (EG:"") for getElementsByTagName('*') for some documents try { testNode.innerHTML = 'foo'; selected = testNode.getElementsByTagName('*'); - starSelectsClosed = (selected && selected.length && selected[0].nodeName.charAt(0) == '/'); + starSelectsClosed = (selected && !!selected.length && selected[0].nodeName.charAt(0) == '/'); } catch(e){}; - this.brokenStarGEBTN = starSelectsComments || starSelectsClosed; - - // IE 8 returns closed nodes (EG:"") for querySelectorAll('*') for some documents - if (testNode.querySelectorAll) try { - testNode.innerHTML = 'foo'; - selected = testNode.querySelectorAll('*'); - this.starSelectsClosedQSA = (selected && selected.length && selected[0].nodeName.charAt(0) == '/'); - } catch(e){}; + features.brokenStarGEBTN = starSelectsComments || starSelectsClosed; // IE returns elements with the name instead of just id for getElementsById for some documents try { - id = 'slick_id_gets_name'; - testNode.innerHTML = ''; - this.idGetsName = document.getElementById(id) === testNode.firstChild; + testNode.innerHTML = ''; + features.idGetsName = document.getElementById(id) === testNode.firstChild; } catch(e){}; - // Safari 3.2 querySelectorAll doesnt work with mixedcase on quirksmode - try { - testNode.innerHTML = ''; - this.brokenMixedCaseQSA = !testNode.querySelectorAll('.MiXedCaSe').length; - } catch(e){}; + if (testNode.getElementsByClassName){ - try { - testNode.innerHTML = ''; - testNode.getElementsByClassName('b').length; - testNode.firstChild.className = 'b'; - cachedGetElementsByClassName = (testNode.getElementsByClassName('b').length != 2); - } catch(e){}; + // Safari 3.2 getElementsByClassName caches results + try { + testNode.innerHTML = ''; + testNode.getElementsByClassName('b').length; + testNode.firstChild.className = 'b'; + cachedGetElementsByClassName = (testNode.getElementsByClassName('b').length != 2); + } catch(e){}; - // Opera 9.6 getElementsByClassName doesnt detects the class if its not the first one - try { - testNode.innerHTML = ''; - brokenSecondClassNameGEBCN = (testNode.getElementsByClassName('a').length != 2); - } catch(e){}; + // Opera 9.6 getElementsByClassName doesnt detects the class if its not the first one + try { + testNode.innerHTML = ''; + brokenSecondClassNameGEBCN = (testNode.getElementsByClassName('a').length != 2); + } catch(e){}; - this.brokenGEBCN = cachedGetElementsByClassName || brokenSecondClassNameGEBCN; - - // Webkit dont return selected options on querySelectorAll + features.brokenGEBCN = cachedGetElementsByClassName || brokenSecondClassNameGEBCN; + } + + if (testNode.querySelectorAll){ + // IE 8 returns closed nodes (EG:"") for querySelectorAll('*') for some documents + try { + testNode.innerHTML = 'foo'; + selected = testNode.querySelectorAll('*'); + features.starSelectsClosedQSA = (selected && !!selected.length && selected[0].nodeName.charAt(0) == '/'); + } catch(e){}; + + // Safari 3.2 querySelectorAll doesnt work with mixedcase on quirksmode + try { + testNode.innerHTML = ''; + features.brokenMixedCaseQSA = !testNode.querySelectorAll('.MiX').length; + } catch(e){}; + + // Webkit and Opera dont return selected options on querySelectorAll + try { + testNode.innerHTML = ''; + features.brokenCheckedQSA = (testNode.querySelectorAll(':checked').length == 0); + } catch(e){}; + + // IE returns incorrect results for attr[*^$]="" selectors on querySelectorAll + try { + testNode.innerHTML = ''; + features.brokenEmptyAttributeQSA = (testNode.querySelectorAll('[class*=""]').length != 0); + } catch(e){}; + + } + + // IE6-7, if a form has an input of id x, form.getAttribute(x) returns a reference to the input try { - testNode.innerHTML = ''; - this.brokenCheckedQSA = (testNode.querySelectorAll(':checked').length == 0); + testNode.innerHTML = '
'; + brokenFormAttributeGetter = (testNode.firstChild.getAttribute('action') != 's'); } catch(e){}; - - // IE returns incorrect results for attr[*^$]="" selectors on querySelectorAll - try { - testNode.innerHTML = ''; - this.brokenEmptyAttributeQSA = (testNode.querySelectorAll('[class*=""]').length != 0); + + // native matchesSelector function + + features.nativeMatchesSelector = root.matches || /*root.msMatchesSelector ||*/ root.mozMatchesSelector || root.webkitMatchesSelector; + if (features.nativeMatchesSelector) try { + // if matchesSelector trows errors on incorrect sintaxes we can use it + features.nativeMatchesSelector.call(root, ':slick'); + features.nativeMatchesSelector = null; } catch(e){}; - + } - root.removeChild(testNode); - testNode = null; + try { + root.slick_expando = 1; + delete root.slick_expando; + features.getUID = this.getUIDHTML; + } catch(e){ + features.getUID = this.getUIDXML; + } - // hasAttribute + testRoot.removeChild(testNode); + testNode = selected = testRoot = null; - this.hasAttribute = (root && this.isNativeCode(root.hasAttribute)) ? function(node, attribute) { + // getAttribute + + features.getAttribute = (features.isHTMLDocument && brokenFormAttributeGetter) ? function(node, name){ + var method = this.attributeGetters[name]; + if (method) return method.call(node); + var attributeNode = node.getAttributeNode(name); + return (attributeNode) ? attributeNode.nodeValue : null; + } : function(node, name){ + var method = this.attributeGetters[name]; + return (method) ? method.call(node) : node.getAttribute(name); + }; + + // hasAttribute + + features.hasAttribute = (root && this.isNativeCode(root.hasAttribute)) ? function(node, attribute){ return node.hasAttribute(attribute); - } : function(node, attribute) { + } : function(node, attribute){ node = node.getAttributeNode(attribute); return !!(node && (node.specified || node.nodeValue)); }; // contains // FIXME: Add specs: local.contains should be different for xml and html documents? - this.contains = (root && this.isNativeCode(root.contains)) ? function(context, node){ + var nativeRootContains = root && this.isNativeCode(root.contains), + nativeDocumentContains = document && this.isNativeCode(document.contains); + + features.contains = (nativeRootContains && nativeDocumentContains) ? function(context, node){ return context.contains(node); + } : (nativeRootContains && !nativeDocumentContains) ? function(context, node){ + // IE8 does not have .contains on document. + return context === node || ((context === document) ? document.documentElement : context).contains(node); } : (root && root.compareDocumentPosition) ? function(context, node){ return context === node || !!(context.compareDocumentPosition(node) & 16); } : function(context, node){ @@ -2184,7 +2170,7 @@ local.setDocument = function(document){ // document order sorting // credits to Sizzle (http://sizzlejs.com/) - this.documentSorter = (root.compareDocumentPosition) ? function(a, b){ + features.documentSorter = (root.compareDocumentPosition) ? function(a, b){ if (!a.compareDocumentPosition || !b.compareDocumentPosition) return 0; return a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1; } : ('sourceIndex' in root) ? function(a, b){ @@ -2200,52 +2186,149 @@ local.setDocument = function(document){ return aRange.compareBoundaryPoints(Range.START_TO_END, bRange); } : null ; - this.getUID = (this.isHTMLDocument) ? this.getUIDHTML : this.getUIDXML; + root = null; + for (feature in features){ + this[feature] = features[feature]; + } }; // Main Method +var reSimpleSelector = /^([#.]?)((?:[\w-]+|\*))$/, + reEmptyAttribute = /\[.+[*$^]=(?:""|'')?\]/, + qsaFailExpCache = {}; + local.search = function(context, expression, append, first){ var found = this.found = (first) ? null : (append || []); - // context checks - - if (!context) return found; // No context - if (context.navigator) context = context.document; // Convert the node from a window to a document - else if (!context.nodeType) return found; // Reject misc junk input + if (!context) return found; + else if (context.navigator) context = context.document; // Convert the node from a window to a document + else if (!context.nodeType) return found; // setup - var parsed, i; - - var uniques = this.uniques = {}; + var parsed, i, + uniques = this.uniques = {}, + hasOthers = !!(append && append.length), + contextIsDocument = (context.nodeType == 9); - if (this.document !== (context.ownerDocument || context)) this.setDocument(context); - - // should sort if there are nodes in append and if you pass multiple expressions. - // should remove duplicates if append already has items - var shouldUniques = !!(append && append.length); + if (this.document !== (contextIsDocument ? context : context.ownerDocument)) this.setDocument(context); // avoid duplicating items already in the append array - if (shouldUniques) for (i = found.length; i--;) this.uniques[this.getUID(found[i])] = true; + if (hasOthers) for (i = found.length; i--;) uniques[this.getUID(found[i])] = true; // expression checks if (typeof expression == 'string'){ // expression is a string - // Overrides + /**/ + var simpleSelector = expression.match(reSimpleSelector); + simpleSelectors: if (simpleSelector){ + + var symbol = simpleSelector[1], + name = simpleSelector[2], + node, nodes; + + if (!symbol){ + + if (name == '*' && this.brokenStarGEBTN) break simpleSelectors; + nodes = context.getElementsByTagName(name); + if (first) return nodes[0] || null; + for (i = 0; node = nodes[i++];){ + if (!(hasOthers && uniques[this.getUID(node)])) found.push(node); + } + + } else if (symbol == '#'){ + + if (!this.isHTMLDocument || !contextIsDocument) break simpleSelectors; + node = context.getElementById(name); + if (!node) return found; + if (this.idGetsName && node.getAttributeNode('id').nodeValue != name) break simpleSelectors; + if (first) return node || null; + if (!(hasOthers && uniques[this.getUID(node)])) found.push(node); + + } else if (symbol == '.'){ + + if (!this.isHTMLDocument || ((!context.getElementsByClassName || this.brokenGEBCN) && context.querySelectorAll)) break simpleSelectors; + if (context.getElementsByClassName && !this.brokenGEBCN){ + nodes = context.getElementsByClassName(name); + if (first) return nodes[0] || null; + for (i = 0; node = nodes[i++];){ + if (!(hasOthers && uniques[this.getUID(node)])) found.push(node); + } + } else { + var matchClass = new RegExp('(^|\\s)'+ Slick.escapeRegExp(name) +'(\\s|$)'); + nodes = context.getElementsByTagName('*'); + for (i = 0; node = nodes[i++];){ + className = node.className; + if (!(className && matchClass.test(className))) continue; + if (first) return node; + if (!(hasOthers && uniques[this.getUID(node)])) found.push(node); + } + } + + } + + if (hasOthers) this.sort(found); + return (first) ? null : found; + + } + /**/ + + /**/ + querySelector: if (context.querySelectorAll){ + + if (!this.isHTMLDocument + || qsaFailExpCache[expression] + //TODO: only skip when expression is actually mixed case + || this.brokenMixedCaseQSA + || (this.brokenCheckedQSA && expression.indexOf(':checked') > -1) + || (this.brokenEmptyAttributeQSA && reEmptyAttribute.test(expression)) + || (!contextIsDocument //Abort when !contextIsDocument and... + // there are multiple expressions in the selector + // since we currently only fix non-document rooted QSA for single expression selectors + && expression.indexOf(',') > -1 + ) + || Slick.disableQSA + ) break querySelector; + + var _expression = expression, _context = context; + if (!contextIsDocument){ + // non-document rooted QSA + // credits to Andrew Dupont + var currentId = _context.getAttribute('id'), slickid = 'slickid__'; + _context.setAttribute('id', slickid); + _expression = '#' + slickid + ' ' + _expression; + context = _context.parentNode; + } + + try { + if (first) return context.querySelector(_expression) || null; + else nodes = context.querySelectorAll(_expression); + } catch(e){ + qsaFailExpCache[expression] = 1; + break querySelector; + } finally { + if (!contextIsDocument){ + if (currentId) _context.setAttribute('id', currentId); + else _context.removeAttribute('id'); + context = _context; + } + } - for (i = this.overrides.length; i--;){ - var override = this.overrides[i]; - if (override.regexp.test(expression)){ - var result = override.method.call(context, expression, found, first); - if (result === false) continue; - if (result === true) return found; - return result; + if (this.starSelectsClosedQSA) for (i = 0; node = nodes[i++];){ + if (node.nodeName > '@' && !(hasOthers && uniques[this.getUID(node)])) found.push(node); + } else for (i = 0; node = nodes[i++];){ + if (!(hasOthers && uniques[this.getUID(node)])) found.push(node); } + + if (hasOthers) this.sort(found); + return found; + } + /**/ parsed = this.Slick.parse(expression); if (!parsed.length) return found; @@ -2260,10 +2343,10 @@ local.search = function(context, expression, append, first){ return found; } - // cache elements for the nth selectors - /**//**/ + // cache elements for the nth selectors + this.posNTH = {}; this.posNTHLast = {}; this.posNTHType = {}; @@ -2272,7 +2355,7 @@ local.search = function(context, expression, append, first){ /**//**/ // if append is null and there is only a single selector with one expression use pushArray, else use pushUID - this.push = (!shouldUniques && (first || (parsed.length == 1 && parsed.expressions[0].length == 1))) ? this.pushArray : this.pushUID; + this.push = (!hasOthers && (first || (parsed.length == 1 && parsed.expressions[0].length == 1))) ? this.pushArray : this.pushUID; if (found == null) found = []; @@ -2318,7 +2401,8 @@ local.search = function(context, expression, append, first){ currentItems = this.found; } - if (shouldUniques || (parsed.expressions.length > 1)) this.sort(found); + // should sort if there are nodes in append and if you pass multiple expressions. + if (hasOthers || (parsed.expressions.length > 1)) this.sort(found); return (first) ? (found[0] || null) : found; }; @@ -2326,7 +2410,7 @@ local.search = function(context, expression, append, first){ // Utils local.uidx = 1; -local.uidk = 'slick:uniqueid'; +local.uidk = 'slick-uniqueid'; local.getUIDXML = function(node){ var uid = node.getAttribute(this.uidk); @@ -2380,12 +2464,12 @@ local.createNTHPseudo = function(child, sibling, positions, ofType){ if (ofType){ var nodeName = node.nodeName; do { - if (el.nodeName !== nodeName) continue; + if (el.nodeName != nodeName) continue; this[positions][this.getUID(el)] = count++; } while ((el = el[sibling])); } else { do { - if (el.nodeType !== 1) continue; + if (el.nodeType != 1) continue; this[positions][this.getUID(el)] = count++; } while ((el = el[sibling])); } @@ -2419,17 +2503,29 @@ local.pushUID = function(node, tag, id, classes, attributes, pseudos){ }; local.matchNode = function(node, selector){ + if (this.isHTMLDocument && this.nativeMatchesSelector){ + try { + return this.nativeMatchesSelector.call(node, selector.replace(/\[([^=]+)=\s*([^'"\]]+?)\s*\]/g, '[$1="$2"]')); + } catch(matchError){} + } + var parsed = this.Slick.parse(selector); if (!parsed) return true; // simple (single) selectors - if(parsed.length == 1 && parsed.expressions[0].length == 1){ - var exp = parsed.expressions[0][0]; - return this.matchSelector(node, (this.isXMLDocument) ? exp.tag : exp.tag.toUpperCase(), exp.id, exp.classes, exp.attributes, exp.pseudos); + var expressions = parsed.expressions, simpleExpCounter = 0, i, currentExpression; + for (i = 0; (currentExpression = expressions[i]); i++){ + if (currentExpression.length == 1){ + var exp = currentExpression[0]; + if (this.matchSelector(node, (this.isXMLDocument) ? exp.tag : exp.tag.toUpperCase(), exp.id, exp.classes, exp.attributes, exp.pseudos)) return true; + simpleExpCounter++; + } } - var nodes = this.search(this.document, parsed); - for (var i = 0, item; item = nodes[i++];){ + if (simpleExpCounter == parsed.length) return false; + + var nodes = this.search(this.document, parsed), item; + for (i = 0; item = nodes[i++];){ if (item === node) return true; } return false; @@ -2444,10 +2540,11 @@ local.matchPseudo = function(node, name, argument){ local.matchSelector = function(node, tag, id, classes, attributes, pseudos){ if (tag){ + var nodeName = (this.isXMLDocument) ? node.nodeName : node.nodeName.toUpperCase(); if (tag == '*'){ - if (node.nodeName < '@') return false; // Fix for comment nodes and closed nodes + if (nodeName < '@') return false; // Fix for comment nodes and closed nodes } else { - if (node.nodeName != tag) return false; + if (nodeName != tag) return false; } } @@ -2455,7 +2552,7 @@ local.matchSelector = function(node, tag, id, classes, attributes, pseudos){ var i, part, cls; if (classes) for (i = classes.length; i--;){ - cls = ('className' in node) ? node.className : node.getAttribute('class'); + cls = this.getAttribute(node, 'class'); if (!(cls && classes[i].regexp.test(cls))) return false; } if (attributes) for (i = attributes.length; i--;){ @@ -2484,15 +2581,18 @@ var combinators = { children = node.all[id]; if (!children) return; if (!children[0]) children = [children]; - for (i = 0; item = children[i++];) if (item.getAttributeNode('id').nodeValue == id){ - this.push(item, tag, null, classes, attributes, pseudos); - break; - } + for (i = 0; item = children[i++];){ + var idNode = item.getAttributeNode('id'); + if (idNode && idNode.nodeValue == id){ + this.push(item, tag, null, classes, attributes, pseudos); + break; + } + } return; } if (!item){ // if the context is in the dom we return, else we will try GEBTN, breaking the getById label - if (this.contains(this.document.documentElement, node)) return; + if (this.contains(this.root, node)) return; else break getById; } else if (this.document !== node && !this.contains(node, item)) return; this.push(item, tag, null, classes, attributes, pseudos); @@ -2515,12 +2615,12 @@ var combinators = { '>': function(node, tag, id, classes, attributes, pseudos){ // direct children if ((node = node.firstChild)) do { - if (node.nodeType === 1) this.push(node, tag, id, classes, attributes, pseudos); + if (node.nodeType == 1) this.push(node, tag, id, classes, attributes, pseudos); } while ((node = node.nextSibling)); }, '+': function(node, tag, id, classes, attributes, pseudos){ // next sibling - while ((node = node.nextSibling)) if (node.nodeType === 1){ + while ((node = node.nextSibling)) if (node.nodeType == 1){ this.push(node, tag, id, classes, attributes, pseudos); break; } @@ -2529,14 +2629,14 @@ var combinators = { '^': function(node, tag, id, classes, attributes, pseudos){ // first child node = node.firstChild; if (node){ - if (node.nodeType === 1) this.push(node, tag, id, classes, attributes, pseudos); + if (node.nodeType == 1) this.push(node, tag, id, classes, attributes, pseudos); else this['combinator:+'](node, tag, id, classes, attributes, pseudos); } }, '~': function(node, tag, id, classes, attributes, pseudos){ // next siblings while ((node = node.nextSibling)){ - if (node.nodeType !== 1) continue; + if (node.nodeType != 1) continue; var uid = this.getUID(node); if (this.bitUniques[uid]) break; this.bitUniques[uid] = true; @@ -2554,7 +2654,7 @@ var combinators = { this['combinator:!~'](node, tag, id, classes, attributes, pseudos); }, - '!': function(node, tag, id, classes, attributes, pseudos){ // all parent nodes up to document + '!': function(node, tag, id, classes, attributes, pseudos){ // all parent nodes up to document while ((node = node.parentNode)) if (node !== this.document) this.push(node, tag, id, classes, attributes, pseudos); }, @@ -2564,7 +2664,7 @@ var combinators = { }, '!+': function(node, tag, id, classes, attributes, pseudos){ // previous sibling - while ((node = node.previousSibling)) if (node.nodeType === 1){ + while ((node = node.previousSibling)) if (node.nodeType == 1){ this.push(node, tag, id, classes, attributes, pseudos); break; } @@ -2573,14 +2673,14 @@ var combinators = { '!^': function(node, tag, id, classes, attributes, pseudos){ // last child node = node.lastChild; if (node){ - if (node.nodeType === 1) this.push(node, tag, id, classes, attributes, pseudos); + if (node.nodeType == 1) this.push(node, tag, id, classes, attributes, pseudos); else this['combinator:!+'](node, tag, id, classes, attributes, pseudos); } }, '!~': function(node, tag, id, classes, attributes, pseudos){ // previous siblings while ((node = node.previousSibling)){ - if (node.nodeType !== 1) continue; + if (node.nodeType != 1) continue; var uid = this.getUID(node); if (this.bitUniques[uid]) break; this.bitUniques[uid] = true; @@ -2610,20 +2710,20 @@ var pseudos = { }, 'first-child': function(node){ - while ((node = node.previousSibling)) if (node.nodeType === 1) return false; + while ((node = node.previousSibling)) if (node.nodeType == 1) return false; return true; }, 'last-child': function(node){ - while ((node = node.nextSibling)) if (node.nodeType === 1) return false; + while ((node = node.nextSibling)) if (node.nodeType == 1) return false; return true; }, 'only-child': function(node){ var prev = node; - while ((prev = prev.previousSibling)) if (prev.nodeType === 1) return false; + while ((prev = prev.previousSibling)) if (prev.nodeType == 1) return false; var next = node; - while ((next = next.nextSibling)) if (next.nodeType === 1) return false; + while ((next = next.nextSibling)) if (next.nodeType == 1) return false; return true; }, @@ -2638,14 +2738,14 @@ var pseudos = { 'nth-last-of-type': local.createNTHPseudo('lastChild', 'previousSibling', 'posNTHTypeLast', true), 'index': function(node, index){ - return this['pseudo:nth-child'](node, '' + index + 1); + return this['pseudo:nth-child'](node, '' + (index + 1)); }, - 'even': function(node, argument){ + 'even': function(node){ return this['pseudo:nth-child'](node, '2n'); }, - 'odd': function(node, argument){ + 'odd': function(node){ return this['pseudo:nth-child'](node, '2n+1'); }, @@ -2655,21 +2755,21 @@ var pseudos = { 'first-of-type': function(node){ var nodeName = node.nodeName; - while ((node = node.previousSibling)) if (node.nodeName === nodeName) return false; + while ((node = node.previousSibling)) if (node.nodeName == nodeName) return false; return true; }, 'last-of-type': function(node){ var nodeName = node.nodeName; - while ((node = node.nextSibling)) if (node.nodeName === nodeName) return false; + while ((node = node.nextSibling)) if (node.nodeName == nodeName) return false; return true; }, 'only-of-type': function(node){ var prev = node, nodeName = node.nodeName; - while ((prev = prev.previousSibling)) if (prev.nodeName === nodeName) return false; + while ((prev = prev.previousSibling)) if (prev.nodeName == nodeName) return false; var next = node; - while ((next = next.nextSibling)) if (next.nodeName === nodeName) return false; + while ((next = next.nextSibling)) if (next.nodeName == nodeName) return false; return true; }, @@ -2678,11 +2778,11 @@ var pseudos = { // custom pseudos 'enabled': function(node){ - return (node.disabled === false); + return !node.disabled; }, 'disabled': function(node){ - return (node.disabled === true); + return node.disabled; }, 'checked': function(node){ @@ -2696,7 +2796,7 @@ var pseudos = { 'root': function(node){ return (node === this.root); }, - + 'selected': function(node){ return node.selected; } @@ -2708,11 +2808,7 @@ for (var p in pseudos) local['pseudo:' + p] = pseudos[p]; // attributes methods -local.attributeGetters = { - - 'class': function(){ - return ('className' in this) ? this.className : this.getAttribute('class'); - }, +var attributeGetters = local.attributeGetters = { 'for': function(){ return ('htmlFor' in this) ? this.htmlFor : this.getAttribute('for'); @@ -2724,139 +2820,31 @@ local.attributeGetters = { 'style': function(){ return (this.style) ? this.style.cssText : this.getAttribute('style'); - } - -}; - -local.getAttribute = function(node, name){ - // FIXME: check if getAttribute() will get input elements on a form on this browser - // getAttribute is faster than getAttributeNode().nodeValue - var method = this.attributeGetters[name]; - if (method) return method.call(node); - var attributeNode = node.getAttributeNode(name); - return attributeNode ? attributeNode.nodeValue : null; -}; - -// overrides - -local.overrides = []; - -local.override = function(regexp, method){ - this.overrides.push({regexp: regexp, method: method}); -}; - -/**/ - -/**/ - -var reEmptyAttribute = /\[.*[*$^]=(?:["']{2})?\]/; - -local.override(/./, function(expression, found, first){ //querySelectorAll override - - if (!this.querySelectorAll || this.nodeType != 9 || !local.isHTMLDocument || local.brokenMixedCaseQSA || - (local.brokenCheckedQSA && expression.indexOf(':checked') > -1) || - (local.brokenEmptyAttributeQSA && reEmptyAttribute.test(expression)) || Slick.disableQSA) return false; - - var nodes, node; - try { - if (first) return this.querySelector(expression) || null; - else nodes = this.querySelectorAll(expression); - } catch(error){ - return false; - } - - var i, hasOthers = !!(found.length); - - if (local.starSelectsClosedQSA) for (i = 0; node = nodes[i++];){ - if (node.nodeName > '@' && (!hasOthers || !local.uniques[local.getUIDHTML(node)])) found.push(node); - } else for (i = 0; node = nodes[i++];){ - if (!hasOthers || !local.uniques[local.getUIDHTML(node)]) found.push(node); - } - - if (hasOthers) local.sort(found); - - return true; - -}); - -/**/ - -/**/ - -local.override(/^[\w-]+$|^\*$/, function(expression, found, first){ // tag override - var tag = expression; - if (tag == '*' && local.brokenStarGEBTN) return false; - - var nodes = this.getElementsByTagName(tag); - - if (first) return nodes[0] || null; - var i, node, hasOthers = !!(found.length); - - for (i = 0; node = nodes[i++];){ - if (!hasOthers || !local.uniques[local.getUID(node)]) found.push(node); - } - - if (hasOthers) local.sort(found); - - return true; -}); - -/**/ + }, -/**/ + 'tabindex': function(){ + var attributeNode = this.getAttributeNode('tabindex'); + return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null; + }, -local.override(/^\.[\w-]+$/, function(expression, found, first){ // class override - if (!local.isHTMLDocument || (!this.getElementsByClassName && this.querySelectorAll)) return false; + 'type': function(){ + return this.getAttribute('type'); + }, - var nodes, node, i, hasOthers = !!(found && found.length), className = expression.substring(1); - if (this.getElementsByClassName && !local.brokenGEBCN){ - nodes = this.getElementsByClassName(className); - if (first) return nodes[0] || null; - for (i = 0; node = nodes[i++];){ - if (!hasOthers || !local.uniques[local.getUIDHTML(node)]) found.push(node); - } - } else { - var matchClass = new RegExp('(^|\\s)'+ Slick.escapeRegExp(className) +'(\\s|$)'); - nodes = this.getElementsByTagName('*'); - for (i = 0; node = nodes[i++];){ - className = node.className; - if (!className || !matchClass.test(className)) continue; - if (first) return node; - if (!hasOthers || !local.uniques[local.getUIDHTML(node)]) found.push(node); - } + 'maxlength': function(){ + var attributeNode = this.getAttributeNode('maxLength'); + return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null; } - if (hasOthers) local.sort(found); - return (first) ? null : true; -}); - -/**/ - -/**/ - -local.override(/^#[\w-]+$/, function(expression, found, first){ // ID override - if (!local.isHTMLDocument || this.nodeType != 9) return false; - - var id = expression.substring(1), el = this.getElementById(id); - if (!el) return found; - if (local.idGetsName && el.getAttributeNode('id').nodeValue != id) return false; - if (first) return el || null; - var hasOthers = !!(found.length); - if (!hasOthers || !local.uniques[local.getUIDHTML(el)]) found.push(el); - if (hasOthers) local.sort(found); - return true; -}); - -/**/ -/**/ +}; -if (typeof document != 'undefined') local.setDocument(document); +attributeGetters.MAXLENGTH = attributeGetters.maxLength = attributeGetters.maxlength; // Slick var Slick = local.Slick = (this.Slick || {}); -Slick.version = '0.9dev'; +Slick.version = '1.1.7'; // Slick finder @@ -2878,15 +2866,20 @@ Slick.contains = function(container, node){ // Slick attribute getter Slick.getAttribute = function(node, name){ + local.setDocument(node); return local.getAttribute(node, name); }; +Slick.hasAttribute = function(node, name){ + local.setDocument(node); + return local.hasAttribute(node, name); +}; + // Slick matcher Slick.match = function(node, selector){ if (!(node && selector)) return false; if (!selector || selector === node) return true; - if (typeof selector != 'string') return false; local.setDocument(node); return local.matchNode(node, selector); }; @@ -2936,7 +2929,6 @@ if (!this.Slick) this.Slick = Slick; }).apply(/**/(typeof exports != 'undefined') ? exports : /**/this); - /* --- @@ -2946,30 +2938,32 @@ description: One of the most important items in MooTools. Contains the dollar fu license: MIT-style license. -requires: [Window, Document, Array, String, Function, Number, Slick.Parser, Slick.Finder] +requires: [Window, Document, Array, String, Function, Object, Number, Slick.Parser, Slick.Finder] -provides: [Element, Elements, $, $$, Iframe, Selectors] +provides: [Element, Elements, $, $$, IFrame, Selectors] ... */ -var Element = function(tag, props){ +var Element = this.Element = function(tag, props){ var konstructor = Element.Constructors[tag]; if (konstructor) return konstructor(props); if (typeof tag != 'string') return document.id(tag).set(props); if (!props) props = {}; - if (!tag.test(/^[\w-]+$/)){ + if (!(/^[\w-]+$/).test(tag)){ var parsed = Slick.parse(tag).expressions[0][0]; tag = (parsed.tag == '*') ? 'div' : parsed.tag; if (parsed.id && props.id == null) props.id = parsed.id; var attributes = parsed.attributes; - if (attributes) for (var i = 0, l = attributes.length; i < l; i++){ - var attr = attributes[i]; - if (attr.value != null && attr.operator == '=' && props[attr.key] == null) - props[attr.key] = attr.value; + if (attributes) for (var attr, i = 0, l = attributes.length; i < l; i++){ + attr = attributes[i]; + if (props[attr.key] != null) continue; + + if (attr.value != null && attr.operator == '=') props[attr.key] = attr.value; + else if (!attr.value && !attr.operator) props[attr.key] = true; } if (parsed.classList && props['class'] == null) props['class'] = parsed.classList.join(' '); @@ -2978,7 +2972,16 @@ var Element = function(tag, props){ return document.newElement(tag, props); }; -if (Browser.Element) Element.prototype = Browser.Element.prototype; + +if (Browser.Element){ + Element.prototype = Browser.Element.prototype; + // IE8 and IE9 require the wrapping. + Element.prototype._fireEvent = (function(fireEvent){ + return function(type, event){ + return fireEvent.call(this, type, event); + }; + })(Element.prototype.fireEvent); +} new Type('Element', Element).mirror(function(name){ if (Array.prototype[name]) return; @@ -2999,7 +3002,10 @@ new Type('Element', Element).mirror(function(name){ if (!Browser.Element){ Element.parent = Object; - Element.Prototype = {'$family': Function.from('element').hide()}; + Element.Prototype = { + '$constructor': Element, + '$family': Function.from('element').hide() + }; Element.mirror(function(name, method){ Element.Prototype[name] = method; @@ -3032,7 +3038,7 @@ var IFrame = new Type('IFrame', function(){ var onLoad = function(){ onload.call(iframe.contentWindow); }; - + if (window.frames[props.id]) onLoad(); else iframe.addListener('load', onLoad); return iframe; @@ -3072,6 +3078,15 @@ new Type('Elements', Elements).implement({ return (this.length = length); }.protect(), + unshift: function(){ + var items = []; + for (var i = 0, l = arguments.length; i < l; i++){ + var item = document.id(arguments[i]); + if (item) items.push(item); + } + return Array.prototype.unshift.apply(this, items); + }.protect(), + concat: function(){ var newElements = new Elements(this); for (var i = 0, l = arguments.length; i < l; i++){ @@ -3094,6 +3109,12 @@ new Type('Elements', Elements).implement({ }); +//<1.2compat> + +Elements.alias('extend', 'append'); + +// + (function(){ // FF, IE @@ -3102,41 +3123,66 @@ var splice = Array.prototype.splice, object = {'0': 0, '1': 1, length: 2}; splice.call(object, 1, 1); if (object[1] == 1) Elements.implement('splice', function(){ var length = this.length; - splice.apply(this, arguments); + var result = splice.apply(this, arguments); while (length >= this.length) delete this[length--]; - return this; + return result; }.protect()); -Elements.implement(Array.prototype); +Array.forEachMethod(function(method, name){ + Elements.implement(name, method); +}); Array.mirror(Elements); /**/ var createElementAcceptsHTML; try { - var x = document.createElement(''); - createElementAcceptsHTML = (x.name == 'x'); -} catch(e){} + createElementAcceptsHTML = (document.createElement('').name == 'x'); +} catch (e){} var escapeQuotes = function(html){ return ('' + html).replace(/&/g, '&').replace(/"/g, '"'); }; /**/ +/**/ +// #2479 - IE8 Cannot set HTML of style element +var canChangeStyleHTML = (function(){ + var div = document.createElement('style'), + flag = false; + try { + div.innerHTML = '#justTesing{margin: 0px;}'; + flag = !!div.innerHTML; + } catch(e){} + return flag; +})(); +/**/ + Document.implement({ newElement: function(tag, props){ - if (props && props.checked != null) props.defaultChecked = props.checked; - /**/// Fix for readonly name and type properties in IE < 8 - if (createElementAcceptsHTML && props){ - tag = '<' + tag; - if (props.name) tag += ' name="' + escapeQuotes(props.name) + '"'; - if (props.type) tag += ' type="' + escapeQuotes(props.type) + '"'; - tag += '>'; - delete props.name; - delete props.type; - } - /**/ + if (props){ + if (props.checked != null) props.defaultChecked = props.checked; + if ((props.type == 'checkbox' || props.type == 'radio') && props.value == null) props.value = 'on'; + /**/ // IE needs the type to be set before changing content of style element + if (!canChangeStyleHTML && tag == 'style'){ + var styleElement = document.createElement('style'); + styleElement.setAttribute('type', 'text/css'); + if (props.type) delete props.type; + return this.id(styleElement).set(props); + } + /**/ + /**/// Fix for readonly name and type properties in IE < 8 + if (createElementAcceptsHTML){ + tag = '<' + tag; + if (props.name) tag += ' name="' + escapeQuotes(props.name) + '"'; + if (props.type) tag += ' type="' + escapeQuotes(props.type) + '"'; + tag += '>'; + delete props.name; + delete props.type; + } + /**/ + } return this.id(this.createElement(tag)).set(props); } @@ -3144,6 +3190,11 @@ Document.implement({ })(); +(function(){ + +Slick.uidOf(window); +Slick.uidOf(document); + Document.implement({ newTextNode: function(text){ @@ -3168,8 +3219,13 @@ Document.implement({ }, element: function(el, nocash){ - $uid(el); - if (!nocash && !el.$family && !(/^object|embed$/i).test(el.tagName)){ + Slick.uidOf(el); + if (!nocash && !el.$family && !(/^(?:object|embed)$/i).test(el.tagName)){ + var fireEvent = el.fireEvent; + // wrapping needed in IE7, or else crash + el._fireEvent = function(type, event){ + return fireEvent(type, event); + }; Object.append(el, Element.Prototype); } return el; @@ -3187,7 +3243,7 @@ Document.implement({ }; return function(el, nocash, doc){ - if (el && el.$family && el.uid) return el; + if (el && el.$family && el.uniqueNumber) return el; var type = typeOf(el); return (types[type]) ? types[type](el, nocash, doc || document) : null; }; @@ -3224,8 +3280,19 @@ Window.implement({ }); +var contains = {contains: function(element){ + return Slick.contains(this, element); +}}; + +if (!document.contains) Document.implement(contains); +if (!document.createElement('div').contains) Element.implement(contains); + //<1.2compat> +Element.implement('hasChild', function(element){ + return this !== element && this.contains(element); +}); + (function(search, find, match){ this.Selectors = {}; @@ -3255,6 +3322,74 @@ Window.implement({ })(Slick.search, Slick.find, Slick.match); +// + +// tree walking + +var injectCombinator = function(expression, combinator){ + if (!expression) return combinator; + + expression = Object.clone(Slick.parse(expression)); + + var expressions = expression.expressions; + for (var i = expressions.length; i--;) + expressions[i][0].combinator = combinator; + + return expression; +}; + +Object.forEach({ + getNext: '~', + getPrevious: '!~', + getParent: '!' +}, function(combinator, method){ + Element.implement(method, function(expression){ + return this.getElement(injectCombinator(expression, combinator)); + }); +}); + +Object.forEach({ + getAllNext: '~', + getAllPrevious: '!~', + getSiblings: '~~', + getChildren: '>', + getParents: '!' +}, function(combinator, method){ + Element.implement(method, function(expression){ + return this.getElements(injectCombinator(expression, combinator)); + }); +}); + +Element.implement({ + + getFirst: function(expression){ + return document.id(Slick.search(this, injectCombinator(expression, '>'))[0]); + }, + + getLast: function(expression){ + return document.id(Slick.search(this, injectCombinator(expression, '>')).getLast()); + }, + + getWindow: function(){ + return this.ownerDocument.window; + }, + + getDocument: function(){ + return this.ownerDocument; + }, + + getElementById: function(id){ + return document.id(Slick.find(this, '#' + ('' + id).replace(/(\W)/g, '\\$1'))); + }, + + match: function(expression){ + return !expression || Slick.match(this, expression); + } + +}); + +//<1.2compat> + if (window.$$ == null) Window.implement('$$', function(selector){ var elements = new Elements; if (arguments.length == 1 && typeof selector == 'string') return Slick.search(this.document, selector, elements); @@ -3279,50 +3414,7 @@ if (window.$$ == null) Window.implement('$$', function(selector){ return new Elements(arguments); }); -(function(){ - -var collected = {}, storage = {}; -var props = {input: 'checked', option: 'selected', textarea: 'value'}; - -var get = function(uid){ - return (storage[uid] || (storage[uid] = {})); -}; - -var clean = function(item){ - if (item.removeEvents) item.removeEvents(); - if (item.clearAttributes) item.clearAttributes(); - var uid = item.uid; - if (uid != null){ - delete collected[uid]; - delete storage[uid]; - } - return item; -}; - -var camels = ['defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'maxLength', 'readOnly', - 'rowSpan', 'tabIndex', 'useMap' -]; -var bools = ['compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked', 'disabled', 'readOnly', 'multiple', 'selected', - 'noresize', 'defer' -]; - var attributes = { - 'html': 'innerHTML', - 'class': 'className', - 'for': 'htmlFor', - 'text': (function(){ - var temp = document.createElement('div'); - return (temp.innerText == null) ? 'textContent' : 'innerText'; - })() -}; -var readOnly = ['type']; -var expandos = ['value', 'defaultValue']; -var uriAttrs = /^(?:href|src|usemap)$/i; - -bools = bools.associate(bools); -camels = camels.associate(camels.map(String.toLowerCase)); -readOnly = readOnly.associate(readOnly); - -Object.append(attributes, expandos.associate(expandos)); +// Inserters var inserters = { @@ -3372,70 +3464,232 @@ Object.each(inserters, function(inserter, where){ // -var injectCombinator = function(expression, combinator){ - if (!expression) return combinator; +// getProperty / setProperty - expression = Slick.parse(expression); +var propertyGetters = {}, propertySetters = {}; - var expressions = expression.expressions; - for (var i = expressions.length; i--;) - expressions[i][0].combinator = combinator; +// properties - return expression; -}; +var properties = {}; +Array.forEach([ + 'type', 'value', 'defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', + 'frameBorder', 'rowSpan', 'tabIndex', 'useMap' +], function(property){ + properties[property.toLowerCase()] = property; +}); -Element.implement({ +properties.html = 'innerHTML'; +properties.text = (document.createElement('div').textContent == null) ? 'innerText': 'textContent'; - set: function(prop, value){ - var property = Element.Properties[prop]; - (property && property.set) ? property.set.call(this, value) : this.setProperty(prop, value); - }.overloadSetter(), +Object.forEach(properties, function(real, key){ + propertySetters[key] = function(node, value){ + node[real] = value; + }; + propertyGetters[key] = function(node){ + return node[real]; + }; +}); - get: function(prop){ - var property = Element.Properties[prop]; - return (property && property.get) ? property.get.apply(this) : this.getProperty(prop); - }.overloadGetter(), +/**/ +propertySetters.text = (function(setter){ + return function(node, value){ + if (node.get('tag') == 'style') node.set('html', value); + else node[properties.text] = value; + }; +})(propertySetters.text); - erase: function(prop){ - var property = Element.Properties[prop]; - (property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop); - return this; - }, +propertyGetters.text = (function(getter){ + return function(node){ + return (node.get('tag') == 'style') ? node.innerHTML : getter(node); + }; +})(propertyGetters.text); +/**/ - setProperty: function(attribute, value){ - attribute = camels[attribute] || attribute; - if (value == null) return this.removeProperty(attribute); - var key = attributes[attribute]; - (key) ? this[key] = value : - (bools[attribute]) ? this[attribute] = !!value : this.setAttribute(attribute, '' + value); - return this; +// Booleans + +var bools = [ + 'compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked', + 'disabled', 'readOnly', 'multiple', 'selected', 'noresize', + 'defer', 'defaultChecked', 'autofocus', 'controls', 'autoplay', + 'loop' +]; + +var booleans = {}; +Array.forEach(bools, function(bool){ + var lower = bool.toLowerCase(); + booleans[lower] = bool; + propertySetters[lower] = function(node, value){ + node[bool] = !!value; + }; + propertyGetters[lower] = function(node){ + return !!node[bool]; + }; +}); + +// Special cases + +Object.append(propertySetters, { + + 'class': function(node, value){ + ('className' in node) ? node.className = (value || '') : node.setAttribute('class', value); }, - setProperties: function(attributes){ - for (var attribute in attributes) this.setProperty(attribute, attributes[attribute]); - return this; + 'for': function(node, value){ + ('htmlFor' in node) ? node.htmlFor = value : node.setAttribute('for', value); }, - getProperty: function(attribute){ - attribute = camels[attribute] || attribute; - var key = attributes[attribute] || readOnly[attribute]; - return (key) ? this[key] : - (bools[attribute]) ? !!this[attribute] : - (uriAttrs.test(attribute) ? this.getAttribute(attribute, 2) : - (key = this.getAttributeNode(attribute)) ? key.nodeValue : null) || null; + 'style': function(node, value){ + (node.style) ? node.style.cssText = value : node.setAttribute('style', value); }, - getProperties: function(){ + 'value': function(node, value){ + node.value = (value != null) ? value : ''; + } + +}); + +propertyGetters['class'] = function(node){ + return ('className' in node) ? node.className || null : node.getAttribute('class'); +}; + +/* */ +var el = document.createElement('button'); +// IE sets type as readonly and throws +try { el.type = 'button'; } catch(e){} +if (el.type != 'button') propertySetters.type = function(node, value){ + node.setAttribute('type', value); +}; +el = null; +/* */ + +/**/ + +/**/ +// #2479 - IE8 Cannot set HTML of style element +var canChangeStyleHTML = (function(){ + var div = document.createElement('style'), + flag = false; + try { + div.innerHTML = '#justTesing{margin: 0px;}'; + flag = !!div.innerHTML; + } catch(e){} + return flag; +})(); +/**/ + +var input = document.createElement('input'), volatileInputValue, html5InputSupport; + +// #2178 +input.value = 't'; +input.type = 'submit'; +volatileInputValue = input.value != 't'; + +// #2443 - IE throws "Invalid Argument" when trying to use html5 input types +try { + input.type = 'email'; + html5InputSupport = input.type == 'email'; +} catch(e){} + +input = null; + +if (volatileInputValue || !html5InputSupport) propertySetters.type = function(node, type){ + try { + var value = node.value; + node.type = type; + node.value = value; + } catch (e){} +}; +/**/ + +/* getProperty, setProperty */ + +/* */ +var pollutesGetAttribute = (function(div){ + div.random = 'attribute'; + return (div.getAttribute('random') == 'attribute'); +})(document.createElement('div')); + +var hasCloneBug = (function(test){ + test.innerHTML = ''; + return test.cloneNode(true).firstChild.childNodes.length != 1; +})(document.createElement('div')); +/* */ + +var hasClassList = !!document.createElement('div').classList; + +var classes = function(className){ + var classNames = (className || '').clean().split(" "), uniques = {}; + return classNames.filter(function(className){ + if (className !== "" && !uniques[className]) return uniques[className] = className; + }); +}; + +var addToClassList = function(name){ + this.classList.add(name); +}; + +var removeFromClassList = function(name){ + this.classList.remove(name); +}; + +Element.implement({ + + setProperty: function(name, value){ + var setter = propertySetters[name.toLowerCase()]; + if (setter){ + setter(this, value); + } else { + /* */ + var attributeWhiteList; + if (pollutesGetAttribute) attributeWhiteList = this.retrieve('$attributeWhiteList', {}); + /* */ + + if (value == null){ + this.removeAttribute(name); + /* */ + if (pollutesGetAttribute) delete attributeWhiteList[name]; + /* */ + } else { + this.setAttribute(name, '' + value); + /* */ + if (pollutesGetAttribute) attributeWhiteList[name] = true; + /* */ + } + } + return this; + }, + + setProperties: function(attributes){ + for (var attribute in attributes) this.setProperty(attribute, attributes[attribute]); + return this; + }, + + getProperty: function(name){ + var getter = propertyGetters[name.toLowerCase()]; + if (getter) return getter(this); + /* */ + if (pollutesGetAttribute){ + var attr = this.getAttributeNode(name), attributeWhiteList = this.retrieve('$attributeWhiteList', {}); + if (!attr) return null; + if (attr.expando && !attributeWhiteList[name]){ + var outer = this.outerHTML; + // segment by the opening tag and find mention of attribute name + if (outer.substr(0, outer.search(/\/?['"]?>(?![^<]*<['"])/)).indexOf(name) < 0) return null; + attributeWhiteList[name] = true; + } + } + /* */ + var result = Slick.getAttribute(this, name); + return (!result && !Slick.hasAttribute(this, name)) ? null : result; + }, + + getProperties: function(){ var args = Array.from(arguments); return args.map(this.getProperty, this).associate(args); }, - removeProperty: function(attribute){ - attribute = camels[attribute] || attribute; - var key = attributes[attribute]; - (key) ? this[key] = '' : - (bools[attribute]) ? this[attribute] = false : this.removeAttribute(attribute); - return this; + removeProperty: function(name){ + return this.setProperty(name, null); }, removeProperties: function(){ @@ -3443,17 +3697,43 @@ Element.implement({ return this; }, - hasClass: function(className){ - return this.className.clean().contains(className, ' '); + set: function(prop, value){ + var property = Element.Properties[prop]; + (property && property.set) ? property.set.call(this, value) : this.setProperty(prop, value); + }.overloadSetter(), + + get: function(prop){ + var property = Element.Properties[prop]; + return (property && property.get) ? property.get.apply(this) : this.getProperty(prop); + }.overloadGetter(), + + erase: function(prop){ + var property = Element.Properties[prop]; + (property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop); + return this; + }, + + hasClass: hasClassList ? function(className){ + return this.classList.contains(className); + } : function(className){ + return classes(this.className).contains(className); }, - addClass: function(className){ - if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean(); + addClass: hasClassList ? function(className){ + classes(className).forEach(addToClassList, this); + return this; + } : function(className){ + this.className = classes(className + ' ' + this.className).join(' '); return this; }, - removeClass: function(className){ - this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1'); + removeClass: hasClassList ? function(className){ + classes(className).forEach(removeFromClassList, this); + return this; + } : function(className){ + var classNames = classes(this.className); + classes(className).forEach(classNames.erase, classNames); + this.className = classNames.join(' '); return this; }, @@ -3501,58 +3781,6 @@ Element.implement({ return this.replaces(el).grab(el, where); }, - getPrevious: function(expression){ - return document.id(Slick.find(this, injectCombinator(expression, '!~'))); - }, - - getAllPrevious: function(expression){ - return Slick.search(this, injectCombinator(expression, '!~'), new Elements); - }, - - getNext: function(expression){ - return document.id(Slick.find(this, injectCombinator(expression, '~'))); - }, - - getAllNext: function(expression){ - return Slick.search(this, injectCombinator(expression, '~'), new Elements); - }, - - getFirst: function(expression){ - return document.id(Slick.search(this, injectCombinator(expression, '>'))[0]); - }, - - getLast: function(expression){ - return document.id(Slick.search(this, injectCombinator(expression, '>')).getLast()); - }, - - getParent: function(expression){ - return document.id(Slick.find(this, injectCombinator(expression, '!'))); - }, - - getParents: function(expression){ - return Slick.search(this, injectCombinator(expression, '!'), new Elements); - }, - - getSiblings: function(expression){ - return Slick.search(this, injectCombinator(expression, '~~'), new Elements); - }, - - getChildren: function(expression){ - return Slick.search(this, injectCombinator(expression, '>'), new Elements); - }, - - getWindow: function(){ - return this.ownerDocument.window; - }, - - getDocument: function(){ - return this.ownerDocument; - }, - - getElementById: function(id){ - return document.id(Slick.find(this, '#' + ('' + id).replace(/(\W)/g, '\\$1'))); - }, - getSelected: function(){ this.selectedIndex; // Safari 3.2.1 return new Elements(Array.from(this.options).filter(function(option){ @@ -3576,42 +3804,61 @@ Element.implement({ }); }); return queryString.join('&'); - }, + } - clone: function(contents, keepid){ - contents = contents !== false; - var clone = this.cloneNode(contents); - var clean = function(node, element){ - if (!keepid) node.removeAttribute('id'); - if (Browser.ie){ - node.clearAttributes(); - node.mergeAttributes(element); - node.removeAttribute('uid'); - if (node.options){ - var no = node.options, eo = element.options; - for (var j = no.length; j--;) no[j].selected = eo[j].selected; - } - } - var prop = props[element.tagName.toLowerCase()]; - if (prop && element[prop]) node[prop] = element[prop]; - }; +}); - var i; - if (contents){ - var ce = clone.getElementsByTagName('*'), te = this.getElementsByTagName('*'); - for (i = ce.length; i--;) clean(ce[i], te[i]); - } - clean(clone, this); - if (Browser.ie){ - var ts = this.getElementsByTagName('object'), - cs = clone.getElementsByTagName('object'), - tl = ts.length, cl = cs.length; - for (i = 0; i < tl && i < cl; i++) - cs[i].outerHTML = ts[i].outerHTML; +// appendHTML + +var appendInserters = { + before: 'beforeBegin', + after: 'afterEnd', + bottom: 'beforeEnd', + top: 'afterBegin', + inside: 'beforeEnd' +}; + +Element.implement('appendHTML', ('insertAdjacentHTML' in document.createElement('div')) ? function(html, where){ + this.insertAdjacentHTML(appendInserters[where || 'bottom'], html); + return this; +} : function(html, where){ + var temp = new Element('div', {html: html}), + children = temp.childNodes, + fragment = temp.firstChild; + + if (!fragment) return this; + if (children.length > 1){ + fragment = document.createDocumentFragment(); + for (var i = 0, l = children.length; i < l; i++){ + fragment.appendChild(children[i]); } - return document.id(clone); - }, + } + + inserters[where || 'bottom'](fragment, this); + return this; +}); + +var collected = {}, storage = {}; + +var get = function(uid){ + return (storage[uid] || (storage[uid] = {})); +}; + +var clean = function(item){ + var uid = item.uniqueNumber; + if (item.removeEvents) item.removeEvents(); + if (item.clearAttributes) item.clearAttributes(); + if (uid != null){ + delete collected[uid]; + delete storage[uid]; + } + return item; +}; + +var formProps = {input: 'checked', option: 'selected', textarea: 'value'}; + +Element.implement({ destroy: function(){ var children = clean(this).getElementsByTagName('*'); @@ -3629,77 +3876,91 @@ Element.implement({ return (this.parentNode) ? this.parentNode.removeChild(this) : this; }, - match: function(expression){ - return !expression || Slick.match(this, expression); - } - -}); + clone: function(contents, keepid){ + contents = contents !== false; + var clone = this.cloneNode(contents), ce = [clone], te = [this], i; -var contains = {contains: function(element){ - return Slick.contains(this, element); -}}; + if (contents){ + ce.append(Array.from(clone.getElementsByTagName('*'))); + te.append(Array.from(this.getElementsByTagName('*'))); + } -if (!document.contains) Document.implement(contains); -if (!document.createElement('div').contains) Element.implement(contains); + for (i = ce.length; i--;){ + var node = ce[i], element = te[i]; + if (!keepid) node.removeAttribute('id'); + /**/ + if (node.clearAttributes){ + node.clearAttributes(); + node.mergeAttributes(element); + node.removeAttribute('uniqueNumber'); + if (node.options){ + var no = node.options, eo = element.options; + for (var j = no.length; j--;) no[j].selected = eo[j].selected; + } + } + /**/ + var prop = formProps[element.tagName.toLowerCase()]; + if (prop && element[prop]) node[prop] = element[prop]; + } -//<1.2compat> + /**/ + if (hasCloneBug){ + var co = clone.getElementsByTagName('object'), to = this.getElementsByTagName('object'); + for (i = co.length; i--;) co[i].outerHTML = to[i].outerHTML; + } + /**/ + return document.id(clone); + } -Element.implement('hasChild', function(element){ - return this !== element && this.contains(element); }); -// - [Element, Window, Document].invoke('implement', { addListener: function(type, fn){ - if (type == 'unload'){ - var old = fn, self = this; - fn = function(){ - self.removeListener('unload', fn); - old(); - }; - } else { - collected[this.uid] = this; + if (window.attachEvent && !window.addEventListener){ + collected[Slick.uidOf(this)] = this; } - if (this.addEventListener) this.addEventListener(type, fn, false); + if (this.addEventListener) this.addEventListener(type, fn, !!arguments[2]); else this.attachEvent('on' + type, fn); return this; }, removeListener: function(type, fn){ - if (this.removeEventListener) this.removeEventListener(type, fn, false); + if (this.removeEventListener) this.removeEventListener(type, fn, !!arguments[2]); else this.detachEvent('on' + type, fn); return this; }, retrieve: function(property, dflt){ - var storage = get(this.uid), prop = storage[property]; + var storage = get(Slick.uidOf(this)), prop = storage[property]; if (dflt != null && prop == null) prop = storage[property] = dflt; return prop != null ? prop : null; }, store: function(property, value){ - var storage = get(this.uid); + var storage = get(Slick.uidOf(this)); storage[property] = value; return this; }, eliminate: function(property){ - var storage = get(this.uid); + var storage = get(Slick.uidOf(this)); delete storage[property]; return this; } }); -// IE purge -if (window.attachEvent && !window.addEventListener) window.addListener('unload', function(){ - Object.each(collected, clean); - if (window.CollectGarbage) CollectGarbage(); -}); - -})(); +/**/ +if (window.attachEvent && !window.addEventListener){ + var gc = function(){ + Object.each(collected, clean); + if (window.CollectGarbage) CollectGarbage(); + window.removeListener('unload', gc); + } + window.addListener('unload', gc); +} +/**/ Element.Properties = {}; @@ -3733,244 +3994,276 @@ Element.Properties.tag = { }; -(function(maxLength){ - if (maxLength != null) Element.Properties.maxlength = Element.Properties.maxLength = { - get: function(){ - var maxlength = this.getAttribute('maxLength'); - return maxlength == maxLength ? null : maxlength; - } - }; -})(document.createElement('input').getAttribute('maxLength')); +Element.Properties.html = { -Element.Properties.html = (function(){ - - var tableTest = Function.attempt(function(){ - var table = document.createElement('table'); - table.innerHTML = ''; - }); + set: function(html){ + if (html == null) html = ''; + else if (typeOf(html) == 'array') html = html.join(''); - var wrapper = document.createElement('div'); + /**/ + if (this.styleSheet && !canChangeStyleHTML) this.styleSheet.cssText = html; + else /**/this.innerHTML = html; + }, + erase: function(){ + this.set('html', ''); + } - var translations = { - table: [1, '', '
'], - select: [1, ''], - tbody: [2, '', '
'], - tr: [3, '', '
'] - }; - translations.thead = translations.tfoot = translations.tbody; - - var html = { - set: function(){ - var html = Array.flatten(arguments).join(''); - var wrap = (!tableTest && translations[this.get('tag')]); - if (wrap){ - var first = wrapper; - first.innerHTML = wrap[1] + html + wrap[2]; - for (var i = wrap[0]; i--;) first = first.firstChild; - this.empty().adopt(first.childNodes); - } else { - this.innerHTML = html; - } - } - }; +}; - html.erase = html.set; +var supportsHTML5Elements = true, supportsTableInnerHTML = true, supportsTRInnerHTML = true; + +/**/ +// technique by jdbarlett - http://jdbartlett.com/innershiv/ +var div = document.createElement('div'); +div.innerHTML = ''; +supportsHTML5Elements = (div.childNodes.length == 1); +if (!supportsHTML5Elements){ + var tags = 'abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video'.split(' '), + fragment = document.createDocumentFragment(), l = tags.length; + while (l--) fragment.createElement(tags[l]); +} +div = null; +/**/ - return html; -})(); +/**/ +supportsTableInnerHTML = Function.attempt(function(){ + var table = document.createElement('table'); + table.innerHTML = ''; + return true; +}); +/**/ +var tr = document.createElement('tr'), html = ''; +tr.innerHTML = html; +supportsTRInnerHTML = (tr.innerHTML == html); +tr = null; +/**/ -/* ---- +if (!supportsTableInnerHTML || !supportsTRInnerHTML || !supportsHTML5Elements){ -name: Element.Style + Element.Properties.html.set = (function(set){ -description: Contains methods for interacting with the styles of Elements in a fashionable way. + var translations = { + table: [1, '', '
'], + select: [1, ''], + tbody: [2, '', '
'], + tr: [3, '', '
'] + }; -license: MIT-style license. + translations.thead = translations.tfoot = translations.tbody; -requires: Element + return function(html){ -provides: Element.Style + /**/ + if (this.styleSheet) return set.call(this, html); + /**/ + var wrap = translations[this.get('tag')]; + if (!wrap && !supportsHTML5Elements) wrap = [0, '', '']; + if (!wrap) return set.call(this, html); -... -*/ + var level = wrap[0], wrapper = document.createElement('div'), target = wrapper; + if (!supportsHTML5Elements) fragment.appendChild(wrapper); + wrapper.innerHTML = [wrap[1], html, wrap[2]].flatten().join(''); + while (level--) target = target.firstChild; + this.empty().adopt(target.childNodes); + if (!supportsHTML5Elements) fragment.removeChild(wrapper); + wrapper = null; + }; -(function(){ + })(Element.Properties.html.set); +} +/*
*/ + +/**/ +var testForm = document.createElement('form'); +testForm.innerHTML = ''; + +if (testForm.firstChild.value != 's') Element.Properties.value = { + + set: function(value){ + var tag = this.get('tag'); + if (tag != 'select') return this.setProperty('value', value); + var options = this.getElements('option'); + value = String(value); + for (var i = 0; i < options.length; i++){ + var option = options[i], + attr = option.getAttributeNode('value'), + optionValue = (attr && attr.specified) ? option.value : option.get('text'); + if (optionValue === value) return option.selected = true; + } + }, -var html = document.html; + get: function(){ + var option = this, tag = option.get('tag'); -Element.Properties.styles = {set: function(styles){ - this.setStyles(styles); -}}; + if (tag != 'select' && tag != 'option') return this.getProperty('value'); -var hasOpacity = (html.style.opacity != null); -var reAlpha = /alpha\(opacity=([\d.]+)\)/i; + if (tag == 'select' && !(option = option.getSelected()[0])) return ''; -var setOpacity = function(element, opacity){ - if (!element.currentStyle || !element.currentStyle.hasLayout) element.style.zoom = 1; - if (hasOpacity){ - element.style.opacity = opacity; - } else { - opacity = (opacity == 1) ? '' : 'alpha(opacity=' + opacity * 100 + ')'; - var filter = element.style.filter || element.getComputedStyle('filter') || ''; - element.style.filter = filter.test(reAlpha) ? filter.replace(reAlpha, opacity) : filter + opacity; + var attr = option.getAttributeNode('value'); + return (attr && attr.specified) ? option.value : option.get('text'); } -}; - -Element.Properties.opacity = { - set: function(opacity){ - var visibility = this.style.visibility; - if (opacity == 0 && visibility != 'hidden') this.style.visibility = 'hidden'; - else if (opacity != 0 && visibility != 'visible') this.style.visibility = 'visible'; +}; +testForm = null; +/**/ - setOpacity(this, opacity); +/**/ +if (document.createElement('div').getAttributeNode('id')) Element.Properties.id = { + set: function(id){ + this.id = this.getAttributeNode('id').value = id; }, - - get: (hasOpacity) ? function(){ - var opacity = this.style.opacity || this.getComputedStyle('opacity'); - return (opacity == '') ? 1 : opacity; - } : function(){ - var opacity, filter = (this.style.filter || this.getComputedStyle('filter')); - if (filter) opacity = filter.match(reAlpha); - return (opacity == null || filter == null) ? 1 : (opacity[1] / 100); + get: function(){ + return this.id || null; + }, + erase: function(){ + this.id = this.getAttributeNode('id').value = ''; } - }; +/**/ -var floatName = (html.style.cssFloat == null) ? 'styleFloat' : 'cssFloat'; +})(); -Element.implement({ +/* +--- - getComputedStyle: function(property){ - if (this.currentStyle) return this.currentStyle[property.camelCase()]; - var defaultView = Element.getDocument(this).defaultView, - computed = defaultView ? defaultView.getComputedStyle(this, null) : null; - return (computed) ? computed.getPropertyValue((property == floatName) ? 'float' : property.hyphenate()) : null; - }, +name: Event - setOpacity: function(value){ - setOpacity(this, value); - return this; - }, +description: Contains the Event Type, to make the event object cross-browser. - getOpacity: function(){ - return this.get('opacity'); - }, +license: MIT-style license. - setStyle: function(property, value){ - switch (property){ - case 'opacity': return this.set('opacity', parseFloat(value)); - case 'float': property = floatName; - } - property = property.camelCase(); - if (typeOf(value) != 'string'){ - var map = (Element.Styles[property] || '@').split(' '); - value = Array.from(value).map(function(val, i){ - if (!map[i]) return ''; - return (typeOf(val) == 'number') ? map[i].replace('@', Math.round(val)) : val; - }).join(' '); - } else if (value == String(Number(value))){ - value = Math.round(value); - } - this.style[property] = value; - return this; - }, +requires: [Window, Document, Array, Function, String, Object] - getStyle: function(property){ - switch (property){ - case 'opacity': return this.get('opacity'); - case 'float': property = floatName; - } - property = property.camelCase(); - var result = this.style[property]; - if (!result || property == 'zIndex'){ - result = []; - for (var style in Element.ShortStyles){ - if (property != style) continue; - for (var s in Element.ShortStyles[style]) result.push(this.getStyle(s)); - return result.join(' '); - } - result = this.getComputedStyle(property); +provides: Event + +... +*/ + +(function(){ + +var _keys = {}; +var normalizeWheelSpeed = function(event){ + var normalized; + if (event.wheelDelta){ + normalized = event.wheelDelta % 120 == 0 ? event.wheelDelta / 120 : event.wheelDelta / 12; + } else { + var rawAmount = event.deltaY || event.detail || 0; + normalized = -(rawAmount % 3 == 0 ? rawAmount / 3 : rawAmount * 10); + } + return normalized; +} + +var DOMEvent = this.DOMEvent = new Type('DOMEvent', function(event, win){ + if (!win) win = window; + event = event || win.event; + if (event.$extended) return event; + this.event = event; + this.$extended = true; + this.shift = event.shiftKey; + this.control = event.ctrlKey; + this.alt = event.altKey; + this.meta = event.metaKey; + var type = this.type = event.type; + var target = event.target || event.srcElement; + while (target && target.nodeType == 3) target = target.parentNode; + this.target = document.id(target); + + if (type.indexOf('key') == 0){ + var code = this.code = (event.which || event.keyCode); + this.key = _keys[code]/*<1.3compat>*/ || Object.keyOf(Event.Keys, code)/**/; + if (type == 'keydown' || type == 'keyup'){ + if (code > 111 && code < 124) this.key = 'f' + (code - 111); + else if (code > 95 && code < 106) this.key = code - 96; } - if (result){ - result = String(result); - var color = result.match(/rgba?\([\d\s,]+\)/); - if (color) result = result.replace(color[0], color[0].rgbToHex()); + if (this.key == null) this.key = String.fromCharCode(code).toLowerCase(); + } else if (type == 'click' || type == 'dblclick' || type == 'contextmenu' || type == 'wheel' || type == 'DOMMouseScroll' || type.indexOf('mouse') == 0){ + var doc = win.document; + doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body; + this.page = { + x: (event.pageX != null) ? event.pageX : event.clientX + doc.scrollLeft, + y: (event.pageY != null) ? event.pageY : event.clientY + doc.scrollTop + }; + this.client = { + x: (event.pageX != null) ? event.pageX - win.pageXOffset : event.clientX, + y: (event.pageY != null) ? event.pageY - win.pageYOffset : event.clientY + }; + if (type == 'DOMMouseScroll' || type == 'wheel' || type == 'mousewheel') this.wheel = normalizeWheelSpeed(event); + this.rightClick = (event.which == 3 || event.button == 2); + if (type == 'mouseover' || type == 'mouseout'){ + var related = event.relatedTarget || event[(type == 'mouseover' ? 'from' : 'to') + 'Element']; + while (related && related.nodeType == 3) related = related.parentNode; + this.relatedTarget = document.id(related); } - if (Browser.opera || (Browser.ie && isNaN(parseFloat(result)))){ - if (property.test(/^(height|width)$/)){ - var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0; - values.each(function(value){ - size += this.getStyle('border-' + value + '-width').toInt() + this.getStyle('padding-' + value).toInt(); - }, this); - return this['offset' + property.capitalize()] - size + 'px'; - } - if (Browser.opera && String(result).indexOf('px') != -1) return result; - if (property.test(/(border(.+)Width|margin|padding)/)) return '0px'; + } else if (type.indexOf('touch') == 0 || type.indexOf('gesture') == 0){ + this.rotation = event.rotation; + this.scale = event.scale; + this.targetTouches = event.targetTouches; + this.changedTouches = event.changedTouches; + var touches = this.touches = event.touches; + if (touches && touches[0]){ + var touch = touches[0]; + this.page = {x: touch.pageX, y: touch.pageY}; + this.client = {x: touch.clientX, y: touch.clientY}; } - return result; + } + + if (!this.client) this.client = {}; + if (!this.page) this.page = {}; +}); + +DOMEvent.implement({ + + stop: function(){ + return this.preventDefault().stopPropagation(); }, - setStyles: function(styles){ - for (var style in styles) this.setStyle(style, styles[style]); + stopPropagation: function(){ + if (this.event.stopPropagation) this.event.stopPropagation(); + else this.event.cancelBubble = true; return this; }, - getStyles: function(){ - var result = {}; - Array.flatten(arguments).each(function(key){ - result[key] = this.getStyle(key); - }, this); - return result; + preventDefault: function(){ + if (this.event.preventDefault) this.event.preventDefault(); + else this.event.returnValue = false; + return this; } }); -Element.Styles = { - left: '@px', top: '@px', bottom: '@px', right: '@px', - width: '@px', height: '@px', maxWidth: '@px', maxHeight: '@px', minWidth: '@px', minHeight: '@px', - backgroundColor: 'rgb(@, @, @)', backgroundPosition: '@px @px', color: 'rgb(@, @, @)', - fontSize: '@px', letterSpacing: '@px', lineHeight: '@px', clip: 'rect(@px @px @px @px)', - margin: '@px @px @px @px', padding: '@px @px @px @px', border: '@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)', - borderWidth: '@px @px @px @px', borderStyle: '@ @ @ @', borderColor: 'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)', - zIndex: '@', 'zoom': '@', fontWeight: '@', textIndent: '@px', opacity: '@' +DOMEvent.defineKey = function(code, key){ + _keys[code] = key; + return this; }; -//<1.2compat> +DOMEvent.defineKeys = DOMEvent.defineKey.overloadSetter(true); -Element.Styles = new Hash(Element.Styles); +DOMEvent.defineKeys({ + '38': 'up', '40': 'down', '37': 'left', '39': 'right', + '27': 'esc', '32': 'space', '8': 'backspace', '9': 'tab', + '46': 'delete', '13': 'enter' +}); -// +})(); -Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {}}; +/*<1.3compat>*/ +var Event = DOMEvent; +Event.Keys = {}; +/**/ -['Top', 'Right', 'Bottom', 'Left'].each(function(direction){ - var Short = Element.ShortStyles; - var All = Element.Styles; - ['margin', 'padding'].each(function(style){ - var sd = style + direction; - Short[style][sd] = All[sd] = '@px'; - }); - var bd = 'border' + direction; - Short.border[bd] = All[bd] = '@px @ rgb(@, @, @)'; - var bdw = bd + 'Width', bds = bd + 'Style', bdc = bd + 'Color'; - Short[bd] = {}; - Short.borderWidth[bdw] = Short[bd][bdw] = All[bdw] = '@px'; - Short.borderStyle[bds] = Short[bd][bds] = All[bds] = '@'; - Short.borderColor[bdc] = Short[bd][bdc] = All[bdc] = 'rgb(@, @, @)'; -}); +/*<1.2compat>*/ -})(); +Event.Keys = new Hash(Event.Keys); +/**/ /* --- name: Element.Event -description: Contains Element methods for dealing with events. This file also includes mouseenter and mouseleave custom Element Events. +description: Contains Element methods for dealing with events. This file also includes mouseenter and mouseleave custom Element Events, if necessary. license: MIT-style license. @@ -3999,14 +4292,14 @@ Element.Properties.events = {set: function(events){ condition = fn, self = this; if (custom){ - if (custom.onAdd) custom.onAdd.call(this, fn); + if (custom.onAdd) custom.onAdd.call(this, fn, type); if (custom.condition){ condition = function(event){ - if (custom.condition.call(this, event)) return fn.call(this, event); + if (custom.condition.call(this, event, type)) return fn.call(this, event); return true; }; } - realType = custom.base || realType; + if (custom.base) realType = Function.from(custom.base).call(this, type); } var defn = function(){ return fn.call(self); @@ -4015,11 +4308,11 @@ Element.Properties.events = {set: function(events){ if (nativeEvent){ if (nativeEvent == 2){ defn = function(event){ - event = new Event(event, self.getWindow()); + event = new DOMEvent(event, self.getWindow()); if (condition.call(self, event) === false) event.stop(); }; } - this.addListener(realType, defn); + this.addListener(realType, defn, arguments[2]); } events[type].values.push(defn); return this; @@ -4036,10 +4329,10 @@ Element.Properties.events = {set: function(events){ delete list.values[index]; var custom = Element.Events[type]; if (custom){ - if (custom.onRemove) custom.onRemove.call(this, fn); - type = custom.base || type; + if (custom.onRemove) custom.onRemove.call(this, fn, type); + if (custom.base) type = Function.from(custom.base).call(this, type); } - return (Element.NativeEvents[type]) ? this.removeListener(type, value) : this; + return (Element.NativeEvents[type]) ? this.removeListener(type, value, arguments[2]) : this; }, addEvents: function(events){ @@ -4095,58 +4388,539 @@ Element.Properties.events = {set: function(events){ }); -// IE9 -try { - if (typeof HTMLElement != 'undefined') - HTMLElement.prototype.fireEvent = Element.prototype.fireEvent; -} catch(e){} - -Element.NativeEvents = { - click: 2, dblclick: 2, mouseup: 2, mousedown: 2, contextmenu: 2, //mouse buttons - mousewheel: 2, DOMMouseScroll: 2, //mouse wheel - mouseover: 2, mouseout: 2, mousemove: 2, selectstart: 2, selectend: 2, //mouse movement - keydown: 2, keypress: 2, keyup: 2, //keyboard - orientationchange: 2, // mobile - touchstart: 2, touchmove: 2, touchend: 2, touchcancel: 2, // touch - gesturestart: 2, gesturechange: 2, gestureend: 2, // gesture - focus: 2, blur: 2, change: 2, reset: 2, select: 2, submit: 2, //form elements - load: 2, unload: 1, beforeunload: 2, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window - error: 1, abort: 1, scroll: 1 //misc +Element.NativeEvents = { + click: 2, dblclick: 2, mouseup: 2, mousedown: 2, contextmenu: 2, //mouse buttons + wheel: 2, mousewheel: 2, DOMMouseScroll: 2, //mouse wheel + mouseover: 2, mouseout: 2, mousemove: 2, selectstart: 2, selectend: 2, //mouse movement + keydown: 2, keypress: 2, keyup: 2, //keyboard + orientationchange: 2, // mobile + touchstart: 2, touchmove: 2, touchend: 2, touchcancel: 2, // touch + gesturestart: 2, gesturechange: 2, gestureend: 2, // gesture + focus: 2, blur: 2, change: 2, reset: 2, select: 2, submit: 2, paste: 2, input: 2, //form elements + load: 2, unload: 1, beforeunload: 2, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window + hashchange: 1, popstate: 2, // history + error: 1, abort: 1, scroll: 1, message: 2 //misc +}; + +Element.Events = { + mousewheel: { + base: 'onwheel' in document ? 'wheel' : 'onmousewheel' in document ? 'mousewheel' : 'DOMMouseScroll' + } +}; + +var check = function(event){ + var related = event.relatedTarget; + if (related == null) return true; + if (!related) return false; + return (related != this && related.prefix != 'xul' && typeOf(this) != 'document' && !this.contains(related)); +}; + +if ('onmouseenter' in document.documentElement){ + Element.NativeEvents.mouseenter = Element.NativeEvents.mouseleave = 2; + Element.MouseenterCheck = check; +} else { + Element.Events.mouseenter = { + base: 'mouseover', + condition: check + }; + + Element.Events.mouseleave = { + base: 'mouseout', + condition: check + }; +} + +/**/ +if (!window.addEventListener){ + Element.NativeEvents.propertychange = 2; + Element.Events.change = { + base: function(){ + var type = this.type; + return (this.get('tag') == 'input' && (type == 'radio' || type == 'checkbox')) ? 'propertychange' : 'change'; + }, + condition: function(event){ + return event.type != 'propertychange' || event.event.propertyName == 'checked'; + } + }; +} +/**/ + +//<1.2compat> + +Element.Events = new Hash(Element.Events); + +// + +})(); + +/* +--- + +name: Element.Delegation + +description: Extends the Element native object to include the delegate method for more efficient event management. + +license: MIT-style license. + +requires: [Element.Event] + +provides: [Element.Delegation] + +... +*/ + +(function(){ + +var eventListenerSupport = !!window.addEventListener; + +Element.NativeEvents.focusin = Element.NativeEvents.focusout = 2; + +var bubbleUp = function(self, match, fn, event, target){ + while (target && target != self){ + if (match(target, event)) return fn.call(target, event, target); + target = document.id(target.parentNode); + } +}; + +var map = { + mouseenter: { + base: 'mouseover', + condition: Element.MouseenterCheck + }, + mouseleave: { + base: 'mouseout', + condition: Element.MouseenterCheck + }, + focus: { + base: 'focus' + (eventListenerSupport ? '' : 'in'), + capture: true + }, + blur: { + base: eventListenerSupport ? 'blur' : 'focusout', + capture: true + } +}; + +/**/ +var _key = '$delegation:'; +var formObserver = function(type){ + + return { + + base: 'focusin', + + remove: function(self, uid){ + var list = self.retrieve(_key + type + 'listeners', {})[uid]; + if (list && list.forms) for (var i = list.forms.length; i--;){ + // the form may have been destroyed, so it won't have the + // removeEvent method anymore. In that case the event was + // removed as well. + if (list.forms[i].removeEvent) list.forms[i].removeEvent(type, list.fns[i]); + } + }, + + listen: function(self, match, fn, event, target, uid){ + var form = (target.get('tag') == 'form') ? target : event.target.getParent('form'); + if (!form) return; + + var listeners = self.retrieve(_key + type + 'listeners', {}), + listener = listeners[uid] || {forms: [], fns: []}, + forms = listener.forms, fns = listener.fns; + + if (forms.indexOf(form) != -1) return; + forms.push(form); + + var _fn = function(event){ + bubbleUp(self, match, fn, event, target); + }; + form.addEvent(type, _fn); + fns.push(_fn); + + listeners[uid] = listener; + self.store(_key + type + 'listeners', listeners); + } + }; +}; + +var inputObserver = function(type){ + return { + base: 'focusin', + listen: function(self, match, fn, event, target){ + var events = {blur: function(){ + this.removeEvents(events); + }}; + events[type] = function(event){ + bubbleUp(self, match, fn, event, target); + }; + event.target.addEvents(events); + } + }; +}; + +if (!eventListenerSupport) Object.append(map, { + submit: formObserver('submit'), + reset: formObserver('reset'), + change: inputObserver('change'), + select: inputObserver('select') +}); +/**/ + +var proto = Element.prototype, + addEvent = proto.addEvent, + removeEvent = proto.removeEvent; + +var relay = function(old, method){ + return function(type, fn, useCapture){ + if (type.indexOf(':relay') == -1) return old.call(this, type, fn, useCapture); + var parsed = Slick.parse(type).expressions[0][0]; + if (parsed.pseudos[0].key != 'relay') return old.call(this, type, fn, useCapture); + var newType = parsed.tag; + parsed.pseudos.slice(1).each(function(pseudo){ + newType += ':' + pseudo.key + (pseudo.value ? '(' + pseudo.value + ')' : ''); + }); + old.call(this, type, fn); + return method.call(this, newType, parsed.pseudos[0].value, fn); + }; +}; + +var delegation = { + + addEvent: function(type, match, fn){ + var storage = this.retrieve('$delegates', {}), stored = storage[type]; + if (stored) for (var _uid in stored){ + if (stored[_uid].fn == fn && stored[_uid].match == match) return this; + } + + var _type = type, _match = match, _fn = fn, _map = map[type] || {}; + type = _map.base || _type; + + match = function(target){ + return Slick.match(target, _match); + }; + + var elementEvent = Element.Events[_type]; + if (_map.condition || elementEvent && elementEvent.condition){ + var __match = match, condition = _map.condition || elementEvent.condition; + match = function(target, event){ + return __match(target, event) && condition.call(target, event, type); + }; + } + + var self = this, uid = String.uniqueID(); + var delegator = _map.listen ? function(event, target){ + if (!target && event && event.target) target = event.target; + if (target) _map.listen(self, match, fn, event, target, uid); + } : function(event, target){ + if (!target && event && event.target) target = event.target; + if (target) bubbleUp(self, match, fn, event, target); + }; + + if (!stored) stored = {}; + stored[uid] = { + match: _match, + fn: _fn, + delegator: delegator + }; + storage[_type] = stored; + return addEvent.call(this, type, delegator, _map.capture); + }, + + removeEvent: function(type, match, fn, _uid){ + var storage = this.retrieve('$delegates', {}), stored = storage[type]; + if (!stored) return this; + + if (_uid){ + var _type = type, delegator = stored[_uid].delegator, _map = map[type] || {}; + type = _map.base || _type; + if (_map.remove) _map.remove(this, _uid); + delete stored[_uid]; + storage[_type] = stored; + return removeEvent.call(this, type, delegator, _map.capture); + } + + var __uid, s; + if (fn) for (__uid in stored){ + s = stored[__uid]; + if (s.match == match && s.fn == fn) return delegation.removeEvent.call(this, type, match, fn, __uid); + } else for (__uid in stored){ + s = stored[__uid]; + if (s.match == match) delegation.removeEvent.call(this, type, match, s.fn, __uid); + } + return this; + } + +}; + +[Element, Window, Document].invoke('implement', { + addEvent: relay(addEvent, delegation.addEvent), + removeEvent: relay(removeEvent, delegation.removeEvent) +}); + +})(); + +/* +--- + +name: Element.Style + +description: Contains methods for interacting with the styles of Elements in a fashionable way. + +license: MIT-style license. + +requires: Element + +provides: Element.Style + +... +*/ + +(function(){ + +var html = document.html, el; + +// +// Check for oldIE, which does not remove styles when they're set to null +el = document.createElement('div'); +el.style.color = 'red'; +el.style.color = null; +var doesNotRemoveStyles = el.style.color == 'red'; + +// check for oldIE, which returns border* shorthand styles in the wrong order (color-width-style instead of width-style-color) +var border = '1px solid #123abc'; +el.style.border = border; +var returnsBordersInWrongOrder = el.style.border != border; +el = null; +// + +var hasGetComputedStyle = !!window.getComputedStyle, + supportBorderRadius = document.createElement('div').style.borderRadius != null; + +Element.Properties.styles = {set: function(styles){ + this.setStyles(styles); +}}; + +var hasOpacity = (html.style.opacity != null), + hasFilter = (html.style.filter != null), + reAlpha = /alpha\(opacity=([\d.]+)\)/i; + +var setVisibility = function(element, opacity){ + element.store('$opacity', opacity); + element.style.visibility = opacity > 0 || opacity == null ? 'visible' : 'hidden'; +}; + +// +var setFilter = function(element, regexp, value){ + var style = element.style, + filter = style.filter || element.getComputedStyle('filter') || ''; + style.filter = (regexp.test(filter) ? filter.replace(regexp, value) : filter + ' ' + value).trim(); + if (!style.filter) style.removeAttribute('filter'); +}; +// + +var setOpacity = (hasOpacity ? function(element, opacity){ + element.style.opacity = opacity; +} : (hasFilter ? function(element, opacity){ + if (!element.currentStyle || !element.currentStyle.hasLayout) element.style.zoom = 1; + if (opacity == null || opacity == 1){ + setFilter(element, reAlpha, ''); + if (opacity == 1 && getOpacity(element) != 1) setFilter(element, reAlpha, 'alpha(opacity=100)'); + } else { + setFilter(element, reAlpha, 'alpha(opacity=' + (opacity * 100).limit(0, 100).round() + ')'); + } +} : setVisibility)); + +var getOpacity = (hasOpacity ? function(element){ + var opacity = element.style.opacity || element.getComputedStyle('opacity'); + return (opacity == '') ? 1 : opacity.toFloat(); +} : (hasFilter ? function(element){ + var filter = (element.style.filter || element.getComputedStyle('filter')), + opacity; + if (filter) opacity = filter.match(reAlpha); + return (opacity == null || filter == null) ? 1 : (opacity[1] / 100); +} : function(element){ + var opacity = element.retrieve('$opacity'); + if (opacity == null) opacity = (element.style.visibility == 'hidden' ? 0 : 1); + return opacity; +})); + +var floatName = (html.style.cssFloat == null) ? 'styleFloat' : 'cssFloat', + namedPositions = {left: '0%', top: '0%', center: '50%', right: '100%', bottom: '100%'}, + hasBackgroundPositionXY = (html.style.backgroundPositionX != null); + +// +var removeStyle = function(style, property){ + if (property == 'backgroundPosition'){ + style.removeAttribute(property + 'X'); + property += 'Y'; + } + style.removeAttribute(property); +}; +// + +Element.implement({ + + getComputedStyle: function(property){ + if (!hasGetComputedStyle && this.currentStyle) return this.currentStyle[property.camelCase()]; + var defaultView = Element.getDocument(this).defaultView, + computed = defaultView ? defaultView.getComputedStyle(this, null) : null; + return (computed) ? computed.getPropertyValue((property == floatName) ? 'float' : property.hyphenate()) : ''; + }, + + setStyle: function(property, value){ + if (property == 'opacity'){ + if (value != null) value = parseFloat(value); + setOpacity(this, value); + return this; + } + property = (property == 'float' ? floatName : property).camelCase(); + if (typeOf(value) != 'string'){ + var map = (Element.Styles[property] || '@').split(' '); + value = Array.from(value).map(function(val, i){ + if (!map[i]) return ''; + return (typeOf(val) == 'number') ? map[i].replace('@', Math.round(val)) : val; + }).join(' '); + } else if (value == String(Number(value))){ + value = Math.round(value); + } + this.style[property] = value; + // + if ((value == '' || value == null) && doesNotRemoveStyles && this.style.removeAttribute){ + removeStyle(this.style, property); + } + // + return this; + }, + + getStyle: function(property){ + if (property == 'opacity') return getOpacity(this); + property = (property == 'float' ? floatName : property).camelCase(); + if (supportBorderRadius && property.indexOf('borderRadius') != -1){ + return ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius'].map(function(corner){ + return this.style[corner] || '0px'; + }, this).join(' '); + } + var result = this.style[property]; + if (!result || property == 'zIndex'){ + if (Element.ShortStyles.hasOwnProperty(property)){ + result = []; + for (var s in Element.ShortStyles[property]) result.push(this.getStyle(s)); + return result.join(' '); + } + result = this.getComputedStyle(property); + } + if (hasBackgroundPositionXY && /^backgroundPosition[XY]?$/.test(property)){ + return result.replace(/(top|right|bottom|left)/g, function(position){ + return namedPositions[position]; + }) || '0px'; + } + if (!result && property == 'backgroundPosition') return '0px 0px'; + if (result){ + result = String(result); + var color = result.match(/rgba?\([\d\s,]+\)/); + if (color) result = result.replace(color[0], color[0].rgbToHex()); + } + if (!hasGetComputedStyle && !this.style[property]){ + if ((/^(height|width)$/).test(property) && !(/px$/.test(result))){ + var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0; + values.each(function(value){ + size += this.getStyle('border-' + value + '-width').toInt() + this.getStyle('padding-' + value).toInt(); + }, this); + return this['offset' + property.capitalize()] - size + 'px'; + } + if ((/^border(.+)Width|margin|padding/).test(property) && isNaN(parseFloat(result))){ + return '0px'; + } + } + // + if (returnsBordersInWrongOrder && /^border(Top|Right|Bottom|Left)?$/.test(property) && /^#/.test(result)){ + return result.replace(/^(.+)\s(.+)\s(.+)$/, '$2 $3 $1'); + } + // + + return result; + }, + + setStyles: function(styles){ + for (var style in styles) this.setStyle(style, styles[style]); + return this; + }, + + getStyles: function(){ + var result = {}; + Array.flatten(arguments).each(function(key){ + result[key] = this.getStyle(key); + }, this); + return result; + } + +}); + +Element.Styles = { + left: '@px', top: '@px', bottom: '@px', right: '@px', + width: '@px', height: '@px', maxWidth: '@px', maxHeight: '@px', minWidth: '@px', minHeight: '@px', + backgroundColor: 'rgb(@, @, @)', backgroundSize: '@px', backgroundPosition: '@px @px', color: 'rgb(@, @, @)', + fontSize: '@px', letterSpacing: '@px', lineHeight: '@px', clip: 'rect(@px @px @px @px)', + margin: '@px @px @px @px', padding: '@px @px @px @px', border: '@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)', + borderWidth: '@px @px @px @px', borderStyle: '@ @ @ @', borderColor: 'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)', + zIndex: '@', 'zoom': '@', fontWeight: '@', textIndent: '@px', opacity: '@', borderRadius: '@px @px @px @px' }; -var check = function(event){ - var related = event.relatedTarget; - if (related == null) return true; - if (!related) return false; - return (related != this && related.prefix != 'xul' && typeOf(this) != 'document' && !this.contains(related)); -}; +//<1.3compat> -Element.Events = { +Element.implement({ - mouseenter: { - base: 'mouseover', - condition: check + setOpacity: function(value){ + setOpacity(this, value); + return this; }, - mouseleave: { - base: 'mouseout', - condition: check + getOpacity: function(){ + return getOpacity(this); + } + +}); + +Element.Properties.opacity = { + + set: function(opacity){ + setOpacity(this, opacity); + setVisibility(this, opacity); }, - mousewheel: { - base: (Browser.firefox) ? 'DOMMouseScroll' : 'mousewheel' + get: function(){ + return getOpacity(this); } }; +// + //<1.2compat> -Element.Events = new Hash(Element.Events); +Element.Styles = new Hash(Element.Styles); // -})(); +Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {}}; + +['Top', 'Right', 'Bottom', 'Left'].each(function(direction){ + var Short = Element.ShortStyles; + var All = Element.Styles; + ['margin', 'padding'].each(function(style){ + var sd = style + direction; + Short[style][sd] = All[sd] = '@px'; + }); + var bd = 'border' + direction; + Short.border[bd] = All[bd] = '@px @ rgb(@, @, @)'; + var bdw = bd + 'Width', bds = bd + 'Style', bdc = bd + 'Color'; + Short[bd] = {}; + Short.borderWidth[bdw] = Short[bd][bdw] = All[bdw] = '@px'; + Short.borderStyle[bds] = Short[bd][bds] = All[bds] = '@'; + Short.borderColor[bdc] = Short[bd][bdc] = All[bdc] = 'rgb(@, @, @)'; +}); +if (hasBackgroundPositionXY) Element.ShortStyles.backgroundPosition = {backgroundPositionX: '@', backgroundPositionY: '@'}; +})(); /* --- @@ -4170,6 +4944,38 @@ provides: [Element.Dimensions] (function(){ +var element = document.createElement('div'), + child = document.createElement('div'); +element.style.height = '0'; +element.appendChild(child); +var brokenOffsetParent = (child.offsetParent === element); +element = child = null; + +var heightComponents = ['height', 'paddingTop', 'paddingBottom', 'borderTopWidth', 'borderBottomWidth'], + widthComponents = ['width', 'paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth']; + +var svgCalculateSize = function(el){ + + var gCS = window.getComputedStyle(el), + bounds = {x: 0, y: 0}; + + heightComponents.each(function(css){ + bounds.y += parseFloat(gCS[css]); + }); + widthComponents.each(function(css){ + bounds.x += parseFloat(gCS[css]); + }); + return bounds; +}; + +var isOffset = function(el){ + return styleString(el, 'position') != 'static' || isBody(el); +}; + +var isOffsetStatic = function(el){ + return isOffset(el) || (/^(?:table|td|th)$/i).test(el.tagName); +}; + Element.implement({ scrollTo: function(x, y){ @@ -4184,7 +4990,18 @@ Element.implement({ getSize: function(){ if (isBody(this)) return this.getWindow().getSize(); - return {x: this.offsetWidth, y: this.offsetHeight}; + + // + // This if clause is because IE8- cannot calculate getBoundingClientRect of elements with visibility hidden. + if (!window.getComputedStyle) return {x: this.offsetWidth, y: this.offsetHeight}; + // + + // This svg section under, calling `svgCalculateSize()`, can be removed when FF fixed the svg size bug. + // Bug info: https://bugzilla.mozilla.org/show_bug.cgi?id=530985 + if (this.get('tag') == 'svg') return svgCalculateSize(this); + + var bounds = this.getBoundingClientRect(); + return {x: bounds.width, y: bounds.height}; }, getScrollSize: function(){ @@ -4207,18 +5024,31 @@ Element.implement({ return position; }, - getOffsetParent: function(){ + getOffsetParent: brokenOffsetParent ? function(){ var element = this; - if (isBody(element)) return null; - if (!Browser.ie) return element.offsetParent; + if (isBody(element) || styleString(element, 'position') == 'fixed') return null; + + var isOffsetCheck = (styleString(element, 'position') == 'static') ? isOffsetStatic : isOffset; while ((element = element.parentNode)){ - if (styleString(element, 'position') != 'static' || isBody(element)) return element; + if (isOffsetCheck(element)) return element; } return null; + } : function(){ + var element = this; + if (isBody(element) || styleString(element, 'position') == 'fixed') return null; + + try { + return element.offsetParent; + } catch(e){} + return null; }, getOffsets: function(){ - if (this.getBoundingClientRect && !Browser.Platform.ios){ + var hasGetBoundingClientRect = this.getBoundingClientRect; +//<1.4compat> + hasGetBoundingClientRect = hasGetBoundingClientRect && !Browser.Platform.ios +// + if (hasGetBoundingClientRect){ var bound = this.getBoundingClientRect(), html = document.id(this.getDocument().documentElement), htmlScroll = html.getScroll(), @@ -4227,7 +5057,7 @@ Element.implement({ return { x: bound.left.toInt() + elemScrolls.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft, - y: bound.top.toInt() + elemScrolls.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop + y: bound.top.toInt() + elemScrolls.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop }; } @@ -4237,7 +5067,7 @@ Element.implement({ while (element && !isBody(element)){ position.x += element.offsetLeft; position.y += element.offsetTop; - +//<1.4compat> if (Browser.firefox){ if (!borderBox(element)){ position.x += leftBorder(element); @@ -4252,25 +5082,26 @@ Element.implement({ position.x += leftBorder(element); position.y += topBorder(element); } - +// element = element.offsetParent; } +//<1.4compat> if (Browser.firefox && !borderBox(this)){ position.x -= leftBorder(this); position.y -= topBorder(this); } +// return position; }, getPosition: function(relative){ - if (isBody(this)) return {x: 0, y: 0}; var offset = this.getOffsets(), scroll = this.getScrolls(); var position = { x: offset.x - scroll.x, y: offset.y - scroll.y }; - + if (relative && (relative = document.id(relative))){ var relativePosition = relative.getPosition(); return {x: position.x - relativePosition.x - leftBorder(relative), y: position.y - relativePosition.y - topBorder(relative)}; @@ -4344,28 +5175,28 @@ var styleString = Element.getComputedStyle; function styleNumber(element, style){ return styleString(element, style).toInt() || 0; -}; +} function borderBox(element){ return styleString(element, '-moz-box-sizing') == 'border-box'; -}; +} function topBorder(element){ return styleNumber(element, 'border-top-width'); -}; +} function leftBorder(element){ return styleNumber(element, 'border-left-width'); -}; +} function isBody(element){ return (/^(?:body|html)$/i).test(element.tagName); -}; +} function getCompatElement(element){ var doc = element.getDocument(); return (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body; -}; +} })(); @@ -4408,7 +5239,6 @@ Element.alias({position: 'setPosition'}); //compatability }); - /* --- @@ -4437,9 +5267,11 @@ var Fx = this.Fx = new Class({ onCancel: nil, onComplete: nil, */ - fps: 50, + fps: 60, unit: false, duration: 500, + frames: null, + frameSkip: true, link: 'ignore' }, @@ -4454,14 +5286,22 @@ var Fx = this.Fx = new Class({ }; }, - step: function(){ - var time = Date.now(); - if (time < this.time + this.options.duration){ - var delta = this.transition((time - this.time) / this.options.duration); + step: function(now){ + if (this.options.frameSkip){ + var diff = (this.time != null) ? (now - this.time) : 0, frames = diff / this.frameInterval; + this.time = now; + this.frame += frames; + } else { + this.frame++; + } + + if (this.frame < this.frames){ + var delta = this.transition(this.frame / this.frames); this.set(this.compute(this.from, this.to, delta)); } else { + this.frame = this.frames; this.set(this.compute(this.from, this.to, 1)); - this.complete(); + this.stop(); } }, @@ -4474,7 +5314,7 @@ var Fx = this.Fx = new Class({ }, check: function(){ - if (!this.timer) return true; + if (!this.isRunning()) return true; switch (this.options.link){ case 'cancel': this.cancel(); return true; case 'chain': this.chain(this.caller.pass(arguments, this)); return false; @@ -4484,62 +5324,64 @@ var Fx = this.Fx = new Class({ start: function(from, to){ if (!this.check(from, to)) return this; - var duration = this.options.duration; - this.options.duration = Fx.Durations[duration] || duration.toInt(); this.from = from; this.to = to; - this.time = 0; + this.frame = (this.options.frameSkip) ? 0 : -1; + this.time = null; this.transition = this.getTransition(); - this.startTimer(); - this.onStart(); + var frames = this.options.frames, fps = this.options.fps, duration = this.options.duration; + this.duration = Fx.Durations[duration] || duration.toInt(); + this.frameInterval = 1000 / fps; + this.frames = frames || Math.round(this.duration / this.frameInterval); + this.fireEvent('start', this.subject); + pushInstance.call(this, fps); return this; }, - complete: function(){ - if (this.stopTimer()) this.onComplete(); + stop: function(){ + if (this.isRunning()){ + this.time = null; + pullInstance.call(this, this.options.fps); + if (this.frames == this.frame){ + this.fireEvent('complete', this.subject); + if (!this.callChain()) this.fireEvent('chainComplete', this.subject); + } else { + this.fireEvent('stop', this.subject); + } + } return this; }, cancel: function(){ - if (this.stopTimer()) this.onCancel(); + if (this.isRunning()){ + this.time = null; + pullInstance.call(this, this.options.fps); + this.frame = this.frames; + this.fireEvent('cancel', this.subject).clearChain(); + } return this; }, - onStart: function(){ - this.fireEvent('start', this.subject); - }, - - onComplete: function(){ - this.fireEvent('complete', this.subject); - if (!this.callChain()) this.fireEvent('chainComplete', this.subject); - }, - - onCancel: function(){ - this.fireEvent('cancel', this.subject).clearChain(); - }, - pause: function(){ - this.stopTimer(); + if (this.isRunning()){ + this.time = null; + pullInstance.call(this, this.options.fps); + } return this; }, resume: function(){ - this.startTimer(); + if (this.isPaused()) pushInstance.call(this, this.options.fps); return this; }, - stopTimer: function(){ - if (!this.timer) return false; - this.time = Date.now() - this.time; - this.timer = removeInstance(this); - return true; + isRunning: function(){ + var list = instances[this.options.fps]; + return list && list.contains(this); }, - startTimer: function(){ - if (this.timer) return false; - this.time = Date.now() - this.time; - this.timer = addInstance(this); - return true; + isPaused: function(){ + return (this.frame < this.frames) && !this.isRunning(); } }); @@ -4555,30 +5397,32 @@ Fx.Durations = {'short': 250, 'normal': 500, 'long': 1000}; var instances = {}, timers = {}; var loop = function(){ + var now = Date.now(); for (var i = this.length; i--;){ - if (this[i]) this[i].step(); + var instance = this[i]; + if (instance) instance.step(now); } }; -var addInstance = function(instance){ - var fps = instance.options.fps, - list = instances[fps] || (instances[fps] = []); - list.push(instance); +var pushInstance = function(fps){ + var list = instances[fps] || (instances[fps] = []); + list.push(this); if (!timers[fps]) timers[fps] = loop.periodical(Math.round(1000 / fps), list); - return true; }; -var removeInstance = function(instance){ - var fps = instance.options.fps, - list = instances[fps] || []; - list.erase(instance); - if (!list.length && timers[fps]) timers[fps] = clearInterval(timers[fps]); - return false; +var pullInstance = function(fps){ + var list = instances[fps]; + if (list){ + list.erase(this); + if (!list.length && timers[fps]){ + delete instances[fps]; + timers[fps] = clearInterval(timers[fps]); + } + } }; })(); - /* --- @@ -4603,12 +5447,31 @@ Fx.CSS = new Class({ prepare: function(element, property, values){ values = Array.from(values); - if (values[1] == null){ - values[1] = values[0]; - values[0] = element.getStyle(property); + var from = values[0], to = values[1]; + if (to == null){ + to = from; + from = element.getStyle(property); + var unit = this.options.unit; + // adapted from: https://github.com/ryanmorr/fx/blob/master/fx.js#L299 + if (unit && from && typeof from == 'string' && from.slice(-unit.length) != unit && parseFloat(from) != 0){ + element.setStyle(property, to + unit); + var value = element.getComputedStyle(property); + // IE and Opera support pixelLeft or pixelWidth + if (!(/px$/.test(value))){ + value = element.style[('pixel-' + property).camelCase()]; + if (value == null){ + // adapted from Dean Edwards' http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 + var left = element.style.left; + element.style.left = to + unit; + value = element.style.pixelLeft; + element.style.left = left; + } + } + from = (to || 1) / (parseFloat(value) || 1) * (parseFloat(from) || 0); + element.setStyle(property, from + unit); + } } - var parsed = values.map(this.parse); - return {from: parsed[0], to: parsed[1]}; + return {from: this.parse(from), to: this.parse(to)}; }, //parses a value into an array @@ -4661,23 +5524,32 @@ Fx.CSS = new Class({ search: function(selector){ if (Fx.CSS.Cache[selector]) return Fx.CSS.Cache[selector]; - var to = {}; - Array.each(document.styleSheets, function(sheet, j){ - var href = sheet.href; - if (href && href.contains('://') && !href.contains(document.domain)) return; - var rules = sheet.rules || sheet.cssRules; + var to = {}, selectorTest = new RegExp('^' + selector.escapeRegExp() + '$'); + + var searchStyles = function(rules){ Array.each(rules, function(rule, i){ + if (rule.media){ + searchStyles(rule.rules || rule.cssRules); + return; + } if (!rule.style) return; var selectorText = (rule.selectorText) ? rule.selectorText.replace(/^\w+/, function(m){ return m.toLowerCase(); }) : null; - if (!selectorText || !selectorText.test('^' + selector + '$')) return; - Element.Styles.each(function(value, style){ + if (!selectorText || !selectorTest.test(selectorText)) return; + Object.each(Element.Styles, function(value, style){ if (!rule.style[style] || Element.ShortStyles[style]) return; value = String(rule.style[style]); - to[style] = (value.test(/^rgb/)) ? value.rgbToHex() : value; + to[style] = ((/^rgb/).test(value)) ? value.rgbToHex() : value; }); }); + }; + + Array.each(document.styleSheets, function(sheet, j){ + var href = sheet.href; + if (href && href.indexOf('://') > -1 && href.indexOf(document.domain) == -1) return; + var rules = sheet.rules || sheet.cssRules; + searchStyles(rules); }); return Fx.CSS.Cache[selector] = to; } @@ -4694,146 +5566,40 @@ Fx.CSS.Parsers = { return ((value = value.match(/(\d+),\s*(\d+),\s*(\d+)/))) ? [value[1], value[2], value[3]] : false; }, compute: function(from, to, delta){ - return from.map(function(value, i){ - return Math.round(Fx.compute(from[i], to[i], delta)); - }); - }, - serve: function(value){ - return value.map(Number); - } - }, - - Number: { - parse: parseFloat, - compute: Fx.compute, - serve: function(value, unit){ - return (unit) ? value + unit : value; - } - }, - - String: { - parse: Function.from(false), - compute: function(zero, one){ - return one; - }, - serve: function(zero){ - return zero; - } - } - -}; - -//<1.2compat> - -Fx.CSS.Parsers = new Hash(Fx.CSS.Parsers); - -// - - -/* ---- - -name: Fx.Tween - -description: Formerly Fx.Style, effect to transition any CSS property for an element. - -license: MIT-style license. - -requires: Fx.CSS - -provides: [Fx.Tween, Element.fade, Element.highlight] - -... -*/ - -Fx.Tween = new Class({ - - Extends: Fx.CSS, - - initialize: function(element, options){ - this.element = this.subject = document.id(element); - this.parent(options); - }, - - set: function(property, now){ - if (arguments.length == 1){ - now = property; - property = this.property || this.options.property; - } - this.render(this.element, property, now, this.options.unit); - return this; - }, - - start: function(property, from, to){ - if (!this.check(property, from, to)) return this; - var args = Array.flatten(arguments); - this.property = this.options.property || args.shift(); - var parsed = this.prepare(this.element, this.property, args); - return this.parent(parsed.from, parsed.to); - } - -}); - -Element.Properties.tween = { - - set: function(options){ - this.get('tween').cancel().setOptions(options); - return this; - }, - - get: function(){ - var tween = this.retrieve('tween'); - if (!tween){ - tween = new Fx.Tween(this, {link: 'cancel'}); - this.store('tween', tween); - } - return tween; - } - -}; - -Element.implement({ - - tween: function(property, from, to){ - this.get('tween').start(arguments); - return this; + return from.map(function(value, i){ + return Math.round(Fx.compute(from[i], to[i], delta)); + }); + }, + serve: function(value){ + return value.map(Number); + } }, - fade: function(how){ - var fade = this.get('tween'), o = 'opacity', toggle; - how = [how, 'toggle'].pick(); - switch (how){ - case 'in': fade.start(o, 1); break; - case 'out': fade.start(o, 0); break; - case 'show': fade.set(o, 1); break; - case 'hide': fade.set(o, 0); break; - case 'toggle': - var flag = this.retrieve('fade:flag', this.get('opacity') == 1); - fade.start(o, (flag) ? 0 : 1); - this.store('fade:flag', !flag); - toggle = true; - break; - default: fade.start(o, arguments); + Number: { + parse: parseFloat, + compute: Fx.compute, + serve: function(value, unit){ + return (unit) ? value + unit : value; } - if (!toggle) this.eliminate('fade:flag'); - return this; }, - highlight: function(start, end){ - if (!end){ - end = this.retrieve('highlight:original', this.getStyle('background-color')); - end = (end == 'transparent') ? '#fff' : end; + String: { + parse: Function.from(false), + compute: function(zero, one){ + return one; + }, + serve: function(zero){ + return zero; } - var tween = this.get('tween'); - tween.start('background-color', start || '#ffff88', end).chain(function(){ - this.setStyle('background-color', this.retrieve('highlight:original')); - tween.callChain(); - }.bind(this)); - return this; } -}); +}; + +//<1.2compat> +Fx.CSS.Parsers = new Hash(Fx.CSS.Parsers); + +// /* --- @@ -4913,7 +5679,6 @@ Element.implement({ }); - /* --- @@ -4950,15 +5715,16 @@ Fx.implement({ Fx.Transition = function(transition, params){ params = Array.from(params); - return Object.append(transition, { - easeIn: function(pos){ - return transition(pos, params); - }, + var easeIn = function(pos){ + return transition(pos, params); + }; + return Object.append(easeIn, { + easeIn: easeIn, easeOut: function(pos){ return 1 - transition(1 - pos, params); }, easeInOut: function(pos){ - return (pos <= 0.5) ? transition(2 * pos, params) / 2 : (2 - transition(2 * (1 - pos), params)) / 2; + return (pos <= 0.5 ? transition(2 * pos, params) : (2 - transition(2 * (1 - pos), params))) / 2; } }); }; @@ -4996,7 +5762,7 @@ Fx.Transitions.extend({ }, Sine: function(p){ - return 1 - Math.sin((1 - p) * Math.PI / 2); + return 1 - Math.cos(p * Math.PI / 2); }, Back: function(p, x){ @@ -5023,10 +5789,121 @@ Fx.Transitions.extend({ ['Quad', 'Cubic', 'Quart', 'Quint'].each(function(transition, i){ Fx.Transitions[transition] = new Fx.Transition(function(p){ - return Math.pow(p, [i + 2]); + return Math.pow(p, i + 2); }); }); +/* +--- + +name: Fx.Tween + +description: Formerly Fx.Style, effect to transition any CSS property for an element. + +license: MIT-style license. + +requires: Fx.CSS + +provides: [Fx.Tween, Element.fade, Element.highlight] + +... +*/ + +Fx.Tween = new Class({ + + Extends: Fx.CSS, + + initialize: function(element, options){ + this.element = this.subject = document.id(element); + this.parent(options); + }, + + set: function(property, now){ + if (arguments.length == 1){ + now = property; + property = this.property || this.options.property; + } + this.render(this.element, property, now, this.options.unit); + return this; + }, + + start: function(property, from, to){ + if (!this.check(property, from, to)) return this; + var args = Array.flatten(arguments); + this.property = this.options.property || args.shift(); + var parsed = this.prepare(this.element, this.property, args); + return this.parent(parsed.from, parsed.to); + } + +}); + +Element.Properties.tween = { + + set: function(options){ + this.get('tween').cancel().setOptions(options); + return this; + }, + + get: function(){ + var tween = this.retrieve('tween'); + if (!tween){ + tween = new Fx.Tween(this, {link: 'cancel'}); + this.store('tween', tween); + } + return tween; + } + +}; + +Element.implement({ + + tween: function(property, from, to){ + this.get('tween').start(property, from, to); + return this; + }, + + fade: function(how){ + var fade = this.get('tween'), method, args = ['opacity'].append(arguments), toggle; + if (args[1] == null) args[1] = 'toggle'; + switch (args[1]){ + case 'in': method = 'start'; args[1] = 1; break; + case 'out': method = 'start'; args[1] = 0; break; + case 'show': method = 'set'; args[1] = 1; break; + case 'hide': method = 'set'; args[1] = 0; break; + case 'toggle': + var flag = this.retrieve('fade:flag', this.getStyle('opacity') == 1); + method = 'start'; + args[1] = flag ? 0 : 1; + this.store('fade:flag', !flag); + toggle = true; + break; + default: method = 'start'; + } + if (!toggle) this.eliminate('fade:flag'); + fade[method].apply(fade, args); + var to = args[args.length - 1]; + if (method == 'set' || to != 0) this.setStyle('visibility', to == 0 ? 'hidden' : 'visible'); + else fade.chain(function(){ + this.element.setStyle('visibility', 'hidden'); + this.callChain(); + }); + return this; + }, + + highlight: function(start, end){ + if (!end){ + end = this.retrieve('highlight:original', this.getStyle('background-color')); + end = (end == 'transparent') ? '#fff' : end; + } + var tween = this.get('tween'); + tween.start('background-color', start || '#ffff88', end).chain(function(){ + this.setStyle('background-color', this.retrieve('highlight:original')); + tween.callChain(); + }.bind(this)); + return this; + } + +}); /* --- @@ -5046,7 +5923,8 @@ provides: Request (function(){ -var progressSupport = ('onprogress' in new Browser.Request); +var empty = function(){}, + progressSupport = ('onprogress' in new Browser.Request); var Request = this.Request = new Class({ @@ -5063,7 +5941,8 @@ var Request = this.Request = new Class({ onException: function(headerName, value){}, onTimeout: function(){}, user: '', - password: '',*/ + password: '', + withCredentials: false,*/ url: '', data: '', headers: { @@ -5099,9 +5978,13 @@ var Request = this.Request = new Class({ var status = xhr.status; this.status = (status == 1223) ? 204 : status; }.bind(this)); - xhr.onreadystatechange = function(){}; - clearTimeout(this.timer); - + xhr.onreadystatechange = empty; + if (progressSupport) xhr.onprogress = xhr.onloadstart = empty; + if (this.timer){ + clearTimeout(this.timer); + delete this.timer; + } + this.response = {text: this.xhr.responseText || '', xml: this.xhr.responseXML}; if (this.options.isSuccess.call(this, this.status)) this.success(this.response.text, this.response.xml); @@ -5138,15 +6021,15 @@ var Request = this.Request = new Class({ onFailure: function(){ this.fireEvent('complete').fireEvent('failure', this.xhr); }, - + loadstart: function(event){ this.fireEvent('loadstart', [event, this.xhr]); }, - + progress: function(event){ this.fireEvent('progress', [event, this.xhr]); }, - + timeout: function(){ this.fireEvent('timeout', this.xhr); }, @@ -5170,7 +6053,7 @@ var Request = this.Request = new Class({ } return false; }, - + send: function(options){ if (!this.check(options)) return this; @@ -5206,15 +6089,15 @@ var Request = this.Request = new Class({ } if (!url) url = document.location.pathname; - + var trimPosition = url.lastIndexOf('/'); if (trimPosition > -1 && (trimPosition = url.indexOf('#')) > -1) url = url.substr(0, trimPosition); if (this.options.noCache) - url += (url.contains('?') ? '&' : '?') + String.uniqueID(); + url += (url.indexOf('?') > -1 ? '&' : '?') + String.uniqueID(); - if (data && method == 'get'){ - url += (url.contains('?') ? '&' : '?') + data; + if (data && (method == 'get' || method == 'delete')){ + url += (url.indexOf('?') > -1 ? '&' : '?') + data; data = null; } @@ -5225,8 +6108,8 @@ var Request = this.Request = new Class({ } xhr.open(method.toUpperCase(), url, this.options.async, this.options.user, this.options.password); - if (this.options.user && 'withCredentials' in xhr) xhr.withCredentials = true; - + if ((/*<1.4compat>*/this.options.user || /**/this.options.withCredentials) && 'withCredentials' in xhr) xhr.withCredentials = true; + xhr.onreadystatechange = this.onStateChange.bind(this); Object.each(this.headers, function(value, key){ @@ -5240,7 +6123,7 @@ var Request = this.Request = new Class({ this.fireEvent('request'); xhr.send(data); if (!this.options.async) this.onStateChange(); - if (this.options.timeout) this.timer = this.timeout.delay(this.options.timeout, this); + else if (this.options.timeout) this.timer = this.timeout.delay(this.options.timeout, this); return this; }, @@ -5249,8 +6132,12 @@ var Request = this.Request = new Class({ this.running = false; var xhr = this.xhr; xhr.abort(); - clearTimeout(this.timer); - xhr.onreadystatechange = xhr.onprogress = xhr.onloadstart = function(){}; + if (this.timer){ + clearTimeout(this.timer); + delete this.timer; + } + xhr.onreadystatechange = empty; + if (progressSupport) xhr.onprogress = xhr.onloadstart = empty; this.xhr = new Browser.Request(); this.fireEvent('cancel'); return this; @@ -5259,12 +6146,13 @@ var Request = this.Request = new Class({ }); var methods = {}; -['get', 'post', 'put', 'delete', 'GET', 'POST', 'PUT', 'DELETE'].each(function(method){ +['get', 'post', 'put', 'delete', 'patch', 'head', 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'].each(function(method){ methods[method] = function(data){ - return this.send({ - data: data, + var object = { method: method - }); + }; + if (data != null) object.data = data; + return this.send(object); }; }); @@ -5345,11 +6233,18 @@ Request.HTML = new Class({ var temp = new Element('div').set('html', response.html); response.tree = temp.childNodes; - response.elements = temp.getElements('*'); - - if (options.filter) response.tree = response.elements.filter(options.filter); - if (options.update) document.id(options.update).empty().set('html', response.html); - else if (options.append) document.id(options.append).adopt(temp.getChildren()); + response.elements = temp.getElements(options.filter || '*'); + + if (options.filter) response.tree = response.elements; + if (options.update){ + var update = document.id(options.update).empty(); + if (options.filter) update.adopt(response.elements); + else update.set('html', response.html); + } else if (options.append){ + var append = document.id(options.append); + if (options.filter) response.elements.reverse().inject(append); + else append.adopt(temp.getChildren()); + } if (options.evalScripts) Browser.exec(response.javascript); this.onSuccess(response.tree, response.elements, response.html, response.javascript); @@ -5385,7 +6280,6 @@ Element.implement({ }); - /* --- @@ -5395,7 +6289,7 @@ description: JSON encoder and decoder. license: MIT-style license. -See Also: +SeeAlso: requires: [Array, String, Number, Function] @@ -5404,7 +6298,7 @@ provides: JSON ... */ -if (!this.JSON) this.JSON = {}; +if (typeof JSON == 'undefined') this.JSON = {}; //<1.2compat> @@ -5415,41 +6309,64 @@ JSON = new Hash({ // -Object.append(JSON, { +(function(){ - $specialChars: {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'}, +var special = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'}; - $replaceChars: function(chr){ - return JSON.$specialChars[chr] || '\\u00' + Math.floor(chr.charCodeAt() / 16).toString(16) + (chr.charCodeAt() % 16).toString(16); - }, +var escape = function(chr){ + return special[chr] || '\\u' + ('0000' + chr.charCodeAt(0).toString(16)).slice(-4); +}; - encode: function(obj){ - switch (typeOf(obj)){ - case 'string': - return '"' + obj.replace(/[\x00-\x1f\\"]/g, JSON.$replaceChars) + '"'; - case 'array': - return '[' + String(obj.map(JSON.encode).clean()) + ']'; - case 'object': case 'hash': - var string = []; - Object.each(obj, function(value, key){ - var json = JSON.encode(value); - if (json) string.push(JSON.encode(key) + ':' + json); - }); - return '{' + string + '}'; - case 'number': case 'boolean': return String(obj); - case 'null': return 'null'; - } - return null; - }, +JSON.validate = function(string){ + string = string.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). + replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). + replace(/(?:^|:|,)(?:\s*\[)+/g, ''); + + return (/^[\],:{}\s]*$/).test(string); +}; - decode: function(string, secure){ - if (typeOf(string) != 'string' || !string.length) return null; - if (secure && !(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(string.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''))) return null; - return eval('(' + string + ')'); +JSON.encode = JSON.stringify ? function(obj){ + return JSON.stringify(obj); +} : function(obj){ + if (obj && obj.toJSON) obj = obj.toJSON(); + + switch (typeOf(obj)){ + case 'string': + return '"' + obj.replace(/[\x00-\x1f\\"]/g, escape) + '"'; + case 'array': + return '[' + obj.map(JSON.encode).clean() + ']'; + case 'object': case 'hash': + var string = []; + Object.each(obj, function(value, key){ + var json = JSON.encode(value); + if (json) string.push(JSON.encode(key) + ':' + json); + }); + return '{' + string + '}'; + case 'number': case 'boolean': return '' + obj; + case 'null': return 'null'; } -}); + return null; +}; + +JSON.secure = true; +//<1.4compat> +JSON.secure = false; +// + +JSON.decode = function(string, secure){ + if (!string || typeOf(string) != 'string') return null; + + if (secure == null) secure = JSON.secure; + if (secure){ + if (JSON.parse) return JSON.parse(string); + if (!JSON.validate(string)) throw new Error('JSON could not decode the input; security is enabled and the value is not secure.'); + } + + return eval('(' + string + ')'); +}; +})(); /* --- @@ -5472,6 +6389,7 @@ Request.JSON = new Class({ Extends: Request, options: { + /*onError: function(text, error){},*/ secure: true }, @@ -5484,18 +6402,19 @@ Request.JSON = new Class({ }, success: function(text){ - var secure = this.options.secure; - var json = this.response.json = Function.attempt(function(){ - return JSON.decode(text, secure); - }); - + var json; + try { + json = this.response.json = JSON.decode(text, this.options.secure); + } catch (error){ + this.fireEvent('error', [text, error]); + return; + } if (json == null) this.onFailure(); else this.onSuccess(json, text); } }); - /* --- @@ -5508,7 +6427,7 @@ license: MIT-style license. credits: - Based on the functions by Peter-Paul Koch (http://quirksmode.org). -requires: Options +requires: [Options, Browser] provides: Cookie @@ -5571,7 +6490,6 @@ Cookie.dispose = function(key, options){ return new Cookie(key, options).dispose(); }; - /* --- @@ -5595,21 +6513,18 @@ var ready, checks = [], shouldPoll, timer, - isFramed = true; - -// Thanks to Rich Dougherty -try { - isFramed = window.frameElement != null; -} catch(e){} + testElement = document.createElement('div'); var domready = function(){ clearTimeout(timer); - if (ready) return; - Browser.loaded = ready = true; - document.removeListener('DOMContentLoaded', domready).removeListener('readystatechange', check); - - document.fireEvent('domready'); - window.fireEvent('domready'); + if (!ready) { + Browser.loaded = ready = true; + document.removeListener('DOMContentLoaded', domready).removeListener('readystatechange', check); + document.fireEvent('domready'); + window.fireEvent('domready'); + } + // cleanup scope vars + document = window = testElement = null; }; var check = function(){ @@ -5617,7 +6532,6 @@ var check = function(){ domready(); return true; } - return false; }; @@ -5628,19 +6542,23 @@ var poll = function(){ document.addListener('DOMContentLoaded', domready); +/**/ // doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/ -var testElement = document.createElement('div'); -if (testElement.doScroll && !isFramed){ - checks.push(function(){ - try { - testElement.doScroll(); - return true; - } catch (e){} - - return false; - }); +// testElement.doScroll() throws when the DOM is not ready, only in the top window +var doScrollWorks = function(){ + try { + testElement.doScroll(); + return true; + } catch (e){} + return false; +}; +// If doScroll works already, it can't be used to determine domready +// e.g. in an iframe +if (testElement.doScroll && !doScrollWorks()){ + checks.push(doScrollWorks); shouldPoll = true; } +/**/ if (document.readyState) checks.push(function(){ var state = document.readyState; @@ -5669,7 +6587,6 @@ Element.Events.load = { domready(); delete Element.Events.load; } - return true; } }; @@ -5680,121 +6597,3 @@ window.addEvent('load', function(){ }); })(window, document); - - -/* ---- - -name: Swiff - -description: Wrapper for embedding SWF movies. Supports External Interface Communication. - -license: MIT-style license. - -credits: - - Flash detection & Internet Explorer + Flash Player 9 fix inspired by SWFObject. - -requires: [Options, Object] - -provides: Swiff - -... -*/ - -(function(){ - -var id = 0; - -var Swiff = this.Swiff = new Class({ - - Implements: Options, - - options: { - id: null, - height: 1, - width: 1, - container: null, - properties: {}, - params: { - quality: 'high', - allowScriptAccess: 'always', - wMode: 'window', - swLiveConnect: true - }, - callBacks: {}, - vars: {} - }, - - toElement: function(){ - return this.object; - }, - - initialize: function(path, options){ - this.instance = 'Swiff_' + id++; - - this.setOptions(options); - options = this.options; - var id = this.id = options.id || this.instance; - var container = document.id(options.container); - - Swiff.CallBacks[this.instance] = {}; - - var params = options.params, vars = options.vars, callBacks = options.callBacks; - var properties = Object.append({height: options.height, width: options.width}, options.properties); - - var self = this; - - for (var callBack in callBacks){ - Swiff.CallBacks[this.instance][callBack] = (function(option){ - return function(){ - return option.apply(self.object, arguments); - }; - })(callBacks[callBack]); - vars[callBack] = 'Swiff.CallBacks.' + this.instance + '.' + callBack; - } - - params.flashVars = Object.toQueryString(vars); - if (Browser.ie){ - properties.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; - params.movie = path; - } else { - properties.type = 'application/x-shockwave-flash'; - } - properties.data = path; - - var build = ''; - } - build += ''; - this.object = ((container) ? container.empty() : new Element('div')).set('html', build).firstChild; - }, - - replaces: function(element){ - element = document.id(element, true); - element.parentNode.replaceChild(this.toElement(), element); - return this; - }, - - inject: function(element){ - document.id(element, true).appendChild(this.toElement()); - return this; - }, - - remote: function(){ - return Swiff.remote.apply(Swiff, [this.toElement()].extend(arguments)); - } - -}); - -Swiff.CallBacks = {}; - -Swiff.remote = function(obj, fn){ - var rs = obj.CallFunction('' + __flash__argumentsToXML(arguments, 2) + ''); - return eval(rs); -}; - -})(); - diff --git a/src/templates/exhibition.html b/src/templates/exhibition.html index 0d273be..4137f64 100644 --- a/src/templates/exhibition.html +++ b/src/templates/exhibition.html @@ -3,10 +3,10 @@ <% title %> - + - +