semantic-ui-sass 0.0.3 → 0.8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.rspec +1 -0
  4. data/CHANGELOG.md +8 -0
  5. data/README.md +26 -1
  6. data/app/assets/javascripts/semantic-ui/accordion.js +15 -17
  7. data/app/assets/javascripts/semantic-ui/behavior/api.js +18 -22
  8. data/app/assets/javascripts/semantic-ui/behavior/form.js +18 -24
  9. data/app/assets/javascripts/semantic-ui/behavior/state.js +8 -8
  10. data/app/assets/javascripts/semantic-ui/chatroom.js +18 -14
  11. data/app/assets/javascripts/semantic-ui/checkbox.js +26 -24
  12. data/app/assets/javascripts/semantic-ui/dimmer.js +74 -47
  13. data/app/assets/javascripts/semantic-ui/dropdown.js +226 -153
  14. data/app/assets/javascripts/semantic-ui/modal.js +73 -46
  15. data/app/assets/javascripts/semantic-ui/nag.js +13 -16
  16. data/app/assets/javascripts/semantic-ui/popup.js +352 -263
  17. data/app/assets/javascripts/semantic-ui/rating.js +29 -26
  18. data/app/assets/javascripts/semantic-ui/search.js +18 -24
  19. data/app/assets/javascripts/semantic-ui/shape.js +182 -173
  20. data/app/assets/javascripts/semantic-ui/sidebar.js +66 -43
  21. data/app/assets/javascripts/semantic-ui/tab.js +49 -31
  22. data/app/assets/javascripts/semantic-ui/transition.js +24 -24
  23. data/app/assets/javascripts/semantic-ui/video.js +26 -24
  24. data/app/assets/stylesheets/semantic-ui/collections/_grid.scss +1 -1
  25. data/app/assets/stylesheets/semantic-ui/collections/_menu.scss +85 -37
  26. data/app/assets/stylesheets/semantic-ui/collections/_message.scss +6 -7
  27. data/app/assets/stylesheets/semantic-ui/collections/_table.scss +76 -23
  28. data/app/assets/stylesheets/semantic-ui/elements/_button.scss +415 -241
  29. data/app/assets/stylesheets/semantic-ui/elements/_header.scss +1 -1
  30. data/app/assets/stylesheets/semantic-ui/elements/_icon.scss +26 -24
  31. data/app/assets/stylesheets/semantic-ui/elements/_input.scss +8 -13
  32. data/app/assets/stylesheets/semantic-ui/elements/_label.scss +87 -5
  33. data/app/assets/stylesheets/semantic-ui/elements/_segment.scss +7 -9
  34. data/app/assets/stylesheets/semantic-ui/modules/_accordion.scss +1 -2
  35. data/app/assets/stylesheets/semantic-ui/modules/_checkbox.scss +17 -21
  36. data/app/assets/stylesheets/semantic-ui/modules/_dimmer.scss +4 -27
  37. data/app/assets/stylesheets/semantic-ui/modules/_dropdown.scss +44 -30
  38. data/app/assets/stylesheets/semantic-ui/modules/_modal.scss +68 -9
  39. data/app/assets/stylesheets/semantic-ui/modules/_popup.scss +26 -26
  40. data/app/assets/stylesheets/semantic-ui/modules/_rating.scss +1 -1
  41. data/app/assets/stylesheets/semantic-ui/modules/_reveal.scss +1 -1
  42. data/app/assets/stylesheets/semantic-ui/modules/_shape.scss +81 -7
  43. data/app/assets/stylesheets/semantic-ui/modules/_sidebar.scss +129 -28
  44. data/app/assets/stylesheets/semantic-ui/modules/_transition.scss +12 -10
  45. data/app/assets/stylesheets/semantic-ui/views/_item.scss +0 -10
  46. data/app/assets/stylesheets/semantic-ui/views/_list.scss +6 -6
  47. data/app/helpers/semantic_flash_helper.rb +22 -0
  48. data/app/helpers/semantic_icon_helper.rb +5 -0
  49. data/lib/semantic/ui/sass/version.rb +2 -2
  50. data/semantic-ui-sass.gemspec +3 -0
  51. data/spec/dummy/README.rdoc +28 -0
  52. data/spec/dummy/Rakefile +6 -0
  53. data/spec/dummy/app/assets/images/.keep +0 -0
  54. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  55. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  56. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  57. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  58. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  59. data/spec/dummy/app/mailers/.keep +0 -0
  60. data/spec/dummy/app/models/.keep +0 -0
  61. data/spec/dummy/app/models/concerns/.keep +0 -0
  62. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  63. data/spec/dummy/bin/bundle +3 -0
  64. data/spec/dummy/bin/rails +4 -0
  65. data/spec/dummy/bin/rake +4 -0
  66. data/spec/dummy/config.ru +4 -0
  67. data/spec/dummy/config/application.rb +28 -0
  68. data/spec/dummy/config/boot.rb +5 -0
  69. data/spec/dummy/config/database.yml +25 -0
  70. data/spec/dummy/config/environment.rb +5 -0
  71. data/spec/dummy/config/environments/development.rb +29 -0
  72. data/spec/dummy/config/environments/production.rb +80 -0
  73. data/spec/dummy/config/environments/test.rb +36 -0
  74. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  75. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  76. data/spec/dummy/config/initializers/inflections.rb +16 -0
  77. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  78. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  79. data/spec/dummy/config/initializers/session_store.rb +3 -0
  80. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  81. data/spec/dummy/config/locales/en.yml +23 -0
  82. data/spec/dummy/config/routes.rb +2 -0
  83. data/spec/dummy/lib/assets/.keep +0 -0
  84. data/spec/dummy/log/.keep +0 -0
  85. data/spec/dummy/public/404.html +58 -0
  86. data/spec/dummy/public/422.html +58 -0
  87. data/spec/dummy/public/500.html +57 -0
  88. data/spec/dummy/public/favicon.ico +0 -0
  89. data/spec/helpers/semantic_flash_helper_spec.rb +33 -0
  90. data/spec/helpers/semantic_icon_helper_spec.rb +20 -0
  91. data/spec/spec_helper.rb +8 -0
  92. metadata +132 -4
@@ -24,7 +24,7 @@ $.fn.modal = function(parameters) {
24
24
  methodInvoked = (typeof query == 'string'),
25
25
  queryArguments = [].slice.call(arguments, 1),
26
26
 
27
- invokedResponse
27
+ returnedValue
28
28
  ;
29
29
 
30
30
 
@@ -33,7 +33,7 @@ $.fn.modal = function(parameters) {
33
33
  var
34
34
  settings = ( $.isPlainObject(parameters) )
35
35
  ? $.extend(true, {}, $.fn.modal.settings, parameters)
36
- : $.fn.modal.settings,
36
+ : $.extend({}, $.fn.modal.settings),
37
37
 
38
38
  selector = settings.selector,
39
39
  className = settings.className,
@@ -63,10 +63,20 @@ $.fn.modal = function(parameters) {
63
63
  initialize: function() {
64
64
  module.verbose('Initializing dimmer', $context);
65
65
 
66
+ if(typeof $.fn.dimmer === undefined) {
67
+ module.error(error.dimmer);
68
+ return;
69
+ }
70
+
66
71
  $dimmable = $context
72
+ .dimmer({
73
+ closable : false,
74
+ show : settings.duration * 0.95,
75
+ hide : settings.duration * 1.05
76
+ })
67
77
  .dimmer('add content', $module)
68
78
  ;
69
- $dimmer = $context
79
+ $dimmer = $dimmable
70
80
  .dimmer('get dimmer')
71
81
  ;
72
82
 
@@ -93,8 +103,15 @@ $.fn.modal = function(parameters) {
93
103
  destroy: function() {
94
104
  module.verbose('Destroying previous modal');
95
105
  $module
106
+ .removeData(moduleNamespace)
96
107
  .off(eventNamespace)
97
108
  ;
109
+ $close
110
+ .off(eventNamespace)
111
+ ;
112
+ $context
113
+ .dimmer('destroy')
114
+ ;
98
115
  },
99
116
 
100
117
  refresh: function() {
@@ -126,8 +143,26 @@ $.fn.modal = function(parameters) {
126
143
 
127
144
  event: {
128
145
  close: function() {
129
- module.verbose('Close button pressed');
130
- module.hide();
146
+ module.verbose('Closing element pressed');
147
+ if( $(this).is(selector.approve) ) {
148
+ if($.proxy(settings.onApprove, element)()) {
149
+ module.hide();
150
+ }
151
+ else {
152
+ module.verbose('Approve callback returned false cancelling hide');
153
+ }
154
+ }
155
+ else if( $(this).is(selector.deny) ) {
156
+ if($.proxy(settings.onDeny, element)()) {
157
+ module.hide();
158
+ }
159
+ else {
160
+ module.verbose('Deny callback returned false cancelling hide');
161
+ }
162
+ }
163
+ else {
164
+ module.hide();
165
+ }
131
166
  },
132
167
  click: function(event) {
133
168
  module.verbose('Determining if event occured on dimmer', event);
@@ -146,8 +181,13 @@ $.fn.modal = function(parameters) {
146
181
  escapeKey = 27
147
182
  ;
148
183
  if(keyCode == escapeKey) {
149
- module.debug('Escape key pressed hiding modal');
150
- module.hide();
184
+ if(settings.closable) {
185
+ module.debug('Escape key pressed hiding modal');
186
+ module.hide();
187
+ }
188
+ else {
189
+ module.debug('Escape key pressed, but closable is set to false');
190
+ }
151
191
  event.preventDefault();
152
192
  }
153
193
  },
@@ -188,7 +228,6 @@ $.fn.modal = function(parameters) {
188
228
 
189
229
  showDimmer: function() {
190
230
  module.debug('Showing modal');
191
- module.set.dimmerSettings();
192
231
  $dimmable.dimmer('show');
193
232
  },
194
233
 
@@ -260,7 +299,7 @@ $.fn.modal = function(parameters) {
260
299
 
261
300
  restore: {
262
301
  focus: function() {
263
- if($focusedElement.size() > 0) {
302
+ if($focusedElement && $focusedElement.size() > 0) {
264
303
  $focusedElement.focus();
265
304
  }
266
305
  }
@@ -306,6 +345,7 @@ $.fn.modal = function(parameters) {
306
345
 
307
346
  set: {
308
347
  active: function() {
348
+ module.add.keyboardShortcuts();
309
349
  module.save.focus();
310
350
  module.set.type();
311
351
  $module
@@ -317,20 +357,6 @@ $.fn.modal = function(parameters) {
317
357
  ;
318
358
  }
319
359
  },
320
- dimmerSettings: function() {
321
- module.debug('Setting dimmer settings', $dimmable);
322
- $dimmable
323
- .dimmer('setting', 'closable', false)
324
- .dimmer('setting', 'duration', {
325
- show : settings.duration * 0.95,
326
- hide : settings.duration * 1.05
327
- })
328
- .dimmer('setting', 'onShow' , module.add.keyboardShortcuts)
329
- // destory after changing settings in order to reattach events
330
- .dimmer('destroy')
331
- .dimmer('initialize')
332
- ;
333
- },
334
360
  scrolling: function() {
335
361
  $dimmable.addClass(className.scrolling);
336
362
  $module.addClass(className.scrolling);
@@ -367,26 +393,22 @@ $.fn.modal = function(parameters) {
367
393
  },
368
394
 
369
395
  setting: function(name, value) {
370
- if(value !== undefined) {
371
- if( $.isPlainObject(name) ) {
372
- $.extend(true, settings, name);
373
- }
374
- else {
375
- settings[name] = value;
376
- }
396
+ if( $.isPlainObject(name) ) {
397
+ $.extend(true, settings, name);
398
+ }
399
+ else if(value !== undefined) {
400
+ settings[name] = value;
377
401
  }
378
402
  else {
379
403
  return settings[name];
380
404
  }
381
405
  },
382
406
  internal: function(name, value) {
383
- if(value !== undefined) {
384
- if( $.isPlainObject(name) ) {
385
- $.extend(true, module, name);
386
- }
387
- else {
388
- module[name] = value;
389
- }
407
+ if( $.isPlainObject(name) ) {
408
+ $.extend(true, module, name);
409
+ }
410
+ else if(value !== undefined) {
411
+ module[name] = value;
390
412
  }
391
413
  else {
392
414
  return module[name];
@@ -511,14 +533,14 @@ $.fn.modal = function(parameters) {
511
533
  else if(found !== undefined) {
512
534
  response = found;
513
535
  }
514
- if($.isArray(invokedResponse)) {
515
- invokedResponse.push(response);
536
+ if($.isArray(returnedValue)) {
537
+ returnedValue.push(response);
516
538
  }
517
- else if(typeof invokedResponse == 'string') {
518
- invokedResponse = [invokedResponse, response];
539
+ else if(returnedValue !== undefined) {
540
+ returnedValue = [returnedValue, response];
519
541
  }
520
542
  else if(response !== undefined) {
521
- invokedResponse = response;
543
+ returnedValue = response;
522
544
  }
523
545
  return found;
524
546
  }
@@ -539,8 +561,8 @@ $.fn.modal = function(parameters) {
539
561
  })
540
562
  ;
541
563
 
542
- return (invokedResponse !== undefined)
543
- ? invokedResponse
564
+ return (returnedValue !== undefined)
565
+ ? returnedValue
544
566
  : this
545
567
  ;
546
568
  };
@@ -562,12 +584,17 @@ $.fn.modal.settings = {
562
584
 
563
585
  onShow : function(){},
564
586
  onHide : function(){},
587
+ onApprove : function(){ return true; },
588
+ onDeny : function(){ return true; },
565
589
 
566
590
  selector : {
567
- close : '.close, .actions .button'
591
+ close : '.close, .actions .button',
592
+ approve : '.actions .positive, .actions .approve',
593
+ deny : '.actions .negative, .actions .cancel'
568
594
  },
569
595
  error : {
570
- method : 'The method you called is not defined.'
596
+ dimmer : 'UI Dimmer, a required component is not included in this page',
597
+ method : 'The method you called is not defined.'
571
598
  },
572
599
  className : {
573
600
  active : 'active',
@@ -22,7 +22,7 @@ $.fn.nag = function(parameters) {
22
22
  query = arguments[0],
23
23
  methodInvoked = (typeof query == 'string'),
24
24
  queryArguments = [].slice.call(arguments, 1),
25
- invokedResponse
25
+ returnedValue
26
26
  ;
27
27
  $(this)
28
28
  .each(function() {
@@ -299,14 +299,11 @@ $.fn.nag = function(parameters) {
299
299
  }
300
300
  },
301
301
  setting: function(name, value) {
302
- module.debug('Changing setting', name, value);
303
- if(value !== undefined) {
304
- if( $.isPlainObject(name) ) {
305
- $.extend(true, settings, name);
306
- }
307
- else {
308
- settings[name] = value;
309
- }
302
+ if( $.isPlainObject(name) ) {
303
+ $.extend(true, settings, name);
304
+ }
305
+ else if(value !== undefined) {
306
+ settings[name] = value;
310
307
  }
311
308
  else {
312
309
  return settings[name];
@@ -448,14 +445,14 @@ $.fn.nag = function(parameters) {
448
445
  else if(found !== undefined) {
449
446
  response = found;
450
447
  }
451
- if($.isArray(invokedResponse)) {
452
- invokedResponse.push(response);
448
+ if($.isArray(returnedValue)) {
449
+ returnedValue.push(response);
453
450
  }
454
- else if(typeof invokedResponse == 'string') {
455
- invokedResponse = [invokedResponse, response];
451
+ else if(returnedValue !== undefined) {
452
+ returnedValue = [returnedValue, response];
456
453
  }
457
454
  else if(response !== undefined) {
458
- invokedResponse = response;
455
+ returnedValue = response;
459
456
  }
460
457
  return found;
461
458
  }
@@ -475,8 +472,8 @@ $.fn.nag = function(parameters) {
475
472
 
476
473
  })
477
474
  ;
478
- return (invokedResponse !== undefined)
479
- ? invokedResponse
475
+ return (returnedValue !== undefined)
476
+ ? returnedValue
480
477
  : this
481
478
  ;
482
479
  };
@@ -15,6 +15,7 @@ $.fn.popup = function(parameters) {
15
15
  var
16
16
  $allModules = $(this),
17
17
  $document = $(document),
18
+ $body = $('body'),
18
19
 
19
20
  moduleSelector = $allModules.selector || '',
20
21
 
@@ -25,14 +26,14 @@ $.fn.popup = function(parameters) {
25
26
  methodInvoked = (typeof query == 'string'),
26
27
  queryArguments = [].slice.call(arguments, 1),
27
28
 
28
- invokedResponse
29
+ returnedValue
29
30
  ;
30
31
  $allModules
31
32
  .each(function() {
32
33
  var
33
34
  settings = ( $.isPlainObject(parameters) )
34
35
  ? $.extend(true, {}, $.fn.popup.settings, parameters)
35
- : $.fn.popup.settings,
36
+ : $.extend({}, $.fn.popup.settings),
36
37
 
37
38
  selector = settings.selector,
38
39
  className = settings.className,
@@ -41,14 +42,20 @@ $.fn.popup = function(parameters) {
41
42
  namespace = settings.namespace,
42
43
 
43
44
  eventNamespace = '.' + settings.namespace,
44
- moduleNamespace = settings.namespace + '-module',
45
+ moduleNamespace = 'module-' + namespace,
45
46
 
46
47
  $module = $(this),
48
+ $target = (settings.target)
49
+ ? $(settings.target)
50
+ : $module,
47
51
 
48
52
  $window = $(window),
49
- $offsetParent = $module.offsetParent(),
53
+
54
+ $offsetParent = (settings.inline)
55
+ ? $target.offsetParent()
56
+ : $window,
50
57
  $popup = (settings.inline)
51
- ? $module.next(settings.selector.popup)
58
+ ? $target.next(settings.selector.popup)
52
59
  : $window.children(settings.selector.popup).last(),
53
60
 
54
61
  searchDepth = 0,
@@ -63,17 +70,20 @@ $.fn.popup = function(parameters) {
63
70
  // binds events
64
71
  initialize: function() {
65
72
  module.debug('Initializing module', $module);
66
- if(settings.on == 'hover') {
73
+ if(settings.on == 'click') {
67
74
  $module
68
- .on('mouseenter' + eventNamespace, module.event.mouseenter)
69
- .on('mouseleave' + eventNamespace, module.event.mouseleave)
75
+ .on('click', module.toggle)
70
76
  ;
71
77
  }
72
78
  else {
73
79
  $module
74
- .on(settings.on + '' + eventNamespace, module.event[settings.on])
80
+ .on(module.get.startEvent() + eventNamespace, module.event.start)
81
+ .on(module.get.endEvent() + eventNamespace, module.event.end)
75
82
  ;
76
83
  }
84
+ if(settings.target) {
85
+ module.debug('Target set to element', $target);
86
+ }
77
87
  $window
78
88
  .on('resize' + eventNamespace, module.event.resize)
79
89
  ;
@@ -89,15 +99,24 @@ $.fn.popup = function(parameters) {
89
99
  },
90
100
 
91
101
  refresh: function() {
92
- $popup = (settings.inline)
93
- ? $module.next(selector.popup)
94
- : $window.children(selector.popup).last()
95
- ;
96
- $offsetParent = $module.offsetParent();
102
+ if(settings.inline) {
103
+ $popup = $target.next(selector.popup);
104
+ $offsetParent = $target.offsetParent();
105
+ }
106
+ else {
107
+ console.log('found by refresh');
108
+ $popup = $window.children(selector.popup).last();
109
+ }
97
110
  },
98
111
 
99
112
  destroy: function() {
100
113
  module.debug('Destroying previous module');
114
+ $window
115
+ .off(eventNamespace)
116
+ ;
117
+ $popup
118
+ .remove()
119
+ ;
101
120
  $module
102
121
  .off(eventNamespace)
103
122
  .removeData(moduleNamespace)
@@ -105,30 +124,22 @@ $.fn.popup = function(parameters) {
105
124
  },
106
125
 
107
126
  event: {
108
- mouseenter: function(event) {
109
- var element = this;
127
+ start: function(event) {
110
128
  module.timer = setTimeout(function() {
111
- $.proxy(module.toggle, element)();
112
- if( $(element).hasClass(className.visible) ) {
113
- event.stopPropagation();
129
+ if( module.is.hidden() ) {
130
+ module.show();
114
131
  }
115
132
  }, settings.delay);
116
133
  },
117
- mouseleave: function() {
134
+ end: function() {
118
135
  clearTimeout(module.timer);
119
- if( $module.is(':visible') ) {
136
+ if( module.is.visible() ) {
120
137
  module.hide();
121
138
  }
122
139
  },
123
- click: function(event) {
124
- $.proxy(module.toggle, this)();
125
- if( $(this).hasClass(className.visible) ) {
126
- event.stopPropagation();
127
- }
128
- },
129
140
  resize: function() {
130
- if( $popup.is(':visible') ) {
131
- module.position();
141
+ if( module.is.visible() ) {
142
+ module.set.position();
132
143
  }
133
144
  }
134
145
  },
@@ -163,7 +174,7 @@ $.fn.popup = function(parameters) {
163
174
  else {
164
175
  module.verbose('Appending popup element to body', $popup);
165
176
  $popup
166
- .appendTo( $('body') )
177
+ .appendTo( $body )
167
178
  ;
168
179
  }
169
180
  $.proxy(settings.onCreate, $popup)();
@@ -173,6 +184,66 @@ $.fn.popup = function(parameters) {
173
184
  }
174
185
  },
175
186
 
187
+ // determines popup state
188
+ toggle: function() {
189
+ module.debug('Toggling pop-up');
190
+ if( module.is.hidden() ) {
191
+ module.hideAll();
192
+ module.show();
193
+ }
194
+ else {
195
+ module.hide();
196
+ }
197
+ },
198
+
199
+ show: function(callback) {
200
+ callback = callback || function(){};
201
+ module.debug('Showing pop-up', settings.transition);
202
+ if(!settings.preserve) {
203
+ module.refresh();
204
+ }
205
+ if( !module.exists() ) {
206
+ module.create();
207
+ }
208
+ module.set.position();
209
+ module.animate.show(callback);
210
+ },
211
+
212
+
213
+ hide: function(callback) {
214
+ callback = callback || function(){};
215
+ $module
216
+ .removeClass(className.visible)
217
+ ;
218
+ module.unbind.close();
219
+ if( module.is.visible() ) {
220
+ module.animate.hide(callback);
221
+ }
222
+ },
223
+
224
+ hideAll: function() {
225
+ $(selector.popup)
226
+ .filter(':visible')
227
+ .popup('hide')
228
+ ;
229
+ },
230
+
231
+ hideGracefully: function(event) {
232
+ // don't close on clicks inside popup
233
+ if( $(event.target).closest(selector.popup).size() === 0) {
234
+ module.hide();
235
+ }
236
+ },
237
+
238
+ exists: function() {
239
+ if(settings.inline) {
240
+ return ( $popup.size() !== 0 );
241
+ }
242
+ else {
243
+ return ( $popup.parent($body).size() );
244
+ }
245
+ },
246
+
176
247
  remove: function() {
177
248
  module.debug('Removing popup');
178
249
  $popup
@@ -180,7 +251,72 @@ $.fn.popup = function(parameters) {
180
251
  ;
181
252
  },
182
253
 
254
+ animate: {
255
+ show: function(callback) {
256
+ callback = callback || function(){};
257
+ $module
258
+ .addClass(className.visible)
259
+ ;
260
+ if(settings.transition && $.fn.transition !== undefined) {
261
+ $popup
262
+ .transition(settings.transition + ' in', settings.duration, function() {
263
+ module.bind.close();
264
+ $.proxy(callback, element)();
265
+ })
266
+ ;
267
+ }
268
+ else {
269
+ $popup
270
+ .stop()
271
+ .fadeIn(settings.duration, settings.easing, function() {
272
+ module.bind.close();
273
+ $.proxy(callback, element)();
274
+ })
275
+ ;
276
+ }
277
+ $.proxy(settings.onShow, element)();
278
+ },
279
+ hide: function(callback) {
280
+ callback = callback || function(){};
281
+ module.debug('Hiding pop-up');
282
+ if(settings.transition && $.fn.transition !== undefined) {
283
+ $popup
284
+ .transition(settings.transition + ' out', settings.duration, function() {
285
+ module.reset();
286
+ callback();
287
+ })
288
+ ;
289
+ }
290
+ else {
291
+ $popup
292
+ .stop()
293
+ .fadeOut(settings.duration, settings.easing, function() {
294
+ module.reset();
295
+ callback();
296
+ })
297
+ ;
298
+ }
299
+ $.proxy(settings.onHide, element)();
300
+ }
301
+ },
302
+
183
303
  get: {
304
+ startEvent: function() {
305
+ if(settings.on == 'hover') {
306
+ return 'mouseenter';
307
+ }
308
+ else if(settings.on == 'focus') {
309
+ return 'focus';
310
+ }
311
+ },
312
+ endEvent: function() {
313
+ if(settings.on == 'hover') {
314
+ return 'mouseleave';
315
+ }
316
+ else if(settings.on == 'focus') {
317
+ return 'blur';
318
+ }
319
+ },
184
320
  offstagePosition: function() {
185
321
  var
186
322
  boundary = {
@@ -248,250 +384,201 @@ $.fn.popup = function(parameters) {
248
384
  }
249
385
  },
250
386
 
251
- // determines popup state
252
- toggle: function() {
253
- $module = $(this);
254
- module.debug('Toggling pop-up');
255
- // refresh state of module
256
- module.refresh();
257
- if( !$module.hasClass(className.visible) ) {
258
- if(settings.on == 'click') {
259
- module.hideAll();
260
- }
261
- module.show();
262
- }
263
- else {
264
- // module.hide();
265
- }
266
- },
387
+ set: {
388
+ position: function(position, arrowOffset) {
389
+ var
390
+ windowWidth = $(window).width(),
391
+ windowHeight = $(window).height(),
267
392
 
268
- position: function(position, arrowOffset) {
269
- var
270
- windowWidth = $(window).width(),
271
- windowHeight = $(window).height(),
272
- width = $module.outerWidth(),
273
- height = $module.outerHeight(),
274
- popupWidth = $popup.width(),
275
- popupHeight = $popup.outerHeight(),
276
-
277
- offset = (settings.inline)
278
- ? $module.position()
279
- : $module.offset(),
280
- parentWidth = (settings.inline)
281
- ? $offsetParent.outerWidth()
282
- : $window.outerWidth(),
283
- parentHeight = (settings.inline)
284
- ? $offsetParent.outerHeight()
285
- : $window.outerHeight(),
286
-
287
- positioning,
288
- offstagePosition
289
- ;
290
- position = position || $module.data(metadata.position) || settings.position;
291
- arrowOffset = arrowOffset || $module.data(metadata.arrowOffset) || settings.arrowOffset;
292
- module.debug('Calculating offset for position', position);
293
- switch(position) {
294
- case 'top left':
295
- positioning = {
296
- bottom : parentHeight - offset.top + settings.distanceAway,
297
- right : parentWidth - offset.left - width - arrowOffset,
298
- top : 'auto',
299
- left : 'auto'
300
- };
301
- break;
302
- case 'top center':
303
- positioning = {
304
- bottom : parentHeight - offset.top + settings.distanceAway,
305
- left : offset.left + (width / 2) - (popupWidth / 2) + arrowOffset,
306
- top : 'auto',
307
- right : 'auto'
308
- };
309
- break;
310
- case 'top right':
311
- positioning = {
312
- top : 'auto',
313
- bottom : parentHeight - offset.top + settings.distanceAway,
314
- left : offset.left + arrowOffset
315
- };
316
- break;
317
- case 'left center':
318
- positioning = {
319
- top : offset.top + (height / 2) - (popupHeight / 2),
320
- right : parentWidth - offset.left + settings.distanceAway - arrowOffset,
321
- left : 'auto',
322
- bottom : 'auto'
323
- };
324
- break;
325
- case 'right center':
326
- positioning = {
327
- top : offset.top + (height / 2) - (popupHeight / 2),
328
- left : offset.left + width + settings.distanceAway + arrowOffset,
329
- bottom : 'auto',
330
- right : 'auto'
331
- };
332
- break;
333
- case 'bottom left':
334
- positioning = {
335
- top : offset.top + height + settings.distanceAway,
336
- right : parentWidth - offset.left - width - arrowOffset,
337
- left : 'auto',
338
- bottom : 'auto'
339
- };
340
- break;
341
- case 'bottom center':
342
- positioning = {
343
- top : offset.top + height + settings.distanceAway,
344
- left : offset.left + (width / 2) - (popupWidth / 2) + arrowOffset,
345
- bottom : 'auto',
346
- right : 'auto'
347
- };
348
- break;
349
- case 'bottom right':
350
- positioning = {
351
- top : offset.top + height + settings.distanceAway,
352
- left : offset.left + arrowOffset,
353
- bottom : 'auto',
354
- right : 'auto'
355
- };
356
- break;
357
- }
358
- // true width on popup, avoid rounding error
359
- $.extend(positioning, {
360
- width: $popup.width() + 1
361
- });
362
- // tentatively place on stage
363
- $popup
364
- .css(positioning)
365
- .removeClass(className.position)
366
- .addClass(position)
367
- ;
368
- // check if is offstage
369
- offstagePosition = module.get.offstagePosition();
370
- // recursively find new positioning
371
- if(offstagePosition) {
372
- module.debug('Element is outside boundaries ', offstagePosition);
373
- if(searchDepth < settings.maxSearchDepth) {
374
- position = module.get.nextPosition(position);
375
- searchDepth++;
376
- module.debug('Trying new position: ', position);
377
- return module.position(position);
378
- }
379
- else {
380
- module.error(error.recursion);
381
- searchDepth = 0;
382
- return false;
383
- }
384
- }
385
- else {
386
- module.debug('Position is on stage', position);
387
- searchDepth = 0;
388
- return true;
389
- }
390
- },
393
+ width = $target.outerWidth(),
394
+ height = $target.outerHeight(),
391
395
 
392
- show: function() {
393
- module.debug('Showing pop-up', settings.transition);
394
- if($popup.size() === 0) {
395
- module.create();
396
- }
397
- module.position();
398
- $module
399
- .addClass(className.visible)
400
- ;
401
- if(settings.transition && $.fn.transition !== undefined) {
402
- $popup
403
- .transition(settings.transition + ' in', settings.duration)
396
+ popupWidth = $popup.width(),
397
+ popupHeight = $popup.outerHeight(),
398
+
399
+ parentWidth = $offsetParent.outerWidth(),
400
+ parentHeight = $offsetParent.outerHeight(),
401
+
402
+ distanceAway = settings.distanceAway,
403
+
404
+ offset = (settings.inline)
405
+ ? $target.position()
406
+ : $target.offset(),
407
+
408
+ positioning,
409
+ offstagePosition
404
410
  ;
405
- }
406
- else {
411
+ position = position || $module.data(metadata.position) || settings.position;
412
+ arrowOffset = arrowOffset || $module.data(metadata.offset) || settings.offset;
413
+ // adjust for margin when inline
414
+ if(settings.inline) {
415
+ if(position == 'left center' || position == 'right center') {
416
+ arrowOffset += parseInt( window.getComputedStyle(element).getPropertyValue('margin-top'), 10);
417
+ distanceAway += -parseInt( window.getComputedStyle(element).getPropertyValue('margin-left'), 10);
418
+ }
419
+ else {
420
+ arrowOffset += parseInt( window.getComputedStyle(element).getPropertyValue('margin-left'), 10);
421
+ distanceAway += parseInt( window.getComputedStyle(element).getPropertyValue('margin-top'), 10);
422
+ }
423
+ }
424
+ module.debug('Calculating offset for position', position);
425
+ switch(position) {
426
+ case 'top left':
427
+ positioning = {
428
+ bottom : parentHeight - offset.top + distanceAway,
429
+ right : parentWidth - offset.left - arrowOffset,
430
+ top : 'auto',
431
+ left : 'auto'
432
+ };
433
+ break;
434
+ case 'top center':
435
+ positioning = {
436
+ bottom : parentHeight - offset.top + distanceAway,
437
+ left : offset.left + (width / 2) - (popupWidth / 2) + arrowOffset,
438
+ top : 'auto',
439
+ right : 'auto'
440
+ };
441
+ break;
442
+ case 'top right':
443
+ positioning = {
444
+ top : 'auto',
445
+ bottom : parentHeight - offset.top + distanceAway,
446
+ left : offset.left + width + arrowOffset,
447
+ right : 'auto'
448
+ };
449
+ break;
450
+ case 'left center':
451
+ positioning = {
452
+ top : offset.top + (height / 2) - (popupHeight / 2) + arrowOffset,
453
+ right : parentWidth - offset.left + distanceAway,
454
+ left : 'auto',
455
+ bottom : 'auto'
456
+ };
457
+ break;
458
+ case 'right center':
459
+ positioning = {
460
+ top : offset.top + (height / 2) - (popupHeight / 2) + arrowOffset,
461
+ left : offset.left + width + distanceAway,
462
+ bottom : 'auto',
463
+ right : 'auto'
464
+ };
465
+ break;
466
+ case 'bottom left':
467
+ positioning = {
468
+ top : offset.top + height + distanceAway,
469
+ right : parentWidth - offset.left - arrowOffset,
470
+ left : 'auto',
471
+ bottom : 'auto'
472
+ };
473
+ break;
474
+ case 'bottom center':
475
+ positioning = {
476
+ top : offset.top + height + distanceAway,
477
+ left : offset.left + (width / 2) - (popupWidth / 2) + arrowOffset,
478
+ bottom : 'auto',
479
+ right : 'auto'
480
+ };
481
+ break;
482
+ case 'bottom right':
483
+ positioning = {
484
+ top : offset.top + height + distanceAway,
485
+ left : offset.left + width + arrowOffset,
486
+ bottom : 'auto',
487
+ right : 'auto'
488
+ };
489
+ break;
490
+ }
491
+ // tentatively place on stage
407
492
  $popup
408
- .stop()
409
- .fadeIn(settings.duration, settings.easing)
410
- ;
411
- }
412
- if(settings.on == 'click' && settings.clicktoClose) {
413
- module.debug('Binding popup close event');
414
- $document
415
- .on('click.' + namespace, module.gracefully.hide)
493
+ .css(positioning)
494
+ .removeClass(className.position)
495
+ .addClass(position)
416
496
  ;
497
+ // check if is offstage
498
+ offstagePosition = module.get.offstagePosition();
499
+
500
+ // recursively find new positioning
501
+ if(offstagePosition) {
502
+ module.debug('Element is outside boundaries', offstagePosition);
503
+ if(searchDepth < settings.maxSearchDepth) {
504
+ position = module.get.nextPosition(position);
505
+ searchDepth++;
506
+ module.debug('Trying new position', position);
507
+ return module.set.position(position);
508
+ }
509
+ else {
510
+ module.error(error.recursion);
511
+ searchDepth = 0;
512
+ return false;
513
+ }
514
+ }
515
+ else {
516
+ module.debug('Position is on stage', position);
517
+ searchDepth = 0;
518
+ return true;
519
+ }
417
520
  }
418
- $.proxy(settings.onShow, $popup)();
419
- },
420
521
 
421
- hideAll: function() {
422
- $(selector.popup)
423
- .filter(':visible')
424
- .popup('hide')
425
- ;
426
522
  },
427
523
 
428
- hide: function() {
429
- $module
430
- .removeClass(className.visible)
431
- ;
432
- if($popup.is(':visible') ) {
433
- module.debug('Hiding pop-up');
434
- if(settings.transition && $.fn.transition !== undefined) {
435
- $popup
436
- .transition(settings.transition + ' out', settings.duration, module.reset)
524
+ bind: {
525
+ close:function() {
526
+ if(settings.on == 'click' && settings.closable) {
527
+ module.verbose('Binding popup close event to document');
528
+ $document
529
+ .on('click' + eventNamespace, module.hideGracefully)
437
530
  ;
438
531
  }
439
- else {
440
- $popup
441
- .stop()
442
- .fadeOut(settings.duration, settings.easing, module.reset)
532
+ }
533
+ },
534
+
535
+ unbind: {
536
+ close: function() {
537
+ if(settings.on == 'click' && settings.closable) {
538
+ module.verbose('Removing close event from document');
539
+ $document
540
+ .off('click' + eventNamespace)
443
541
  ;
444
542
  }
445
543
  }
446
- if(settings.on == 'click' && settings.clicktoClose) {
447
- $document
448
- .off('click.' + namespace)
449
- ;
544
+ },
545
+
546
+ is: {
547
+ visible: function() {
548
+ return $popup.is(':visible');
549
+ },
550
+ hidden: function() {
551
+ return !module.is.visible();
450
552
  }
451
- $.proxy(settings.onHide, $popup)();
452
553
  },
453
554
 
454
555
  reset: function() {
455
- module.verbose('Resetting inline styles');
456
556
  $popup
457
557
  .attr('style', '')
458
558
  .removeAttr('style')
459
559
  ;
460
- if(!settings.inline) {
560
+ if(!settings.preserve) {
461
561
  module.remove();
462
562
  }
463
563
  },
464
564
 
465
- gracefully: {
466
- hide: function(event) {
467
- // don't close on clicks inside popup
468
- if( $(event.target).closest(selector.popup).size() === 0) {
469
- module.hide();
470
- }
471
- }
472
- },
473
-
474
565
  setting: function(name, value) {
475
- if(value !== undefined) {
476
- if( $.isPlainObject(name) ) {
477
- $.extend(true, settings, name);
478
- }
479
- else {
480
- settings[name] = value;
481
- }
566
+ if( $.isPlainObject(name) ) {
567
+ $.extend(true, settings, name);
568
+ }
569
+ else if(value !== undefined) {
570
+ settings[name] = value;
482
571
  }
483
572
  else {
484
573
  return settings[name];
485
574
  }
486
575
  },
487
576
  internal: function(name, value) {
488
- if(value !== undefined) {
489
- if( $.isPlainObject(name) ) {
490
- $.extend(true, module, name);
491
- }
492
- else {
493
- module[name] = value;
494
- }
577
+ if( $.isPlainObject(name) ) {
578
+ $.extend(true, module, name);
579
+ }
580
+ else if(value !== undefined) {
581
+ module[name] = value;
495
582
  }
496
583
  else {
497
584
  return module[name];
@@ -605,7 +692,7 @@ $.fn.popup = function(parameters) {
605
692
  return false;
606
693
  }
607
694
  else {
608
- module.error(error.method);
695
+ module.error(error.method, query);
609
696
  return false;
610
697
  }
611
698
  });
@@ -616,14 +703,14 @@ $.fn.popup = function(parameters) {
616
703
  else if(found !== undefined) {
617
704
  response = found;
618
705
  }
619
- if($.isArray(invokedResponse)) {
620
- invokedResponse.push(response);
706
+ if($.isArray(returnedValue)) {
707
+ returnedValue.push(response);
621
708
  }
622
- else if(typeof invokedResponse == 'string') {
623
- invokedResponse = [invokedResponse, response];
709
+ else if(returnedValue !== undefined) {
710
+ returnedValue = [returnedValue, response];
624
711
  }
625
712
  else if(response !== undefined) {
626
- invokedResponse = response;
713
+ returnedValue = response;
627
714
  }
628
715
  return found;
629
716
  }
@@ -644,8 +731,8 @@ $.fn.popup = function(parameters) {
644
731
  })
645
732
  ;
646
733
 
647
- return (invokedResponse !== undefined)
648
- ? invokedResponse
734
+ return (returnedValue !== undefined)
735
+ ? returnedValue
649
736
  : this
650
737
  ;
651
738
  };
@@ -658,7 +745,7 @@ $.fn.popup.settings = {
658
745
  performance : true,
659
746
  namespace : 'popup',
660
747
 
661
- onCreate : function(){},
748
+ onCreate : function(){},
662
749
  onShow : function(){},
663
750
  onHide : function(){},
664
751
 
@@ -668,18 +755,20 @@ $.fn.popup.settings = {
668
755
  title : false,
669
756
 
670
757
  on : 'hover',
671
- clicktoClose : true,
758
+ target : false,
759
+ closable : true,
672
760
 
673
761
  position : 'top center',
674
762
  delay : 150,
675
- inline : true,
763
+ inline : false,
764
+ preserve : false,
676
765
 
677
- duration : 150,
766
+ duration : 250,
678
767
  easing : 'easeOutQuint',
679
768
  transition : 'scale',
680
769
 
681
770
  distanceAway : 0,
682
- arrowOffset : 0,
771
+ offset : 0,
683
772
  maxSearchDepth : 10,
684
773
 
685
774
  error: {
@@ -689,19 +778,19 @@ $.fn.popup.settings = {
689
778
  },
690
779
 
691
780
  metadata: {
692
- arrowOffset : 'arrowOffset',
693
- content : 'content',
694
- html : 'html',
695
- position : 'position',
696
- title : 'title',
697
- variation : 'variation'
781
+ content : 'content',
782
+ html : 'html',
783
+ offset : 'offset',
784
+ position : 'position',
785
+ title : 'title',
786
+ variation : 'variation'
698
787
  },
699
788
 
700
789
  className : {
701
- popup : 'ui popup',
702
- visible : 'visible',
703
790
  loading : 'loading',
704
- position : 'top left center bottom right'
791
+ popup : 'ui popup',
792
+ position : 'top left center bottom right',
793
+ visible : 'visible'
705
794
  },
706
795
 
707
796
  selector : {