~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to lib/shadowbox-2.0/src/adapter/shadowbox-ext.js

Restructured Helioviewer.org project layout. Custom code for both client- and server-side now resides in src/ folders, images/css in resources/. Removed legacy libraries and code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * An adapter for Shadowbox and the Ext JavaScript framework.
3
 
 *
4
 
 * This file is part of Shadowbox.
5
 
 *
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.
11
 
 *
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
16
 
 * license.
17
 
 *
18
 
 * If you wish to use Shadowbox for commercial purposes, licensing information
19
 
 * can be found at http://mjijackson.com/shadowbox/.
20
 
 *
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 $
25
 
 */
26
 
 
27
 
if(typeof Ext == 'undefined'){
28
 
    // Note: requires ext-core.js
29
 
    throw 'Unable to load Shadowbox, core Ext framework not found';
30
 
}
31
 
 
32
 
// create the Shadowbox object first
33
 
var Shadowbox = {};
34
 
 
35
 
Shadowbox.lib = function(){
36
 
 
37
 
    // shorthand
38
 
    var E = Ext.lib.Event;
39
 
 
40
 
    return {
41
 
 
42
 
        adapter: 'ext',
43
 
 
44
 
        /**
45
 
         * Gets the value of the style on the given element.
46
 
         *
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
50
 
         * @public
51
 
         */
52
 
        getStyle: function(el, style){
53
 
            return Ext.get(el).getStyle(style);
54
 
        },
55
 
 
56
 
        /**
57
 
         * Sets the style on the given element to the given value. May be an
58
 
         * object to specify multiple values.
59
 
         *
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 =>
63
 
         *                                  value pairs
64
 
         * @param   {String}        value   The value to set the given style to
65
 
         * @return  void
66
 
         * @public
67
 
         */
68
 
        setStyle: function(el, style, value){
69
 
            Ext.get(el).setStyle(style, value);
70
 
        },
71
 
 
72
 
        /**
73
 
         * Gets a reference to the given element.
74
 
         *
75
 
         * @param   {String/HTMLElement}    el      The element to fetch
76
 
         * @return  {HTMLElement}                   A reference to the element
77
 
         * @public
78
 
         */
79
 
        get: function(el){
80
 
            return Ext.getDom(el);
81
 
        },
82
 
 
83
 
        /**
84
 
         * Removes an element from the DOM.
85
 
         *
86
 
         * @param   {HTMLElement}           el      The element to remove
87
 
         * @return  void
88
 
         * @public
89
 
         */
90
 
        remove: function(el){
91
 
            Ext.get(el).remove();
92
 
        },
93
 
 
94
 
        /**
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
97
 
         * addEvent().
98
 
         *
99
 
         * @param   {mixed}                 e       The event object
100
 
         * @return  {HTMLElement}                   The event's target element
101
 
         * @public
102
 
         */
103
 
        getTarget: function(e){
104
 
            return E.getTarget(e);
105
 
        },
106
 
 
107
 
        /**
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().
112
 
         *
113
 
         * @param   {mixed}         e       The event object
114
 
         * @return  {Array}                 The page X/Y coordinates
115
 
         * @public
116
 
         * @static
117
 
         */
118
 
        getPageXY: function(e){
119
 
            return [E.getPageX(e), E.getPageY(e)];
120
 
        },
121
 
 
122
 
        /**
123
 
         * Prevents the event's default behavior. The event object passed will
124
 
         * be the same object that is passed to listeners registered with
125
 
         * addEvent().
126
 
         *
127
 
         * @param   {mixed}                 e       The event object
128
 
         * @return  void
129
 
         * @public
130
 
         */
131
 
        preventDefault: function(e){
132
 
            E.preventDefault(e);
133
 
        },
134
 
 
135
 
        /**
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().
139
 
         *
140
 
         * @param   {mixed}         e       The event object
141
 
         * @return  {Number}                The key code of the event
142
 
         * @public
143
 
         * @static
144
 
         */
145
 
        keyCode: function(e){
146
 
            return E.getCharCode(e);
147
 
        },
148
 
 
149
 
        /**
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.
152
 
         *
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
157
 
         * @return  void
158
 
         * @public
159
 
         */
160
 
        addEvent: function(el, name, handler){
161
 
            E.addListener(el, name, handler);
162
 
        },
163
 
 
164
 
        /**
165
 
         * Removes an event listener from the given element.
166
 
         *
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
171
 
         * @return  void
172
 
         * @public
173
 
         */
174
 
        removeEvent: function(el, name, handler){
175
 
            E.removeListener(el, name, handler);
176
 
        },
177
 
 
178
 
        /**
179
 
         * Appends an HTML fragment to the given element.
180
 
         *
181
 
         * @param   {HTMLElement}       el      The element to append to
182
 
         * @param   {String}            html    The HTML fragment to use
183
 
         * @return  void
184
 
         * @public
185
 
         */
186
 
        append: function(el, html){
187
 
            Ext.DomHelper.append(el, html);
188
 
        }
189
 
 
190
 
    };
191
 
 
192
 
}();