jquery.imgareaselect.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. * imgAreaSelect jQuery plugin
  3. * version 0.9.10
  4. *
  5. * Copyright (c) 2008-2013 Michal Wojciechowski (odyniec.net)
  6. *
  7. * Dual licensed under the MIT (MIT-LICENSE.txt)
  8. * and GPL (GPL-LICENSE.txt) licenses.
  9. *
  10. * http://odyniec.net/projects/imgareaselect/
  11. *
  12. */
  13. (function($) {
  14. var abs = Math.abs,
  15. max = Math.max,
  16. min = Math.min,
  17. round = Math.round;
  18. function div() {
  19. return $('<div/>');
  20. }
  21. $.imgAreaSelect = function (img, options) {
  22. var
  23. $img = $(img),
  24. imgLoaded,
  25. $box = div(),
  26. $area = div(),
  27. $border = div().add(div()).add(div()).add(div()),
  28. $outer = div().add(div()).add(div()).add(div()),
  29. $handles = $([]),
  30. $areaOpera,
  31. left, top,
  32. imgOfs = { left: 0, top: 0 },
  33. imgWidth, imgHeight,
  34. $parent,
  35. parOfs = { left: 0, top: 0 },
  36. zIndex = 0,
  37. position = 'absolute',
  38. startX, startY,
  39. scaleX, scaleY,
  40. resize,
  41. minWidth, minHeight, maxWidth, maxHeight,
  42. aspectRatio,
  43. shown,
  44. x1, y1, x2, y2,
  45. selection = { x1: 0, y1: 0, x2: 0, y2: 0, width: 0, height: 0 },
  46. docElem = document.documentElement,
  47. ua = navigator.userAgent,
  48. $p, d, i, o, w, h, adjusted;
  49. function viewX(x) {
  50. return x + imgOfs.left - parOfs.left;
  51. }
  52. function viewY(y) {
  53. return y + imgOfs.top - parOfs.top;
  54. }
  55. function selX(x) {
  56. return x - imgOfs.left + parOfs.left;
  57. }
  58. function selY(y) {
  59. return y - imgOfs.top + parOfs.top;
  60. }
  61. function evX(event) {
  62. return event.pageX - parOfs.left;
  63. }
  64. function evY(event) {
  65. return event.pageY - parOfs.top;
  66. }
  67. function getSelection(noScale) {
  68. var sx = noScale || scaleX, sy = noScale || scaleY;
  69. return { x1: round(selection.x1 * sx),
  70. y1: round(selection.y1 * sy),
  71. x2: round(selection.x2 * sx),
  72. y2: round(selection.y2 * sy),
  73. width: round(selection.x2 * sx) - round(selection.x1 * sx),
  74. height: round(selection.y2 * sy) - round(selection.y1 * sy) };
  75. }
  76. function setSelection(x1, y1, x2, y2, noScale) {
  77. var sx = noScale || scaleX, sy = noScale || scaleY;
  78. selection = {
  79. x1: round(x1 / sx || 0),
  80. y1: round(y1 / sy || 0),
  81. x2: round(x2 / sx || 0),
  82. y2: round(y2 / sy || 0)
  83. };
  84. selection.width = selection.x2 - selection.x1;
  85. selection.height = selection.y2 - selection.y1;
  86. }
  87. function adjust() {
  88. if (!imgLoaded || !$img.width())
  89. return;
  90. imgOfs = { left: round($img.offset().left), top: round($img.offset().top) };
  91. imgWidth = $img.innerWidth();
  92. imgHeight = $img.innerHeight();
  93. imgOfs.top += ($img.outerHeight() - imgHeight) >> 1;
  94. imgOfs.left += ($img.outerWidth() - imgWidth) >> 1;
  95. minWidth = round(options.minWidth / scaleX) || 0;
  96. minHeight = round(options.minHeight / scaleY) || 0;
  97. maxWidth = round(min(options.maxWidth / scaleX || 1<<24, imgWidth));
  98. maxHeight = round(min(options.maxHeight / scaleY || 1<<24, imgHeight));
  99. if ($().jquery == '1.3.2' && position == 'fixed' &&
  100. !docElem['getBoundingClientRect'])
  101. {
  102. imgOfs.top += max(document.body.scrollTop, docElem.scrollTop);
  103. imgOfs.left += max(document.body.scrollLeft, docElem.scrollLeft);
  104. }
  105. parOfs = /absolute|relative/.test($parent.css('position')) ?
  106. { left: round($parent.offset().left) - $parent.scrollLeft(),
  107. top: round($parent.offset().top) - $parent.scrollTop() } :
  108. position == 'fixed' ?
  109. { left: $(document).scrollLeft(), top: $(document).scrollTop() } :
  110. { left: 0, top: 0 };
  111. left = viewX(0);
  112. top = viewY(0);
  113. if (selection.x2 > imgWidth || selection.y2 > imgHeight)
  114. doResize();
  115. }
  116. function update(resetKeyPress) {
  117. if (!shown) return;
  118. $box.css({ left: viewX(selection.x1), top: viewY(selection.y1) })
  119. .add($area).width(w = selection.width).height(h = selection.height);
  120. $area.add($border).add($handles).css({ left: 0, top: 0 });
  121. $border
  122. .width(max(w - $border.outerWidth() + $border.innerWidth(), 0))
  123. .height(max(h - $border.outerHeight() + $border.innerHeight(), 0));
  124. $($outer[0]).css({ left: left, top: top,
  125. width: selection.x1, height: imgHeight });
  126. $($outer[1]).css({ left: left + selection.x1, top: top,
  127. width: w, height: selection.y1 });
  128. $($outer[2]).css({ left: left + selection.x2, top: top,
  129. width: imgWidth - selection.x2, height: imgHeight });
  130. $($outer[3]).css({ left: left + selection.x1, top: top + selection.y2,
  131. width: w, height: imgHeight - selection.y2 });
  132. w -= $handles.outerWidth();
  133. h -= $handles.outerHeight();
  134. switch ($handles.length) {
  135. case 8:
  136. $($handles[4]).css({ left: w >> 1 });
  137. $($handles[5]).css({ left: w, top: h >> 1 });
  138. $($handles[6]).css({ left: w >> 1, top: h });
  139. $($handles[7]).css({ top: h >> 1 });
  140. case 4:
  141. $handles.slice(1,3).css({ left: w });
  142. $handles.slice(2,4).css({ top: h });
  143. }
  144. if (resetKeyPress !== false) {
  145. if ($.imgAreaSelect.onKeyPress != docKeyPress)
  146. $(document).unbind($.imgAreaSelect.keyPress,
  147. $.imgAreaSelect.onKeyPress);
  148. if (options.keys)
  149. $(document)[$.imgAreaSelect.keyPress](
  150. $.imgAreaSelect.onKeyPress = docKeyPress);
  151. }
  152. if (msie && $border.outerWidth() - $border.innerWidth() == 2) {
  153. $border.css('margin', 0);
  154. setTimeout(function () { $border.css('margin', 'auto'); }, 0);
  155. }
  156. }
  157. function doUpdate(resetKeyPress) {
  158. adjust();
  159. update(resetKeyPress);
  160. x1 = viewX(selection.x1); y1 = viewY(selection.y1);
  161. x2 = viewX(selection.x2); y2 = viewY(selection.y2);
  162. }
  163. function hide($elem, fn) {
  164. options.fadeSpeed ? $elem.fadeOut(options.fadeSpeed, fn) : $elem.hide();
  165. }
  166. function areaMouseMove(event) {
  167. var x = selX(evX(event)) - selection.x1,
  168. y = selY(evY(event)) - selection.y1;
  169. if (!adjusted) {
  170. adjust();
  171. adjusted = true;
  172. $box.one('mouseout', function () { adjusted = false; });
  173. }
  174. resize = '';
  175. if (options.resizable) {
  176. if (y <= options.resizeMargin)
  177. resize = 'n';
  178. else if (y >= selection.height - options.resizeMargin)
  179. resize = 's';
  180. if (x <= options.resizeMargin)
  181. resize += 'w';
  182. else if (x >= selection.width - options.resizeMargin)
  183. resize += 'e';
  184. }
  185. $box.css('cursor', resize ? resize + '-resize' :
  186. options.movable ? 'move' : '');
  187. if ($areaOpera)
  188. $areaOpera.toggle();
  189. }
  190. function docMouseUp(event) {
  191. $('body').css('cursor', '');
  192. if (options.autoHide || selection.width * selection.height == 0)
  193. hide($box.add($outer), function () { $(this).hide(); });
  194. $(document).unbind('mousemove', selectingMouseMove);
  195. $box.mousemove(areaMouseMove);
  196. options.onSelectEnd(img, getSelection());
  197. }
  198. function areaMouseDown(event) {
  199. if (event.which != 1) return false;
  200. adjust();
  201. if (resize) {
  202. $('body').css('cursor', resize + '-resize');
  203. x1 = viewX(selection[/w/.test(resize) ? 'x2' : 'x1']);
  204. y1 = viewY(selection[/n/.test(resize) ? 'y2' : 'y1']);
  205. $(document).mousemove(selectingMouseMove)
  206. .one('mouseup', docMouseUp);
  207. $box.unbind('mousemove', areaMouseMove);
  208. }
  209. else if (options.movable) {
  210. startX = left + selection.x1 - evX(event);
  211. startY = top + selection.y1 - evY(event);
  212. $box.unbind('mousemove', areaMouseMove);
  213. $(document).mousemove(movingMouseMove)
  214. .one('mouseup', function () {
  215. options.onSelectEnd(img, getSelection());
  216. $(document).unbind('mousemove', movingMouseMove);
  217. $box.mousemove(areaMouseMove);
  218. });
  219. }
  220. else
  221. $img.mousedown(event);
  222. return false;
  223. }
  224. function fixAspectRatio(xFirst) {
  225. if (aspectRatio)
  226. if (xFirst) {
  227. x2 = max(left, min(left + imgWidth,
  228. x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1)));
  229. y2 = round(max(top, min(top + imgHeight,
  230. y1 + abs(x2 - x1) / aspectRatio * (y2 > y1 || -1))));
  231. x2 = round(x2);
  232. }
  233. else {
  234. y2 = max(top, min(top + imgHeight,
  235. y1 + abs(x2 - x1) / aspectRatio * (y2 > y1 || -1)));
  236. x2 = round(max(left, min(left + imgWidth,
  237. x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1))));
  238. y2 = round(y2);
  239. }
  240. }
  241. function doResize() {
  242. x1 = min(x1, left + imgWidth);
  243. y1 = min(y1, top + imgHeight);
  244. if (abs(x2 - x1) < minWidth) {
  245. x2 = x1 - minWidth * (x2 < x1 || -1);
  246. if (x2 < left)
  247. x1 = left + minWidth;
  248. else if (x2 > left + imgWidth)
  249. x1 = left + imgWidth - minWidth;
  250. }
  251. if (abs(y2 - y1) < minHeight) {
  252. y2 = y1 - minHeight * (y2 < y1 || -1);
  253. if (y2 < top)
  254. y1 = top + minHeight;
  255. else if (y2 > top + imgHeight)
  256. y1 = top + imgHeight - minHeight;
  257. }
  258. x2 = max(left, min(x2, left + imgWidth));
  259. y2 = max(top, min(y2, top + imgHeight));
  260. fixAspectRatio(abs(x2 - x1) < abs(y2 - y1) * aspectRatio);
  261. if (abs(x2 - x1) > maxWidth) {
  262. x2 = x1 - maxWidth * (x2 < x1 || -1);
  263. fixAspectRatio();
  264. }
  265. if (abs(y2 - y1) > maxHeight) {
  266. y2 = y1 - maxHeight * (y2 < y1 || -1);
  267. fixAspectRatio(true);
  268. }
  269. selection = { x1: selX(min(x1, x2)), x2: selX(max(x1, x2)),
  270. y1: selY(min(y1, y2)), y2: selY(max(y1, y2)),
  271. width: abs(x2 - x1), height: abs(y2 - y1) };
  272. update();
  273. options.onSelectChange(img, getSelection());
  274. }
  275. function selectingMouseMove(event) {
  276. x2 = /w|e|^$/.test(resize) || aspectRatio ? evX(event) : viewX(selection.x2);
  277. y2 = /n|s|^$/.test(resize) || aspectRatio ? evY(event) : viewY(selection.y2);
  278. doResize();
  279. return false;
  280. }
  281. function doMove(newX1, newY1) {
  282. x2 = (x1 = newX1) + selection.width;
  283. y2 = (y1 = newY1) + selection.height;
  284. $.extend(selection, { x1: selX(x1), y1: selY(y1), x2: selX(x2),
  285. y2: selY(y2) });
  286. update();
  287. options.onSelectChange(img, getSelection());
  288. }
  289. function movingMouseMove(event) {
  290. x1 = max(left, min(startX + evX(event), left + imgWidth - selection.width));
  291. y1 = max(top, min(startY + evY(event), top + imgHeight - selection.height));
  292. doMove(x1, y1);
  293. event.preventDefault();
  294. return false;
  295. }
  296. function startSelection() {
  297. $(document).unbind('mousemove', startSelection);
  298. adjust();
  299. x2 = x1;
  300. y2 = y1;
  301. doResize();
  302. resize = '';
  303. if (!$outer.is(':visible'))
  304. $box.add($outer).hide().fadeIn(options.fadeSpeed||0);
  305. shown = true;
  306. $(document).unbind('mouseup', cancelSelection)
  307. .mousemove(selectingMouseMove).one('mouseup', docMouseUp);
  308. $box.unbind('mousemove', areaMouseMove);
  309. options.onSelectStart(img, getSelection());
  310. }
  311. function cancelSelection() {
  312. $(document).unbind('mousemove', startSelection)
  313. .unbind('mouseup', cancelSelection);
  314. hide($box.add($outer));
  315. setSelection(selX(x1), selY(y1), selX(x1), selY(y1));
  316. if (!(this instanceof $.imgAreaSelect)) {
  317. options.onSelectChange(img, getSelection());
  318. options.onSelectEnd(img, getSelection());
  319. }
  320. }
  321. function imgMouseDown(event) {
  322. if (event.which != 1 || $outer.is(':animated')) return false;
  323. adjust();
  324. startX = x1 = evX(event);
  325. startY = y1 = evY(event);
  326. $(document).mousemove(startSelection).mouseup(cancelSelection);
  327. return false;
  328. }
  329. function windowResize() {
  330. doUpdate(false);
  331. }
  332. function imgLoad() {
  333. imgLoaded = true;
  334. setOptions(options = $.extend({
  335. classPrefix: 'imgareaselect',
  336. movable: true,
  337. parent: 'body',
  338. resizable: true,
  339. resizeMargin: 10,
  340. onInit: function () {},
  341. onSelectStart: function () {},
  342. onSelectChange: function () {},
  343. onSelectEnd: function () {}
  344. }, options));
  345. $box.add($outer).css({ visibility: '' });
  346. if (options.show) {
  347. shown = true;
  348. adjust();
  349. update();
  350. $box.add($outer).hide().fadeIn(options.fadeSpeed||0);
  351. }
  352. setTimeout(function () { options.onInit(img, getSelection()); }, 0);
  353. }
  354. var docKeyPress = function(event) {
  355. var k = options.keys, d, t, key = event.keyCode;
  356. d = !isNaN(k.alt) && (event.altKey || event.originalEvent.altKey) ? k.alt :
  357. !isNaN(k.ctrl) && event.ctrlKey ? k.ctrl :
  358. !isNaN(k.shift) && event.shiftKey ? k.shift :
  359. !isNaN(k.arrows) ? k.arrows : 10;
  360. if (k.arrows == 'resize' || (k.shift == 'resize' && event.shiftKey) ||
  361. (k.ctrl == 'resize' && event.ctrlKey) ||
  362. (k.alt == 'resize' && (event.altKey || event.originalEvent.altKey)))
  363. {
  364. switch (key) {
  365. case 37:
  366. d = -d;
  367. case 39:
  368. t = max(x1, x2);
  369. x1 = min(x1, x2);
  370. x2 = max(t + d, x1);
  371. fixAspectRatio();
  372. break;
  373. case 38:
  374. d = -d;
  375. case 40:
  376. t = max(y1, y2);
  377. y1 = min(y1, y2);
  378. y2 = max(t + d, y1);
  379. fixAspectRatio(true);
  380. break;
  381. default:
  382. return;
  383. }
  384. doResize();
  385. }
  386. else {
  387. x1 = min(x1, x2);
  388. y1 = min(y1, y2);
  389. switch (key) {
  390. case 37:
  391. doMove(max(x1 - d, left), y1);
  392. break;
  393. case 38:
  394. doMove(x1, max(y1 - d, top));
  395. break;
  396. case 39:
  397. doMove(x1 + min(d, imgWidth - selX(x2)), y1);
  398. break;
  399. case 40:
  400. doMove(x1, y1 + min(d, imgHeight - selY(y2)));
  401. break;
  402. default:
  403. return;
  404. }
  405. }
  406. return false;
  407. };
  408. function styleOptions($elem, props) {
  409. for (var option in props)
  410. if (options[option] !== undefined)
  411. $elem.css(props[option], options[option]);
  412. }
  413. function setOptions(newOptions) {
  414. if (newOptions.parent)
  415. ($parent = $(newOptions.parent)).append($box.add($outer));
  416. $.extend(options, newOptions);
  417. adjust();
  418. if (newOptions.handles != null) {
  419. $handles.remove();
  420. $handles = $([]);
  421. i = newOptions.handles ? newOptions.handles == 'corners' ? 4 : 8 : 0;
  422. while (i--)
  423. $handles = $handles.add(div());
  424. $handles.addClass(options.classPrefix + '-handle').css({
  425. position: 'absolute',
  426. fontSize: 0,
  427. zIndex: zIndex + 1 || 1
  428. });
  429. if (!parseInt($handles.css('width')) >= 0)
  430. $handles.width(5).height(5);
  431. if (o = options.borderWidth)
  432. $handles.css({ borderWidth: o, borderStyle: 'solid' });
  433. styleOptions($handles, { borderColor1: 'border-color',
  434. borderColor2: 'background-color',
  435. borderOpacity: 'opacity' });
  436. }
  437. scaleX = options.imageWidth / imgWidth || 1;
  438. scaleY = options.imageHeight / imgHeight || 1;
  439. if (newOptions.x1 != null) {
  440. setSelection(newOptions.x1, newOptions.y1, newOptions.x2,
  441. newOptions.y2);
  442. newOptions.show = !newOptions.hide;
  443. }
  444. if (newOptions.keys)
  445. options.keys = $.extend({ shift: 1, ctrl: 'resize' },
  446. newOptions.keys);
  447. $outer.addClass(options.classPrefix + '-outer');
  448. $area.addClass(options.classPrefix + '-selection');
  449. for (i = 0; i++ < 4;)
  450. $($border[i-1]).addClass(options.classPrefix + '-border' + i);
  451. styleOptions($area, { selectionColor: 'background-color',
  452. selectionOpacity: 'opacity' });
  453. styleOptions($border, { borderOpacity: 'opacity',
  454. borderWidth: 'border-width' });
  455. styleOptions($outer, { outerColor: 'background-color',
  456. outerOpacity: 'opacity' });
  457. if (o = options.borderColor1)
  458. $($border[0]).css({ borderStyle: 'solid', borderColor: o });
  459. if (o = options.borderColor2)
  460. $($border[1]).css({ borderStyle: 'dashed', borderColor: o });
  461. $box.append($area.add($border).add($areaOpera)).append($handles);
  462. if (msie) {
  463. if (o = ($outer.css('filter')||'').match(/opacity=(\d+)/))
  464. $outer.css('opacity', o[1]/100);
  465. if (o = ($border.css('filter')||'').match(/opacity=(\d+)/))
  466. $border.css('opacity', o[1]/100);
  467. }
  468. if (newOptions.hide)
  469. hide($box.add($outer));
  470. else if (newOptions.show && imgLoaded) {
  471. shown = true;
  472. $box.add($outer).fadeIn(options.fadeSpeed||0);
  473. doUpdate();
  474. }
  475. aspectRatio = (d = (options.aspectRatio || '').split(/:/))[0] / d[1];
  476. $img.add($outer).unbind('mousedown', imgMouseDown);
  477. if (options.disable || options.enable === false) {
  478. $box.unbind('mousemove', areaMouseMove).unbind('mousedown', areaMouseDown);
  479. $(window).unbind('resize', windowResize);
  480. }
  481. else {
  482. if (options.enable || options.disable === false) {
  483. if (options.resizable || options.movable)
  484. $box.mousemove(areaMouseMove).mousedown(areaMouseDown);
  485. $(window).resize(windowResize);
  486. }
  487. if (!options.persistent)
  488. $img.add($outer).mousedown(imgMouseDown);
  489. }
  490. options.enable = options.disable = undefined;
  491. }
  492. this.remove = function () {
  493. setOptions({ disable: true });
  494. $box.add($outer).remove();
  495. };
  496. this.getOptions = function () { return options; };
  497. this.setOptions = setOptions;
  498. this.getSelection = getSelection;
  499. this.setSelection = setSelection;
  500. this.cancelSelection = cancelSelection;
  501. this.update = doUpdate;
  502. var msie = (/msie ([\w.]+)/i.exec(ua)||[])[1],
  503. opera = /opera/i.test(ua),
  504. safari = /webkit/i.test(ua) && !/chrome/i.test(ua);
  505. $p = $img;
  506. while ($p.length) {
  507. zIndex = max(zIndex,
  508. !isNaN($p.css('z-index')) ? $p.css('z-index') : zIndex);
  509. if ($p.css('position') == 'fixed')
  510. position = 'fixed';
  511. $p = $p.parent(':not(body)');
  512. }
  513. zIndex = options.zIndex || zIndex;
  514. if (msie)
  515. $img.attr('unselectable', 'on');
  516. $.imgAreaSelect.keyPress = msie || safari ? 'keydown' : 'keypress';
  517. if (opera)
  518. $areaOpera = div().css({ width: '100%', height: '100%',
  519. position: 'absolute', zIndex: zIndex + 2 || 2 });
  520. $box.add($outer).css({ visibility: 'hidden', position: position,
  521. overflow: 'hidden', zIndex: zIndex || '0' });
  522. $box.css({ zIndex: zIndex + 2 || 2 });
  523. $area.add($border).css({ position: 'absolute', fontSize: 0 });
  524. img.complete || img.readyState == 'complete' || !$img.is('img') ?
  525. imgLoad() : $img.one('load', imgLoad);
  526. if (!imgLoaded && msie && msie >= 7)
  527. img.src = img.src;
  528. };
  529. $.fn.imgAreaSelect = function (options) {
  530. options = options || {};
  531. this.each(function () {
  532. if ($(this).data('imgAreaSelect')) {
  533. if (options.remove) {
  534. $(this).data('imgAreaSelect').remove();
  535. $(this).removeData('imgAreaSelect');
  536. }
  537. else
  538. $(this).data('imgAreaSelect').setOptions(options);
  539. }
  540. else if (!options.remove) {
  541. if (options.enable === undefined && options.disable === undefined)
  542. options.enable = true;
  543. $(this).data('imgAreaSelect', new $.imgAreaSelect(this, options));
  544. }
  545. });
  546. if (options.instance)
  547. return $(this).data('imgAreaSelect');
  548. return this;
  549. };
  550. })(jQuery);