changeset 135:0cd87e69dd65

Reorganize.
author Edho Arief <edho@myconan.net>
date Mon, 12 Nov 2012 17:41:48 +0700
parents 3c777dbd6b11
children b327d80c5ff9
files app/assets/javascripts/init.tabs.js
diffstat 1 files changed, 34 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/app/assets/javascripts/init.tabs.js	Mon Nov 12 17:30:22 2012 +0700
+++ b/app/assets/javascripts/init.tabs.js	Mon Nov 12 17:41:48 2012 +0700
@@ -2,9 +2,7 @@
   if ($('#paste-show').length !== 1) {
     return;
   }
-  var raw = $('#plain pre').text(),
-    markdown = $('#markdown div'),
-    update_state = function() {
+  var     update_state = function() {
       var paste = $('#paste'),
         mode = paste.data('mode'),
         width = paste.data('width'),
@@ -29,27 +27,39 @@
         paste.data('width', size);
       }
       update_state();
+    },
+    paste_resize_menu_handler = function() {
+      paste_resize($(this).data('size'));
+      $('.open').removeClass('open');
+      return false;
+    },
+    paste_mode_state_handler = function() {
+      $('#paste').data('mode', $(this).prop('href').split('#')[1]);
+      update_state();
+    },
+    init_state = function() {
+      mode = window.location.hash.substr(2).split('.');
+      if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); }
+      else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); };
+      if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); }
+    },
+    init_tabs_base = function() {
+      var raw = $('#plain pre').text(),
+        markdown = $('#markdown div');
+      markdown.html(marked(raw));
+      $('#highlight pre').text(raw);
+
+      markdown.find('pre').addClass('prettyprint');
+      markdown.find('a').prop('rel', 'nofollow');
+      prettyPrint();
+    },
+    init_tabs_menu = function() {
+      $('#paste-mode a').click(paste_mode_state_handler);
+      $('#paste-resize ul a').click(paste_resize_menu_handler);
     };
 
-  markdown.html(marked(raw));
-  $('#highlight pre').text(raw);
-
-  markdown.find('pre').addClass('prettyprint');
-  markdown.find('a').prop('rel', 'nofollow');
-  prettyPrint();
-
-  $('#paste-mode a').click(function() {
-    $('#paste').data('mode', $(this).prop('href').split('#')[1]);
-    update_state();
-  });
-  $('#paste-resize ul a').click(function() {
-    paste_resize($(this).data('size'));
-    $('.open').removeClass('open');
-    return false;
-  });
-
-  mode = window.location.hash.substr(2).split('.');
-  if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); }
-  else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); };
-  if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); }
+  init_tabs_base();
+  init_tabs_menu();
+  init_state();
+  update_state();
 });