SHARE
TWEET

Untitled

a guest May 1st, 2014 16 Never
  1. /*
  2.  * On-Hover-Menu (OHM)
  3.  */
  4.  
  5. Ohm = {
  6.         init: function(){
  7.                 Ohm.preload([  // Preload images for non-lag during hover
  8.                         'https://dl.dropboxusercontent.com/u/931983/chan/favorite.png',
  9.                         'https://dl.dropboxusercontent.com/u/931983/chan/mode.png',
  10.                         'https://dl.dropboxusercontent.com/u/931983/chan/contextmenu.png'
  11.                 ]);
  12.                 OhmThumbs.add(); // Add all thumbs on page
  13.                 OhmThumbFooter.init();
  14.                 OhmThumbToolbar.init();
  15.                 OhmThumbContextMenu.init();
  16.                 OhmThumbsListener.apply();
  17.         },
  18.         preload: function(arrayOfImages) {
  19.                 jQuery(arrayOfImages).each(function(){
  20.                         jQuery('<img/>')[0].src = this;
  21.                 });
  22.         },
  23. };
  24.  
  25. OhmOptions = { // Default options
  26.         toolbar: {
  27.                 display: true, // Display toolbar?
  28.                 mode: 0, // Current mode
  29.                 parenting: false // Display parenting icons
  30.         },
  31.         footer: true,
  32.        
  33.         translations: {
  34.                 language: "e",
  35.                 "Add to favorites": "Add to favorites desu",
  36.         },
  37.        
  38.         trans: function(english){ // return japanese or english translation
  39.                 return english;
  40.         },
  41.        
  42.         init: function(){ // overwrite default options with options from the cookies
  43.        
  44.         },
  45. };
  46.  
  47. OhmThumbs = {
  48.         current: undefined, // Currently hovered thumb
  49.         chosen: undefined, // Currently chosen thumb
  50.         all: {}, // All thumbs
  51.         last: {}, // Last added thumbs
  52.        
  53.         add: function(thumbs){
  54.                
  55.                 OhmThumbs.last = {}; //  Empty last added thumbs
  56.        
  57.                 if(!thumbs) { // Get all thumbs from page if no thumbs provided
  58.                         thumbs = jQuery('.thumb');
  59.                 }
  60.                
  61.                 thumbs.each(function(){ // Create div, set ids and push them in the database
  62.                
  63.                         var obj = jQuery(this);
  64.                         if(!obj.data("hasOhm")){ // If thumb doesnt have Ohm
  65.                         obj.data("hasOhm", true)
  66.                        
  67.                         var thumb = {};
  68.                        
  69.                         // Get post-id and generate ohmid
  70.                         thumb.ohmid = obj.attr('id').substr(1); // Id of the ohm containers
  71.                         thumb.id = thumb.ohmid; // Post id
  72.                         while(OhmThumbs.all[thumb.ohmid]){ // While defined
  73.                                 thumb.ohmid = thumb.ohmid + "n";
  74.                         }
  75.                         obj.data("ohmid", thumb.ohmid);
  76.                        
  77.                         thumb.src = obj.find("img").attr("src");
  78.                        
  79.                         // Get thumb-info out of the title
  80.                         var title = obj.find("img").attr("title");
  81.                         var parts = /(.*) Rating:(\w)\w+ Score:(\S+) Size:(\d+)x(\d+) User:(.*)/.exec(title);
  82.                         thumb.tags = parts[1];
  83.                         thumb.rating = parts[2].toLowerCase();
  84.                         thumb.score = parts[3];
  85.                         thumb.width = parseInt(parts[4]);
  86.                         thumb.height = parseInt(parts[5]);
  87.                         thumb.user = parts[6];
  88.                         obj.find("img").attr("title", ""); // suppress the current tooltip
  89.                        
  90.                         // Set css of thumb
  91.                         obj.css({
  92.                                 position: "relative",
  93.                         });
  94.                        
  95.                         // Create div-containers
  96.                         obj.prepend('<div id="abovethumb-'+thumb.ohmid+'" class="ohmAboveThumb"></div>');
  97.                         obj.append('<div id="belowthumb-'+thumb.ohmid+'" class="ohmBelowThumb"></div>');
  98.                        
  99.                         thumb.obj = obj;
  100.                        
  101.                         // Add thumb
  102.                         OhmThumbs.last[thumb.ohmid] = thumb;
  103.                         OhmThumbs.all[thumb.ohmid] = thumb;
  104.                         }
  105.                 });
  106.                
  107.         },
  108. };
  109.  
  110. OhmThumbsListener = {
  111.         apply: function(last){ // Apply listener to all thumbs
  112.                
  113.                 var thumbs = {};
  114.                 if(!last) {
  115.                         thumbs = OhmThumbs.all;
  116.                 }
  117.                 else{
  118.                         thumbs = OhmThumbs.last;
  119.                 }
  120.                
  121.                 for(var ohmid in thumbs){
  122.                         var thumb = thumbs[ohmid];
  123.                         var obj = thumb.obj;
  124.                         if(obj) { // if defined
  125.                                 obj.mouseenter(function(event){
  126.                                         console.log("enter")
  127.                                         var ohmid = jQuery(this).data("ohmid");
  128.                                         OhmThumbs.current = OhmThumbs.all[ohmid];
  129.                                        
  130.                                         OhmThumbFooter.placeToCurrent();
  131.                                         OhmThumbFooter.show();
  132.                                        
  133.                                         OhmThumbToolbar.placeToCurrent();
  134.                                         OhmThumbToolbar.show();
  135.                                 });
  136.                                
  137.                                 obj.mouseleave(function(event){
  138.                                         OhmThumbFooter.hide();
  139.                                         OhmThumbToolbar.hide();
  140.                                         OhmThumbContextMenu.hide();
  141.                                 });
  142.                         }
  143.                 }
  144.         },
  145. };
  146.  
  147. OhmThumbFooter = {
  148.         init: function() { // Create footer and append it to body
  149.                 jQuery(document.body).append('<div id="ohmThumbFooter"></div>');
  150.         },
  151.        
  152.         show: function() {
  153.                 jQuery("#ohmThumbFooter").show();
  154.         },
  155.        
  156.         hide: function() {
  157.                 jQuery("#ohmThumbFooter").hide();
  158.         },
  159.        
  160.         placeToCurrent: function() { // Place the footer to currently hovered thumb
  161.                 var footer = jQuery("#ohmThumbFooter");
  162.                 var thumb = OhmThumbs.current;
  163.                
  164.                 footer.html(thumb.width + 'x' + thumb.height + ' / ' + thumb.rating + ' / ' + thumb.user);
  165.                 thumb.obj.append(footer);
  166.         },
  167.        
  168. };
  169.  
  170. OhmThumbToolbar = {
  171.         init: function() { // Create toolbar and append it to body
  172.                 jQuery(document.body).append('<div id="ohmThumbToolbar"><a href="javascript:OhmThumbActions.favoriteCurrent();" id="ohmThumbToolbarFavoriteIcon" title="Add to favorites"></a><a href="javascript:OhmThumbActions.executeMode();" id="ohmThumbToolbarModeIcon" title="No mode selected" ></a><a href="javascript:OhmThumbActions.displayContextMenu();" id="ohmThumbToolbarContextMenuIcon" title="Open context menu"></a></div>');
  173.         },
  174.        
  175.         show: function() {
  176.                 jQuery("#ohmThumbToolbar").show();
  177.         },
  178.        
  179.         hide: function() {
  180.                 jQuery("#ohmThumbToolbar").hide();
  181.         },
  182.        
  183.         placeToCurrent: function() {
  184.                 var toolbar = jQuery("#ohmThumbToolbar");
  185.                 var thumb = OhmThumbs.current;
  186.                 thumb.obj.append(toolbar);
  187.         },
  188. };
  189.  
  190. OhmThumbContextMenu = {
  191.         init: function(){ // Create contextmenu and append it to body
  192.                 jQuery(document.body).append('<div id="ohmThumbContextMenu">Mode Options:<br><a href="javascript:OhmThumbActions.openPreview();">Open preview</a><br><a href="javascript:OhmThumbActions.quickEdit();">Quick edit</a><br><a href="javascript:OhmThumbActions.flagPost();">Flag post</a><br><a href="javascript:OhmThumbActions.editTagScript();">Edit tag script</a><br><a href="javascript:OhmThumbActions.applyTagScript();">Apply tag script</a><br><a href="javascript:OhmThumbActions.findSimilar();">Find similar posts</a><br><br>Change content rating:<br><div id="ohmThumbsContextMenuChangeRating"></div><br><br>Advanced operations:<br><a href="javascript:OhmThumbActions.choose();">Choose post</a><br><a href="javascript:OhmThumbActions.choose();">Set as child</a><br><a href="javascript:OhmThumbActions.choose();">Set as parent</a><br><a href="javascript:OhmThumbActions.choose();">Merge tags with chosen</a><br><a href="javascript:OhmThumbActions.choose();">Merge tags with parent</a><br><a href="javascript:OhmThumbActions.choose();">Toggle parenting icons</a><br><a href="javascript:OhmThumbActions.choose();">Toggle parenting infos</a><br></div>')
  193.         },
  194.        
  195.         show: function() {
  196.                 jQuery("#ohmThumbContextMenu").show();
  197.         },
  198.        
  199.         hide: function() {
  200.                 jQuery("#ohmThumbContextMenu").hide().removeClass("left");
  201.         },
  202.        
  203.         isVisible: function() {
  204.                 return jQuery("#ohmThumbContextMenu").is(":visible");
  205.         },
  206.        
  207.         placeToCurrent: function() {
  208.                 var contextmenu = jQuery("#ohmThumbContextMenu");
  209.                 var thumb = OhmThumbs.current;
  210.                 thumb.obj.append(contextmenu);
  211.         },
  212. };
  213.  
  214. OhmInfoBox = {
  215.  
  216. };
  217.  
  218. OhmEditBox = {
  219.  
  220. };
  221.  
  222. OhmThumbActions = {
  223.         displayContextMenu: function(){
  224.                 if(OhmThumbContextMenu.isVisible()) {
  225.                         OhmThumbContextMenu.hide();
  226.                 }
  227.                 else {
  228.                         OhmThumbContextMenu.placeToCurrent();
  229.                         var w = jQuery(document).width();
  230.                         OhmThumbContextMenu.show();
  231.                         var ocm = jQuery("#ohmThumbContextMenu").offset().left;
  232.                         var wcm = jQuery("#ohmThumbContextMenu").width();
  233.                        
  234.                         console.log(ocm+wcm);
  235.                        
  236.                         if(w < ocm+wcm) { // If context menu is outside of document to the right
  237.                                 jQuery("#ohmThumbContextMenu").addClass("left");
  238.                         }
  239.                 }
  240.         },
  241. };
  242.  
  243.  
  244. jQuery(document).ready(function(){
  245.  
  246.         console.log('ok');
  247.        
  248.         Ohm.init();
  249.        
  250.         console.log('end');
  251. });
RAW Paste Data
Top