vpn.email
Version:
vpn.email client
125 lines (105 loc) • 3.81 kB
JavaScript
$.widget( "metro.listview" , {
version: "3.0.0",
options: {
onExpand: function(group){},
onCollapse: function(group){},
onActivate: function(list){},
onListClick: function(list){}
},
_create: function () {
var that = this, element = this.element, o = this.options;
$.each(element.data(), function(key, value){
if (key in o) {
try {
o[key] = $.parseJSON(value);
} catch (e) {
o[key] = value;
}
}
});
this._initList();
this._createEvents();
element.data('listview', this);
},
_initList: function(){
var that = this, element = this.element, o = this.options;
var groups = element.find('.list-group');
$.each(groups, function(){
var group = $(this);
if (group.hasClass('collapsed')) {
group.find('.list-group-content').hide();
}
});
},
_createEvents: function(){
var that = this, element = this.element, o = this.options;
element.on('click', '.list-group-toggle', function(e){
var toggle = $(this), parent = toggle.parent();
var result;
if (toggle.parent().hasClass('keep-open')) {
return;
}
parent.toggleClass('collapsed');
if (!parent.hasClass('collapsed')) {
toggle.siblings('.list-group-content').slideDown('fast');
if (typeof o.onExpand === 'function') {
o.onExpand(parent);
} else {
if (typeof window[o.onExpand] === 'function') {
window[o.onExpand](parent);
} else {
result = eval("(function(){"+o.onExpand+"})");
result.call(parent);
}
}
} else {
toggle.siblings('.list-group-content').slideUp('fast');
if (typeof o.onCollapse === 'function') {
o.onCollapse(parent);
} else {
if (typeof window[o.onCollapse] === 'function') {
window[o.onCollapse](parent);
} else {
result = eval("(function(){"+o.onCollapse+"})");
result.call(parent);
}
}
}
e.preventDefault();
e.stopPropagation();
});
element.on('click', '.list', function(e){
var list = $(this);
var result;
element.find('.list').removeClass('active');
list.addClass('active');
if (typeof o.onActivate === 'function') {
o.onActivate(list);
} else {
if (typeof window[o.onActivate] === 'function') {
window[o.onActivate](list);
} else {
result = eval("(function(){"+o.onActivate+"})");
result.call(list);
}
}
if (typeof o.onListClick === 'function') {
o.onListClick(list);
} else {
if (typeof window[o.onListClick] === 'function') {
window[o.onListClick](list);
} else {
result = eval("(function(){"+o.onListClick+"})");
result.call(list);
}
}
e.preventDefault();
e.stopPropagation();
});
},
_destroy: function () {
},
_setOption: function ( key, value ) {
this._super('_setOption', key, value);
}
});