Permalink
Browse files

If policy notes aren't present on the page then we shouldn't link the…

… update at time.
  • Loading branch information...
1 parent a8ac8c1 commit c794fc415af71a95c4b48c1c106ff5631b13465d Jason Cale committed Feb 3, 2012
@@ -1,21 +1,22 @@
(function($) {
$.fn.policyUpdateNotes = function (options) {
- var _this = $(this);
- var _link;
+ if ($(this).length > 0) {
+ var _this = $(this);
+ var _link;
- if (_link = $(options.link)) {
- _this.hide();
- if (!_link.is('a')) {
- _link.wrap('<a href="#"></a>');
- _link = _link.parent();
- };
-
- _link.click(function () {
- _this.fadeToggle();
- return false;
- })
- };
+ if (_link = $(options.link)) {
+ _this.hide();
+ if (!_link.is('a')) {
+ _link.wrap('<a href="#"></a>');
+ _link = _link.parent();
+ };
- return _this;
+ _link.click(function () {
+ _this.fadeToggle();
+ return false;
+ })
+ };
+ }
+ return $(this);
};
})(jQuery);
@@ -41,4 +41,10 @@ test("Passing an anchor in the link selector should override on click event and
ok($('.changes').is(':hidden'));
$('a.an_anchor').click();
ok($('.changes').is(':visible'));
-});
+});
+
+test("If policy change notes aren't present on the page then the link shouldn't be attached", function () {
+ $('.element-that-wont-exist').policyUpdateNotes({link: 'span.updated_at'});
+ equals($('a span.updated_at').length, 0);
+});
+

0 comments on commit c794fc4

Please sign in to comment.