PluginProbe
Comments Extra Fields For Post,Pages and CPT / 5.1
Comments Extra Fields For Post,Pages and CPT v5.1
trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.2 2.3 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 5.0 5.1 5.2
wp-comment-fields / js / image-tooltip.js

image-tooltip.js in Comments Extra Fields For Post,Pages and CPT 5.1, at js/image-tooltip.js

67 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 $.fn.imageTooltip = function (options) {
3
4 var defaults = {
5 imgWidth: 'initial',
6 backgroundColor: '#fff'
7 };
8
9 if (typeof (options) === 'object') {
10 options = $.extend(defaults, options);
11 } else {
12 var tempOptions = {};
13 tempOptions.imgWidth = arguments[0] || defaults.imgWidth;
14 tempOptions.backgroundColor = arguments[1] || defaults.backgroundColor;
15 options = tempOptions;
16 }
17
18 function calLeft(x, imgWidth) {
19 return window.innerWidth - x > imgWidth ? x : x - imgWidth;
20 }
21
22 function calTop(y, imgHeight) {
23 return window.innerHeight - y > imgHeight ? y + 25 : y - imgHeight - 25;
24 }
25
26 return this.each(function () {
27
28 var imgContainer = $('<p>', {
29 css: {
30 display: 'none',
31 backgroundColor: options.backgroundColor,
32 padding: '5px',
33 position: 'fixed',
34 'max-width': '350px',
35 'z-index': '9999'
36 }
37 });
38
39 var img = $('<img>', {
40 src: $(this).data('image-tooltip') || $(this).attr('src'),
41 alt: 'Image Not Available',
42 width: options.imgWidth
43 });
44
45 imgContainer.append(img);
46
47 $(this).hover(
48 function (e) {
49 imgContainer.css({
50 left: calLeft(e.clientX, imgContainer.outerWidth()) + 'px',
51 top: calTop(e.clientY, imgContainer.outerHeight()) + 'px'
52 });
53 $('body').append(imgContainer);
54 imgContainer.fadeIn('fast');
55 },
56 function () {
57 imgContainer.remove();
58 }
59 ).mousemove(function (e) {
60 imgContainer.css({
61 left: calLeft(e.clientX, imgContainer.outerWidth()) + 'px',
62 top: calTop(e.clientY, imgContainer.outerHeight()) + 'px'
63 });
64 });
65 });
66 };
67 }(jQuery));