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 4th, 2014
13
Never
- /*
- * On-Hover-Menu (OHM)
- */
- Ohm = {
- init: function(){
- Ohm.preload([ // Preload images for non-lag during hover
- 'https://dl.dropboxusercontent.com/u/931983/chan/heart.png',
- 'https://dl.dropboxusercontent.com/u/931983/chan/0.png',
- 'https://dl.dropboxusercontent.com/u/931983/chan/menu.png'
- ]);
- OhmThumbs.add(); // Add all thumbs on page
- OhmThumbFooter.init();
- OhmThumbToolbar.init();
- OhmThumbContextMenu.init();
- OhmEditBox.init();
- OhmTagsBox.init();
- OhmThumbsListener.apply();
- },
- preload: function(arrayOfImages) {
- jQuery(arrayOfImages).each(function(){
- jQuery('<img/>')[0].src = this;
- });
- },
- };
- OhmOptions = { // Default options
- toolbar: {
- display: true, // Display toolbar?
- mode: undefined, // 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);
- obj.find("img").data("ohmid", thumb.ohmid);
- var src = {};
- src.link = obj.find("img").attr("src");
- src.width = obj.find("img").attr("width");
- src.height = obj.find("img").attr("height");
- thumb.src = src;
- thumb.favorited = false;
- if(obj.find("img").hasClass("favorited")){
- thumb.favorited = true;
- }
- // 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;
- }
- OhmThumbs.compare(OhmThumbs.last);
- });
- },
- getById: function(id){ // return all thumbs by given id (hint: multiple ids because thumbs can appear more than once on page)
- var thumbs = {};
- for(var ohmid in OhmThumbs.all){
- var thumb = OhmThumbs.all[ohmid];
- if(thumb.id === id){
- thumbs[thumb.ohmid] = thumb;
- }
- }
- return thumbs;
- },
- compare: function(thumbs){ // compare all thumbs with the chosen post and set them as good or bad
- var chosen = OhmThumbs.chosen;
- if(OhmThumbs.chosen){ // if chosen post is defined
- if(!thumbs){ // if thumbs are undefined
- thumbs = OhmThumbs.all;
- // remove last comparison
- for(var ohmid in thumbs){
- var thumb = thumbs[ohmid];
- thumb.obj.removeClass("better worse chosen");
- }
- }
- for(var ohmid in thumbs){ // for all thumbs
- var thumb = thumbs[ohmid];
- if(thumb.id !== chosen.id){ // if thumb is not chosen thumb
- var ratioThumb = Math.round(thumb.width * 100 / thumb.height);
- var ratioChosen = Math.round(chosen.width * 100 / chosen.height);
- if(ratioThumb === ratioChosen){ // if thumb is same ratio, compare
- if(thumb.width > chosen.width && thumb.height > chosen.height) { // if thumb is bigger than chosen one, it's better
- thumb.obj.addClass("better");
- }
- else if(thumb.width < chosen.width && thumb.height < chosen.height){ // if thumb is smaller than chosen one, it's worse
- thumb.obj.addClass("worse");
- }
- else { // else compare age of post, this works almost ever
- if(parseInt(thumb.id) < parseInt(chosen.id)){ // if thumb is older
- thumb.obj.addClass("better");
- }
- else{
- thumb.obj.addClass("worse");
- }
- }
- }
- }
- else{ // if thumb is chosen thumb
- thumb.obj.addClass("chosen");
- }
- }
- }
- else{ // if chosen post is undefined
- // remove last comparison
- for(var ohmid in OhmThumbs.all){
- var thumb = OhmThumbs.all[ohmid];
- thumb.obj.removeClass("better worse chosen");
- }
- }
- }
- };
- 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){
- var ohmid = jQuery(this).data("ohmid");
- OhmThumbs.current = OhmThumbs.all[ohmid];
- OhmThumbFooter.placeToCurrent();
- OhmThumbFooter.show();
- OhmThumbToolbar.placeToCurrent();
- OhmThumbToolbar.show();
- });
- obj.mouseleave(function(event){
- var ohmid = jQuery(this).data("ohmid");
- OhmThumbFooter.hide();
- OhmThumbToolbar.hide();
- OhmThumbContextMenu.hide();
- });
- // Different Listener for the image
- obj.find("img").mouseenter(function(event){
- var ohmid = obj.find("img").data("ohmid");
- OhmThumbs.all[ohmid].hover = true;
- OhmThumbs.all[ohmid].timer = setTimeout(function(){ // display tags after some time
- if(OhmThumbs.all[ohmid].hover){ // if still hovering
- OhmTagsBox.placeToCurrent();
- OhmTagsBox.show();
- }
- }, 1500);
- });
- obj.find("img").mouseleave(function(event){
- var ohmid = obj.find("img").data("ohmid");
- //clearTimeout(OhmThumbs.all[ohmid].timer); // reset timer for displaying tags if thumb is left
- OhmThumbs.all[ohmid].hover = false;
- OhmTagsBox.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 onclick="javascript:OhmThumbActions.favoriteCurrent();" id="ohmThumbToolbarFavoriteIcon" class="ohmIcon" title="Add to favorites"></a><a onclick="javascript:OhmThumbActions.executeMode();" id="ohmThumbToolbarModeIcon" class="ohmIcon" title="No mode selected" ></a><a onclick="javascript:OhmThumbActions.displayContextMenu();" id="ohmThumbToolbarContextMenuIcon" class="ohmIcon" 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;
- if(thumb.favorited){
- jQuery("#ohmThumbToolbarFavoriteIcon").addClass("clicked");
- }
- else{
- jQuery("#ohmThumbToolbarFavoriteIcon").removeClass("clicked");
- }
- thumb.obj.append(toolbar);
- },
- };
- OhmThumbContextMenu = {
- left: false, // If contextmenu is placed left
- init: function(){ // Create contextmenu and append it to body
- jQuery(document.body).append('<div id="ohmThumbContextMenu"> Mode Options: <br><div style="display:block;vertical-aling:center"><a href="javascript:OhmThumbActions.setMode(\'preview\');" id="ohmThumbContextMenuPreviewIcon" class="ohmIcon" title="Set this as mode"></a><a href="javascript:OhmThumbActions.openPreview();"> Open preview </a></div><div style="display:block;vertical-aling:center"><a href="javascript:OhmThumbActions.setMode(\'quickedit\');" id="ohmThumbContextMenuQuickEditIcon" class="ohmIcon" title="Set this as mode"></a><a href="javascript:OhmThumbActions.quickEdit();"> Quick edit </a></div><div style="display:block;vertical-aling:center"><a href="javascript:OhmThumbActions.setMode(\'flag\');" id="ohmThumbContextMenuFlagIcon" class="ohmIcon" title="Set this as mode"></a><a href="javascript:OhmThumbActions.flagPost();"> Flag post </a></div><div style="display:block;vertical-aling:center"><a href="javascript:OhmThumbActions.setMode(\'similar\');" id="ohmThumbContextMenuFindSimilarIcon" class="ohmIcon" title="Set this as mode"></a><a href="javascript:OhmThumbActions.findSimilar();"> Find similar posts </a></div><br>Advanced operations: <div style="display:block;vertical-aling:center"><a href="javascript:OhmThumbActions.setMode(\'choose\');" id="ohmThumbContextMenuChooseIcon" class="ohmIcon" title="Set this as mode"><a href="javascript:OhmThumbActions.choose();"> Choose post </a></div><div style="display:block;vertical-aling:center"><a href="javascript:OhmThumbActions.setMode(\'child\');" id="ohmThumbContextMenuChildIcon" class="ohmIcon" title="Set this as mode"><a href="javascript:OhmThumbActions.setAsChild();"> Set as child </a></div><div style="display:block;vertical-aling:center"><a href="javascript:OhmThumbActions.setMode(\'parent\');" id="ohmThumbContextMenuParentIcon" class="ohmIcon" title="Set this as mode"><a href="javascript:OhmThumbActions.setAsParent();"> Set as parent </a></div><div style="display:block;vertical-aling:center"><a href="javascript:OhmThumbActions.removeParent();"> Remove parent </a></div><div style="display:block;vertical-aling:center"><a href="javascript:OhmThumbActions.toggleParentingIcons();"> Toggle parenting icons </a></div></div>');
- },
- show: function() {
- jQuery("#ohmThumbContextMenu").show();
- jQuery("#ohmThumbToolbarContextMenuIcon").addClass("clicked");
- },
- hide: function() {
- jQuery("#ohmThumbContextMenu").hide().removeClass("left");
- jQuery("#ohmThumbToolbarContextMenuIcon").removeClass("clicked");
- OhmThumbContextMenu.left = false;
- },
- isVisible: function() {
- return jQuery("#ohmThumbContextMenu").is(":visible");
- },
- placeToCurrent: function() {
- var contextmenu = jQuery("#ohmThumbContextMenu");
- var thumb = OhmThumbs.current;
- thumb.obj.append(contextmenu);
- },
- placeLeft: function() {
- jQuery("#ohmThumbContextMenu").addClass("left");
- OhmThumbContextMenu.left = true;
- },
- };
- OhmTagsBox = { // display a box below
- init: function(){ // create box and append it to body
- jQuery(document.body).append('<div id="ohmTagsBox"></div>');
- },
- placeToCurrent: function(){ // place box to current thumb
- var thumb = OhmThumbs.current;
- var box = jQuery("#ohmTagsBox");
- box.html(thumb.tags);
- thumb.obj.append(box);
- },
- show: function(){
- jQuery("#ohmTagsBox").show();
- },
- hide: function(){
- jQuery("#ohmTagsBox").hide();
- },
- },
- OhmInfoBox = {
- };
- OhmEditBox = {
- thumb: undefined, // thumb which is currently loaded into the editbox
- init: function(){ // Create edit box with Listener for drag and drop and append it to body
- jQuery(document.body).append('<div id="ohmEditBox" onmousedown="javascript:OhmEditBox.startMoving(event);" onmouseup="javascript:OhmEditBox.stopMoving();" ></div>');
- },
- placeToCurrent: function(){
- var box = jQuery("#ohmEditBox");
- var thumb = OhmThumbs.current;
- // thumb position in relation to window
- var thumbTop = thumb.obj.offset().top - jQuery(window).scrollTop();
- var thumbLeft = thumb.obj.offset().left - jQuery(window).scrollLeft();
- var boxTop;
- var boxLeft;
- // calculate box position in relation to contextmenu and thumb
- if(OhmThumbContextMenu.left) { // if cm is left to thumb, put box left to contextmenu
- boxTop = thumbTop;
- boxLeft = thumbLeft - box.width() - jQuery("#ohmThumbContextMenu").width();
- }
- else{ // put it left to thumb
- boxTop = thumbTop;
- boxLeft = thumbLeft - box.width();
- }
- if(boxTop < 0) {
- boxTop = 0;
- }
- if(boxLeft < 0) {
- boxLeft = 0;
- }
- box.css({
- left:boxLeft,
- top:boxTop,
- });
- },
- show: function() {
- jQuery("#ohmEditBox").show();
- },
- hide: function() {
- jQuery("#ohmEditBox").hide();
- },
- move : function(divid,xpos,ypos){
- var a = document.getElementById(divid);
- $(divid).style.left = xpos + 'px';
- $(divid).style.top = ypos + 'px';
- },
- startMoving : function(evt){
- if(!(document.activeElement.nodeName === "INPUT" || document.activeElement.nodeName === "TEXTAREA")){
- evt = evt || window.event;
- var posX = evt.clientX,
- posY = evt.clientY,
- a = document.getElementById('ohmEditBox'),
- divTop = a.style.top,
- divLeft = a.style.left;
- divTop = divTop.replace('px','');
- divLeft = divLeft.replace('px','');
- var diffX = posX - divLeft,
- diffY = posY - divTop;
- document.onmousemove = function(evt){
- evt = evt || window.event;
- var posX = evt.clientX,
- posY = evt.clientY,
- aX = posX - diffX,
- aY = posY - diffY;
- OhmEditBox.move('ohmEditBox',aX,aY);
- }
- }
- },
- stopMoving : function(){
- var a = document.createElement('script');
- document.onmousemove = function(){}
- },
- };
- 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();
- if(w < ocm+wcm) { // If context menu is outside of document to the right
- OhmThumbContextMenu.placeLeft();
- }
- }
- },
- quickEdit: function(){
- // Place content in Editbox and show it
- var box = jQuery("#ohmEditBox");
- var thumb = OhmThumbs.current;
- OhmEditBox.thumb = thumb;
- var rating;
- switch(thumb.rating){
- case 's':
- rating = 'safe';
- break;
- case 'q':
- rating = 'questionable';
- break;
- case 'e':
- rating = 'explicit';
- break;
- }
- // Bug fix: Get source width and height again in case it's 0
- if((thumb.src.width === 0) || (thumb.src.height === 0)){
- thumb.src.width = thumb.obj.find("img").width();
- thumb.src.height = thumb.obj.find("img").height();
- OhmThumbs.all[thumb.ohmid].src.width = thumb.src.width;
- OhmThumbs.all[thumb.ohmid].src.height = thumb.src.height;
- }
- box.html('<div id="ohmEditBoxTitle"> Edit Post:</div><a onclick="javascript:OhmEditBox.hide();" id="ohmEditBoxCloseIcon" class="ohmIcon"></a><hr color="white" size="1"><div style="display:table"><div id="ohmEditBoxTagDiv" style="display:table-cell;vertical-align:top;text-align:center;height:100%;text-align:left;overflow-y:auto;background-color:white"></div><div style="display:inline-block;vertical-align:top;text-align:center" class="thumb"><div class="ohmAboveThumb"> Id: ' + thumb.id + ' </div><a href="javascript:OhmThumbActions.toggleZoomDuringEdit();"><div id="ohmEditBoxThumbImageDiv"><img class="preview" src="' + thumb.src.link + '" title="" alt="Toggle Zoom" width="' + thumb.src.width + '" height="' + thumb.src.height + '"></div></a><div class="ohmBelowThumb"> ' + thumb.width + 'x' + thumb.height + ' <br>User: ' + thumb.user + ' <br>Rating: ' + rating + ' </div></div><div style="display:inline-block;vertical-align:top"><table style="border-width:1px;"><tbody style="border:none;"><tr style="color:white;background-color: rgba(125,125,125,0.8);"><th><label class="block" for="post_rating_questionable"> Rating </label></th><td style="border:none;"><input id="ohm_post_rating_explicit" name="post[rating]" tabindex="1" type="radio" value="explicit"><label for="ohm_post_rating_explicit"> Explicit </label><input id="ohm_post_rating_questionable" name="post[rating]" tabindex="2" type="radio" value="questionable"><label for="ohm_post_rating_questionable"> Questionable </label><input checked="" id="ohm_post_rating_safe" name="post[rating]" tabindex="3" type="radio" value="safe"><label for="ohm_post_rating_safe"> Safe </label></td></tr><tr style="color:white;background-color: rgba(125,125,125,0.8);"><th><label class="block" for="post_tags"> Tags </label></th><td style="border:none;"><textarea cols="50" id="ohm_post_tags" name="post[tags]" rows="4" tabindex="10"> ' + thumb.tags + ' </textarea></td></tr></tbody></table><div style="text-align:right"><input type="button" value="Save" onclick="javascript:OhmThumbActions.quickEditSave();"><input type="button" value="Save and close" onclick="javascript:OhmThumbActions.quickEditSaveAndClose();"><input type="button" value="Cancel" onclick="javascript:OhmEditBox.hide();"></div></div></div>');
- box.show();
- jQuery("#ohmEditBoxThumbImageDiv").data("zoom", false);
- // Place Editbox next to thumb
- OhmEditBox.placeToCurrent();
- },
- quickEditSave: function(){
- var thumb = OhmEditBox.thumb;
- var params = {};
- params["id"] = thumb.id;
- params["post[tags]"] = jQuery("#ohm_post_tags").val();
- // Post.update(thumb.id, params);
- var rating = '';
- if(jQuery("#ohm_post_rating_explicit").is(":checked")){
- rating = jQuery("#ohm_post_rating_explicit").attr("value");
- }
- else if(jQuery("#ohm_post_rating_questionable").is(":checked")){
- rating = jQuery("#ohm_post_rating_questionable").attr("value");
- }
- else if(jQuery("#ohm_post_rating_safe").is(":checked")){
- rating = jQuery("#ohm_post_rating_safe").attr("value");
- }
- params["post[rating]"] = rating;
- Post.notice_update("inc")
- new Ajax.Request('/post/update.json', {
- parameters: params,
- onComplete: function(resp) {
- Post.notice_update("dec")
- var resp = resp.responseJSON
- if (resp.success) {
- Post.register(resp.post)
- } else {
- notice('Error: ' + resp.reason)
- }
- OhmThumbs.all[thumb.ohmid].tags = params["post[tags]"];
- OhmEditBox.thumb = OhmThumbs.all[thumb.ohmid];
- // Update Tag field
- var tagDiv = jQuery("#ohmEditBoxTagDiv");
- jQuery(document.body).append('<div id="ohmHiddenPost" style="display:none"></div>');
- var hiddenPostDiv = jQuery("#ohmHiddenPost");
- var link = "http://chan.sankakucomplex.com/post/show/" + thumb.id;
- hiddenPostDiv.load(link+" #post-view", function(){
- tagDiv.html(hiddenPostDiv.find("#tag-sidebar").clone().wrap('<p>').parent().html());
- tagDiv.css("width", "212px");
- tagDiv.find("ul").css({
- "height": "5px",
- "overflow": "initial",
- });
- // Remove hidden post
- hiddenPostDiv.remove();
- });
- }
- })
- },
- quickEditSaveAndClose: function(){
- var thumb = OhmEditBox.thumb;
- var params = {};
- params["id"] = thumb.id;
- params["post[tags]"] = jQuery("#ohm_post_tags").val();
- var rating = '';
- if(jQuery("#ohm_post_rating_explicit").is(":checked")){
- rating = jQuery("#ohm_post_rating_explicit").attr("value");
- }
- else if(jQuery("#ohm_post_rating_questionable").is(":checked")){
- rating = jQuery("#ohm_post_rating_questionable").attr("value");
- }
- else if(jQuery("#ohm_post_rating_safe").is(":checked")){
- rating = jQuery("#ohm_post_rating_safe").attr("value");
- }
- params["post[rating]"] = rating;
- // Post.update(thumb.id, params);
- Post.notice_update("inc")
- new Ajax.Request('/post/update.json', {
- parameters: params,
- onComplete: function(resp) {
- Post.notice_update("dec")
- var resp = resp.responseJSON
- if (resp.success) {
- Post.register(resp.post)
- } else {
- notice('Error: ' + resp.reason)
- }
- OhmThumbs.all[thumb.ohmid].tags = params["post[tags]"];
- OhmEditBox.thumb = OhmThumbs.all[thumb.ohmid];
- OhmEditBox.hide();
- }
- })
- },
- toggleZoomDuringEdit: function(){
- var thumb = OhmEditBox.thumb;
- var imgDiv = jQuery("#ohmEditBoxThumbImageDiv");
- var tagDiv = jQuery("#ohmEditBoxTagDiv");
- if(!imgDiv.data("zoom")){ // If not zoomed in, load image
- var link = "http://chan.sankakucomplex.com/post/show/" + thumb.id;
- if(!jQuery("#ohmHiddenPost").get(0)){ // if hidden post container doesnt exist create one
- jQuery(document.body).append('<div id="ohmHiddenPost" style="display:none"></div>');
- }
- var hiddenPostDiv = jQuery("#ohmHiddenPost");
- hiddenPostDiv.load(link+" #post-view", function(){
- tagDiv.html(hiddenPostDiv.find("#tag-sidebar").clone().wrap('<p>').parent().html());
- tagDiv.css("width", "212px");
- tagDiv.find("ul").css({
- "height": "5px",
- "overflow": "initial",
- });
- imgDiv.html(hiddenPostDiv.find("#image").clone().wrap('<p>').parent().html());
- var width = imgDiv.find("img").attr("width");
- var height = imgDiv.find("img").attr("height");
- var newWidth = width;
- var newHeight = height;
- var maxLength = 500;
- if(width > height){ // If wide image, maximize width and set height
- if(width>maxLength){
- newWidth = maxLength;
- newHeight = maxLength*height/width;
- }
- }
- else{
- if(height>maxLength){
- newHeight = maxLength;
- newWidth = maxLength*width/height;
- }
- }
- imgDiv.find("img").attr("width", newWidth);
- imgDiv.find("img").attr("height", newHeight);
- // Remove hidden post
- //hiddenPostDiv.remove();
- imgDiv.data("zoom", true);
- });
- }
- else{
- imgDiv.html('<img class="preview" src="' + thumb.src.link + '" title="" alt="Toggle Zoom" width="' + thumb.src.width + '" height="' + thumb.src.height + '">');
- imgDiv.data("zoom", false);
- }
- },
- favoriteCurrent: function(){
- var thumb = OhmThumbs.current;
- var post_id = thumb.id;
- if(!thumb.favorited){ // if not favorited, add to favorites
- notice('Adding post #' + post_id)
- new Ajax.Request('/favorite/create.json', {
- parameters: {
- id: post_id
- },
- onComplete: function(resp) {
- var resp = resp.responseJSON
- if (resp.success) {
- notice("Post #" + post_id + " added to favorites")
- // Set all thumbs to favorited
- var thumbs = OhmThumbs.getById(post_id);
- console.log(thumbs);
- for(var ohmid in thumbs){
- var t = thumbs[ohmid];
- t.obj.find("img").addClass("favorited");
- OhmThumbs.all[t.ohmid].favorited = true;
- }
- if(OhmThumbs.current.id === post_id){ // if still hovering image, update heart icon
- jQuery("#ohmThumbToolbarFavoriteIcon").addClass("clicked");
- jQuery("#ohmThumbToolbarFavoriteIcon").attr("title", "Remove from favorites");
- }
- } else {
- notice("Error: " + resp.reason)
- }
- }
- });
- }
- else{ // remove from favorites
- notice('Removing post #' + post_id)
- new Ajax.Request('/favorite/destroy.json', {
- parameters: {
- id: post_id
- },
- onComplete: function(resp) {
- var resp = resp.responseJSON
- notice("Post #" + post_id + " removed from your favorites")
- // Set all thumbs to not favorited
- var thumbs = OhmThumbs.getById(post_id);
- console.log(thumbs);
- for(var ohmid in thumbs){
- var t = thumbs[ohmid];
- t.obj.find("img").removeClass("favorited");
- OhmThumbs.all[ohmid].favorited = false;
- }
- if(OhmThumbs.current.id === post_id){ // if still hovering image, update heart icon
- jQuery("#ohmThumbToolbarFavoriteIcon").removeClass("clicked");
- jQuery("#ohmThumbToolbarFavoriteIcon").attr("title", "Add to favorites");
- }
- }
- });
- }
- },
- setMode: function(mode){
- if(mode){ // if mode is defined
- // Remove clicked status from every class
- jQuery("#ohmThumbContextMenuPreviewIcon").removeClass("clicked");
- jQuery("#ohmThumbContextMenuQuickEditIcon").removeClass("clicked");
- jQuery("#ohmThumbContextMenuFlagIcon").removeClass("clicked");
- jQuery("#ohmThumbContextMenuFindSimilarIcon").removeClass("clicked");
- jQuery("#ohmThumbContextMenuChooseIcon").removeClass("clicked");
- jQuery("#ohmThumbContextMenuChildIcon").removeClass("clicked");
- jQuery("#ohmThumbContextMenuParentIcon").removeClass("clicked");
- // Set mode Icon in toolbar
- var icon;
- var title;
- switch(mode){
- case 'preview':
- icon = jQuery("#ohmThumbContextMenuPreviewIcon");
- title = "Preview";
- break;
- case 'quickedit':
- icon = jQuery("#ohmThumbContextMenuQuickEditIcon");
- title = "Quick Edit";
- break;
- case 'flag':
- icon = jQuery("#ohmThumbContextMenuFlagIcon");
- title = "Flag";
- break;
- case 'similar':
- icon = jQuery("#ohmThumbContextMenuFindSimilarIcon");
- title = "Find similar posts";
- break;
- case 'choose':
- icon = jQuery("#ohmThumbContextMenuChooseIcon");
- title = "Choose Post";
- break;
- case 'child':
- icon = jQuery("#ohmThumbContextMenuChildIcon");
- title = "Set this post as child of the chosen post";
- break;
- case 'parent':
- icon = jQuery("#ohmThumbContextMenuParentIcon");
- title = "Set this post as parent of the chosen post";
- break;
- }
- var bgx = icon.css("background-image");
- icon.addClass("clicked");
- jQuery("#ohmThumbToolbarModeIcon").css("background-image", bgx).attr("title", title);
- // Set mode in options
- OhmOptions.toolbar.mode = mode;
- }
- },
- executeMode: function(){
- switch(OhmOptions.toolbar.mode){
- case 'preview':
- OhmThumbActions.openPreview();
- break;
- case 'quickedit':
- OhmThumbActions.quickEdit();
- break;
- case 'flag':
- OhmThumbActions.flagPost();
- break;
- case 'similar':
- OhmThumbActions.findSimilar();
- break;
- case 'choose':
- OhmThumbActions.choose();
- break;
- case 'child':
- OhmThumbActions.setAsChild();
- break;
- case 'parent':
- OhmThumbActions.setAsParent();
- break;
- }
- },
- openPreview: function(){
- var thumb = OhmThumbs.current;
- var link = "http://chan.sankakucomplex.com/post/show/" + thumb.id;
- if(!jQuery("#ohmHiddenPost").get(0)){ // if hidden post container doesnt exist, create one
- jQuery(document.body).append('<div id="ohmHiddenPost" style="display:none"></div>');
- }
- var hiddenPostDiv = jQuery("#ohmHiddenPost");
- hiddenPostDiv.load(link+" #post-view", function(){
- jQuery(document.body).append('<a href="javascript:OhmThumbActions.closePreview();" id="ohmThumbPreview" class="ohmThumbPreview"></a>');
- var preview = jQuery("#ohmThumbPreview");
- // Load image into preview-container
- preview.html(hiddenPostDiv.find("#image").clone().wrap('<p>').parent().html());
- // Put image in center
- var imgWidth = preview.find("#image").attr("width");
- var imgHeight = preview.find("#image").attr("height");
- var winWidth = jQuery(window).width();
- var winHeight = jQuery(window).height();
- var prevWidth = imgWidth;
- var prevHeight = imgHeight;
- if(winWidth < imgWidth){ // Fit to width
- prevWidth = winWidth;
- prevHeight = winWidth*imgHeight/imgWidth;
- }
- imgWidth = prevWidth;
- imgHeight = prevHeight;
- if(winHeight < imgHeight){ // Fit image to height
- prevWidth = winHeight*imgWidth/imgHeight;
- prevHeight = winHeight;
- }
- preview.find("#image").attr("width", prevWidth);
- preview.find("#image").attr("height", prevHeight);
- preview.css({
- "width": prevWidth,
- "height": prevHeight,
- "left": (winWidth - prevWidth) * 0.5,
- "top": (winHeight - prevHeight) * 0.5,
- "position": "fixed",
- });
- // Remove hiddenPost
- //setTimeout(function(){hiddenPostDiv.remove();}, 2000);
- });
- },
- closePreview: function(){
- jQuery("#ohmThumbPreview").remove();
- },
- flagPost: function(){
- Post.flag(OhmThumbs.current.id);
- },
- findSimilar: function(){
- var thumb = OhmThumbs.current;
- var link = "http://chan.sankakucomplex.com/post/similar?id="+thumb.id;
- var fmid = thumb.ohmid;
- while(jQuery("#ohmFindSimilar-"+fmid).get(0)){ // While defined
- fmid = fmid + "n";
- }
- thumb.obj.after('<div id="ohmFindSimilar-' + fmid + '" class="status-notice ohm"></div>');
- var findsim = jQuery('#ohmFindSimilar-' + fmid);
- findsim.load(link+' #similar-form', function(){
- findsim.find("#similar-image-form").remove();
- findsim.find(".thumb").removeClass("blacklisted");
- OhmThumbs.add(findsim.find(".thumb"));
- OhmThumbsListener.apply();
- // append close button
- findsim.append('<a onclick="javascript:jQuery(\'#ohmFindSimilar-' + fmid + '\').hide();" id="ohmFindSimilarCloseIcon" class="ohmIcon"></a>');
- });
- },
- toggleParentingIcons: function(){
- if(OhmOptions.toolbar.parenting){ // if parenting icons are already displayed, remove them
- jQuery("#ohmThumbToolbar").html('<a onclick="javascript:OhmThumbActions.favoriteCurrent();" id="ohmThumbToolbarFavoriteIcon" class="ohmIcon" title="Add to favorites"></a><a onclick="javascript:OhmThumbActions.executeMode();" id="ohmThumbToolbarModeIcon" class="ohmIcon" title="No mode selected" ></a><a onclick="javascript:OhmThumbActions.displayContextMenu();" id="ohmThumbToolbarContextMenuIcon" class="ohmIcon" title="Open context menu"></a>');
- jQuery("#ohmThumbToolbarFavoriteIcon").css('left', '30px');
- jQuery("#ohmThumbToolbarModeIcon").css('left', '77px');
- jQuery("#ohmThumbToolbarContextMenuIcon").css('left', '124px');
- if(OhmThumbs.current.favorited){
- jQuery("#ohmThumbToolbarFavoriteIcon").addClass("clicked");
- }
- OhmOptions.toolbar.parenting = false;
- OhmThumbActions.setMode(OhmOptions.toolbar.mode);
- }
- else{ // parenting icons are not visible, create them
- jQuery("#ohmThumbToolbar").html('<a onclick="javascript:OhmThumbActions.favoriteCurrent();" id="ohmThumbToolbarFavoriteIcon" class="ohmIcon" title="Add to favorites"></a><a onclick="javascript:OhmThumbActions.choose();" id="ohmThumbToolbarChooseIcon" class="ohmIcon" title="Choose Post" ><a onclick="javascript:OhmThumbActions.setAsChild();" id="ohmThumbToolbarChildIcon" class="ohmIcon" title="Set this post as child of the chosen post" ><a onclick="javascript:OhmThumbActions.setAsParent();" id="ohmThumbToolbarParentIcon" class="ohmIcon" title="Set this post as parent of the chosen post" ><a onclick="javascript:OhmThumbActions.executeMode();" id="ohmThumbToolbarModeIcon" class="ohmIcon" title="No mode selected" ></a><a onclick="javascript:OhmThumbActions.displayContextMenu();" id="ohmThumbToolbarContextMenuIcon" class="ohmIcon" title="Open context menu"></a>');
- jQuery("#ohmThumbToolbarFavoriteIcon").css('left', '12px');
- jQuery("#ohmThumbToolbarChooseIcon").css('left', '38px');
- jQuery("#ohmThumbToolbarChildIcon").css('left', '64px');
- jQuery("#ohmThumbToolbarParentIcon").css('left', '90px');
- jQuery("#ohmThumbToolbarModeIcon").css('left', '116px');
- jQuery("#ohmThumbToolbarContextMenuIcon").css('left', '142px');
- if(OhmThumbs.current.favorited){
- jQuery("#ohmThumbToolbarFavoriteIcon").addClass("clicked");
- }
- OhmOptions.toolbar.parenting = true;
- OhmThumbActions.setMode(OhmOptions.toolbar.mode);
- }
- },
- choose: function(){ // choose a post and also save in cookies
- var thumb = OhmThumbs.current;
- if(OhmThumbs.chosen){ // if chosen thumb is defined
- if(OhmThumbs.chosen.id !== thumb.id){ // if the chosen thumb is not the currently chosen thumb
- OhmThumbs.chosen = thumb;
- OhmThumbs.compare(); // compare all thumbs with the chosen post
- }
- else{ // else reject it
- OhmThumbs.chosen = undefined;
- OhmThumbs.compare();
- }
- }
- else{ // if chosen thumb is undefined, choose it
- OhmThumbs.chosen = thumb;
- OhmThumbs.compare(); // compare all thumbs with the chosen post
- }
- },
- setAsParent: function(){ // set current post as parent of the chosen post
- var current = OhmThumbs.current;
- var chosen = OhmThumbs.chosen;
- var params = {};
- params["id"] = chosen.id;
- params["post[parent_id]"] = current.id;
- Post.notice_update("inc")
- new Ajax.Request('/post/update.json', {
- parameters: params,
- onComplete: function(resp) {
- Post.notice_update("dec")
- var resp = resp.responseJSON
- if (resp.success) {
- Post.register(resp.post)
- } else {
- notice('Error: ' + resp.reason)
- }
- // Set all thumbs with the same id as chosen_id to has-parent
- var thumbs = OhmThumbs.getById(chosen.id);
- for(var ohmid in thumbs){
- thumbs[ohmid].obj.find("img").addClass("has-parent");
- }
- // Set all thumbs with the same id as current_id to has-children
- thumbs = OhmThumbs.getById(current.id);
- for(var ohmid in thumbs){
- thumbs[ohmid].obj.find("img").addClass("has-children");
- }
- }
- });
- },
- setAsChild: function(){ // set current post as child of the chosen post
- var current = OhmThumbs.current;
- var chosen = OhmThumbs.chosen;
- var params = {};
- params["id"] = current.id;
- params["post[parent_id]"] = chosen.id;
- Post.notice_update("inc")
- new Ajax.Request('/post/update.json', {
- parameters: params,
- onComplete: function(resp) {
- Post.notice_update("dec")
- var resp = resp.responseJSON
- if (resp.success) {
- Post.register(resp.post)
- } else {
- notice('Error: ' + resp.reason)
- }
- // Set all thumbs with the same id as chosen_id to has-children
- var thumbs = OhmThumbs.getById(chosen.id);
- for(var ohmid in thumbs){
- thumbs[ohmid].obj.find("img").addClass("has-children");
- }
- // Set all thumbs with the same id as current_id to has-parent
- thumbs = OhmThumbs.getById(current.id);
- for(var ohmid in thumbs){
- thumbs[ohmid].obj.find("img").addClass("has-parent");
- }
- }
- });
- },
- removeParent: function(){ // remove parent of the current post
- var current = OhmThumbs.current;
- var params = {};
- params["id"] = current.id;
- params["post[parent_id]"] = "";
- Post.notice_update("inc")
- new Ajax.Request('/post/update.json', {
- parameters: params,
- onComplete: function(resp) {
- Post.notice_update("dec")
- var resp = resp.responseJSON
- if (resp.success) {
- Post.register(resp.post)
- } else {
- notice('Error: ' + resp.reason)
- }
- // Remove has-parent from all thumbs with the current id
- var thumbs = OhmThumbs.getById(current.id);
- for(var ohmid in thumbs){
- thumbs[ohmid].obj.find("img").removeClass("has-parent");
- }
- }
- });
- },
- };
- // OhmTags = {
- // all: {},
- // last: {},
- // current: undefined,
- // add: function(){ // get tags from sidebar
- // var sidebar = jQuery("#tag-sidebar");
- // if(!sidebar.get(0)){ // if undefined
- // sidebar = jQuery("#tag-subs-sidebar");
- // }
- // if(sidebar.get(0)){ // if defined
- // sidebar.find("li").each(function(i){
- // var li = $(this);
- // var ohmid = "ohmtag"+i;
- // var tag = {};
- // var tag.obj = li.first(); // get the first link
- // });
- // }
- // },
- // };
- OhmTagsListener = {
- apply: function(){
- },
- }
- OhmTagContextMenu = { // contextmenu for tags in sidebar
- init: function(){
- },
- };
- OhmTagActions = { // Actions for the contextmenu in the tag sidebar
- }
- OhmFix = { // Fix stuff which is already implemented on the site
- noticeBox: function(){
- var notice = jQuery("#notice");
- notice.css({
- "font-size": "1.2em",
- "color": "red",
- "font-weight": "bold",
- "margin-bottom": "1em",
- "padding-left": "20px",
- "padding-right": "20px",
- "position": "fixed",
- "left": "0px",
- "top": "0px",
- "background-color": "white",
- "z-index": "99999999",
- "border": "2px solid #DDD;",
- });
- notice.bind('DOMNodeInserted DOMSubtreeModified DOMNodeRemoved', function(){
- notice.stop().css({"opacity":"1"});
- setTimeout(function(){
- notice.fadeOut();
- }, 3000);
- });
- },
- };
- jQuery(document).ready(function(){
- console.log('ok');
- Ohm.init();
- OhmFix.noticeBox();
- console.log('end');
- });
RAW Paste Data
