From 90e299637380b6e852aa5e4206a8fd9e98b8d5e2 Mon Sep 17 00:00:00 2001 From: VodkaBears Date: Wed, 5 Mar 2014 19:39:00 +0400 Subject: [PATCH] Return instance when calling remodal() --- demo/index.html | 19 +++++++++++++++++-- src/jquery.remodal.js | 14 +++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/demo/index.html b/demo/index.html index 6eb0e16..22a6b89 100644 --- a/demo/index.html +++ b/demo/index.html @@ -33,6 +33,15 @@

Remodal

Cancel OK + +
+

Another one window

+

+ Hello! +

+
+ Hello! +
@@ -70,8 +79,14 @@

Remodal

console.log('cancel'); }); - var inst = $.remodal.lookup[$('[data-remodal-id=modal]').data('remodal')]; - inst.open(); + // You can open or close it like this: + // var inst = $.remodal.lookup[$('[data-remodal-id=modal]').data('remodal')]; + // inst.open(); + // inst.close(); + + // Or init in this way: + var inst = $('[data-remodal-id=modal2]').remodal(); + // inst.open(); diff --git a/src/jquery.remodal.js b/src/jquery.remodal.js index b55e9c2..6011122 100644 --- a/src/jquery.remodal.js +++ b/src/jquery.remodal.js @@ -227,13 +227,21 @@ if ($) { $["fn"][pluginName] = function (opts) { - return this["each"](function (i, e) { + var instance; + this["each"](function (i, e) { var $e = $(e); if (!$e.data(pluginName)) { - var instance = new Remodal($e, opts); + instance = new Remodal($e, opts); $e.data(pluginName, instance.index); + + if (instance.settings.hashTracking && + $e.attr("data-" + pluginName + "-id") === location.hash.substr(1)) { + instance.open(); + } } }); + + return instance; }; } @@ -289,6 +297,7 @@ if ($elem.length) { var instance = $[pluginName].lookup[$elem.data(pluginName)]; + if (instance && instance.settings.hashTracking) { instance.open(); } @@ -297,5 +306,4 @@ } }; $(window).bind("hashchange." + pluginName, hashHandler); - hashHandler(null, false); })(window["jQuery"] || window["Zepto"]); \ No newline at end of file