'use strict';
var _Object$keys = require('babel-runtime/core-js/object/keys')['default'];
var elements = require('../elements');
var Element = require('../element');
var ElementsArray = require('../elements_array');
/**
* Prefer use of {@link ElementsArray#getAttribute} and {@link ElementsArray#setAttribute}
* <pre><code>
* .attr(values)
* .attr(name, value)
* </code></pre>
* @name ElementsArray#attr
* @method
*/
/**
* Prefer use of {@link ElementsArray#getProperty} and {@link ElementsArray#setProperty}
* <pre><code>
* .prop(properties)
* .prop(name, value)
* </code></pre>
*
* @name ElementsArray#prop
* @method
*/
/**
* Prefer use of {@link ElementsArray#getStyle} and {@link ElementsArray#setStyle}
* <pre><code>
* .style(properties)
* .style(name, value)
* </code></pre>
*
* @name ElementsArray#style
* @method
*/
/**
* Prefer use of {@link Element#getAttribute} and {@link Element#setAttribute}
* <pre><code>
* .attr(values)
* .attr(name, value)
* .attr(name)
* </code></pre>
*
* @name Element#attr
* @method
*/
/**
* Prefer use of {@link Element#getProperty} and {@link Element#setProperty}
* <pre><code>
* .prop(properties)
* .prop(name, value)
* .prop(name)
* </code></pre>
*
* @name Element#prop
* @method
*/
/**
* Prefer use of {@link Element#getStyle} and {@link Element#setStyle}
* <pre><code>
* .style(properties)
* .style(name, value)
* .style(name)
* </code></pre>
*
* @name Element#style
* @method
*
*
*/
var _methodCalledToMethodSuffix = {
attr: 'Attribute',
prop: 'Property',
style: 'Style'
};
'attr prop style'.split(' ').forEach( /** @function
* @param mName */function (mName) {
var mEltSuffix = _methodCalledToMethodSuffix[mName];
Element.prototype[mName] = /** @function
* @param name
* @param value */function (name, value) {
if (arguments.length === 1) {
if (typeof name === 'object') {
var elt = this[0],
fn = elements['set' + mEltSuffix];
_Object$keys(name).forEach(name, /** @function
* @param key */function (key) {
fn.call(null, elt, key, name[key]);
});
return this;
}
return elements['get' + mEltSuffix].call(null, this[0], name);
}
elements['set' + mEltSuffix].call(null, this[0], name, value);
return this;
};
ElementsArray.prototype[mName] = /** @function
* @param name
* @param value */function (name, value) {
/*#if DEV*/
if (value === undefined) {
throw new Error('Cannot get ' + mName + ' from an list of elements');
}
/*#/if*/
this._forEach( /** @function
* @param e */function (e) {
elements['set' + mEltSuffix].call(null, e, name, value);
});
return this;
};
Element.prototype[mName].displayName = ElementsArray.prototype[mName].displayName = mName;
});
('setAttributes setAttribute setProperty setClass setId addClass removeClass toggleClass' + ' setValue setStyle').split(' ').forEach( /** @function
* @param mName */function (mName) {
elements.addMethodWithArgumentsReturnThis(mName);
});
/**
* Get the value of an element
*
* @name Element#getValue
* @method
* @return {*}
*/
/**
* Get the inner content as html
* @name Element#getHtml
* @method
* @return {String|null}
*/
/**
* Get the inner content as text
* @name Element#getText
* @method
* @return {String|null}
*/
'getValue getHtml getText'.split(' ').forEach( /** @function
* @param mName */function (mName) {
Element.prototype[mName] = /** @function */function () {
return elements[mName].call(null, this[0]);
};
Element.prototype[mName].displayName = mName;
try {
Element.prototype[mName].name = mName;
} catch (e) {} // some browsers doesn't like redefining the name of a function
});
/**
* Get an attribute of an element
*
* @name Element#getAttribute
* @method
* @param {string} attributeName
* @return {string}
*/
/**
* Get a property of an element
*
* @name Element#getProperty
* @method
* @param {string} propertyName
* @return {*}
*/
'getAttribute getProperty matches hasClass getStyle getIntStyle'.split(' ').forEach( /** @function
* @param mName */function (mName) {
elements.addElementMethodWithArgumentsReturnResult(mName);
});
/**
* Remove an attribute of an element
*
* @name Element#removeAttribute
* @method
* @param {string} attributeName
* @return {Element}
*/
'removeAttribute'.split(' ').forEach( /** @function
* @param mName */function (mName) {
Element.prototype[mName] = /** @function
* @param arg */function (arg) {
elements[mName].call(null, this[0], arg);
return this;
};
Element.prototype[mName].displayName = mName;
try {
Element.prototype[mName].name = mName;
} catch (e) {} // some browsers doesn't like redefining the name of a function
});
//# sourceMappingURL=dom.js.map |