From 9428f40422c3e4dde5f20326d76975826faef52e Mon Sep 17 00:00:00 2001 From: Kevin Mehall Date: Tue, 3 Sep 2013 16:11:55 -0400 Subject: [PATCH] Add a `.expectOne` method to jQuery objects. It asserts that the result set is exactly one element. (imported from commit c78ff131deb4a13c65c2a68e4b8e09279ece3ea0) --- static/js/util.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/static/js/util.js b/static/js/util.js index 91038e0872..05e29a9bc0 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -315,6 +315,15 @@ exports.enforce_arity = function util_enforce_arity(func) { }; }; +if (typeof $ !== 'undefined') { + $.fn.expectOne = function () { + if (blueslip && this.length !== 1) { + blueslip.error("Expected one element in jQuery set, " + this.length + " found"); + } + return this; + }; +} + return exports; }()); if (typeof module !== 'undefined') {