diff --git a/src/weave.js b/src/weave.js index 1f051ba..e70dcf2 100644 --- a/src/weave.js +++ b/src/weave.js @@ -12,6 +12,7 @@ define([ "jquery", "troopjs-utils/getargs" ], function WeaveModule($, getargs) { var FUNCTION = Function; var ARRAY_PROTO = ARRAY.prototype; var JOIN = ARRAY_PROTO.join; + var PUSH = ARRAY_PROTO.push; var POP = ARRAY_PROTO.pop; var $WHEN = $.when; var THEN = "then"; @@ -108,7 +109,7 @@ define([ "jquery", "troopjs-utils/getargs" ], function WeaveModule($, getargs) { var matches; // Push dfdWeave on pending to signify we're starting a new task - pending.push(dfdWeave); + PUSH.call(pending, dfdWeave); $element // Make sure to remove DATA_WEAVE (so we don't try processing this again) @@ -237,7 +238,7 @@ define([ "jquery", "troopjs-utils/getargs" ], function WeaveModule($, getargs) { var widget; // Push dfdUnweave on pending to signify we're starting a new task - pending.push(dfdUnweave); + PUSH.call(pending, dfdUnweave); // Remove WOVEN data delete $data[WOVEN]; @@ -277,4 +278,29 @@ define([ "jquery", "troopjs-utils/getargs" ], function WeaveModule($, getargs) { return $elements; }; + + $.fn[WOVEN] = function woven(/* arg, arg */) { + var result = []; + var widgets = arguments.length > 0 + ? RegExp($.map(arguments, function (widget) { + return "^" + widget + "$"; + }).join("|"), "m") + : UNDEFINED; + + $(this).each(function elementIterator(index, element) { + if (!$.hasData(element)) { + return; + } + + PUSH.apply(result, widgets === UNDEFINED + ? $.data(element, WOVEN) + : $.map($.data(element, WOVEN), function (woven) { + return widgets.test(woven.displayName) + ? woven + : UNDEFINED; + })); + }); + + return result; + }; });