semantic-ui-sass 2.1.8.0 → 2.2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -1
  3. data/app/assets/javascripts/semantic-ui.js +21465 -24
  4. data/app/assets/javascripts/semantic-ui/accordion.js +20 -6
  5. data/app/assets/javascripts/semantic-ui/api.js +41 -16
  6. data/app/assets/javascripts/semantic-ui/checkbox.js +31 -9
  7. data/app/assets/javascripts/semantic-ui/colorize.js +233 -227
  8. data/app/assets/javascripts/semantic-ui/dimmer.js +27 -9
  9. data/app/assets/javascripts/semantic-ui/dropdown.js +485 -207
  10. data/app/assets/javascripts/semantic-ui/embed.js +50 -13
  11. data/app/assets/javascripts/semantic-ui/form.js +58 -23
  12. data/app/assets/javascripts/semantic-ui/modal.js +28 -13
  13. data/app/assets/javascripts/semantic-ui/nag.js +28 -7
  14. data/app/assets/javascripts/semantic-ui/popup.js +136 -76
  15. data/app/assets/javascripts/semantic-ui/progress.js +177 -62
  16. data/app/assets/javascripts/semantic-ui/rating.js +41 -8
  17. data/app/assets/javascripts/semantic-ui/search.js +109 -56
  18. data/app/assets/javascripts/semantic-ui/shape.js +52 -19
  19. data/app/assets/javascripts/semantic-ui/sidebar.js +21 -7
  20. data/app/assets/javascripts/semantic-ui/site.js +2 -2
  21. data/app/assets/javascripts/semantic-ui/state.js +20 -7
  22. data/app/assets/javascripts/semantic-ui/sticky.js +48 -19
  23. data/app/assets/javascripts/semantic-ui/tab.js +57 -27
  24. data/app/assets/javascripts/semantic-ui/transition.js +24 -8
  25. data/app/assets/javascripts/semantic-ui/video.js +6 -14
  26. data/app/assets/javascripts/semantic-ui/visibility.js +89 -22
  27. data/app/assets/javascripts/semantic-ui/visit.js +13 -5
  28. data/app/assets/stylesheets/semantic-ui/collections/_breadcrumb.scss +4 -5
  29. data/app/assets/stylesheets/semantic-ui/collections/_form.scss +91 -85
  30. data/app/assets/stylesheets/semantic-ui/collections/_grid.scss +41 -37
  31. data/app/assets/stylesheets/semantic-ui/collections/_menu.scss +138 -94
  32. data/app/assets/stylesheets/semantic-ui/collections/_message.scss +74 -55
  33. data/app/assets/stylesheets/semantic-ui/collections/_table.scss +80 -68
  34. data/app/assets/stylesheets/semantic-ui/elements/_button.scss +458 -305
  35. data/app/assets/stylesheets/semantic-ui/elements/_container.scss +1 -2
  36. data/app/assets/stylesheets/semantic-ui/elements/_divider.scss +2 -4
  37. data/app/assets/stylesheets/semantic-ui/elements/_flag.scss +2 -3
  38. data/app/assets/stylesheets/semantic-ui/elements/_header.scss +46 -46
  39. data/app/assets/stylesheets/semantic-ui/elements/_icon.scss +812 -252
  40. data/app/assets/stylesheets/semantic-ui/elements/_image.scss +7 -3
  41. data/app/assets/stylesheets/semantic-ui/elements/_input.scss +35 -35
  42. data/app/assets/stylesheets/semantic-ui/elements/_label.scss +127 -127
  43. data/app/assets/stylesheets/semantic-ui/elements/_list.scss +37 -25
  44. data/app/assets/stylesheets/semantic-ui/elements/_loader.scss +101 -38
  45. data/app/assets/stylesheets/semantic-ui/elements/_rail.scss +24 -4
  46. data/app/assets/stylesheets/semantic-ui/elements/_reveal.scss +9 -6
  47. data/app/assets/stylesheets/semantic-ui/elements/_segment.scss +92 -51
  48. data/app/assets/stylesheets/semantic-ui/elements/_step.scss +42 -23
  49. data/app/assets/stylesheets/semantic-ui/globals/_reset.scss +1 -6
  50. data/app/assets/stylesheets/semantic-ui/globals/_site.scss +7 -9
  51. data/app/assets/stylesheets/semantic-ui/modules/_accordion.scss +7 -6
  52. data/app/assets/stylesheets/semantic-ui/modules/_checkbox.scss +40 -37
  53. data/app/assets/stylesheets/semantic-ui/modules/_dimmer.scss +7 -8
  54. data/app/assets/stylesheets/semantic-ui/modules/_dropdown.scss +107 -88
  55. data/app/assets/stylesheets/semantic-ui/modules/_embed.scss +6 -7
  56. data/app/assets/stylesheets/semantic-ui/modules/_modal.scss +9 -10
  57. data/app/assets/stylesheets/semantic-ui/modules/_nag.scss +6 -7
  58. data/app/assets/stylesheets/semantic-ui/modules/_popup.scss +415 -36
  59. data/app/assets/stylesheets/semantic-ui/modules/_progress.scss +47 -48
  60. data/app/assets/stylesheets/semantic-ui/modules/_rating.scss +12 -13
  61. data/app/assets/stylesheets/semantic-ui/modules/_search.scss +21 -21
  62. data/app/assets/stylesheets/semantic-ui/modules/_shape.scss +11 -8
  63. data/app/assets/stylesheets/semantic-ui/modules/_sidebar.scss +31 -14
  64. data/app/assets/stylesheets/semantic-ui/modules/_sticky.scss +2 -3
  65. data/app/assets/stylesheets/semantic-ui/modules/_tab.scss +1 -2
  66. data/app/assets/stylesheets/semantic-ui/modules/_transition.scss +1 -2
  67. data/app/assets/stylesheets/semantic-ui/views/_ad.scss +2 -2
  68. data/app/assets/stylesheets/semantic-ui/views/_card.scss +62 -42
  69. data/app/assets/stylesheets/semantic-ui/views/_comment.scss +2 -3
  70. data/app/assets/stylesheets/semantic-ui/views/_feed.scss +5 -6
  71. data/app/assets/stylesheets/semantic-ui/views/_item.scss +11 -12
  72. data/app/assets/stylesheets/semantic-ui/views/_statistic.scss +44 -45
  73. data/app/helpers/semantic_icon_helper.rb +6 -3
  74. data/lib/semantic/ui/sass/engine.rb +5 -1
  75. data/lib/semantic/ui/sass/version.rb +2 -2
  76. data/spec/helpers/semantic_icon_helper_spec.rb +22 -10
  77. metadata +3 -3
@@ -3,7 +3,6 @@
3
3
  * http://github.com/semantic-org/semantic-ui/
4
4
  *
5
5
  *
6
- * Copyright 2015 Contributors
7
6
  * Released under the MIT license
8
7
  * http://opensource.org/licenses/MIT
9
8
  *
@@ -13,6 +12,13 @@
13
12
 
14
13
  "use strict";
15
14
 
15
+ window = (typeof window != 'undefined' && window.Math == Math)
16
+ ? window
17
+ : (typeof self != 'undefined' && self.Math == Math)
18
+ ? self
19
+ : Function('return this')()
20
+ ;
21
+
16
22
  $.fn.accordion = function(parameters) {
17
23
  var
18
24
  $allModules = $(this),
@@ -367,7 +373,12 @@ $.fn.accordion = function(parameters) {
367
373
  $.extend(true, settings, name);
368
374
  }
369
375
  else if(value !== undefined) {
370
- settings[name] = value;
376
+ if($.isPlainObject(settings[name])) {
377
+ $.extend(true, settings[name], value);
378
+ }
379
+ else {
380
+ settings[name] = value;
381
+ }
371
382
  }
372
383
  else {
373
384
  return settings[name];
@@ -388,7 +399,7 @@ $.fn.accordion = function(parameters) {
388
399
  }
389
400
  },
390
401
  debug: function() {
391
- if(settings.debug) {
402
+ if(!settings.silent && settings.debug) {
392
403
  if(settings.performance) {
393
404
  module.performance.log(arguments);
394
405
  }
@@ -399,7 +410,7 @@ $.fn.accordion = function(parameters) {
399
410
  }
400
411
  },
401
412
  verbose: function() {
402
- if(settings.verbose && settings.debug) {
413
+ if(!settings.silent && settings.verbose && settings.debug) {
403
414
  if(settings.performance) {
404
415
  module.performance.log(arguments);
405
416
  }
@@ -410,8 +421,10 @@ $.fn.accordion = function(parameters) {
410
421
  }
411
422
  },
412
423
  error: function() {
413
- module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
414
- module.error.apply(console, arguments);
424
+ if(!settings.silent) {
425
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
426
+ module.error.apply(console, arguments);
427
+ }
415
428
  },
416
429
  performance: {
417
430
  log: function(message) {
@@ -544,6 +557,7 @@ $.fn.accordion.settings = {
544
557
  name : 'Accordion',
545
558
  namespace : 'accordion',
546
559
 
560
+ silent : false,
547
561
  debug : false,
548
562
  verbose : false,
549
563
  performance : true,
@@ -3,16 +3,23 @@
3
3
  * http://github.com/semantic-org/semantic-ui/
4
4
  *
5
5
  *
6
- * Copyright 2015 Contributors
7
6
  * Released under the MIT license
8
7
  * http://opensource.org/licenses/MIT
9
8
  *
10
9
  */
11
10
 
12
- ;(function ( $, window, document, undefined ) {
11
+ ;(function ($, window, document, undefined) {
13
12
 
14
13
  "use strict";
15
14
 
15
+ var
16
+ window = (typeof window != 'undefined' && window.Math == Math)
17
+ ? window
18
+ : (typeof self != 'undefined' && self.Math == Math)
19
+ ? self
20
+ : Function('return this')()
21
+ ;
22
+
16
23
  $.api = $.fn.api = function(parameters) {
17
24
 
18
25
  var
@@ -141,7 +148,7 @@ $.api = $.fn.api = function(parameters) {
141
148
  response = sessionStorage.getItem(url);
142
149
  module.debug('Using cached response', url, response);
143
150
  response = module.decode.json(response);
144
- return false;
151
+ return response;
145
152
  }
146
153
  },
147
154
  write: {
@@ -233,7 +240,6 @@ $.api = $.fn.api = function(parameters) {
233
240
 
234
241
  module.debug('Querying URL', ajaxSettings.url);
235
242
  module.verbose('Using AJAX settings', ajaxSettings);
236
-
237
243
  if(settings.cache === 'local' && module.read.cachedResponse(url)) {
238
244
  module.debug('Response returned from local cache');
239
245
  module.request = module.create.request();
@@ -276,6 +282,9 @@ $.api = $.fn.api = function(parameters) {
276
282
  disabled: function() {
277
283
  return ($module.filter(selector.disabled).length > 0);
278
284
  },
285
+ expectingJSON: function() {
286
+ return settings.dataType === 'json' || settings.dataType === 'jsonp';
287
+ },
279
288
  form: function() {
280
289
  return $module.is('form') || $context.is('form');
281
290
  },
@@ -286,7 +295,10 @@ $.api = $.fn.api = function(parameters) {
286
295
  return $module.is('input');
287
296
  },
288
297
  loading: function() {
289
- return (module.request && module.request.state() == 'pending');
298
+ return (module.request)
299
+ ? (module.request.state() == 'pending')
300
+ : false
301
+ ;
290
302
  },
291
303
  abortedRequest: function(xhr) {
292
304
  if(xhr && xhr.readyState !== undefined && xhr.readyState === 0) {
@@ -299,7 +311,7 @@ $.api = $.fn.api = function(parameters) {
299
311
  }
300
312
  },
301
313
  validResponse: function(response) {
302
- if( (settings.dataType !== 'json' && settings.dataType !== 'jsonp') || !$.isFunction(settings.successTest) ) {
314
+ if( (!module.is.expectingJSON()) || !$.isFunction(settings.successTest) ) {
303
315
  module.verbose('Response is not JSON, skipping validation', settings.successTest, response);
304
316
  return true;
305
317
  }
@@ -469,7 +481,9 @@ $.api = $.fn.api = function(parameters) {
469
481
  elapsedTime = (new Date().getTime() - requestStartTime),
470
482
  timeLeft = (settings.loadingDuration - elapsedTime),
471
483
  translatedResponse = ( $.isFunction(settings.onResponse) )
472
- ? settings.onResponse.call(context, $.extend(true, {}, response))
484
+ ? module.is.expectingJSON()
485
+ ? settings.onResponse.call(context, $.extend(true, {}, response))
486
+ : settings.onResponse.call(context, response)
473
487
  : false
474
488
  ;
475
489
  timeLeft = (timeLeft > 0)
@@ -550,11 +564,12 @@ $.api = $.fn.api = function(parameters) {
550
564
  if(status == 'aborted') {
551
565
  module.debug('XHR Aborted (Most likely caused by page navigation or CORS Policy)', status, httpMessage);
552
566
  settings.onAbort.call(context, status, $module, xhr);
567
+ return true;
553
568
  }
554
569
  else if(status == 'invalid') {
555
570
  module.debug('JSON did not pass success test. A server-side error has most likely occurred', response);
556
571
  }
557
- else if(status == 'error') {
572
+ else if(status == 'error') {
558
573
  if(xhr !== undefined) {
559
574
  module.debug('XHR produced a server error', status, httpMessage);
560
575
  // make sure we have an error to display to console
@@ -647,7 +662,7 @@ $.api = $.fn.api = function(parameters) {
647
662
  .done(module.event.xhr.done)
648
663
  .fail(module.event.xhr.fail)
649
664
  ;
650
- module.verbose('Created server request', xhr);
665
+ module.verbose('Created server request', xhr, ajaxSettings);
651
666
  return xhr;
652
667
  }
653
668
  },
@@ -678,7 +693,7 @@ $.api = $.fn.api = function(parameters) {
678
693
  get: {
679
694
  responseFromXHR: function(xhr) {
680
695
  return $.isPlainObject(xhr)
681
- ? (settings.dataType == 'json' || settings.dataType == 'jsonp')
696
+ ? (module.is.expectingJSON())
682
697
  ? module.decode.json(xhr.responseText)
683
698
  : xhr.responseText
684
699
  : false
@@ -723,6 +738,9 @@ $.api = $.fn.api = function(parameters) {
723
738
  if(runSettings === undefined) {
724
739
  module.error(error.noReturnedValue);
725
740
  }
741
+ if(runSettings === false) {
742
+ return runSettings;
743
+ }
726
744
  return (runSettings !== undefined)
727
745
  ? $.extend(true, {}, runSettings)
728
746
  : $.extend(true, {}, settings)
@@ -749,7 +767,7 @@ $.api = $.fn.api = function(parameters) {
749
767
  if( module.is.input() ) {
750
768
  data.value = $module.val();
751
769
  }
752
- else if( !module.is.form() ) {
770
+ else if( module.is.form() ) {
753
771
 
754
772
  }
755
773
  else {
@@ -828,7 +846,12 @@ $.api = $.fn.api = function(parameters) {
828
846
  $.extend(true, settings, name);
829
847
  }
830
848
  else if(value !== undefined) {
831
- settings[name] = value;
849
+ if($.isPlainObject(settings[name])) {
850
+ $.extend(true, settings[name], value);
851
+ }
852
+ else {
853
+ settings[name] = value;
854
+ }
832
855
  }
833
856
  else {
834
857
  return settings[name];
@@ -846,7 +869,7 @@ $.api = $.fn.api = function(parameters) {
846
869
  }
847
870
  },
848
871
  debug: function() {
849
- if(settings.debug) {
872
+ if(!settings.silent && settings.debug) {
850
873
  if(settings.performance) {
851
874
  module.performance.log(arguments);
852
875
  }
@@ -857,7 +880,7 @@ $.api = $.fn.api = function(parameters) {
857
880
  }
858
881
  },
859
882
  verbose: function() {
860
- if(settings.verbose && settings.debug) {
883
+ if(!settings.silent && settings.verbose && settings.debug) {
861
884
  if(settings.performance) {
862
885
  module.performance.log(arguments);
863
886
  }
@@ -868,8 +891,10 @@ $.api = $.fn.api = function(parameters) {
868
891
  }
869
892
  },
870
893
  error: function() {
871
- module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
872
- module.error.apply(console, arguments);
894
+ if(!settings.silent) {
895
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
896
+ module.error.apply(console, arguments);
897
+ }
873
898
  },
874
899
  performance: {
875
900
  log: function(message) {
@@ -3,16 +3,22 @@
3
3
  * http://github.com/semantic-org/semantic-ui/
4
4
  *
5
5
  *
6
- * Copyright 2015 Contributors
7
6
  * Released under the MIT license
8
7
  * http://opensource.org/licenses/MIT
9
8
  *
10
9
  */
11
10
 
12
- ;(function ( $, window, document, undefined ) {
11
+ ;(function ($, window, document, undefined) {
13
12
 
14
13
  "use strict";
15
14
 
15
+ window = (typeof window != 'undefined' && window.Math == Math)
16
+ ? window
17
+ : (typeof self != 'undefined' && self.Math == Math)
18
+ ? self
19
+ : Function('return this')()
20
+ ;
21
+
16
22
  $.fn.checkbox = function(parameters) {
17
23
  var
18
24
  $allModules = $(this),
@@ -120,13 +126,13 @@ $.fn.checkbox = function(parameters) {
120
126
 
121
127
  hide: {
122
128
  input: function() {
123
- module.verbose('Modfying <input> z-index to be unselectable');
129
+ module.verbose('Modifying <input> z-index to be unselectable');
124
130
  $input.addClass(className.hidden);
125
131
  }
126
132
  },
127
133
  show: {
128
134
  input: function() {
129
- module.verbose('Modfying <input> z-index to be selectable');
135
+ module.verbose('Modifying <input> z-index to be selectable');
130
136
  $input.removeClass(className.hidden);
131
137
  }
132
138
  },
@@ -268,6 +274,8 @@ $.fn.checkbox = function(parameters) {
268
274
  }
269
275
  module.debug('Enabling checkbox');
270
276
  module.set.enabled();
277
+ settings.onEnable.call(input);
278
+ // preserve legacy callbacks
271
279
  settings.onEnabled.call(input);
272
280
  },
273
281
 
@@ -278,6 +286,8 @@ $.fn.checkbox = function(parameters) {
278
286
  }
279
287
  module.debug('Disabling checkbox');
280
288
  module.set.disabled();
289
+ settings.onDisable.call(input);
290
+ // preserve legacy callbacks
281
291
  settings.onDisabled.call(input);
282
292
  },
283
293
 
@@ -584,7 +594,12 @@ $.fn.checkbox = function(parameters) {
584
594
  $.extend(true, settings, name);
585
595
  }
586
596
  else if(value !== undefined) {
587
- settings[name] = value;
597
+ if($.isPlainObject(settings[name])) {
598
+ $.extend(true, settings[name], value);
599
+ }
600
+ else {
601
+ settings[name] = value;
602
+ }
588
603
  }
589
604
  else {
590
605
  return settings[name];
@@ -602,7 +617,7 @@ $.fn.checkbox = function(parameters) {
602
617
  }
603
618
  },
604
619
  debug: function() {
605
- if(settings.debug) {
620
+ if(!settings.silent && settings.debug) {
606
621
  if(settings.performance) {
607
622
  module.performance.log(arguments);
608
623
  }
@@ -613,7 +628,7 @@ $.fn.checkbox = function(parameters) {
613
628
  }
614
629
  },
615
630
  verbose: function() {
616
- if(settings.verbose && settings.debug) {
631
+ if(!settings.silent && settings.verbose && settings.debug) {
617
632
  if(settings.performance) {
618
633
  module.performance.log(arguments);
619
634
  }
@@ -624,8 +639,10 @@ $.fn.checkbox = function(parameters) {
624
639
  }
625
640
  },
626
641
  error: function() {
627
- module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
628
- module.error.apply(console, arguments);
642
+ if(!settings.silent) {
643
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
644
+ module.error.apply(console, arguments);
645
+ }
629
646
  },
630
647
  performance: {
631
648
  log: function(message) {
@@ -760,6 +777,7 @@ $.fn.checkbox.settings = {
760
777
  name : 'Checkbox',
761
778
  namespace : 'checkbox',
762
779
 
780
+ silent : false,
763
781
  debug : false,
764
782
  verbose : true,
765
783
  performance : true,
@@ -784,6 +802,10 @@ $.fn.checkbox.settings = {
784
802
  onEnable : function(){},
785
803
  onDisable : function(){},
786
804
 
805
+ // preserve misspelled callbacks (will be removed in 3.0)
806
+ onEnabled : function(){},
807
+ onDisabled : function(){},
808
+
787
809
  className : {
788
810
  checked : 'checked',
789
811
  indeterminate : 'indeterminate',
@@ -3,272 +3,278 @@
3
3
  * http://github.com/semantic-org/semantic-ui/
4
4
  *
5
5
  *
6
- * Copyright 2015 Contributors
7
6
  * Released under the MIT license
8
7
  * http://opensource.org/licenses/MIT
9
8
  *
10
9
  */
11
10
 
12
- ;(function ( $, window, document, undefined ) {
11
+ ;(function ($, window, document, undefined) {
13
12
 
14
- "use strict";
13
+ "use strict";
15
14
 
16
- $.fn.colorize = function(parameters) {
17
- var
18
- settings = ( $.isPlainObject(parameters) )
19
- ? $.extend(true, {}, $.fn.colorize.settings, parameters)
20
- : $.extend({}, $.fn.colorize.settings),
21
- // hoist arguments
22
- moduleArguments = arguments || false
23
- ;
24
- $(this)
25
- .each(function(instanceIndex) {
15
+ window = (typeof window != 'undefined' && window.Math == Math)
16
+ ? window
17
+ : (typeof self != 'undefined' && self.Math == Math)
18
+ ? self
19
+ : Function('return this')()
20
+ ;
26
21
 
27
- var
28
- $module = $(this),
22
+ $.fn.colorize = function(parameters) {
23
+ var
24
+ settings = ( $.isPlainObject(parameters) )
25
+ ? $.extend(true, {}, $.fn.colorize.settings, parameters)
26
+ : $.extend({}, $.fn.colorize.settings),
27
+ // hoist arguments
28
+ moduleArguments = arguments || false
29
+ ;
30
+ $(this)
31
+ .each(function(instanceIndex) {
29
32
 
30
- mainCanvas = $('<canvas />')[0],
31
- imageCanvas = $('<canvas />')[0],
32
- overlayCanvas = $('<canvas />')[0],
33
+ var
34
+ $module = $(this),
33
35
 
34
- backgroundImage = new Image(),
36
+ mainCanvas = $('<canvas />')[0],
37
+ imageCanvas = $('<canvas />')[0],
38
+ overlayCanvas = $('<canvas />')[0],
35
39
 
36
- // defs
37
- mainContext,
38
- imageContext,
39
- overlayContext,
40
+ backgroundImage = new Image(),
40
41
 
41
- image,
42
- imageName,
42
+ // defs
43
+ mainContext,
44
+ imageContext,
45
+ overlayContext,
43
46
 
44
- width,
45
- height,
47
+ image,
48
+ imageName,
46
49
 
47
- // shortucts
48
- colors = settings.colors,
49
- paths = settings.paths,
50
- namespace = settings.namespace,
51
- error = settings.error,
50
+ width,
51
+ height,
52
52
 
53
- // boilerplate
54
- instance = $module.data('module-' + namespace),
55
- module
56
- ;
53
+ // shortcuts
54
+ colors = settings.colors,
55
+ paths = settings.paths,
56
+ namespace = settings.namespace,
57
+ error = settings.error,
57
58
 
58
- module = {
59
+ // boilerplate
60
+ instance = $module.data('module-' + namespace),
61
+ module
62
+ ;
59
63
 
60
- checkPreconditions: function() {
61
- module.debug('Checking pre-conditions');
64
+ module = {
62
65
 
63
- if( !$.isPlainObject(colors) || $.isEmptyObject(colors) ) {
64
- module.error(error.undefinedColors);
65
- return false;
66
- }
67
- return true;
68
- },
66
+ checkPreconditions: function() {
67
+ module.debug('Checking pre-conditions');
69
68
 
70
- async: function(callback) {
71
- if(settings.async) {
72
- setTimeout(callback, 0);
73
- }
74
- else {
75
- callback();
76
- }
77
- },
69
+ if( !$.isPlainObject(colors) || $.isEmptyObject(colors) ) {
70
+ module.error(error.undefinedColors);
71
+ return false;
72
+ }
73
+ return true;
74
+ },
78
75
 
79
- getMetadata: function() {
80
- module.debug('Grabbing metadata');
81
- image = $module.data('image') || settings.image || undefined;
82
- imageName = $module.data('name') || settings.name || instanceIndex;
83
- width = settings.width || $module.width();
84
- height = settings.height || $module.height();
85
- if(width === 0 || height === 0) {
86
- module.error(error.undefinedSize);
87
- }
88
- },
76
+ async: function(callback) {
77
+ if(settings.async) {
78
+ setTimeout(callback, 0);
79
+ }
80
+ else {
81
+ callback();
82
+ }
83
+ },
84
+
85
+ getMetadata: function() {
86
+ module.debug('Grabbing metadata');
87
+ image = $module.data('image') || settings.image || undefined;
88
+ imageName = $module.data('name') || settings.name || instanceIndex;
89
+ width = settings.width || $module.width();
90
+ height = settings.height || $module.height();
91
+ if(width === 0 || height === 0) {
92
+ module.error(error.undefinedSize);
93
+ }
94
+ },
89
95
 
90
- initialize: function() {
91
- module.debug('Initializing with colors', colors);
92
- if( module.checkPreconditions() ) {
93
-
94
- module.async(function() {
95
- module.getMetadata();
96
- module.canvas.create();
97
-
98
- module.draw.image(function() {
99
- module.draw.colors();
100
- module.canvas.merge();
101
- });
102
- $module
103
- .data('module-' + namespace, module)
104
- ;
105
- });
106
- }
107
- },
96
+ initialize: function() {
97
+ module.debug('Initializing with colors', colors);
98
+ if( module.checkPreconditions() ) {
108
99
 
109
- redraw: function() {
110
- module.debug('Redrawing image');
111
100
  module.async(function() {
112
- module.canvas.clear();
113
- module.draw.colors();
114
- module.canvas.merge();
115
- });
116
- },
101
+ module.getMetadata();
102
+ module.canvas.create();
117
103
 
118
- change: {
119
- color: function(colorName, color) {
120
- module.debug('Changing color', colorName);
121
- if(colors[colorName] === undefined) {
122
- module.error(error.missingColor);
123
- return false;
124
- }
125
- colors[colorName] = color;
126
- module.redraw();
104
+ module.draw.image(function() {
105
+ module.draw.colors();
106
+ module.canvas.merge();
107
+ });
108
+ $module
109
+ .data('module-' + namespace, module)
110
+ ;
111
+ });
112
+ }
113
+ },
114
+
115
+ redraw: function() {
116
+ module.debug('Redrawing image');
117
+ module.async(function() {
118
+ module.canvas.clear();
119
+ module.draw.colors();
120
+ module.canvas.merge();
121
+ });
122
+ },
123
+
124
+ change: {
125
+ color: function(colorName, color) {
126
+ module.debug('Changing color', colorName);
127
+ if(colors[colorName] === undefined) {
128
+ module.error(error.missingColor);
129
+ return false;
127
130
  }
128
- },
131
+ colors[colorName] = color;
132
+ module.redraw();
133
+ }
134
+ },
129
135
 
130
- canvas: {
131
- create: function() {
132
- module.debug('Creating canvases');
136
+ canvas: {
137
+ create: function() {
138
+ module.debug('Creating canvases');
133
139
 
134
- mainCanvas.width = width;
135
- mainCanvas.height = height;
136
- imageCanvas.width = width;
137
- imageCanvas.height = height;
138
- overlayCanvas.width = width;
139
- overlayCanvas.height = height;
140
+ mainCanvas.width = width;
141
+ mainCanvas.height = height;
142
+ imageCanvas.width = width;
143
+ imageCanvas.height = height;
144
+ overlayCanvas.width = width;
145
+ overlayCanvas.height = height;
140
146
 
141
- mainContext = mainCanvas.getContext('2d');
142
- imageContext = imageCanvas.getContext('2d');
143
- overlayContext = overlayCanvas.getContext('2d');
147
+ mainContext = mainCanvas.getContext('2d');
148
+ imageContext = imageCanvas.getContext('2d');
149
+ overlayContext = overlayCanvas.getContext('2d');
144
150
 
145
- $module
146
- .append( mainCanvas )
147
- ;
148
- mainContext = $module.children('canvas')[0].getContext('2d');
149
- },
150
- clear: function(context) {
151
- module.debug('Clearing canvas');
152
- overlayContext.fillStyle = '#FFFFFF';
153
- overlayContext.fillRect(0, 0, width, height);
154
- },
155
- merge: function() {
156
- if( !$.isFunction(mainContext.blendOnto) ) {
157
- module.error(error.missingPlugin);
158
- return;
159
- }
160
- mainContext.putImageData( imageContext.getImageData(0, 0, width, height), 0, 0);
161
- overlayContext.blendOnto(mainContext, 'multiply');
162
- }
151
+ $module
152
+ .append( mainCanvas )
153
+ ;
154
+ mainContext = $module.children('canvas')[0].getContext('2d');
155
+ },
156
+ clear: function(context) {
157
+ module.debug('Clearing canvas');
158
+ overlayContext.fillStyle = '#FFFFFF';
159
+ overlayContext.fillRect(0, 0, width, height);
163
160
  },
161
+ merge: function() {
162
+ if( !$.isFunction(mainContext.blendOnto) ) {
163
+ module.error(error.missingPlugin);
164
+ return;
165
+ }
166
+ mainContext.putImageData( imageContext.getImageData(0, 0, width, height), 0, 0);
167
+ overlayContext.blendOnto(mainContext, 'multiply');
168
+ }
169
+ },
164
170
 
165
- draw: {
166
-
167
- image: function(callback) {
168
- module.debug('Drawing image');
169
- callback = callback || function(){};
170
- if(image) {
171
- backgroundImage.src = image;
172
- backgroundImage.onload = function() {
173
- imageContext.drawImage(backgroundImage, 0, 0);
174
- callback();
175
- };
176
- }
177
- else {
178
- module.error(error.noImage);
179
- callback();
180
- }
181
- },
171
+ draw: {
182
172
 
183
- colors: function() {
184
- module.debug('Drawing color overlays', colors);
185
- $.each(colors, function(colorName, color) {
186
- settings.onDraw(overlayContext, imageName, colorName, color);
187
- });
173
+ image: function(callback) {
174
+ module.debug('Drawing image');
175
+ callback = callback || function(){};
176
+ if(image) {
177
+ backgroundImage.src = image;
178
+ backgroundImage.onload = function() {
179
+ imageContext.drawImage(backgroundImage, 0, 0);
180
+ callback();
181
+ };
182
+ }
183
+ else {
184
+ module.error(error.noImage);
185
+ callback();
188
186
  }
189
-
190
187
  },
191
188
 
192
- debug: function(message, variableName) {
193
- if(settings.debug) {
194
- if(variableName !== undefined) {
195
- console.info(settings.name + ': ' + message, variableName);
196
- }
197
- else {
198
- console.info(settings.name + ': ' + message);
199
- }
189
+ colors: function() {
190
+ module.debug('Drawing color overlays', colors);
191
+ $.each(colors, function(colorName, color) {
192
+ settings.onDraw(overlayContext, imageName, colorName, color);
193
+ });
194
+ }
195
+
196
+ },
197
+
198
+ debug: function(message, variableName) {
199
+ if(settings.debug) {
200
+ if(variableName !== undefined) {
201
+ console.info(settings.name + ': ' + message, variableName);
200
202
  }
201
- },
202
- error: function(errorMessage) {
203
- console.warn(settings.name + ': ' + errorMessage);
204
- },
205
- invoke: function(methodName, context, methodArguments) {
206
- var
207
- method
208
- ;
209
- methodArguments = methodArguments || Array.prototype.slice.call( arguments, 2 );
210
-
211
- if(typeof methodName == 'string' && instance !== undefined) {
212
- methodName = methodName.split('.');
213
- $.each(methodName, function(index, name) {
214
- if( $.isPlainObject( instance[name] ) ) {
215
- instance = instance[name];
216
- return true;
217
- }
218
- else if( $.isFunction( instance[name] ) ) {
219
- method = instance[name];
220
- return true;
221
- }
222
- module.error(settings.error.method);
223
- return false;
224
- });
203
+ else {
204
+ console.info(settings.name + ': ' + message);
225
205
  }
226
- return ( $.isFunction( method ) )
227
- ? method.apply(context, methodArguments)
228
- : false
229
- ;
230
206
  }
231
-
232
- };
233
- if(instance !== undefined && moduleArguments) {
234
- // simpler than invoke realizing to invoke itself (and losing scope due prototype.call()
235
- if(moduleArguments[0] == 'invoke') {
236
- moduleArguments = Array.prototype.slice.call( moduleArguments, 1 );
207
+ },
208
+ error: function(errorMessage) {
209
+ console.warn(settings.name + ': ' + errorMessage);
210
+ },
211
+ invoke: function(methodName, context, methodArguments) {
212
+ var
213
+ method
214
+ ;
215
+ methodArguments = methodArguments || Array.prototype.slice.call( arguments, 2 );
216
+
217
+ if(typeof methodName == 'string' && instance !== undefined) {
218
+ methodName = methodName.split('.');
219
+ $.each(methodName, function(index, name) {
220
+ if( $.isPlainObject( instance[name] ) ) {
221
+ instance = instance[name];
222
+ return true;
223
+ }
224
+ else if( $.isFunction( instance[name] ) ) {
225
+ method = instance[name];
226
+ return true;
227
+ }
228
+ module.error(settings.error.method);
229
+ return false;
230
+ });
237
231
  }
238
- return module.invoke(moduleArguments[0], this, Array.prototype.slice.call( moduleArguments, 1 ) );
232
+ return ( $.isFunction( method ) )
233
+ ? method.apply(context, methodArguments)
234
+ : false
235
+ ;
236
+ }
237
+
238
+ };
239
+ if(instance !== undefined && moduleArguments) {
240
+ // simpler than invoke realizing to invoke itself (and losing scope due prototype.call()
241
+ if(moduleArguments[0] == 'invoke') {
242
+ moduleArguments = Array.prototype.slice.call( moduleArguments, 1 );
239
243
  }
240
- // initializing
241
- module.initialize();
242
- })
243
- ;
244
- return this;
245
- };
246
-
247
- $.fn.colorize.settings = {
248
- name : 'Image Colorizer',
249
- debug : true,
250
- namespace : 'colorize',
251
-
252
- onDraw : function(overlayContext, imageName, colorName, color) {},
253
-
254
- // whether to block execution while updating canvas
255
- async : true,
256
- // object containing names and default values of color regions
257
- colors : {},
258
-
259
- metadata: {
260
- image : 'image',
261
- name : 'name'
262
- },
263
-
264
- error: {
265
- noImage : 'No tracing image specified',
266
- undefinedColors : 'No default colors specified.',
267
- missingColor : 'Attempted to change color that does not exist',
268
- missingPlugin : 'Blend onto plug-in must be included',
269
- undefinedHeight : 'The width or height of image canvas could not be automatically determined. Please specify a height.'
270
- }
271
-
272
- };
244
+ return module.invoke(moduleArguments[0], this, Array.prototype.slice.call( moduleArguments, 1 ) );
245
+ }
246
+ // initializing
247
+ module.initialize();
248
+ })
249
+ ;
250
+ return this;
251
+ };
252
+
253
+ $.fn.colorize.settings = {
254
+ name : 'Image Colorizer',
255
+ debug : true,
256
+ namespace : 'colorize',
257
+
258
+ onDraw : function(overlayContext, imageName, colorName, color) {},
259
+
260
+ // whether to block execution while updating canvas
261
+ async : true,
262
+ // object containing names and default values of color regions
263
+ colors : {},
264
+
265
+ metadata: {
266
+ image : 'image',
267
+ name : 'name'
268
+ },
269
+
270
+ error: {
271
+ noImage : 'No tracing image specified',
272
+ undefinedColors : 'No default colors specified.',
273
+ missingColor : 'Attempted to change color that does not exist',
274
+ missingPlugin : 'Blend onto plug-in must be included',
275
+ undefinedHeight : 'The width or height of image canvas could not be automatically determined. Please specify a height.'
276
+ }
277
+
278
+ };
273
279
 
274
280
  })( jQuery, window, document );