diff --git a/element.methods.js b/element.methods.js index ce701bf..df37f30 100644 --- a/element.methods.js +++ b/element.methods.js @@ -151,4 +151,38 @@ Element.Methods.enableClassName = function(element, className, condition) { return Element[condition ? 'addClassName' : 'removeClassName'](element, className); }; +/** + * Element.wrapContent(@element, wrapper, attributes) -> @element + * + * Wraps element's content with wrapper (i.e. a DOMElement or an html string) + * + * + *
+ * some content some tag
+ *
+ * ...
+ * $('foo').wrapContent('');
+ * ...
+ *
+ *
+ * some content some tag
+ *
+ *
+ *
+ **/
+Element.Methods.wrapContent = function(element, wrapper, attributes) {
+ if (!(element = $(element))) return;
+ if (Object.isElement(wrapper))
+ $(wrapper).writeAttribute(attributes || { })
+ else if (Object.isString(wrapper))
+ wrapper = new Element(wrapper, attributes);
+ else wrapper = new Element('div', wrapper);
+
+ while (element.firstChild)
+ wrapper.appendChild(element.firstChild)
+
+ element.appendChild(wrapper);
+ return element;
+};
+
Element.addMethods();
\ No newline at end of file
diff --git a/function.extensions.js b/function.extensions.js
index cebbe06..3384bd0 100644
--- a/function.extensions.js
+++ b/function.extensions.js
@@ -1,15 +1,15 @@
/**
- * Function#negate() -> Function
+ * Function#not() -> Function
*
* Returns negated function
*
* Find all hidden elements:
*
* $$('*').findAll(function(element) { return !element.visible() }); // old way
- * $$('*').findAll(Element.visible.negate()); // using negate
+ * $$('*').findAll(Element.visible.not()); // using not
*
**/
-Function.prototype.negate = function() {
+Function.prototype.not = function() {
var f = this;
return function() {
return !f.apply(f, arguments);
@@ -44,7 +44,7 @@ Function.prototype.runOnce = function() {
*
**/
Function.prototype._new = function() {
- var __method = this, args = arguments;
+ var __method = this, args = $A(arguments);
function C() { return __method.apply(this, args); };
C.prototype = __method.prototype;
return new C;
diff --git a/test/function.extensions.html b/test/function.extensions.html
index a586bf6..192c26f 100644
--- a/test/function.extensions.html
+++ b/test/function.extensions.html
@@ -21,16 +21,16 @@