2016-02-08 15:41:00 +01:00
|
|
|
/*! Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-02-18 19:34:39 +01:00
|
|
|
|
2014-03-26 08:40:41 +01:00
|
|
|
/* jQuery Plugins */
|
2014-03-04 14:07:28 +01:00
|
|
|
(function ($) {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2019-07-29 15:58:41 +02:00
|
|
|
/* Get data value or default */
|
|
|
|
$.fn.getData = function (name, fallback) {
|
|
|
|
var value = this.data(name);
|
|
|
|
if (typeof value !== 'undefined') {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fallback;
|
|
|
|
};
|
|
|
|
|
2014-08-19 12:22:36 +02:00
|
|
|
/* Whether a HTML tag has a specific attribute */
|
|
|
|
$.fn.hasAttr = function(name) {
|
|
|
|
// We have inconsistent behaviour across browsers (false VS undef)
|
|
|
|
var val = this.attr(name);
|
|
|
|
return typeof val !== 'undefined' && val !== false;
|
|
|
|
};
|
|
|
|
|
2014-03-26 08:40:41 +01:00
|
|
|
/* Get class list */
|
2014-03-04 14:07:28 +01:00
|
|
|
$.fn.classes = function (callback) {
|
|
|
|
|
|
|
|
var classes = [];
|
|
|
|
|
|
|
|
$.each(this, function (i, el) {
|
|
|
|
var c = $(el).attr('class');
|
|
|
|
if (typeof c === 'string') {
|
|
|
|
$.each(c.split(/\s+/), function(i, p) {
|
|
|
|
if (classes.indexOf(p) === -1) {
|
|
|
|
classes.push(p);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
for (var i in classes) {
|
|
|
|
if (classes.hasOwnProperty(i)) {
|
|
|
|
callback(classes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return classes;
|
|
|
|
};
|
|
|
|
|
2014-03-26 08:40:41 +01:00
|
|
|
/* Serialize form elements to an object */
|
|
|
|
$.fn.serializeObject = function()
|
|
|
|
{
|
|
|
|
var o = {};
|
|
|
|
var a = this.serializeArray();
|
|
|
|
$.each(a, function() {
|
|
|
|
if (o[this.name] !== undefined) {
|
|
|
|
if (!o[this.name].push) {
|
|
|
|
o[this.name] = [o[this.name]];
|
|
|
|
}
|
|
|
|
o[this.name].push(this.value || '');
|
|
|
|
} else {
|
|
|
|
o[this.name] = this.value || '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return o;
|
|
|
|
};
|
|
|
|
|
2014-03-04 14:07:28 +01:00
|
|
|
})(jQuery);
|