2
* An adapter for Shadowbox and the MooTools JavaScript framework.
4
* This file is part of Shadowbox.
6
* Shadowbox is an online media viewer application that supports all of the
7
* web's most popular media publishing formats. Shadowbox is written entirely
8
* in JavaScript and CSS and is highly customizable. Using Shadowbox, website
9
* authors can showcase a wide assortment of media in all major browsers without
10
* navigating users away from the linking page.
12
* Shadowbox is released under version 3.0 of the Creative Commons Attribution-
13
* Noncommercial-Share Alike license. This means that it is absolutely free
14
* for personal, noncommercial use provided that you 1) make attribution to the
15
* author and 2) release any derivative work under the same or a similar
18
* If you wish to use Shadowbox for commercial purposes, licensing information
19
* can be found at http://mjijackson.com/shadowbox/.
21
* @author Michael J. I. Jackson <mjijackson@gmail.com>
22
* @copyright 2007-2008 Michael J. I. Jackson
23
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
24
* @version SVN: $Id: shadowbox-mootools.js 110 2008-07-11 04:42:10Z mjijackson $
27
if(typeof MooTools == 'undefined'){
28
// Note: requires MooTools 1.2 Core
29
throw 'Unable to load Shadowbox, MooTools library not found';
32
// create the Shadowbox object first
35
Shadowbox.lib = function(){
37
var alphaRe = /alpha\([^\)]*\)/gi;
40
* Sets the opacity of the given element to the specified level. Necessary
41
* in the MooTools adapter to prevent MooTools from messing with the
42
* element's visibility.
44
* @param {HTMLElement} el The element
45
* @param {Number} opacity The opacity to use
50
var setOpacity = function(el, opacity){
52
if(window.ActiveXObject){ // IE
54
s.filter = (s.filter || '').replace(alphaRe, '') +
55
(opacity == 1 ? '' : ' alpha(opacity=' + opacity * 100 + ')');
66
* Gets the value of the style on the given element.
68
* @param {HTMLElement} el The DOM element
69
* @param {String} style The name of the style (e.g. margin-top)
70
* @return {mixed} The value of the given style
74
getStyle: function(el, style){
75
return $(el).getStyle(style);
79
* Sets the style on the given element to the given value. May be an
80
* object to specify multiple values.
82
* @param {HTMLElement} el The DOM element
83
* @param {String/Object} style The name of the style to set if a
84
* string, or an object of name =>
86
* @param {String} value The value to set the given style to
91
setStyle: function(el, style, value){
93
if(typeof style != 'object'){
100
setOpacity(el, style[s]);
102
el.setStyle(s, style[s]);
108
* Gets a reference to the given element.
110
* @param {String/HTMLElement} el The element to fetch
111
* @return {HTMLElement} A reference to the element
120
* Removes an element from the DOM.
122
* @param {HTMLElement} el The element to remove
127
remove: function(el){
128
el.parentNode.removeChild(el);
132
* Gets the target of the given event. The event object passed will be
133
* the same object that is passed to listeners registered with
136
* @param {mixed} e The event object
137
* @return {HTMLElement} The event's target element
141
getTarget: function(e){
146
* Gets the page X/Y coordinates of the mouse event in an [x, y] array.
147
* The page coordinates should be relative to the document, and not the
148
* viewport. The event object provided here will be the same object that
149
* is passed to listeners registered with addEvent().
151
* @param {mixed} e The event object
152
* @return {Array} The page X/Y coordinates
156
getPageXY: function(e){
157
return [e.page.x, e.page.y];
161
* Prevents the event's default behavior. The event object passed will
162
* be the same object that is passed to listeners registered with
165
* @param {mixed} e The event object
170
preventDefault: function(e){
175
* Gets the key code of the given event object (keydown). The event
176
* object here will be the same object that is passed to listeners
177
* registered with addEvent().
179
* @param {mixed} e The event object
180
* @return {Number} The key code of the event
184
keyCode: function(e){
189
* Adds an event listener to the given element. It is expected that this
190
* function will be passed the event as its first argument.
192
* @param {HTMLElement} el The DOM element to listen to
193
* @param {String} name The name of the event to register
194
* (i.e. 'click', 'scroll', etc.)
195
* @param {Function} handler The event handler function
200
addEvent: function(el, name, handler){
201
$(el).addEvent(name, handler);
205
* Removes an event listener from the given element.
207
* @param {HTMLElement} el The DOM element to stop listening to
208
* @param {String} name The name of the event to stop
209
* listening for (i.e. 'click')
210
* @param {Function} handler The event handler function
215
removeEvent: function(el, name, handler){
216
$(el).removeEvent(name, handler);
220
* Appends an HTML fragment to the given element.
222
* @param {HTMLElement} el The element to append to
223
* @param {String} html The HTML fragment to use
228
append: function(el, html){
229
if(el.insertAdjacentHTML){
230
el.insertAdjacentHTML('BeforeEnd', html);
231
}else if(el.lastChild){
232
var range = el.ownerDocument.createRange();
233
range.setStartAfter(el.lastChild);
234
var frag = range.createContextualFragment(html);
235
el.appendChild(frag);