automizy-js-api
Version:
JavaScript API library for Automizy Marketing Automation software
68 lines (66 loc) • 2.11 kB
JavaScript
define([], function () {
$.fn.removeAttributes = function () {
return this.each(function () {
var attributes = $.map(this.attributes, function (item) {
return item.name;
});
var img = $(this);
$.each(attributes, function (i, item) {
img.removeAttr(item);
});
});
}
$.fn.getAttributes = function () {
var obj = {};
$.each(this[0].attributes, function () {
if (this.specified) {
obj[this.name] = this.value;
}
});
return obj;
}
$.fn.removeClassPrefix = function (prefix) {
this.each(function (i, el) {
var classes = el.className.split(" ").filter(function (c) {
return c.lastIndexOf(prefix, 0) !== 0;
});
el.className = $.trim(classes.join(" "));
});
return this;
};
$.fn.ashow = function () {
this.removeClass('automizy-hide');
return this;
};
$.fn.ahide = function () {
this.addClass('automizy-hide');
return this;
};
$.fn.serializeObject = function(addUnchecked){
var result = {};
var addUnchecked = addUnchecked || false;
var extend = function (i, e) {
var n = result[e.name];
if (typeof n !== 'undefined' && n !== null) {
if ($.isArray(n)) {
n.push(e.value);
} else {
result[e.name] = [n, e.value];
}
} else {
result[e.name] = e.value;
}
};
values = this.serializeArray();
if(addUnchecked){
values = values.concat(
this.find('input[type=checkbox]:not(:checked)').map(
function() {
return {name:this.name, value:"off"}
}).get()
);
}
$.each(values, extend);
return result;
}
});