~jstys-z/helioviewer.org/timeline

« back to all changes in this revision

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

  • Committer: Keith Hughitt
  • Date: 2010-02-17 22:00:59 UTC
  • mfrom: (402.1.68 hv)
  • Revision ID: keith.hughitt@nasa.gov-20100217220059-wmdq7kgokj4seryx
Merged with Keith's branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * An adapter for Shadowbox and the Prototpe JavaScript library.
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-prototype.js 103 2008-06-27 06:19:21Z mjijackson $
25
 
 */
26
 
 
27
 
if(typeof Prototype == 'undefined'){
28
 
    throw 'Unable to load Shadowbox, Prototype framework not found';
29
 
}
30
 
 
31
 
// create the Shadowbox object first
32
 
var Shadowbox = {};
33
 
 
34
 
Shadowbox.lib = function(){
35
 
 
36
 
    // local style camelizing for speed
37
 
    var styleCache = {};
38
 
    var camelRe = /(-[a-z])/gi;
39
 
    var camelFn = function(m, a){
40
 
        return a.charAt(1).toUpperCase();
41
 
    };
42
 
    var toCamel = function(style){
43
 
        var camel;
44
 
        if(!(camel = styleCache[style])){
45
 
            camel = styleCache[style] = style.replace(camelRe, camelFn);
46
 
        }
47
 
        return camel;
48
 
    };
49
 
 
50
 
    return {
51
 
 
52
 
        adapter: 'prototype',
53
 
 
54
 
        /**
55
 
         * Gets the value of the style on the given element.
56
 
         *
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
60
 
         * @public
61
 
         */
62
 
        getStyle: function(el, style){
63
 
            return Element.getStyle(el, style);
64
 
        },
65
 
 
66
 
        /**
67
 
         * Sets the style on the given element to the given value. May be an
68
 
         * object to specify multiple values.
69
 
         *
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 =>
73
 
         *                                  value pairs
74
 
         * @param   {String}        value   The value to set the given style to
75
 
         * @return  void
76
 
         * @public
77
 
         */
78
 
        setStyle: function(el, style, value){
79
 
            if(typeof style == 'string'){
80
 
                var temp = {};
81
 
                temp[toCamel(style)] = value;
82
 
                style = temp;
83
 
            }
84
 
            Element.setStyle(el, style);
85
 
        },
86
 
 
87
 
        /**
88
 
         * Gets a reference to the given element.
89
 
         *
90
 
         * @param   {String/HTMLElement}    el      The element to fetch
91
 
         * @return  {HTMLElement}                   A reference to the element
92
 
         * @public
93
 
         */
94
 
        get: function(el){
95
 
            return $(el);
96
 
        },
97
 
 
98
 
        /**
99
 
         * Removes an element from the DOM.
100
 
         *
101
 
         * @param   {HTMLElement}           el      The element to remove
102
 
         * @return  void
103
 
         * @public
104
 
         */
105
 
        remove: function(el){
106
 
            Element.remove(el);
107
 
        },
108
 
 
109
 
        /**
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
112
 
         * addEvent().
113
 
         *
114
 
         * @param   {mixed}                 e       The event object
115
 
         * @return  {HTMLElement}                   The event's target element
116
 
         * @public
117
 
         */
118
 
        getTarget: function(e){
119
 
            return Event.element(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
 
            Event.stop(e);
133
 
        },
134
 
 
135
 
        /**
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().
140
 
         *
141
 
         * @param   {mixed}         e       The event object
142
 
         * @return  {Array}                 The page X/Y coordinates
143
 
         * @public
144
 
         * @static
145
 
         */
146
 
        getPageXY: function(e){
147
 
            var p = Event.pointer(e);
148
 
            return [p.x, p.y];
149
 
        },
150
 
 
151
 
        /**
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().
155
 
         *
156
 
         * @param   {mixed}         e       The event object
157
 
         * @return  {Number}                The key code of the event
158
 
         * @public
159
 
         * @static
160
 
         */
161
 
        keyCode: function(e){
162
 
            return e.keyCode;
163
 
        },
164
 
 
165
 
        /**
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.
168
 
         *
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
173
 
         * @return  void
174
 
         * @public
175
 
         */
176
 
        addEvent: function(el, name, handler){
177
 
            Event.observe(el, name, handler);
178
 
        },
179
 
 
180
 
        /**
181
 
         * Removes an event listener from the given element.
182
 
         *
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
187
 
         * @return  void
188
 
         * @public
189
 
         */
190
 
        removeEvent: function(el, name, handler){
191
 
            Event.stopObserving(el, name, handler);
192
 
        },
193
 
 
194
 
        /**
195
 
         * Appends an HTML fragment to the given element.
196
 
         *
197
 
         * @param   {HTMLElement}       el      The element to append to
198
 
         * @param   {String}            html    The HTML fragment to use
199
 
         * @return  void
200
 
         * @public
201
 
         */
202
 
        append: function(el, html){
203
 
            Element.insert(el, html);
204
 
        }
205
 
 
206
 
    };
207
 
 
208
 
}();