vpn.email
Version:
vpn.email client
83 lines (65 loc) • 2.42 kB
JavaScript
$.widget( "metro.group" , {
version: "3.0.0",
options: {
groupType: 'one-state', // 'multi-state'
buttonStyle: false,
onChange: function(index, btn){return true;},
onChanged: function(index, btn){}
},
_create: function () {
var that = this, element = this.element, o = this.options;
var result;
$.each(element.data(), function(key, value){
if (key in o) {
try {
o[key] = $.parseJSON(value);
} catch (e) {
o[key] = value;
}
}
});
if (!element.hasClass('group-of-buttons')) {element.addClass('group-of-buttons');}
var buttons = element.find('.button, .toolbar-button');
for(var i = 0; i < buttons.length; i++) {
$(buttons[i]).data('index', i);
}
if (o.buttonStyle !== false) {
buttons.addClass(o.buttonStyle);
}
element.on('click', '.button, .toolbar-button', function(){
var button = $(this), index = button.data('index');
if (typeof o.onChange === 'function') {
if (!o.onChange(index, button)) {return false;}
} else {
if (typeof window[o.onChange] === 'function') {
if (!window[o.onChange](index, button)) {return false;}
} else {
result = eval("(function(){"+o.onChange+"})");
if (!result.call(index, button)) {return false;}
}
}
if (o.groupType === 'one-state') {
buttons.removeClass('active');
$(this).addClass('active');
} else {
$(this).toggleClass('active');
}
if (typeof o.onChanged === 'function') {
o.onChanged(index, button);
} else {
if (typeof window[o.onChanged] === 'function') {
window[o.onChanged](index, button);
} else {
result = eval("(function(){"+o.onChanged+"})");
result.call(index, button);
}
}
});
element.data('group', this);
},
_destroy: function () {
},
_setOption: function ( key, value ) {
this._super('_setOption', key, value);
}
});