Changeset 19682 for trunk/themes/default/js/plugins/jquery.Jcrop.js
- Timestamp:
- Dec 31, 2012, 7:13:14 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/themes/default/js/plugins/jquery.Jcrop.js
r13038 r19682 1 1 /** 2 * jquery.Jcrop.js v0.9.9 3 * jQuery Image Cropping Plugin 4 * @author Kelly Hallman <khallman@gmail.com> 5 * Copyright (c) 2008-2011 Kelly Hallman - released under MIT License {{{ 2 * jquery.Jcrop.js v0.9.10 3 * jQuery Image Cropping Plugin - released under MIT License 4 * Author: Kelly Hallman <khallman@gmail.com> 5 * http://github.com/tapmodo/Jcrop 6 * Copyright (c) 2008-2012 Tapmodo Interactive LLC {{{ 6 7 * 7 8 * Permission is hereby granted, free of charge, to any person … … 37 38 // Internal Methods {{{ 38 39 function px(n) { 39 return parseInt(n, 10) + 'px'; 40 } 41 function pct(n) { 42 return parseInt(n, 10) + '%'; 40 return n + 'px'; 43 41 } 44 42 function cssClass(cl) { … … 50 48 function getPos(obj) //{{{ 51 49 { 52 // Updated in v0.9.4 to use built-in dimensions plugin53 50 var pos = $(obj).offset(); 54 51 return [pos.left, pos.top]; … … 62 59 function setOptions(opt) //{{{ 63 60 { 64 if (typeof(opt) !== 'object') { 65 opt = {}; 66 } 61 if (typeof(opt) !== 'object') opt = {}; 67 62 options = $.extend(options, opt); 68 63 69 if (typeof(options.onChange) !== 'function') { 70 options.onChange = function () {}; 71 } 72 if (typeof(options.onSelect) !== 'function') { 73 options.onSelect = function () {}; 74 } 75 if (typeof(options.onRelease) !== 'function') { 76 options.onRelease = function () {}; 77 } 78 } 79 //}}} 80 function myCursor(type) //{{{ 81 { 82 if (type !== lastcurs) { 83 Tracker.setCursor(type); 84 lastcurs = type; 85 } 64 $.each(['onChange','onSelect','onRelease','onDblClick'],function(i,e) { 65 if (typeof(options[e]) !== 'function') options[e] = function () {}; 66 }); 86 67 } 87 68 //}}} … … 188 169 return false; 189 170 } 171 172 // Fix position of crop area when dragged the very first time. 173 // Necessary when crop image is in a hidden element when page is loaded. 174 docOffset = getPos($img); 175 190 176 btndown = true; 191 177 startDragMode(ord, mouseAbs(e)); … … 216 202 { 217 203 return { 218 x: parseInt(c.x * xscale, 10),219 y: parseInt(c.y * yscale, 10),220 x2: parseInt(c.x2 * xscale, 10),221 y2: parseInt(c.y2 * yscale, 10),222 w: parseInt(c.w * xscale, 10),223 h: parseInt(c.h * yscale, 10)204 x: c.x * xscale, 205 y: c.y * yscale, 206 x2: c.x2 * xscale, 207 y2: c.y2 * yscale, 208 w: c.w * xscale, 209 h: c.h * yscale 224 210 }; 225 211 } … … 248 234 docOffset = getPos($img); 249 235 Selection.disableHandles(); 250 myCursor('crosshair');236 Tracker.setCursor('crosshair'); 251 237 var pos = mouseAbs(e); 252 238 Coords.setPressed(pos); … … 300 286 var img_css = { 301 287 border: 'none', 288 visibility: 'visible', 302 289 margin: 0, 303 290 padding: 0, 304 position: 'absolute' 291 position: 'absolute', 292 top: 0, 293 left: 0 305 294 }; 306 295 307 var $origimg = $(obj); 308 var $img = $origimg.clone().removeAttr('id').css(img_css); 309 310 $img.width($origimg.width()); 311 $img.height($origimg.height()); 312 $origimg.after($img).hide(); 296 var $origimg = $(obj), 297 img_mode = true; 298 299 if (obj.tagName == 'IMG') { 300 // Fix size of crop image. 301 // Necessary when crop image is within a hidden element when page is loaded. 302 if ($origimg[0].width != 0 && $origimg[0].height != 0) { 303 // Obtain dimensions from contained img element. 304 $origimg.width($origimg[0].width); 305 $origimg.height($origimg[0].height); 306 } else { 307 // Obtain dimensions from temporary image in case the original is not loaded yet (e.g. IE 7.0). 308 var tempImage = new Image(); 309 tempImage.src = $origimg[0].src; 310 $origimg.width(tempImage.width); 311 $origimg.height(tempImage.height); 312 } 313 314 var $img = $origimg.clone().removeAttr('id').css(img_css).show(); 315 316 $img.width($origimg.width()); 317 $img.height($origimg.height()); 318 $origimg.after($img).hide(); 319 320 } else { 321 $img = $origimg.css(img_css).show(); 322 img_mode = false; 323 if (options.shade === null) { options.shade = true; } 324 } 313 325 314 326 presize($img, options.boxWidth, options.boxHeight); … … 323 335 }).insertAfter($origimg).append($img); 324 336 325 delete(options.bgColor);326 337 if (options.addClass) { 327 338 $div.addClass(options.addClass); 328 339 } 329 340 330 var $img2 = $('<img />') 331 .attr('src', $img.attr('src')).css(img_css).width(boundx).height(boundy), 341 var $img2 = $('<div />'), 332 342 333 343 $img_holder = $('<div />') 334 .width( pct(100)).height(pct(100)).css({344 .width('100%').height('100%').css({ 335 345 zIndex: 310, 336 346 position: 'absolute', 337 347 overflow: 'hidden' 338 }) .append($img2),348 }), 339 349 340 350 $hdl_holder = $('<div />') 341 .width( pct(100)).height(pct(100)).css('zIndex', 320),351 .width('100%').height('100%').css('zIndex', 320), 342 352 343 353 $sel = $('<div />') 344 354 .css({ 345 355 position: 'absolute', 346 zIndex: 300 356 zIndex: 600 357 }).dblclick(function(){ 358 var c = Coords.getFixed(); 359 options.onDblClick.call(api,c); 347 360 }).insertBefore($img).append($img_holder, $hdl_holder); 361 362 if (img_mode) { 363 364 $img2 = $('<img />') 365 .attr('src', $img.attr('src')).css(img_css).width(boundx).height(boundy), 366 367 $img_holder.append($img2); 368 369 } 348 370 349 371 if (ie6mode) { … … 363 385 /* }}} */ 364 386 // Set more variables {{{ 365 var bgopacity = options.bgOpacity, 387 var bgcolor = options.bgColor, 388 bgopacity = options.bgOpacity, 366 389 xlimit, ylimit, xmin, ymin, xscale, yscale, enabled = true, 367 390 btndown, animating, shift_down; … … 517 540 rha = Math.abs(rh), 518 541 real_ratio = rwa / rha, 519 xx, yy ;542 xx, yy, w, h; 520 543 521 544 if (max_x === 0) { … … 631 654 yb = y1; 632 655 } 633 return [ Math.round(xa), Math.round(ya), Math.round(xb), Math.round(yb)];656 return [xa, ya, xb, yb]; 634 657 } 635 658 //}}} … … 719 742 720 743 //}}} 744 // Shade Module {{{ 745 var Shade = (function() { 746 var enabled = false, 747 holder = $('<div />').css({ 748 position: 'absolute', 749 zIndex: 240, 750 opacity: 0 751 }), 752 shades = { 753 top: createShade(), 754 left: createShade().height(boundy), 755 right: createShade().height(boundy), 756 bottom: createShade() 757 }; 758 759 function resizeShades(w,h) { 760 shades.left.css({ height: px(h) }); 761 shades.right.css({ height: px(h) }); 762 } 763 function updateAuto() 764 { 765 return updateShade(Coords.getFixed()); 766 } 767 function updateShade(c) 768 { 769 shades.top.css({ 770 left: px(c.x), 771 width: px(c.w), 772 height: px(c.y) 773 }); 774 shades.bottom.css({ 775 top: px(c.y2), 776 left: px(c.x), 777 width: px(c.w), 778 height: px(boundy-c.y2) 779 }); 780 shades.right.css({ 781 left: px(c.x2), 782 width: px(boundx-c.x2) 783 }); 784 shades.left.css({ 785 width: px(c.x) 786 }); 787 } 788 function createShade() { 789 return $('<div />').css({ 790 position: 'absolute', 791 backgroundColor: options.shadeColor||options.bgColor 792 }).appendTo(holder); 793 } 794 function enableShade() { 795 if (!enabled) { 796 enabled = true; 797 holder.insertBefore($img); 798 updateAuto(); 799 Selection.setBgOpacity(1,0,1); 800 $img2.hide(); 801 802 setBgColor(options.shadeColor||options.bgColor,1); 803 if (Selection.isAwake()) 804 { 805 setOpacity(options.bgOpacity,1); 806 } 807 else setOpacity(1,1); 808 } 809 } 810 function setBgColor(color,now) { 811 colorChangeMacro(getShades(),color,now); 812 } 813 function disableShade() { 814 if (enabled) { 815 holder.remove(); 816 $img2.show(); 817 enabled = false; 818 if (Selection.isAwake()) { 819 Selection.setBgOpacity(options.bgOpacity,1,1); 820 } else { 821 Selection.setBgOpacity(1,1,1); 822 Selection.disableHandles(); 823 } 824 colorChangeMacro($div,0,1); 825 } 826 } 827 function setOpacity(opacity,now) { 828 if (enabled) { 829 if (options.bgFade && !now) { 830 holder.animate({ 831 opacity: 1-opacity 832 },{ 833 queue: false, 834 duration: options.fadeTime 835 }); 836 } 837 else holder.css({opacity:1-opacity}); 838 } 839 } 840 function refreshAll() { 841 options.shade ? enableShade() : disableShade(); 842 if (Selection.isAwake()) setOpacity(options.bgOpacity); 843 } 844 function getShades() { 845 return holder.children(); 846 } 847 848 return { 849 update: updateAuto, 850 updateRaw: updateShade, 851 getShades: getShades, 852 setBgColor: setBgColor, 853 enable: enableShade, 854 disable: disableShade, 855 resize: resizeShades, 856 refresh: refreshAll, 857 opacity: setOpacity 858 }; 859 }()); 860 // }}} 721 861 // Selection Module {{{ 722 862 var Selection = (function () { 723 var awake, hdep = 370; 724 var borders = {}; 725 var handle = {}; 726 var seehandles = false; 727 var hhs = options.handleOffset; 863 var awake, 864 hdep = 370, 865 borders = {}, 866 handle = {}, 867 dragbar = {}, 868 seehandles = false; 728 869 729 870 // Private Methods … … 744 885 position: 'absolute', 745 886 zIndex: zi 746 }) ;887 }).addClass('ord-'+ord); 747 888 748 889 if (Touch.support) { 749 jq.bind('touchstart ', Touch.createDragger(ord));890 jq.bind('touchstart.jcrop', Touch.createDragger(ord)); 750 891 } 751 892 … … 756 897 function insertHandle(ord) //{{{ 757 898 { 899 var hs = options.handleSize; 758 900 return dragDiv(ord, hdep++).css({ 759 top: px(-hhs + 1),760 left: px(-hhs + 1),761 901 opacity: options.handleOpacity 762 }). addClass(cssClass('handle'));902 }).width(hs).height(hs).addClass(cssClass('handle')); 763 903 } 764 904 //}}} 765 905 function insertDragbar(ord) //{{{ 766 906 { 767 var s = options.handleSize, 768 h = s, 769 w = s, 770 t = hhs, 771 l = hhs; 772 773 switch (ord) { 774 case 'n': 775 case 's': 776 w = pct(100); 777 break; 778 case 'e': 779 case 'w': 780 h = pct(100); 781 break; 782 } 783 784 return dragDiv(ord, hdep++).width(w).height(h).css({ 785 top: px(-t + 1), 786 left: px(-l + 1) 787 }); 907 return dragDiv(ord, hdep++).addClass('jcrop-dragbar'); 908 } 909 //}}} 910 function createDragbars(li) //{{{ 911 { 912 var i; 913 for (i = 0; i < li.length; i++) { 914 dragbar[li[i]] = insertDragbar(li[i]); 915 } 916 } 917 //}}} 918 function createBorders(li) //{{{ 919 { 920 var cl,i; 921 for (i = 0; i < li.length; i++) { 922 switch(li[i]){ 923 case'n': cl='hline'; break; 924 case's': cl='hline bottom'; break; 925 case'e': cl='vline right'; break; 926 case'w': cl='vline'; break; 927 } 928 borders[li[i]] = insertBorder(cl); 929 } 788 930 } 789 931 //}}} … … 796 938 } 797 939 //}}} 798 function moveHandles(c) //{{{ 799 { 800 var midvert = Math.round((c.h / 2) - hhs), 801 midhoriz = Math.round((c.w / 2) - hhs), 802 north = -hhs + 1, 803 west = -hhs + 1, 804 east = c.w - hhs, 805 south = c.h - hhs, 806 x, y; 807 808 if (handle.e) { 809 handle.e.css({ 810 top: px(midvert), 811 left: px(east) 940 function moveto(x, y) //{{{ 941 { 942 if (!options.shade) { 943 $img2.css({ 944 top: px(-y), 945 left: px(-x) 812 946 }); 813 handle.w.css({ 814 top: px(midvert) 815 }); 816 handle.s.css({ 817 top: px(south), 818 left: px(midhoriz) 819 }); 820 handle.n.css({ 821 left: px(midhoriz) 822 }); 823 } 824 if (handle.ne) { 825 handle.ne.css({ 826 left: px(east) 827 }); 828 handle.se.css({ 829 top: px(south), 830 left: px(east) 831 }); 832 handle.sw.css({ 833 top: px(south) 834 }); 835 } 836 if (handle.b) { 837 handle.b.css({ 838 top: px(south) 839 }); 840 handle.r.css({ 841 left: px(east) 842 }); 843 } 844 } 845 //}}} 846 function moveto(x, y) //{{{ 847 { 848 $img2.css({ 849 top: px(-y), 850 left: px(-x) 851 }); 947 } 852 948 $sel.css({ 853 949 top: px(y), … … 873 969 874 970 // Internal Methods 875 function updateVisible( ) //{{{971 function updateVisible(select) //{{{ 876 972 { 877 973 if (awake) { 878 return update( );879 } 880 } 881 //}}} 882 function update( ) //{{{974 return update(select); 975 } 976 } 977 //}}} 978 function update(select) //{{{ 883 979 { 884 980 var c = Coords.getFixed(); … … 886 982 resize(c.w, c.h); 887 983 moveto(c.x, c.y); 888 889 /* 890 options.drawBorders && 891 borders.right.css({ left: px(c.w-1) }) && 892 borders.bottom.css({ top: px(c.h-1) }); 893 */ 894 895 if (seehandles) { 896 moveHandles(c); 897 } 898 if (!awake) { 899 show(); 900 } 901 902 options.onChange.call(api, unscale(c)); 984 if (options.shade) Shade.updateRaw(c); 985 986 awake || show(); 987 988 if (select) { 989 options.onSelect.call(api, unscale(c)); 990 } else { 991 options.onChange.call(api, unscale(c)); 992 } 993 } 994 //}}} 995 function setBgOpacity(opacity,force,now) //{{{ 996 { 997 if (!awake && !force) return; 998 if (options.bgFade && !now) { 999 $img.animate({ 1000 opacity: opacity 1001 },{ 1002 queue: false, 1003 duration: options.fadeTime 1004 }); 1005 } else { 1006 $img.css('opacity', opacity); 1007 } 903 1008 } 904 1009 //}}} … … 907 1012 $sel.show(); 908 1013 909 if (options.bgFade) { 910 $img.fadeTo(options.fadeTime, bgopacity); 911 } else { 912 $img.css('opacity', bgopacity); 913 } 1014 if (options.shade) Shade.opacity(bgopacity); 1015 else setBgOpacity(bgopacity,true); 914 1016 915 1017 awake = true; … … 921 1023 $sel.hide(); 922 1024 923 if (options.bgFade) { 924 $img.fadeTo(options.fadeTime, 1); 925 } else { 926 $img.css('opacity', 1); 927 } 1025 if (options.shade) Shade.opacity(1); 1026 else setBgOpacity(1); 928 1027 929 1028 awake = false; … … 934 1033 { 935 1034 if (seehandles) { 936 moveHandles(Coords.getFixed());937 1035 $hdl_holder.show(); 938 1036 } … … 943 1041 seehandles = true; 944 1042 if (options.allowResize) { 945 moveHandles(Coords.getFixed());946 1043 $hdl_holder.show(); 947 1044 return true; … … 970 1067 } 971 1068 //}}} 972 /* Insert draggable elements {{{*/ 973 1069 // Insert draggable elements {{{ 974 1070 // Insert border divs for outline 975 if (options.drawBorders) { 976 borders = { 977 top: insertBorder('hline'), 978 bottom: insertBorder('hline bottom'), 979 left: insertBorder('vline'), 980 right: insertBorder('vline right') 981 }; 982 } 983 984 // Insert handles on edges 985 if (options.dragEdges) { 986 handle.t = insertDragbar('n'); 987 handle.b = insertDragbar('s'); 988 handle.r = insertDragbar('e'); 989 handle.l = insertDragbar('w'); 990 } 991 992 // Insert side and corner handles 993 if (options.sideHandles) { 994 createHandles(['n', 's', 'e', 'w']); 995 } 996 if (options.cornerHandles) { 997 createHandles(['sw', 'nw', 'ne', 'se']); 998 } 999 1000 1001 //}}} 1071 1072 if (options.dragEdges && $.isArray(options.createDragbars)) 1073 createDragbars(options.createDragbars); 1074 1075 if ($.isArray(options.createHandles)) 1076 createHandles(options.createHandles); 1077 1078 if (options.drawBorders && $.isArray(options.createBorders)) 1079 createBorders(options.createBorders); 1080 1081 //}}} 1082 1083 // This is a hack for iOS5 to support drag/move touch functionality 1084 $(document).bind('touchstart.jcrop-ios',function(e) { 1085 if ($(e.currentTarget).hasClass('jcrop-tracker')) e.stopPropagation(); 1086 }); 1002 1087 1003 1088 var $track = newTracker().mousedown(createDragger('move')).css({ … … 1032 1117 disableHandles: disableHandles, 1033 1118 animMode: animMode, 1119 setBgOpacity: setBgOpacity, 1034 1120 done: done 1035 1121 }; … … 1048 1134 zIndex: 450 1049 1135 }); 1136 if (Touch.support) { 1137 $(document) 1138 .bind('touchmove.jcrop', trackTouchMove) 1139 .bind('touchend.jcrop', trackTouchEnd); 1140 } 1050 1141 if (trackDoc) { 1051 1142 $(document) 1052 .bind('mousemove ',trackMove)1053 .bind('mouseup ',trackUp);1143 .bind('mousemove.jcrop',trackMove) 1144 .bind('mouseup.jcrop',trackUp); 1054 1145 } 1055 1146 } … … 1060 1151 zIndex: 290 1061 1152 }); 1062 if (trackDoc) { 1063 $(document) 1064 .unbind('mousemove', trackMove) 1065 .unbind('mouseup', trackUp); 1066 } 1153 $(document).unbind('.jcrop'); 1067 1154 } 1068 1155 //}}} … … 1123 1210 } 1124 1211 //}}} 1125 1126 if (Touch.support) {1127 $(document)1128 .bind('touchmove', trackTouchMove)1129 .bind('touchend', trackTouchEnd);1130 }1131 1212 1132 1213 if (!trackDoc) { … … 1170 1251 if (options.allowMove) { 1171 1252 Coords.moveOffset([x, y]); 1172 Selection.updateVisible( );1253 Selection.updateVisible(true); 1173 1254 } 1174 1255 e.preventDefault(); … … 1178 1259 function parseKey(e) //{{{ 1179 1260 { 1180 if (e.ctrlKey ) {1261 if (e.ctrlKey || e.metaKey) { 1181 1262 return true; 1182 1263 } … … 1198 1279 break; 1199 1280 case 27: 1200 Selection.release();1281 if (options.allowSelect) Selection.release(); 1201 1282 break; 1202 1283 case 9: … … 1236 1317 function animateTo(a, callback) //{{{ 1237 1318 { 1238 var x1 = parseInt(a[0], 10)/ xscale,1239 y1 = parseInt(a[1], 10)/ yscale,1240 x2 = parseInt(a[2], 10)/ xscale,1241 y2 = parseInt(a[3], 10)/ yscale;1319 var x1 = a[0] / xscale, 1320 y1 = a[1] / yscale, 1321 x2 = a[2] / xscale, 1322 y2 = a[3] / yscale; 1242 1323 1243 1324 if (animating) { … … 1296 1377 function setSelect(rect) //{{{ 1297 1378 { 1298 setSelectRaw([ 1299 parseInt(rect[0], 10) / xscale, parseInt(rect[1], 10) / yscale, parseInt(rect[2], 10) / xscale, parseInt(rect[3], 10) / yscale]); 1379 setSelectRaw([rect[0] / xscale, rect[1] / yscale, rect[2] / xscale, rect[3] / yscale]); 1380 options.onSelect.call(api, unscale(Coords.getFixed())); 1381 Selection.enableHandles(); 1300 1382 } 1301 1383 //}}} … … 1369 1451 $trk.width(boundx + (bound * 2)).height(boundy + (bound * 2)); 1370 1452 $div.width(boundx).height(boundy); 1453 Shade.resize(boundx,boundy); 1371 1454 enableCrop(); 1372 1455 … … 1378 1461 } 1379 1462 //}}} 1463 function colorChangeMacro($obj,color,now) { 1464 var mycolor = color || options.bgColor; 1465 if (options.bgFade && supportsColorFade() && options.fadeTime && !now) { 1466 $obj.animate({ 1467 backgroundColor: mycolor 1468 }, { 1469 queue: false, 1470 duration: options.fadeTime 1471 }); 1472 } else { 1473 $obj.css('backgroundColor', mycolor); 1474 } 1475 } 1380 1476 function interfaceUpdate(alt) //{{{ 1381 1477 // This method tweaks the interface based on options object. … … 1395 1491 Selection.setCursor(options.allowMove ? 'move' : 'default'); 1396 1492 1493 if (options.hasOwnProperty('trueSize')) { 1494 xscale = options.trueSize[0] / boundx; 1495 yscale = options.trueSize[1] / boundy; 1496 } 1397 1497 1398 1498 if (options.hasOwnProperty('setSelect')) { … … 1402 1502 } 1403 1503 1404 if (options.hasOwnProperty('trueSize')) { 1405 xscale = options.trueSize[0] / boundx; 1406 yscale = options.trueSize[1] / boundy; 1407 } 1408 if (options.hasOwnProperty('bgColor')) { 1409 1410 if (supportsColorFade() && options.fadeTime) { 1411 $div.animate({ 1412 backgroundColor: options.bgColor 1413 }, { 1414 queue: false, 1415 duration: options.fadeTime 1416 }); 1417 } else { 1418 $div.css('backgroundColor', options.bgColor); 1419 } 1420 1421 delete(options.bgColor); 1422 } 1423 if (options.hasOwnProperty('bgOpacity')) { 1504 Shade.refresh(); 1505 1506 if (options.bgColor != bgcolor) { 1507 colorChangeMacro( 1508 options.shade? Shade.getShades(): $div, 1509 options.shade? 1510 (options.shadeColor || options.bgColor): 1511 options.bgColor 1512 ); 1513 bgcolor = options.bgColor; 1514 } 1515 1516 if (bgopacity != options.bgOpacity) { 1424 1517 bgopacity = options.bgOpacity; 1425 1426 if (Selection.isAwake()) { 1427 if (options.fadeTime) { 1428 $img.fadeTo(options.fadeTime, bgopacity); 1429 } else { 1430 $div.css('opacity', options.opacity); 1431 } 1432 } 1433 delete(options.bgOpacity); 1518 if (options.shade) Shade.refresh(); 1519 else Selection.setBgOpacity(bgopacity); 1434 1520 } 1435 1521 … … 1449 1535 //}}} 1450 1536 1451 if (Touch.support) { 1452 $trk.bind('touchstart', Touch.newSelection); 1453 } 1537 if (Touch.support) $trk.bind('touchstart.jcrop', Touch.newSelection); 1454 1538 1455 1539 $hdl_holder.hide(); … … 1482 1566 return [xscale, yscale]; 1483 1567 }, 1568 getOptions: function() { 1569 // careful: internal values are returned 1570 return options; 1571 }, 1484 1572 1485 1573 ui: { … … 1489 1577 }; 1490 1578 1491 if ($.browser.msie) { 1492 $div.bind('selectstart', function () { 1493 return false; 1494 }); 1495 } 1579 if ($.browser.msie) 1580 $div.bind('selectstart', function () { return false; }); 1496 1581 1497 1582 $origimg.data('Jcrop', api); … … 1500 1585 $.fn.Jcrop = function (options, callback) //{{{ 1501 1586 { 1502 1503 function attachWhenDone(from) //{{{ 1504 { 1505 var opt = (typeof(options) === 'object') ? options : {}; 1506 var loadsrc = opt.useImg || from.src; 1507 var img = new Image(); 1508 img.onload = function () { 1509 function attachJcrop() { 1510 var api = $.Jcrop(from, opt); 1511 if (typeof(callback) === 'function') { 1512 callback.call(api); 1513 } 1514 } 1515 1516 function attachAttempt() { 1517 if (!img.width || !img.height) { 1518 window.setTimeout(attachAttempt, 50); 1519 } else { 1520 attachJcrop(); 1521 } 1522 } 1523 window.setTimeout(attachAttempt, 50); 1524 }; 1525 img.src = loadsrc; 1526 } 1527 //}}} 1528 1587 var api; 1529 1588 // Iterate over each object, attach Jcrop 1530 1589 this.each(function () { … … 1532 1591 if ($(this).data('Jcrop')) { 1533 1592 // The API can be requested this way (undocumented) 1534 if (options === 'api') { 1535 return $(this).data('Jcrop'); 1536 } 1593 if (options === 'api') return $(this).data('Jcrop'); 1537 1594 // Otherwise, we just reset the options... 1538 else { 1539 $(this).data('Jcrop').setOptions(options); 1540 } 1595 else $(this).data('Jcrop').setOptions(options); 1541 1596 } 1542 1597 // If we haven't been attached, preload and attach 1543 1598 else { 1544 attachWhenDone(this); 1599 if (this.tagName == 'IMG') 1600 $.Jcrop.Loader(this,function(){ 1601 $(this).css({display:'block',visibility:'hidden'}); 1602 api = $.Jcrop(this, options); 1603 if ($.isFunction(callback)) callback.call(api); 1604 }); 1605 else { 1606 $(this).css({display:'block',visibility:'hidden'}); 1607 api = $.Jcrop(this, options); 1608 if ($.isFunction(callback)) callback.call(api); 1609 } 1545 1610 } 1546 1611 }); … … 1549 1614 return this; 1550 1615 }; 1616 //}}} 1617 // $.Jcrop.Loader - basic image loader {{{ 1618 1619 $.Jcrop.Loader = function(imgobj,success,error){ 1620 var $img = $(imgobj), img = $img[0]; 1621 1622 function completeCheck(){ 1623 if (img.complete) { 1624 $img.unbind('.jcloader'); 1625 if ($.isFunction(success)) success.call(img); 1626 } 1627 else window.setTimeout(completeCheck,50); 1628 } 1629 1630 $img 1631 .bind('load.jcloader',completeCheck) 1632 .bind('error.jcloader',function(e){ 1633 $img.unbind('.jcloader'); 1634 if ($.isFunction(error)) error.call(img); 1635 }); 1636 1637 if (img.complete && $.isFunction(success)){ 1638 $img.unbind('.jcloader'); 1639 success.call(img); 1640 } 1641 }; 1642 1551 1643 //}}} 1552 1644 // Global Defaults {{{ … … 1568 1660 borderOpacity: 0.4, 1569 1661 handleOpacity: 0.5, 1570 handleSize: 9, 1571 handleOffset: 5, 1662 handleSize: 7, 1572 1663 1573 1664 aspectRatio: 0, 1574 1665 keySupport: true, 1575 cornerHandles: true, 1576 sideHandles: true, 1666 createHandles: ['n','s','e','w','nw','ne','se','sw'], 1667 createDragbars: ['n','s','e','w'], 1668 createBorders: ['n','s','e','w'], 1577 1669 drawBorders: true, 1578 1670 dragEdges: true, 1579 1671 fixedSupport: true, 1580 1672 touchSupport: null, 1673 1674 shade: null, 1581 1675 1582 1676 boxWidth: 0, … … 1594 1688 onChange: function () {}, 1595 1689 onSelect: function () {}, 1690 onDblClick: function () {}, 1596 1691 onRelease: function () {} 1597 1692 };
Note: See TracChangeset
for help on using the changeset viewer.