Przeglądaj źródła

implementing JS module pattern to expose functions for unit testing

El RIDO 9 lat temu
rodzic
commit
8029c2819f
3 zmienionych plików z 17 dodań i 9 usunięć
  1. 15 7
      js/privatebin.js
  2. 1 1
      tpl/bootstrap.php
  3. 1 1
      tpl/page.php

+ 15 - 7
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)));
+

+ 1 - 1
tpl/bootstrap.php

@@ -69,7 +69,7 @@ if ($MARKDOWN):
 <?php
 endif;
 ?>
-		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-n74tkij+nVUsfoO68TgNUptNTTGxVeeuMPD59XjP2yKnAnpWKQJ2GM5qZVGbtiOCc02F1IH49tJRgAyZGHETlA==" crossorigin="anonymous"></script>
+		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-BQtm9WwSHdMAGNuJYDpAICZGADZxANQ2DkJ6cXnWHlemnTq3xtdL+7cYoB/0no9Aa+PnA7JLvNTQWa+g2hIawA==" crossorigin="anonymous"></script>
 		<!--[if lt IE 10]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->

+ 1 - 1
tpl/page.php

@@ -47,7 +47,7 @@ if ($MARKDOWN):
 <?php
 endif;
 ?>
-		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-n74tkij+nVUsfoO68TgNUptNTTGxVeeuMPD59XjP2yKnAnpWKQJ2GM5qZVGbtiOCc02F1IH49tJRgAyZGHETlA==" crossorigin="anonymous"></script>
+		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-BQtm9WwSHdMAGNuJYDpAICZGADZxANQ2DkJ6cXnWHlemnTq3xtdL+7cYoB/0no9Aa+PnA7JLvNTQWa+g2hIawA==" crossorigin="anonymous"></script>
 		<!--[if lt IE 10]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->