imgareaselect-rails 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in imgareaselect-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 OrgSync, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # imgAreaSelect for Rails
2
+
3
+ Places [imgAreaSelect](http://odyniec.net/projects/imgareaselect/) into the Rails asset pipeline.
4
+
5
+ ## Versioning
6
+
7
+ This project uses [Semantic Versioning](http://semver.org/) and will attempt to account for the underlying imgAreaSelect JavaScript library versioning.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'imgareaselect-rails', '~> 1.0'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Application Wide Usage
20
+
21
+ In your application.js:
22
+
23
+ //= require jquery.imgareaselect
24
+
25
+ In your application.scss
26
+
27
+ @import 'imgareaselect-default'
28
+
29
+ or
30
+
31
+ @import 'imgareaselect-animated'
32
+
33
+ or
34
+
35
+ @import 'imgareaselect-deprecated'
36
+
37
+ ## Per Page Usage
38
+
39
+ On the page you want to use it on include a stylesheet and the JavaScript:
40
+
41
+ <%= stylesheet_link_tag 'imgareaselect-default' %>
42
+ <%= javascript_include_tag 'jquery.imgareaselect' %>
43
+
44
+ ## Updating
45
+
46
+ When new versions of imgAreaSelect are released the gem will be updated. If there's no update for the current version, contact me or contribute by updating the library and issuing a pull request.
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/imgareaselect/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Aaron Lasseigne']
6
+ gem.email = ['aaron@orgsync.com']
7
+ gem.description = %Q{Places imgAreaSelect #{Imgareaselect::VERSION} in the Rails asset pipeline.}
8
+ gem.summary = %Q{Places imgAreaSelect #{Imgareaselect::VERSION} in the Rails asset pipeline.}
9
+ gem.homepage = 'https://github.com/orgsync/imgareaselect-rails'
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = 'imgareaselect-rails'
15
+ gem.require_paths = ['lib']
16
+ gem.version = Imgareaselect::Rails::VERSION
17
+
18
+ gem.add_runtime_dependency 'rails', '>= 3.1'
19
+ end
@@ -0,0 +1,6 @@
1
+ module Imgareaselect
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Imgareaselect
2
+ VERSION = '0.9.8'
3
+ module Rails
4
+ VERSION = '1.0.0'
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ require 'imgareaselect/rails/version'
2
+ require 'imgareaselect/rails/engine'
@@ -0,0 +1 @@
1
+ require 'imgareaselect/rails'
Binary file
Binary file
@@ -0,0 +1,724 @@
1
+ /*
2
+ * imgAreaSelect jQuery plugin
3
+ * version 0.9.8
4
+ *
5
+ * Copyright (c) 2008-2011 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
+
14
+ (function($) {
15
+
16
+ var abs = Math.abs,
17
+ max = Math.max,
18
+ min = Math.min,
19
+ round = Math.round;
20
+
21
+ function div() {
22
+ return $('<div/>');
23
+ }
24
+
25
+ $.imgAreaSelect = function (img, options) {
26
+ var
27
+
28
+ $img = $(img),
29
+
30
+ imgLoaded,
31
+
32
+ $box = div(),
33
+ $area = div(),
34
+ $border = div().add(div()).add(div()).add(div()),
35
+ $outer = div().add(div()).add(div()).add(div()),
36
+ $handles = $([]),
37
+
38
+ $areaOpera,
39
+
40
+ left, top,
41
+
42
+ imgOfs = { left: 0, top: 0 },
43
+
44
+ imgWidth, imgHeight,
45
+
46
+ $parent,
47
+
48
+ parOfs = { left: 0, top: 0 },
49
+
50
+ zIndex = 0,
51
+
52
+ position = 'absolute',
53
+
54
+ startX, startY,
55
+
56
+ scaleX, scaleY,
57
+
58
+ resize,
59
+
60
+ minWidth, minHeight, maxWidth, maxHeight,
61
+
62
+ aspectRatio,
63
+
64
+ shown,
65
+
66
+ x1, y1, x2, y2,
67
+
68
+ selection = { x1: 0, y1: 0, x2: 0, y2: 0, width: 0, height: 0 },
69
+
70
+ docElem = document.documentElement,
71
+
72
+ $p, d, i, o, w, h, adjusted;
73
+
74
+ function viewX(x) {
75
+ return x + imgOfs.left - parOfs.left;
76
+ }
77
+
78
+ function viewY(y) {
79
+ return y + imgOfs.top - parOfs.top;
80
+ }
81
+
82
+ function selX(x) {
83
+ return x - imgOfs.left + parOfs.left;
84
+ }
85
+
86
+ function selY(y) {
87
+ return y - imgOfs.top + parOfs.top;
88
+ }
89
+
90
+ function evX(event) {
91
+ return event.pageX - parOfs.left;
92
+ }
93
+
94
+ function evY(event) {
95
+ return event.pageY - parOfs.top;
96
+ }
97
+
98
+ function getSelection(noScale) {
99
+ var sx = noScale || scaleX, sy = noScale || scaleY;
100
+
101
+ return { x1: round(selection.x1 * sx),
102
+ y1: round(selection.y1 * sy),
103
+ x2: round(selection.x2 * sx),
104
+ y2: round(selection.y2 * sy),
105
+ width: round(selection.x2 * sx) - round(selection.x1 * sx),
106
+ height: round(selection.y2 * sy) - round(selection.y1 * sy) };
107
+ }
108
+
109
+ function setSelection(x1, y1, x2, y2, noScale) {
110
+ var sx = noScale || scaleX, sy = noScale || scaleY;
111
+
112
+ selection = {
113
+ x1: round(x1 / sx || 0),
114
+ y1: round(y1 / sy || 0),
115
+ x2: round(x2 / sx || 0),
116
+ y2: round(y2 / sy || 0)
117
+ };
118
+
119
+ selection.width = selection.x2 - selection.x1;
120
+ selection.height = selection.y2 - selection.y1;
121
+ }
122
+
123
+ function adjust() {
124
+ if (!$img.width())
125
+ return;
126
+
127
+ imgOfs = { left: round($img.offset().left), top: round($img.offset().top) };
128
+
129
+ imgWidth = $img.innerWidth();
130
+ imgHeight = $img.innerHeight();
131
+
132
+ imgOfs.top += ($img.outerHeight() - imgHeight) >> 1;
133
+ imgOfs.left += ($img.outerWidth() - imgWidth) >> 1;
134
+
135
+ minWidth = round(options.minWidth / scaleX) || 0;
136
+ minHeight = round(options.minHeight / scaleY) || 0;
137
+ maxWidth = round(min(options.maxWidth / scaleX || 1<<24, imgWidth));
138
+ maxHeight = round(min(options.maxHeight / scaleY || 1<<24, imgHeight));
139
+
140
+ if ($().jquery == '1.3.2' && position == 'fixed' &&
141
+ !docElem['getBoundingClientRect'])
142
+ {
143
+ imgOfs.top += max(document.body.scrollTop, docElem.scrollTop);
144
+ imgOfs.left += max(document.body.scrollLeft, docElem.scrollLeft);
145
+ }
146
+
147
+ parOfs = /absolute|relative/.test($parent.css('position')) ?
148
+ { left: round($parent.offset().left) - $parent.scrollLeft(),
149
+ top: round($parent.offset().top) - $parent.scrollTop() } :
150
+ position == 'fixed' ?
151
+ { left: $(document).scrollLeft(), top: $(document).scrollTop() } :
152
+ { left: 0, top: 0 };
153
+
154
+ left = viewX(0);
155
+ top = viewY(0);
156
+
157
+ if (selection.x2 > imgWidth || selection.y2 > imgHeight)
158
+ doResize();
159
+ }
160
+
161
+ function update(resetKeyPress) {
162
+ if (!shown) return;
163
+
164
+ $box.css({ left: viewX(selection.x1), top: viewY(selection.y1) })
165
+ .add($area).width(w = selection.width).height(h = selection.height);
166
+
167
+ $area.add($border).add($handles).css({ left: 0, top: 0 });
168
+
169
+ $border
170
+ .width(max(w - $border.outerWidth() + $border.innerWidth(), 0))
171
+ .height(max(h - $border.outerHeight() + $border.innerHeight(), 0));
172
+
173
+ $($outer[0]).css({ left: left, top: top,
174
+ width: selection.x1, height: imgHeight });
175
+ $($outer[1]).css({ left: left + selection.x1, top: top,
176
+ width: w, height: selection.y1 });
177
+ $($outer[2]).css({ left: left + selection.x2, top: top,
178
+ width: imgWidth - selection.x2, height: imgHeight });
179
+ $($outer[3]).css({ left: left + selection.x1, top: top + selection.y2,
180
+ width: w, height: imgHeight - selection.y2 });
181
+
182
+ w -= $handles.outerWidth();
183
+ h -= $handles.outerHeight();
184
+
185
+ switch ($handles.length) {
186
+ case 8:
187
+ $($handles[4]).css({ left: w >> 1 });
188
+ $($handles[5]).css({ left: w, top: h >> 1 });
189
+ $($handles[6]).css({ left: w >> 1, top: h });
190
+ $($handles[7]).css({ top: h >> 1 });
191
+ case 4:
192
+ $handles.slice(1,3).css({ left: w });
193
+ $handles.slice(2,4).css({ top: h });
194
+ }
195
+
196
+ if (resetKeyPress !== false) {
197
+ if ($.imgAreaSelect.keyPress != docKeyPress)
198
+ $(document).unbind($.imgAreaSelect.keyPress,
199
+ $.imgAreaSelect.onKeyPress);
200
+
201
+ if (options.keys)
202
+ $(document)[$.imgAreaSelect.keyPress](
203
+ $.imgAreaSelect.onKeyPress = docKeyPress);
204
+ }
205
+
206
+ if ($.browser.msie && $border.outerWidth() - $border.innerWidth() == 2) {
207
+ $border.css('margin', 0);
208
+ setTimeout(function () { $border.css('margin', 'auto'); }, 0);
209
+ }
210
+ }
211
+
212
+ function doUpdate(resetKeyPress) {
213
+ adjust();
214
+ update(resetKeyPress);
215
+ x1 = viewX(selection.x1); y1 = viewY(selection.y1);
216
+ x2 = viewX(selection.x2); y2 = viewY(selection.y2);
217
+ }
218
+
219
+ function hide($elem, fn) {
220
+ options.fadeSpeed ? $elem.fadeOut(options.fadeSpeed, fn) : $elem.hide();
221
+
222
+ }
223
+
224
+ function areaMouseMove(event) {
225
+ var x = selX(evX(event)) - selection.x1,
226
+ y = selY(evY(event)) - selection.y1;
227
+
228
+ if (!adjusted) {
229
+ adjust();
230
+ adjusted = true;
231
+
232
+ $box.one('mouseout', function () { adjusted = false; });
233
+ }
234
+
235
+ resize = '';
236
+
237
+ if (options.resizable) {
238
+ if (y <= options.resizeMargin)
239
+ resize = 'n';
240
+ else if (y >= selection.height - options.resizeMargin)
241
+ resize = 's';
242
+ if (x <= options.resizeMargin)
243
+ resize += 'w';
244
+ else if (x >= selection.width - options.resizeMargin)
245
+ resize += 'e';
246
+ }
247
+
248
+ $box.css('cursor', resize ? resize + '-resize' :
249
+ options.movable ? 'move' : '');
250
+ if ($areaOpera)
251
+ $areaOpera.toggle();
252
+ }
253
+
254
+ function docMouseUp(event) {
255
+ $('body').css('cursor', '');
256
+ if (options.autoHide || selection.width * selection.height == 0)
257
+ hide($box.add($outer), function () { $(this).hide(); });
258
+
259
+ $(document).unbind('mousemove', selectingMouseMove);
260
+ $box.mousemove(areaMouseMove);
261
+
262
+ options.onSelectEnd(img, getSelection());
263
+ }
264
+
265
+ function areaMouseDown(event) {
266
+ if (event.which != 1) return false;
267
+
268
+ adjust();
269
+
270
+ if (resize) {
271
+ $('body').css('cursor', resize + '-resize');
272
+
273
+ x1 = viewX(selection[/w/.test(resize) ? 'x2' : 'x1']);
274
+ y1 = viewY(selection[/n/.test(resize) ? 'y2' : 'y1']);
275
+
276
+ $(document).mousemove(selectingMouseMove)
277
+ .one('mouseup', docMouseUp);
278
+ $box.unbind('mousemove', areaMouseMove);
279
+ }
280
+ else if (options.movable) {
281
+ startX = left + selection.x1 - evX(event);
282
+ startY = top + selection.y1 - evY(event);
283
+
284
+ $box.unbind('mousemove', areaMouseMove);
285
+
286
+ $(document).mousemove(movingMouseMove)
287
+ .one('mouseup', function () {
288
+ options.onSelectEnd(img, getSelection());
289
+
290
+ $(document).unbind('mousemove', movingMouseMove);
291
+ $box.mousemove(areaMouseMove);
292
+ });
293
+ }
294
+ else
295
+ $img.mousedown(event);
296
+
297
+ return false;
298
+ }
299
+
300
+ function fixAspectRatio(xFirst) {
301
+ if (aspectRatio)
302
+ if (xFirst) {
303
+ x2 = max(left, min(left + imgWidth,
304
+ x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1)));
305
+
306
+ y2 = round(max(top, min(top + imgHeight,
307
+ y1 + abs(x2 - x1) / aspectRatio * (y2 > y1 || -1))));
308
+ x2 = round(x2);
309
+ }
310
+ else {
311
+ y2 = max(top, min(top + imgHeight,
312
+ y1 + abs(x2 - x1) / aspectRatio * (y2 > y1 || -1)));
313
+ x2 = round(max(left, min(left + imgWidth,
314
+ x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1))));
315
+ y2 = round(y2);
316
+ }
317
+ }
318
+
319
+ function doResize() {
320
+ x1 = min(x1, left + imgWidth);
321
+ y1 = min(y1, top + imgHeight);
322
+
323
+ if (abs(x2 - x1) < minWidth) {
324
+ x2 = x1 - minWidth * (x2 < x1 || -1);
325
+
326
+ if (x2 < left)
327
+ x1 = left + minWidth;
328
+ else if (x2 > left + imgWidth)
329
+ x1 = left + imgWidth - minWidth;
330
+ }
331
+
332
+ if (abs(y2 - y1) < minHeight) {
333
+ y2 = y1 - minHeight * (y2 < y1 || -1);
334
+
335
+ if (y2 < top)
336
+ y1 = top + minHeight;
337
+ else if (y2 > top + imgHeight)
338
+ y1 = top + imgHeight - minHeight;
339
+ }
340
+
341
+ x2 = max(left, min(x2, left + imgWidth));
342
+ y2 = max(top, min(y2, top + imgHeight));
343
+
344
+ fixAspectRatio(abs(x2 - x1) < abs(y2 - y1) * aspectRatio);
345
+
346
+ if (abs(x2 - x1) > maxWidth) {
347
+ x2 = x1 - maxWidth * (x2 < x1 || -1);
348
+ fixAspectRatio();
349
+ }
350
+
351
+ if (abs(y2 - y1) > maxHeight) {
352
+ y2 = y1 - maxHeight * (y2 < y1 || -1);
353
+ fixAspectRatio(true);
354
+ }
355
+
356
+ selection = { x1: selX(min(x1, x2)), x2: selX(max(x1, x2)),
357
+ y1: selY(min(y1, y2)), y2: selY(max(y1, y2)),
358
+ width: abs(x2 - x1), height: abs(y2 - y1) };
359
+
360
+ update();
361
+
362
+ options.onSelectChange(img, getSelection());
363
+ }
364
+
365
+ function selectingMouseMove(event) {
366
+ x2 = /w|e|^$/.test(resize) || aspectRatio ? evX(event) : viewX(selection.x2);
367
+ y2 = /n|s|^$/.test(resize) || aspectRatio ? evY(event) : viewY(selection.y2);
368
+
369
+ doResize();
370
+
371
+ return false;
372
+
373
+ }
374
+
375
+ function doMove(newX1, newY1) {
376
+ x2 = (x1 = newX1) + selection.width;
377
+ y2 = (y1 = newY1) + selection.height;
378
+
379
+ $.extend(selection, { x1: selX(x1), y1: selY(y1), x2: selX(x2),
380
+ y2: selY(y2) });
381
+
382
+ update();
383
+
384
+ options.onSelectChange(img, getSelection());
385
+ }
386
+
387
+ function movingMouseMove(event) {
388
+ x1 = max(left, min(startX + evX(event), left + imgWidth - selection.width));
389
+ y1 = max(top, min(startY + evY(event), top + imgHeight - selection.height));
390
+
391
+ doMove(x1, y1);
392
+
393
+ event.preventDefault();
394
+
395
+ return false;
396
+ }
397
+
398
+ function startSelection() {
399
+ $(document).unbind('mousemove', startSelection);
400
+ adjust();
401
+
402
+ x2 = x1;
403
+ y2 = y1;
404
+
405
+ doResize();
406
+
407
+ resize = '';
408
+
409
+ if (!$outer.is(':visible'))
410
+ $box.add($outer).hide().fadeIn(options.fadeSpeed||0);
411
+
412
+ shown = true;
413
+
414
+ $(document).unbind('mouseup', cancelSelection)
415
+ .mousemove(selectingMouseMove).one('mouseup', docMouseUp);
416
+ $box.unbind('mousemove', areaMouseMove);
417
+
418
+ options.onSelectStart(img, getSelection());
419
+ }
420
+
421
+ function cancelSelection() {
422
+ $(document).unbind('mousemove', startSelection)
423
+ .unbind('mouseup', cancelSelection);
424
+ hide($box.add($outer));
425
+
426
+ setSelection(selX(x1), selY(y1), selX(x1), selY(y1));
427
+
428
+ if (!this instanceof $.imgAreaSelect) {
429
+ options.onSelectChange(img, getSelection());
430
+ options.onSelectEnd(img, getSelection());
431
+ }
432
+ }
433
+
434
+ function imgMouseDown(event) {
435
+ if (event.which != 1 || $outer.is(':animated')) return false;
436
+
437
+ adjust();
438
+ startX = x1 = evX(event);
439
+ startY = y1 = evY(event);
440
+
441
+ $(document).mousemove(startSelection).mouseup(cancelSelection);
442
+
443
+ return false;
444
+ }
445
+
446
+ function windowResize() {
447
+ doUpdate(false);
448
+ }
449
+
450
+ function imgLoad() {
451
+ imgLoaded = true;
452
+
453
+ setOptions(options = $.extend({
454
+ classPrefix: 'imgareaselect',
455
+ movable: true,
456
+ parent: 'body',
457
+ resizable: true,
458
+ resizeMargin: 10,
459
+ onInit: function () {},
460
+ onSelectStart: function () {},
461
+ onSelectChange: function () {},
462
+ onSelectEnd: function () {}
463
+ }, options));
464
+
465
+ $box.add($outer).css({ visibility: '' });
466
+
467
+ if (options.show) {
468
+ shown = true;
469
+ adjust();
470
+ update();
471
+ $box.add($outer).hide().fadeIn(options.fadeSpeed||0);
472
+ }
473
+
474
+ setTimeout(function () { options.onInit(img, getSelection()); }, 0);
475
+ }
476
+
477
+ var docKeyPress = function(event) {
478
+ var k = options.keys, d, t, key = event.keyCode;
479
+
480
+ d = !isNaN(k.alt) && (event.altKey || event.originalEvent.altKey) ? k.alt :
481
+ !isNaN(k.ctrl) && event.ctrlKey ? k.ctrl :
482
+ !isNaN(k.shift) && event.shiftKey ? k.shift :
483
+ !isNaN(k.arrows) ? k.arrows : 10;
484
+
485
+ if (k.arrows == 'resize' || (k.shift == 'resize' && event.shiftKey) ||
486
+ (k.ctrl == 'resize' && event.ctrlKey) ||
487
+ (k.alt == 'resize' && (event.altKey || event.originalEvent.altKey)))
488
+ {
489
+ switch (key) {
490
+ case 37:
491
+ d = -d;
492
+ case 39:
493
+ t = max(x1, x2);
494
+ x1 = min(x1, x2);
495
+ x2 = max(t + d, x1);
496
+ fixAspectRatio();
497
+ break;
498
+ case 38:
499
+ d = -d;
500
+ case 40:
501
+ t = max(y1, y2);
502
+ y1 = min(y1, y2);
503
+ y2 = max(t + d, y1);
504
+ fixAspectRatio(true);
505
+ break;
506
+ default:
507
+ return;
508
+ }
509
+
510
+ doResize();
511
+ }
512
+ else {
513
+ x1 = min(x1, x2);
514
+ y1 = min(y1, y2);
515
+
516
+ switch (key) {
517
+ case 37:
518
+ doMove(max(x1 - d, left), y1);
519
+ break;
520
+ case 38:
521
+ doMove(x1, max(y1 - d, top));
522
+ break;
523
+ case 39:
524
+ doMove(x1 + min(d, imgWidth - selX(x2)), y1);
525
+ break;
526
+ case 40:
527
+ doMove(x1, y1 + min(d, imgHeight - selY(y2)));
528
+ break;
529
+ default:
530
+ return;
531
+ }
532
+ }
533
+
534
+ return false;
535
+ };
536
+
537
+ function styleOptions($elem, props) {
538
+ for (option in props)
539
+ if (options[option] !== undefined)
540
+ $elem.css(props[option], options[option]);
541
+ }
542
+
543
+ function setOptions(newOptions) {
544
+ if (newOptions.parent)
545
+ ($parent = $(newOptions.parent)).append($box.add($outer));
546
+
547
+ $.extend(options, newOptions);
548
+
549
+ adjust();
550
+
551
+ if (newOptions.handles != null) {
552
+ $handles.remove();
553
+ $handles = $([]);
554
+
555
+ i = newOptions.handles ? newOptions.handles == 'corners' ? 4 : 8 : 0;
556
+
557
+ while (i--)
558
+ $handles = $handles.add(div());
559
+
560
+ $handles.addClass(options.classPrefix + '-handle').css({
561
+ position: 'absolute',
562
+ fontSize: 0,
563
+ zIndex: zIndex + 1 || 1
564
+ });
565
+
566
+ if (!parseInt($handles.css('width')) >= 0)
567
+ $handles.width(5).height(5);
568
+
569
+ if (o = options.borderWidth)
570
+ $handles.css({ borderWidth: o, borderStyle: 'solid' });
571
+
572
+ styleOptions($handles, { borderColor1: 'border-color',
573
+ borderColor2: 'background-color',
574
+ borderOpacity: 'opacity' });
575
+ }
576
+
577
+ scaleX = options.imageWidth / imgWidth || 1;
578
+ scaleY = options.imageHeight / imgHeight || 1;
579
+
580
+ if (newOptions.x1 != null) {
581
+ setSelection(newOptions.x1, newOptions.y1, newOptions.x2,
582
+ newOptions.y2);
583
+ newOptions.show = !newOptions.hide;
584
+ }
585
+
586
+ if (newOptions.keys)
587
+ options.keys = $.extend({ shift: 1, ctrl: 'resize' },
588
+ newOptions.keys);
589
+
590
+ $outer.addClass(options.classPrefix + '-outer');
591
+ $area.addClass(options.classPrefix + '-selection');
592
+ for (i = 0; i++ < 4;)
593
+ $($border[i-1]).addClass(options.classPrefix + '-border' + i);
594
+
595
+ styleOptions($area, { selectionColor: 'background-color',
596
+ selectionOpacity: 'opacity' });
597
+ styleOptions($border, { borderOpacity: 'opacity',
598
+ borderWidth: 'border-width' });
599
+ styleOptions($outer, { outerColor: 'background-color',
600
+ outerOpacity: 'opacity' });
601
+ if (o = options.borderColor1)
602
+ $($border[0]).css({ borderStyle: 'solid', borderColor: o });
603
+ if (o = options.borderColor2)
604
+ $($border[1]).css({ borderStyle: 'dashed', borderColor: o });
605
+
606
+ $box.append($area.add($border).add($areaOpera).add($handles));
607
+
608
+ if ($.browser.msie) {
609
+ if (o = $outer.css('filter').match(/opacity=(\d+)/))
610
+ $outer.css('opacity', o[1]/100);
611
+ if (o = $border.css('filter').match(/opacity=(\d+)/))
612
+ $border.css('opacity', o[1]/100);
613
+ }
614
+
615
+ if (newOptions.hide)
616
+ hide($box.add($outer));
617
+ else if (newOptions.show && imgLoaded) {
618
+ shown = true;
619
+ $box.add($outer).fadeIn(options.fadeSpeed||0);
620
+ doUpdate();
621
+ }
622
+
623
+ aspectRatio = (d = (options.aspectRatio || '').split(/:/))[0] / d[1];
624
+
625
+ $img.add($outer).unbind('mousedown', imgMouseDown);
626
+
627
+ if (options.disable || options.enable === false) {
628
+ $box.unbind('mousemove', areaMouseMove).unbind('mousedown', areaMouseDown);
629
+ $(window).unbind('resize', windowResize);
630
+ }
631
+ else {
632
+ if (options.enable || options.disable === false) {
633
+ if (options.resizable || options.movable)
634
+ $box.mousemove(areaMouseMove).mousedown(areaMouseDown);
635
+
636
+ $(window).resize(windowResize);
637
+ }
638
+
639
+ if (!options.persistent)
640
+ $img.add($outer).mousedown(imgMouseDown);
641
+ }
642
+
643
+ options.enable = options.disable = undefined;
644
+ }
645
+
646
+ this.remove = function () {
647
+ setOptions({ disable: true });
648
+ $box.add($outer).remove();
649
+ };
650
+
651
+ this.getOptions = function () { return options; };
652
+
653
+ this.setOptions = setOptions;
654
+
655
+ this.getSelection = getSelection;
656
+
657
+ this.setSelection = setSelection;
658
+
659
+ this.cancelSelection = cancelSelection;
660
+
661
+ this.update = doUpdate;
662
+
663
+ $p = $img;
664
+
665
+ while ($p.length) {
666
+ zIndex = max(zIndex,
667
+ !isNaN($p.css('z-index')) ? $p.css('z-index') : zIndex);
668
+ if ($p.css('position') == 'fixed')
669
+ position = 'fixed';
670
+
671
+ $p = $p.parent(':not(body)');
672
+ }
673
+
674
+ zIndex = options.zIndex || zIndex;
675
+
676
+ if ($.browser.msie)
677
+ $img.attr('unselectable', 'on');
678
+
679
+ $.imgAreaSelect.keyPress = $.browser.msie ||
680
+ $.browser.safari ? 'keydown' : 'keypress';
681
+
682
+ if ($.browser.opera)
683
+ $areaOpera = div().css({ width: '100%', height: '100%',
684
+ position: 'absolute', zIndex: zIndex + 2 || 2 });
685
+
686
+ $box.add($outer).css({ visibility: 'hidden', position: position,
687
+ overflow: 'hidden', zIndex: zIndex || '0' });
688
+ $box.css({ zIndex: zIndex + 2 || 2 });
689
+ $area.add($border).css({ position: 'absolute', fontSize: 0 });
690
+
691
+ img.complete || img.readyState == 'complete' || !$img.is('img') ?
692
+ imgLoad() : $img.one('load', imgLoad);
693
+
694
+ if ($.browser.msie && $.browser.version >= 7)
695
+ img.src = img.src;
696
+ };
697
+
698
+ $.fn.imgAreaSelect = function (options) {
699
+ options = options || {};
700
+
701
+ this.each(function () {
702
+ if ($(this).data('imgAreaSelect')) {
703
+ if (options.remove) {
704
+ $(this).data('imgAreaSelect').remove();
705
+ $(this).removeData('imgAreaSelect');
706
+ }
707
+ else
708
+ $(this).data('imgAreaSelect').setOptions(options);
709
+ }
710
+ else if (!options.remove) {
711
+ if (options.enable === undefined && options.disable === undefined)
712
+ options.enable = true;
713
+
714
+ $(this).data('imgAreaSelect', new $.imgAreaSelect(this, options));
715
+ }
716
+ });
717
+
718
+ if (options.instance)
719
+ return $(this).data('imgAreaSelect');
720
+
721
+ return this;
722
+ };
723
+
724
+ })(jQuery);
@@ -0,0 +1,41 @@
1
+ /*
2
+ * imgAreaSelect animated border style
3
+ */
4
+
5
+ .imgareaselect-border1 {
6
+ background: url(border-anim-v.gif) repeat-y left top;
7
+ }
8
+
9
+ .imgareaselect-border2 {
10
+ background: url(border-anim-h.gif) repeat-x left top;
11
+ }
12
+
13
+ .imgareaselect-border3 {
14
+ background: url(border-anim-v.gif) repeat-y right top;
15
+ }
16
+
17
+ .imgareaselect-border4 {
18
+ background: url(border-anim-h.gif) repeat-x left bottom;
19
+ }
20
+
21
+ .imgareaselect-border1, .imgareaselect-border2,
22
+ .imgareaselect-border3, .imgareaselect-border4 {
23
+ filter: alpha(opacity=50);
24
+ opacity: 0.5;
25
+ }
26
+
27
+ .imgareaselect-handle {
28
+ background-color: #fff;
29
+ border: solid 1px #000;
30
+ filter: alpha(opacity=50);
31
+ opacity: 0.5;
32
+ }
33
+
34
+ .imgareaselect-outer {
35
+ background-color: #000;
36
+ filter: alpha(opacity=50);
37
+ opacity: 0.5;
38
+ }
39
+
40
+ .imgareaselect-selection {
41
+ }
@@ -0,0 +1,41 @@
1
+ /*
2
+ * imgAreaSelect default style
3
+ */
4
+
5
+ .imgareaselect-border1 {
6
+ background: url(border-v.gif) repeat-y left top;
7
+ }
8
+
9
+ .imgareaselect-border2 {
10
+ background: url(border-h.gif) repeat-x left top;
11
+ }
12
+
13
+ .imgareaselect-border3 {
14
+ background: url(border-v.gif) repeat-y right top;
15
+ }
16
+
17
+ .imgareaselect-border4 {
18
+ background: url(border-h.gif) repeat-x left bottom;
19
+ }
20
+
21
+ .imgareaselect-border1, .imgareaselect-border2,
22
+ .imgareaselect-border3, .imgareaselect-border4 {
23
+ filter: alpha(opacity=50);
24
+ opacity: 0.5;
25
+ }
26
+
27
+ .imgareaselect-handle {
28
+ background-color: #fff;
29
+ border: solid 1px #000;
30
+ filter: alpha(opacity=50);
31
+ opacity: 0.5;
32
+ }
33
+
34
+ .imgareaselect-outer {
35
+ background-color: #000;
36
+ filter: alpha(opacity=50);
37
+ opacity: 0.5;
38
+ }
39
+
40
+ .imgareaselect-selection {
41
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * imgAreaSelect style to be used with deprecated options
3
+ */
4
+
5
+ .imgareaselect-border1, .imgareaselect-border2,
6
+ .imgareaselect-border3, .imgareaselect-border4 {
7
+ filter: alpha(opacity=50);
8
+ opacity: 0.5;
9
+ }
10
+
11
+ .imgareaselect-border1 {
12
+ border: solid 1px #000;
13
+ }
14
+
15
+ .imgareaselect-border2 {
16
+ border: dashed 1px #fff;
17
+ }
18
+
19
+ .imgareaselect-handle {
20
+ background-color: #fff;
21
+ border: solid 1px #000;
22
+ filter: alpha(opacity=50);
23
+ opacity: 0.5;
24
+ }
25
+
26
+ .imgareaselect-outer {
27
+ background-color: #000;
28
+ filter: alpha(opacity=40);
29
+ opacity: 0.4;
30
+ }
31
+
32
+ .imgareaselect-selection {
33
+ background-color: #fff;
34
+ filter: alpha(opacity=0);
35
+ opacity: 0;
36
+ }
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imgareaselect-rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Aaron Lasseigne
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-14 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 5
29
+ segments:
30
+ - 3
31
+ - 1
32
+ version: "3.1"
33
+ name: rails
34
+ version_requirements: *id001
35
+ description: Places imgAreaSelect 0.9.8 in the Rails asset pipeline.
36
+ email:
37
+ - aaron@orgsync.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - LICENSE
48
+ - README.md
49
+ - Rakefile
50
+ - imgareaselect-rails.gemspec
51
+ - lib/imgareaselect-rails.rb
52
+ - lib/imgareaselect/rails.rb
53
+ - lib/imgareaselect/rails/engine.rb
54
+ - lib/imgareaselect/rails/version.rb
55
+ - vendor/assets/images/border-anim-h.gif
56
+ - vendor/assets/images/border-anim-v.gif
57
+ - vendor/assets/images/border-h.gif
58
+ - vendor/assets/images/border-v.gif
59
+ - vendor/assets/javascripts/jquery.imgareaselect.js
60
+ - vendor/assets/stylesheets/imgareaselect-animated.css
61
+ - vendor/assets/stylesheets/imgareaselect-default.css
62
+ - vendor/assets/stylesheets/imgareaselect-deprecated.css
63
+ homepage: https://github.com/orgsync/imgareaselect-rails
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.17
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Places imgAreaSelect 0.9.8 in the Rails asset pipeline.
96
+ test_files: []
97
+