From b9dc51437d2c5fdf8652abf3602003a3935d6188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xoan=20Sampai=C3=B1o?= Date: Wed, 27 Jun 2012 18:29:24 +0200 Subject: [PATCH] Added data(attr) and data(attr, val) functions to jquery compat plugin --- jquery-compat/README.md | 2 +- jquery-compat/jquery-compat.js | 63 ++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/jquery-compat/README.md b/jquery-compat/README.md index 036f1fd..744cad9 100644 --- a/jquery-compat/README.md +++ b/jquery-compat/README.md @@ -1,3 +1,3 @@ jQuery Compatibility Plug-In for XUI ------------- -Adds functions `add`, `end`, `show` and `hide`, for compatibility with jQuery. +Adds functions `add`, `end`, `show`, `hide` and `data`, for compatibility with jQuery. diff --git a/jquery-compat/jquery-compat.js b/jquery-compat/jquery-compat.js index 9dd905b..67b3582 100644 --- a/jquery-compat/jquery-compat.js +++ b/jquery-compat/jquery-compat.js @@ -1,28 +1,41 @@ xui.extend({ - /** - * Adds more DOM nodes to the existing element list. - */ - add: function(q) { - [].push.apply(this, slice(xui(q))); - return this.set(this.reduce()); - }, + /** + * Adds more DOM nodes to the existing element list. + */ + add: function(q) { + [].push.apply(this, slice(xui(q))); + return this.set(this.reduce()); + }, - /** - * Pops the last selector from XUI - */ - end: function () { - return this.set(this.cache || []); - }, - /** - * Sets the `display` CSS property to `block`. - */ - show:function() { - return this.setStyle('display','block'); - }, - /** - * Sets the `display` CSS property to `none`. - */ - hide:function() { - return this.setStyle('display','none'); - } + /** + * Pops the last selector from XUI + */ + end: function () { + return this.set(this.cache || []); + }, + + /** + * Sets the `display` CSS property to `block`. + */ + show: function() { + return this.setStyle('display','block'); + }, + + /** + * Sets the `display` CSS property to `none`. + */ + hide: function() { + return this.setStyle('display','none'); + }, + + /** + * Gets or sets `data` attributes on elements. + */ + data: function(attr, val) { + if (arguments.length == 2) { + return this.attr('data-' + attr, val); + } else { + return this.attr('data-' + attr); + } + } });