1. Takafumi Arakaki
  2. neorg

Commits

Takafumi Arakaki  committed 5514650

simplified neorg.js using closure and tweaked bound function to prevent scrolling by arrow keys during navigation.

  • Participants
  • Parent commits 82b7f21
  • Branches default

Comments (0)

Files changed (1)

File neorg/static/neorg.js

View file
-function openFirstImageByColorBox() {
-    $.colorbox($.extend({}, neorgCBSetting, {
-        href: $('img.neorg-gene-image').first().attr('src')
-    }));
-}
-
 function neorgCBOpen(arrow) {
     var otd, oa;
     var ctd = $.colorbox.element().parent();
     }
 }
 
-function neorgCBOpenLeft() {
-    neorgCBOpen('left');
-}
-
-function neorgCBOpenRight() {
-    neorgCBOpen('right');
-}
-
-function neorgCBOpenUp() {
-    neorgCBOpen('up');
-}
-
-function neorgCBOpenDown() {
-    neorgCBOpen('down');
-}
-
 function bindKeydown(key, func) {
     $(document).bind('keydown.neorg.' + key, key, func);
 }
 
-function unBindKeydown(key, func) {
+function bindKeydownToNeorgCBOpen(key) {
+    bindKeydown(key, function(e) {
+        e.preventDefault();
+        neorgCBOpen(key);
+    });
+}
+
+function unBindKeydown(key) {
     $(document).unbind('keydown.neorg.' + key);
 }
 
 });
 
 
+var arrowKeyArray = ['left', 'right', 'up', 'down']
+
 var neorgCBSetting = {
     title: function() {
         $(this).attr('title', $(this).prev('p').text());
     fixed: true,
     onOpen: function() {
         // alert('onOpen');
-        bindKeydown('left', neorgCBOpenLeft);
-        bindKeydown('right', neorgCBOpenRight);
-        bindKeydown('up', neorgCBOpenUp);
-        bindKeydown('down', neorgCBOpenDown);
+        var i;
+        for (i in arrowKeyArray) {
+            bindKeydownToNeorgCBOpen(arrowKeyArray[i]);
+        }
     },
     onClosed: function() {
         // alert('onClosed');
-        unBindKeydown('left');
-        unBindKeydown('right');
-        unBindKeydown('up');
-        unBindKeydown('down');
+        var i;
+        for (i in arrowKeyArray) {
+            unBindKeydown(arrowKeyArray[i]);
+        }
     }
 };