Projet

Général

Profil

Paste
Télécharger (12 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / adminimal_theme / skins / material / material.js @ a192dc0b

1
(function($) {
2
'use strict';
3

    
4
// Add wave effect.
5
Drupal.behaviors.adminimal_material_wave_effect = {
6
  attach: function (context, settings) {
7
    // Init Waves
8
    $( ".action-links li a" ).addClass("waves-effect waves-button waves-float waves-classic");
9
    //$( ".form-actions input" ).addClass("waves-effect");
10
    //$( 'input[type="submit"]' ).addClass("waves-effect");
11
    $( "#navigation ul.tabs.primary li a" ).addClass("waves-effect waves-button waves-classic");
12
    $( "#navigation ul.tabs.secondary li a" ).addClass("waves-effect waves-button waves-classic");
13
    $( "#admin-menu a" ).addClass("waves-effect waves-button waves-light waves-classic");
14
    $( ".theme-info .operations a" ).addClass("waves-effect waves-button waves-classic");
15
    $( "table tbody td a" ).addClass("waves-effect waves-button waves-classic");
16
  }
17
};
18

    
19
})(jQuery);
20

    
21
/*!
22
 * Waves v0.6.6
23
 * http://fian.my.id/Waves
24
 *
25
 * Copyright 2014 Alfiana E. Sibuea and other contributors
26
 * Released under the MIT license
27
 * https://github.com/fians/Waves/blob/master/LICENSE
28
 */
29

    
30
;(function(window, factory) {
31
    "use strict";
32

    
33
    // AMD. Register as an anonymous module.  Wrap in function so we have access
34
    // to root via `this`.
35
    if (typeof define === "function" && define.amd) {
36
        define([], function() {
37
            return factory.apply(window);
38
        });
39
    }
40

    
41
    // Node. Does not work with strict CommonJS, but only CommonJS-like
42
    // environments that support module.exports, like Node.
43
    else if (typeof exports === "object") {
44
        module.exports = factory.call(window);
45
    }
46

    
47
    // Browser globals.
48
    else {
49
        window.Waves = factory.call(window);
50
    }
51
})(typeof global === "object" ? global : this, function () {
52
    "use strict";
53

    
54
    var Waves = Waves || {};
55
    var $$ = document.querySelectorAll.bind(document);
56

    
57
    // Find exact position of element
58
    function isWindow(obj) {
59
        return obj !== null && obj === obj.window;
60
    }
61

    
62
    function getWindow(elem) {
63
        return isWindow(elem) ? elem : elem.nodeType === 9 && elem.defaultView;
64
    }
65

    
66
    function offset(elem) {
67
        var docElem, win,
68
            box = {top: 0, left: 0},
69
            doc = elem && elem.ownerDocument;
70

    
71
        docElem = doc.documentElement;
72

    
73
        if (typeof elem.getBoundingClientRect !== typeof undefined) {
74
            box = elem.getBoundingClientRect();
75
        }
76
        win = getWindow(doc);
77
        return {
78
            top: box.top + win.pageYOffset - docElem.clientTop,
79
            left: box.left + win.pageXOffset - docElem.clientLeft
80
        };
81
    }
82

    
83
    function convertStyle(obj) {
84
        var style = '';
85

    
86
        for (var a in obj) {
87
            if (obj.hasOwnProperty(a)) {
88
                style += (a + ':' + obj[a] + ';');
89
            }
90
        }
91

    
92
        return style;
93
    }
94

    
95
    var Effect = {
96

    
97
        // Effect delay
98
        duration: 750,
99

    
100
        show: function(e, element) {
101

    
102
            // Disable right click
103
            if (e.button === 2) {
104
                return false;
105
            }
106

    
107
            var el = element || this;
108

    
109
            // Create ripple
110
            var ripple = document.createElement('div');
111
            ripple.className = 'waves-ripple';
112
            el.appendChild(ripple);
113

    
114
            // Get click coordinate and element witdh
115
            var pos         = offset(el);
116
            var relativeY   = (e.pageY - pos.top);
117
            var relativeX   = (e.pageX - pos.left);
118
            var scale       = 'scale('+((el.clientWidth / 100) * 3)+')';
119

    
120
            // Support for touch devices
121
            if ('touches' in e) {
122
              relativeY   = (e.touches[0].pageY - pos.top);
123
              relativeX   = (e.touches[0].pageX - pos.left);
124
            }
125

    
126
            // Attach data to element
127
            ripple.setAttribute('data-hold', Date.now());
128
            ripple.setAttribute('data-scale', scale);
129
            ripple.setAttribute('data-x', relativeX);
130
            ripple.setAttribute('data-y', relativeY);
131

    
132
            // Set ripple position
133
            var rippleStyle = {
134
                'top': relativeY+'px',
135
                'left': relativeX+'px'
136
            };
137

    
138
            ripple.className = ripple.className + ' waves-notransition';
139
            ripple.setAttribute('style', convertStyle(rippleStyle));
140
            ripple.className = ripple.className.replace('waves-notransition', '');
141

    
142
            // Scale the ripple
143
            rippleStyle['-webkit-transform'] = scale;
144
            rippleStyle['-moz-transform'] = scale;
145
            rippleStyle['-ms-transform'] = scale;
146
            rippleStyle['-o-transform'] = scale;
147
            rippleStyle.transform = scale;
148
            rippleStyle.opacity   = '1';
149

    
150
            rippleStyle['-webkit-transition-duration'] = Effect.duration + 'ms';
151
            rippleStyle['-moz-transition-duration']    = Effect.duration + 'ms';
152
            rippleStyle['-o-transition-duration']      = Effect.duration + 'ms';
153
            rippleStyle['transition-duration']         = Effect.duration + 'ms';
154

    
155
            ripple.setAttribute('style', convertStyle(rippleStyle));
156
        },
157

    
158
        hide: function(e) {
159
            TouchHandler.touchup(e);
160

    
161
            var el = this;
162
            var width = el.clientWidth * 1.4;
163

    
164
            // Get first ripple
165
            var ripple = null;
166
            var ripples = el.getElementsByClassName('waves-ripple');
167
            if (ripples.length > 0) {
168
                ripple = ripples[ripples.length - 1];
169
            } else {
170
                return false;
171
            }
172

    
173
            var relativeX   = ripple.getAttribute('data-x');
174
            var relativeY   = ripple.getAttribute('data-y');
175
            var scale       = ripple.getAttribute('data-scale');
176

    
177
            // Get delay beetween mousedown and mouse leave
178
            var diff = Date.now() - Number(ripple.getAttribute('data-hold'));
179
            var delay = 350 - diff;
180

    
181
            if (delay < 0) {
182
                delay = 0;
183
            }
184

    
185
            // Fade out ripple after delay
186
            setTimeout(function() {
187
                var style = {
188
                    'top': relativeY+'px',
189
                    'left': relativeX+'px',
190
                    'opacity': '0',
191

    
192
                    // Duration
193
                    '-webkit-transition-duration': Effect.duration + 'ms',
194
                    '-moz-transition-duration': Effect.duration + 'ms',
195
                    '-o-transition-duration': Effect.duration + 'ms',
196
                    'transition-duration': Effect.duration + 'ms',
197
                    '-webkit-transform': scale,
198
                    '-moz-transform': scale,
199
                    '-ms-transform': scale,
200
                    '-o-transform': scale,
201
                    'transform': scale
202
                };
203

    
204
                ripple.setAttribute('style', convertStyle(style));
205

    
206
                setTimeout(function() {
207
                    try {
208
                        el.removeChild(ripple);
209
                    } catch(e) {
210
                        return false;
211
                    }
212
                }, Effect.duration);
213
            }, delay);
214
        },
215

    
216
        // Little hack to make <input> can perform waves effect
217
        wrapInput: function(elements) {
218
            for (var a = 0; a < elements.length; a++) {
219
                var el = elements[a];
220

    
221
                if (el.tagName.toLowerCase() === 'input') {
222
                    var parent = el.parentNode;
223

    
224
                    // If input already have parent just pass through
225
                    if (parent.tagName.toLowerCase() === 'i' && parent.className.indexOf('waves-effect') !== -1) {
226
                        continue;
227
                    }
228

    
229
                    // Put element class and style to the specified parent
230
                    var wrapper = document.createElement('i');
231
                    wrapper.className = el.className + ' waves-input-wrapper';
232

    
233
                    var elementStyle = el.getAttribute('style');
234

    
235
                    if (!elementStyle) {
236
                        elementStyle = '';
237
                    }
238

    
239
                    wrapper.setAttribute('style', elementStyle);
240

    
241
                    el.className = 'waves-button-input';
242
                    el.removeAttribute('style');
243

    
244
                    // Put element as child
245
                    parent.replaceChild(wrapper, el);
246
                    wrapper.appendChild(el);
247
                }
248
            }
249
        }
250
    };
251

    
252

    
253
    /**
254
     * Disable mousedown event for 500ms during and after touch
255
     */
256
    var TouchHandler = {
257
        /* uses an integer rather than bool so there's no issues with
258
         * needing to clear timeouts if another touch event occurred
259
         * within the 500ms. Cannot mouseup between touchstart and
260
         * touchend, nor in the 500ms after touchend. */
261
        touches: 0,
262
        allowEvent: function(e) {
263
            var allow = true;
264

    
265
            if (e.type === 'touchstart') {
266
                TouchHandler.touches += 1; //push
267
            } else if (e.type === 'touchend' || e.type === 'touchcancel') {
268
                setTimeout(function() {
269
                    if (TouchHandler.touches > 0) {
270
                        TouchHandler.touches -= 1; //pop after 500ms
271
                    }
272
                }, 500);
273
            } else if (e.type === 'mousedown' && TouchHandler.touches > 0) {
274
                allow = false;
275
            }
276

    
277
            return allow;
278
        },
279
        touchup: function(e) {
280
            TouchHandler.allowEvent(e);
281
        }
282
    };
283

    
284

    
285
    /**
286
     * Delegated click handler for .waves-effect element.
287
     * returns null when .waves-effect element not in "click tree"
288
     */
289
    function getWavesEffectElement(e) {
290
        if (TouchHandler.allowEvent(e) === false) {
291
            return null;
292
        }
293

    
294
        var element = null;
295
        var target = e.target || e.srcElement;
296

    
297
        while (target.parentElement !== null) {
298
            if (!(target instanceof SVGElement) && target.className.indexOf('waves-effect') !== -1) {
299
                element = target;
300
                break;
301
            } else if (target.classList.contains('waves-effect')) {
302
                element = target;
303
                break;
304
            }
305
            target = target.parentElement;
306
        }
307

    
308
        return element;
309
    }
310

    
311
    /**
312
     * Bubble the click and show effect if .waves-effect elem was found
313
     */
314
    function showEffect(e) {
315
        var element = getWavesEffectElement(e);
316

    
317
        if (element !== null) {
318
            Effect.show(e, element);
319

    
320
            if ('ontouchstart' in window) {
321
                element.addEventListener('touchend', Effect.hide, false);
322
                element.addEventListener('touchcancel', Effect.hide, false);
323
            }
324

    
325
            element.addEventListener('mouseup', Effect.hide, false);
326
            element.addEventListener('mouseleave', Effect.hide, false);
327
        }
328
    }
329

    
330
    Waves.displayEffect = function(options) {
331
        options = options || {};
332

    
333
        if ('duration' in options) {
334
            Effect.duration = options.duration;
335
        }
336

    
337
        //Wrap input inside <i> tag
338
        Effect.wrapInput($$('.waves-effect'));
339

    
340
        if ('ontouchstart' in window) {
341
            document.body.addEventListener('touchstart', showEffect, false);
342
        }
343

    
344
        document.body.addEventListener('mousedown', showEffect, false);
345
    };
346

    
347
    /**
348
     * Attach Waves to an input element (or any element which doesn't
349
     * bubble mouseup/mousedown events).
350
     *   Intended to be used with dynamically loaded forms/inputs, or
351
     * where the user doesn't want a delegated click handler.
352
     */
353
    Waves.attach = function(element) {
354
        //FUTURE: automatically add waves classes and allow users
355
        // to specify them with an options param? Eg. light/classic/button
356
        if (element.tagName.toLowerCase() === 'input') {
357
            Effect.wrapInput([element]);
358
            element = element.parentElement;
359
        }
360

    
361
        if ('ontouchstart' in window) {
362
            element.addEventListener('touchstart', showEffect, false);
363
        }
364

    
365
        element.addEventListener('mousedown', showEffect, false);
366
    };
367

    
368
    return Waves;
369
});
370

    
371
// Init Waves
372
(function ($) {
373
  Drupal.behaviors.wavesInit = {
374
    attach: function (context, settings) {
375
        Waves.displayEffect();
376
    }
377
  };
378
})(jQuery);