UNPKG

vpn.email

Version:
109 lines (85 loc) 3.3 kB
$.fn.reverse = Array.prototype.reverse; $.Metro = { initWidgets: function(widgets) { $.each(widgets, function () { var $this = $(this), w = this; var roles = $this.data('role').split(/\s*,\s*/); roles.map(function (func) { try { //$(w)[func](); if ($.fn[func] !== undefined && $this.data(func + '-initiated') !== true) { $.fn[func].call($this); $this.data(func + '-initiated', true); } } catch (e) { if (window.METRO_DEBUG) { console.log(e.message, e.stack); } } }); }); }, initHotkeys: function(hotkeys){ $.each(hotkeys, function(){ var element = $(this); var hotkey = element.data('hotkey').toLowerCase(); //if ($.Metro.hotkeys.indexOf(hotkey) > -1) { // return; //} if (element.data('hotKeyBonded') === true ) { return; } $.Metro.hotkeys.push(hotkey); $(document).on('keyup', null, hotkey, function(e){ if (element === undefined) return; if (element[0].tagName === 'A' && element.attr('href') !== undefined && element.attr('href').trim() !== '' && element.attr('href').trim() !== '#') { document.location.href = element.attr('href'); } else { element.click(); } return false; }); element.data('hotKeyBonded', true); }); }, init: function(){ var widgets = $("[data-role]"); var hotkeys = $("[data-hotkey]"); $.Metro.initHotkeys(hotkeys); $.Metro.initWidgets(widgets); var observer, observerOptions, observerCallback; observerOptions = { 'childList': true, 'subtree': true }; observerCallback = function(mutations){ //console.log(mutations); mutations.map(function(record){ if (record.addedNodes) { /*jshint loopfunc: true */ var obj, widgets, plugins, hotkeys; for(var i = 0, l = record.addedNodes.length; i < l; i++) { obj = $(record.addedNodes[i]); plugins = obj.find("[data-role]"); hotkeys = obj.find("[data-hotkey]"); $.Metro.initHotkeys(hotkeys); if (obj.data('role') !== undefined) { widgets = $.merge(plugins, obj); } else { widgets = plugins; } if (widgets.length) { $.Metro.initWidgets(widgets); } } } }); }; //console.log($(document)); observer = new MutationObserver(observerCallback); observer.observe(document, observerOptions); } };