From 8029c2819f67572cf1c4adaf0e71861f59dd9065 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 22 Jan 2017 10:42:11 +0100 Subject: [PATCH] implementing JS module pattern to expose functions for unit testing --- js/privatebin.js | 22 +++++++++++++++------- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 7e4de064..59417512 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -25,7 +25,7 @@ // Immediately start random number generator collector. sjcl.random.startCollectors(); -$(function() { +jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { /** * static helper methods * @@ -1782,9 +1782,17 @@ $(function() { } } - /** - * main application start, called when DOM is fully loaded - * runs privatebin when translations were loaded - */ - i18n.loadTranslations($.proxy(privatebin.init, privatebin)); -}); + return { + helper: helper, + i18n: i18n, + filter: filter, + privatebin: privatebin + }; +}(jQuery, sjcl, Base64, RawDeflate); + +/** + * main application start, called when DOM is fully loaded + * runs privatebin when translations were loaded + */ +jQuery(jQuery.PrivateBin.i18n.loadTranslations(jQuery.proxy(jQuery.PrivateBin.privatebin.init, jQuery.PrivateBin.privatebin))); + diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 04f03668..3d51379c 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index bc18c41c..40c3e124 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - +