Created
July 26, 2012 15:06
-
-
Save kmaglione/3182602 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imagesearch.sbi.mousemove = function(event) { | |
option = imagesearch.sbi.preferences.option(); | |
if (option == 'mouseover') { | |
var pos = {top: event.pageY, left: event.pageX}; | |
$('img', content.document).each(function() { | |
var currentImage = $(this); | |
// Skipping rendering the camera button for the followings: | |
// 1. Images on the image result page, e.g. <img class="rg_i">. | |
// 2. Images inside imagebox_bigimages, e.g. <img class="th "> | |
// 3. Images that contain id="imgthumb", e.g. <img id="imgthumb"> | |
if (currentImage.hasClass('rg_i') || | |
currentImage.hasClass('th ') || | |
// As of jQuery 1.6, the .attr() method returns undefined for | |
// attributes that have not been set, so we need to test for that. | |
(typeof(currentImage.attr('id')) != 'undefined' && | |
currentImage.attr('id').indexOf('imgthumb') == 0)) { | |
return; | |
} else { | |
var paddingLeft = parseFloat(currentImage.css('paddingLeft')); | |
var paddingTop = parseFloat(currentImage.css('paddingTop')); | |
if ((pos.top >= currentImage.offset().top + paddingTop) && | |
(pos.top <= | |
currentImage.offset().top + paddingTop + currentImage.height()) && | |
(pos.left >= currentImage.offset().left + paddingLeft) && | |
(pos.left <= | |
currentImage.offset().left + paddingLeft + currentImage.width())) { | |
// "next" is the next dom element of the current element. It should be | |
// the camera icon if the current image is actived. | |
var next = currentImage.next(); | |
var height = currentImage.height(); | |
var width = currentImage.width(); | |
// Ignore too images and hidden images. | |
if ((height < imagesearch.sbi.HOVER_IMAGE_MINIMAL_HEIGHT) || | |
(width < imagesearch.sbi.HOVER_IMAGE_MINIMAL_WIDTH) || | |
(currentImage.css('display') == 'none')) { | |
return; | |
} | |
var left = currentImage.position().left; | |
var top = currentImage.position().top; | |
left += width; | |
left -= imagesearch.sbi.CAMERA_BUTTON_RIGHT_MARGIN; | |
left -= imagesearch.sbi.CAMERA_BUTTON_WIDTH; | |
left += parseFloat(currentImage.css('marginLeft')); | |
left += paddingLeft; | |
top += height; | |
top -= imagesearch.sbi.CAMERA_BUTTON_BOTTOM_MARGIN; | |
top -= imagesearch.sbi.CAMERA_BUTTON_HEIGHT; | |
top += parseFloat(currentImage.css('marginTop')); | |
top += paddingTop; | |
var src = this.src; | |
var cameraHtml; | |
if (src.indexOf('data:') == 0) { | |
// If this is an inline image. | |
var base64Offset = src.indexOf(','); | |
if (base64Offset != -1) { | |
var inlineImage = imagesearch.sbi.translateInlineImage(src); | |
imagesearch.sbi.preferences.saveImage(src); | |
cameraHtml = '<form id="' + | |
imagesearch.sbi.FIREFOX_EXTENSION_SUBMIT_FORM_ID + | |
'" class="sbi_tempore_link" ' + | |
'action="http://' + imagesearch.sbi.BACKEND_SERVER + | |
'/searchbyimage/upload" ' + | |
'method="POST" enctype="multipart/form-data" ' + | |
'target="_blank">' + | |
'<input type="hidden" name="image_content" value="' + | |
inlineImage + '" />' + | |
'<input type="hidden" name="filename" value="" />' + | |
'<input type="hidden" name="image_url" value="" />' + | |
'<input type="hidden" name="' + | |
imagesearch.sbi.FIREFOX_EXTENSION_VERSION_PARAMETER_NAME + | |
'" value="' + imagesearch.sbi.FIREFOX_EXTENSION_VERSION + | |
'" /><img class="sbi_search" ' + | |
'src="chrome://sbi/skin/empty.png" style="left:' + | |
left.toString() + 'px;top:' + top.toString() + | |
'px;z-index:2147483647;width:' + | |
imagesearch.sbi.CAMERA_BUTTON_WIDTH + | |
'px;height:' + imagesearch.sbi.CAMERA_BUTTON_HEIGHT + 'px;' + | |
'position:absolute!important;border:none;' + | |
'margin:0px 0px 0px 0px;padding:0px 0px 0px 0px' + | |
'background-color:transparent" onclick="' + | |
'document.getElementById(\'' + | |
imagesearch.sbi.FIREFOX_EXTENSION_SUBMIT_FORM_ID + | |
'\').submit();return false"/></form>'; | |
} | |
} else { | |
var url = 'http://' + imagesearch.sbi.SERVER + '/searchbyimage?' + | |
imagesearch.sbi.FIREFOX_EXTENSION_VERSION_PARAMETER_NAME + '=' + | |
imagesearch.sbi.FIREFOX_EXTENSION_VERSION + '&image_url=' + | |
encodeURIComponent(src); | |
cameraHtml = '<a class="sbi_tempore_link" href="' + url + | |
'" onclick="this.href =\'' + url + | |
'\';window.open(this.href);return false" target="_blank" ' + | |
'style="width:0px;height:0px;padding:0;' + | |
'border-spacing:0;margin:0;border:none">' + | |
'<img class="sbi_search" ' + | |
'src="chrome://sbi/skin/empty.png" style="left:' + | |
left.toString() + 'px;top:' + top.toString() + | |
'px;z-index:2147483647;width:' + | |
imagesearch.sbi.CAMERA_BUTTON_WIDTH + | |
'px;height:' + imagesearch.sbi.CAMERA_BUTTON_HEIGHT + 'px;' + | |
'position:absolute!important;border:none;' + | |
'margin:0px 0px 0px 0px;padding:0px 0px 0px 0px' + | |
'background-color:transparent"/></a>'; | |
} | |
if (next.hasClass('sbi_tempore_link')) { | |
if (($('img', next).position().top != top) || | |
($('img', next).position().left != left)) { | |
next.replaceWith(cameraHtml); | |
} | |
} else { | |
currentImage.after(cameraHtml); | |
} | |
} else { | |
var next = currentImage.next(); | |
if (next.hasClass('sbi_tempore_link')) { | |
next.replaceWith(''); | |
} | |
} | |
} | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment