Pastebin PRO Accounts 2016 NEW YEARS SPECIAL! For a limited time only get 40% discount on a LIFETIME PRO account!
SHARE
TWEET
Untitled
a guest
May 1st, 2014
16
Never
- /*
- * On-Hover-Menu (OHM)
- */
- Ohm = {
- init: function(){
- Ohm.preload([ // Preload images for non-lag during hover
- 'https://dl.dropboxusercontent.com/u/931983/chan/favorite.png',
- 'https://dl.dropboxusercontent.com/u/931983/chan/mode.png',
- 'https://dl.dropboxusercontent.com/u/931983/chan/contextmenu.png'
- ]);
- OhmThumbs.add(); // Add all thumbs on page
- OhmThumbFooter.init();
- OhmThumbToolbar.init();
- OhmThumbContextMenu.init();
- OhmThumbsListener.apply();
- },
- preload: function(arrayOfImages) {
- jQuery(arrayOfImages).each(function(){
- jQuery('<img/>')[0].src = this;
- });
- },
- };
- OhmOptions = { // Default options
- toolbar: {
- display: true, // Display toolbar?
- mode: 0, // Current mode
- parenting: false // Display parenting icons
- },
- footer: true,
- translations: {
- language: "e",
- "Add to favorites": "Add to favorites desu",
- },
- trans: function(english){ // return japanese or english translation
- return english;
- },
- init: function(){ // overwrite default options with options from the cookies
- },
- };
- OhmThumbs = {
- current: undefined, // Currently hovered thumb
- chosen: undefined, // Currently chosen thumb
- all: {}, // All thumbs
- last: {}, // Last added thumbs
- add: function(thumbs){
- OhmThumbs.last = {}; // Empty last added thumbs
- if(!thumbs) { // Get all thumbs from page if no thumbs provided
- thumbs = jQuery('.thumb');
- }
- thumbs.each(function(){ // Create div, set ids and push them in the database
- var obj = jQuery(this);
- if(!obj.data("hasOhm")){ // If thumb doesnt have Ohm
- obj.data("hasOhm", true)
- var thumb = {};
- // Get post-id and generate ohmid
- thumb.ohmid = obj.attr('id').substr(1); // Id of the ohm containers
- thumb.id = thumb.ohmid; // Post id
- while(OhmThumbs.all[thumb.ohmid]){ // While defined
- thumb.ohmid = thumb.ohmid + "n";
- }
- obj.data("ohmid", thumb.ohmid);
- thumb.src = obj.find("img").attr("src");
- // Get thumb-info out of the title
- var title = obj.find("img").attr("title");
- var parts = /(.*) Rating:(\w)\w+ Score:(\S+) Size:(\d+)x(\d+) User:(.*)/.exec(title);
- thumb.tags = parts[1];
- thumb.rating = parts[2].toLowerCase();
- thumb.score = parts[3];
- thumb.width = parseInt(parts[4]);
- thumb.height = parseInt(parts[5]);
- thumb.user = parts[6];
- obj.find("img").attr("title", ""); // suppress the current tooltip
- // Set css of thumb
- obj.css({
- position: "relative",
- });
- // Create div-containers
- obj.prepend('<div id="abovethumb-'+thumb.ohmid+'" class="ohmAboveThumb"></div>');
- obj.append('<div id="belowthumb-'+thumb.ohmid+'" class="ohmBelowThumb"></div>');
- thumb.obj = obj;
- // Add thumb
- OhmThumbs.last[thumb.ohmid] = thumb;
- OhmThumbs.all[thumb.ohmid] = thumb;
- }
- });
- },
- };
- OhmThumbsListener = {
- apply: function(last){ // Apply listener to all thumbs
- var thumbs = {};
- if(!last) {
- thumbs = OhmThumbs.all;
- }
- else{
- thumbs = OhmThumbs.last;
- }
- for(var ohmid in thumbs){
- var thumb = thumbs[ohmid];
- var obj = thumb.obj;
- if(obj) { // if defined
- obj.mouseenter(function(event){
- console.log("enter")
- var ohmid = jQuery(this).data("ohmid");
- OhmThumbs.current = OhmThumbs.all[ohmid];
- OhmThumbFooter.placeToCurrent();
- OhmThumbFooter.show();
- OhmThumbToolbar.placeToCurrent();
- OhmThumbToolbar.show();
- });
- obj.mouseleave(function(event){
- OhmThumbFooter.hide();
- OhmThumbToolbar.hide();
- OhmThumbContextMenu.hide();
- });
- }
- }
- },
- };
- OhmThumbFooter = {
- init: function() { // Create footer and append it to body
- jQuery(document.body).append('<div id="ohmThumbFooter"></div>');
- },
- show: function() {
- jQuery("#ohmThumbFooter").show();
- },
- hide: function() {
- jQuery("#ohmThumbFooter").hide();
- },
- placeToCurrent: function() { // Place the footer to currently hovered thumb
- var footer = jQuery("#ohmThumbFooter");
- var thumb = OhmThumbs.current;
- footer.html(thumb.width + 'x' + thumb.height + ' / ' + thumb.rating + ' / ' + thumb.user);
- thumb.obj.append(footer);
- },
- };
- OhmThumbToolbar = {
- init: function() { // Create toolbar and append it to body
- 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>');
- },
- show: function() {
- jQuery("#ohmThumbToolbar").show();
- },
- hide: function() {
- jQuery("#ohmThumbToolbar").hide();
- },
- placeToCurrent: function() {
- var toolbar = jQuery("#ohmThumbToolbar");
- var thumb = OhmThumbs.current;
- thumb.obj.append(toolbar);
- },
- };
- OhmThumbContextMenu = {
- init: function(){ // Create contextmenu and append it to body
- 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>')
- },
- show: function() {
- jQuery("#ohmThumbContextMenu").show();
- },
- hide: function() {
- jQuery("#ohmThumbContextMenu").hide().removeClass("left");
- },
- isVisible: function() {
- return jQuery("#ohmThumbContextMenu").is(":visible");
- },
- placeToCurrent: function() {
- var contextmenu = jQuery("#ohmThumbContextMenu");
- var thumb = OhmThumbs.current;
- thumb.obj.append(contextmenu);
- },
- };
- OhmInfoBox = {
- };
- OhmEditBox = {
- };
- OhmThumbActions = {
- displayContextMenu: function(){
- if(OhmThumbContextMenu.isVisible()) {
- OhmThumbContextMenu.hide();
- }
- else {
- OhmThumbContextMenu.placeToCurrent();
- var w = jQuery(document).width();
- OhmThumbContextMenu.show();
- var ocm = jQuery("#ohmThumbContextMenu").offset().left;
- var wcm = jQuery("#ohmThumbContextMenu").width();
- console.log(ocm+wcm);
- if(w < ocm+wcm) { // If context menu is outside of document to the right
- jQuery("#ohmThumbContextMenu").addClass("left");
- }
- }
- },
- };
- jQuery(document).ready(function(){
- console.log('ok');
- Ohm.init();
- console.log('end');
- });
RAW Paste Data
