2
* An adapter for Shadowbox and the Prototpe JavaScript library.
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-prototype.js 103 2008-06-27 06:19:21Z mjijackson $
27
if(typeof Prototype == 'undefined'){
28
throw 'Unable to load Shadowbox, Prototype framework not found';
31
// create the Shadowbox object first
34
Shadowbox.lib = function(){
36
// local style camelizing for speed
38
var camelRe = /(-[a-z])/gi;
39
var camelFn = function(m, a){
40
return a.charAt(1).toUpperCase();
42
var toCamel = function(style){
44
if(!(camel = styleCache[style])){
45
camel = styleCache[style] = style.replace(camelRe, camelFn);
55
* Gets the value of the style on the given element.
57
* @param {HTMLElement} el The DOM element
58
* @param {String} style The name of the style (e.g. margin-top)
59
* @return {mixed} The value of the given style
62
getStyle: function(el, style){
63
return Element.getStyle(el, style);
67
* Sets the style on the given element to the given value. May be an
68
* object to specify multiple values.
70
* @param {HTMLElement} el The DOM element
71
* @param {String/Object} style The name of the style to set if a
72
* string, or an object of name =>
74
* @param {String} value The value to set the given style to
78
setStyle: function(el, style, value){
79
if(typeof style == 'string'){
81
temp[toCamel(style)] = value;
84
Element.setStyle(el, style);
88
* Gets a reference to the given element.
90
* @param {String/HTMLElement} el The element to fetch
91
* @return {HTMLElement} A reference to the element
99
* Removes an element from the DOM.
101
* @param {HTMLElement} el The element to remove
105
remove: function(el){
110
* Gets the target of the given event. The event object passed will be
111
* the same object that is passed to listeners registered with
114
* @param {mixed} e The event object
115
* @return {HTMLElement} The event's target element
118
getTarget: function(e){
119
return Event.element(e);
123
* Prevents the event's default behavior. The event object passed will
124
* be the same object that is passed to listeners registered with
127
* @param {mixed} e The event object
131
preventDefault: function(e){
136
* Gets the page X/Y coordinates of the mouse event in an [x, y] array.
137
* The page coordinates should be relative to the document, and not the
138
* viewport. The event object provided here will be the same object that
139
* is passed to listeners registered with addEvent().
141
* @param {mixed} e The event object
142
* @return {Array} The page X/Y coordinates
146
getPageXY: function(e){
147
var p = Event.pointer(e);
152
* Gets the key code of the given event object (keydown). The event
153
* object here will be the same object that is passed to listeners
154
* registered with addEvent().
156
* @param {mixed} e The event object
157
* @return {Number} The key code of the event
161
keyCode: function(e){
166
* Adds an event listener to the given element. It is expected that this
167
* function will be passed the event as its first argument.
169
* @param {HTMLElement} el The DOM element to listen to
170
* @param {String} name The name of the event to register
171
* (i.e. 'click', 'scroll', etc.)
172
* @param {Function} handler The event handler function
176
addEvent: function(el, name, handler){
177
Event.observe(el, name, handler);
181
* Removes an event listener from the given element.
183
* @param {HTMLElement} el The DOM element to stop listening to
184
* @param {String} name The name of the event to stop
185
* listening for (i.e. 'click')
186
* @param {Function} handler The event handler function
190
removeEvent: function(el, name, handler){
191
Event.stopObserving(el, name, handler);
195
* Appends an HTML fragment to the given element.
197
* @param {HTMLElement} el The element to append to
198
* @param {String} html The HTML fragment to use
202
append: function(el, html){
203
Element.insert(el, html);