]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - app/Resources/static/themes/baggy/js/init.js
manage assets through npm
[github/wallabag/wallabag.git] / app / Resources / static / themes / baggy / js / init.js
similarity index 56%
rename from src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/init.js
rename to app/Resources/static/themes/baggy/js/init.js
index 9bdc6f2126eaf70dc5b3fec86ec02f015892f6a1..1721ae41ab392ffc1bd64827586733a904f64479 100755 (executable)
@@ -1,3 +1,9 @@
+var $ = global.jquery = require('jquery');
+require('jquery.cookie');
+require('jquery-ui');
+var annotator = require('annotator');
+
+
 $.fn.ready(function() {
 
   var $listmode = $('#listmode'),
@@ -19,7 +25,7 @@ $.fn.ready(function() {
      ========================================================================== */
 
   $listmode.click(function(){
-    if ( $.cookie("listmode") == 1 ) {
+    if ( jquery.cookie("listmode") == 1 ) {
       // Cookie
       $.removeCookie("listmode");
 
@@ -29,7 +35,7 @@ $.fn.ready(function() {
     }
     else {
       // Cookie
-      $.cookie("listmode", 1, {expires: 365});
+      jquery.cookie("listmode", 1, {expires: 365});
 
       $listentries.addClass("listmode");
       $listmode.removeClass("listmode");
@@ -42,7 +48,7 @@ $.fn.ready(function() {
      Cookie listmode
      ========================================================================== */
 
-  if ( $.cookie("listmode") == 1 ) {
+  if ( jquery.cookie("listmode") == 1 ) {
     $listentries.addClass("listmode");
     $listmode.removeClass("listmode");
     $listmode.addClass("tablemode");
@@ -60,4 +66,36 @@ $.fn.ready(function() {
        return false;
     });
 
+  /* ==========================================================================
+     Annotations & Remember position
+     ========================================================================== */
+
+    if ($("article").length) {
+        var app = new annotator.App();
+
+        app.include(annotator.ui.main, {
+            element: document.querySelector('article')
+        });
+
+        var x = JSON.parse($('#annotationroutes').html());
+        app.include(annotator.storage.http, x);
+
+        app.start().then(function () {
+             app.annotations.load({entry: x.entryId});
+        });
+
+        $(window).scroll(function(e){
+            var scrollTop = $(window).scrollTop();
+            var docHeight = $(document).height();
+            var scrollPercent = (scrollTop) / (docHeight);
+            var scrollPercentRounded = Math.round(scrollPercent*100)/100;
+            savePercent(x.entryId, scrollPercentRounded);
+        });
+
+        retrievePercent(x.entryId);
+
+        $(window).resize(function(){
+            retrievePercent(x.entryId);
+        });
+    }
 });