2
* An adapter for Shadowbox and the Ext 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-ext.js 103 2008-06-27 06:19:21Z mjijackson $
27
if(typeof Ext == 'undefined'){
28
// Note: requires ext-core.js
29
throw 'Unable to load Shadowbox, core Ext framework not found';
32
// create the Shadowbox object first
35
Shadowbox.lib = function(){
38
var E = Ext.lib.Event;
45
* Gets the value of the style on the given element.
47
* @param {HTMLElement} el The DOM element
48
* @param {String} style The name of the style (e.g. margin-top)
49
* @return {mixed} The value of the given style
52
getStyle: function(el, style){
53
return Ext.get(el).getStyle(style);
57
* Sets the style on the given element to the given value. May be an
58
* object to specify multiple values.
60
* @param {HTMLElement} el The DOM element
61
* @param {String/Object} style The name of the style to set if a
62
* string, or an object of name =>
64
* @param {String} value The value to set the given style to
68
setStyle: function(el, style, value){
69
Ext.get(el).setStyle(style, value);
73
* Gets a reference to the given element.
75
* @param {String/HTMLElement} el The element to fetch
76
* @return {HTMLElement} A reference to the element
80
return Ext.getDom(el);
84
* Removes an element from the DOM.
86
* @param {HTMLElement} el The element to remove
95
* Gets the target of the given event. The event object passed will be
96
* the same object that is passed to listeners registered with
99
* @param {mixed} e The event object
100
* @return {HTMLElement} The event's target element
103
getTarget: function(e){
104
return E.getTarget(e);
108
* Gets the page X/Y coordinates of the mouse event in an [x, y] array.
109
* The page coordinates should be relative to the document, and not the
110
* viewport. The event object provided here will be the same object that
111
* is passed to listeners registered with addEvent().
113
* @param {mixed} e The event object
114
* @return {Array} The page X/Y coordinates
118
getPageXY: function(e){
119
return [E.getPageX(e), E.getPageY(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 key code of the given event object (keydown). The event
137
* object here will be the same object that is passed to listeners
138
* registered with addEvent().
140
* @param {mixed} e The event object
141
* @return {Number} The key code of the event
145
keyCode: function(e){
146
return E.getCharCode(e);
150
* Adds an event listener to the given element. It is expected that this
151
* function will be passed the event as its first argument.
153
* @param {HTMLElement} el The DOM element to listen to
154
* @param {String} name The name of the event to register
155
* (i.e. 'click', 'scroll', etc.)
156
* @param {Function} handler The event handler function
160
addEvent: function(el, name, handler){
161
E.addListener(el, name, handler);
165
* Removes an event listener from the given element.
167
* @param {HTMLElement} el The DOM element to stop listening to
168
* @param {String} name The name of the event to stop
169
* listening for (i.e. 'click')
170
* @param {Function} handler The event handler function
174
removeEvent: function(el, name, handler){
175
E.removeListener(el, name, handler);
179
* Appends an HTML fragment to the given element.
181
* @param {HTMLElement} el The element to append to
182
* @param {String} html The HTML fragment to use
186
append: function(el, html){
187
Ext.DomHelper.append(el, html);