less-rails-semantic_ui 2.0.2.0 → 2.0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/Appraisals +3 -3
  4. data/README.md +1 -1
  5. data/assets/javascripts/semantic_ui/definitions/behaviors/api.js +14 -1
  6. data/assets/javascripts/semantic_ui/definitions/behaviors/form.js +135 -91
  7. data/assets/javascripts/semantic_ui/definitions/behaviors/visibility.js +9 -6
  8. data/assets/javascripts/semantic_ui/definitions/modules/checkbox.js +16 -3
  9. data/assets/javascripts/semantic_ui/definitions/modules/dropdown.js +67 -20
  10. data/assets/javascripts/semantic_ui/definitions/modules/modal.js +12 -10
  11. data/assets/javascripts/semantic_ui/definitions/modules/popup.js +92 -59
  12. data/assets/javascripts/semantic_ui/definitions/modules/sidebar.js +0 -1
  13. data/assets/javascripts/semantic_ui/definitions/modules/sticky.js +14 -11
  14. data/assets/javascripts/semantic_ui/definitions/modules/transition.js +6 -3
  15. data/assets/stylesheets/semantic_ui/definitions/collections/form.less +6 -1
  16. data/assets/stylesheets/semantic_ui/definitions/collections/menu.less +35 -15
  17. data/assets/stylesheets/semantic_ui/definitions/collections/message.less +1 -2
  18. data/assets/stylesheets/semantic_ui/definitions/collections/table.less +22 -11
  19. data/assets/stylesheets/semantic_ui/definitions/elements/button.less +17 -20
  20. data/assets/stylesheets/semantic_ui/definitions/elements/container.less +1 -6
  21. data/assets/stylesheets/semantic_ui/definitions/elements/divider.less +1 -0
  22. data/assets/stylesheets/semantic_ui/definitions/elements/icon.less +13 -0
  23. data/assets/stylesheets/semantic_ui/definitions/elements/input.less +2 -2
  24. data/assets/stylesheets/semantic_ui/definitions/elements/segment.less +20 -16
  25. data/assets/stylesheets/semantic_ui/definitions/elements/step.less +35 -25
  26. data/assets/stylesheets/semantic_ui/definitions/modules/accordion.less +2 -1
  27. data/assets/stylesheets/semantic_ui/definitions/modules/checkbox.less +99 -62
  28. data/assets/stylesheets/semantic_ui/definitions/modules/modal.less +1 -1
  29. data/assets/stylesheets/semantic_ui/definitions/modules/popup.less +7 -0
  30. data/assets/stylesheets/semantic_ui/themes/basic/elements/step.overrides +3 -0
  31. data/assets/stylesheets/semantic_ui/themes/basic/elements/step.variables +12 -4
  32. data/assets/stylesheets/semantic_ui/themes/colored/modules/checkbox.variables +15 -3
  33. data/assets/stylesheets/semantic_ui/themes/default/collections/form.variables +1 -1
  34. data/assets/stylesheets/semantic_ui/themes/default/collections/menu.variables +12 -11
  35. data/assets/stylesheets/semantic_ui/themes/default/collections/table.variables +11 -2
  36. data/assets/stylesheets/semantic_ui/themes/default/elements/icon.overrides +2 -0
  37. data/assets/stylesheets/semantic_ui/themes/default/elements/segment.variables +6 -5
  38. data/assets/stylesheets/semantic_ui/themes/default/elements/step.variables +6 -3
  39. data/assets/stylesheets/semantic_ui/themes/default/globals/site.variables +10 -9
  40. data/assets/stylesheets/semantic_ui/themes/default/modules/checkbox.variables +32 -11
  41. data/assets/stylesheets/semantic_ui/themes/github/elements/segment.variables +0 -1
  42. data/assets/stylesheets/semantic_ui/themes/github/elements/step.variables +7 -1
  43. data/less-rails-semantic_ui.gemspec +1 -1
  44. data/lib/less/rails/semantic_ui/version.rb +1 -1
  45. metadata +3 -3
@@ -309,15 +309,19 @@ $.fn.dropdown = function(parameters) {
309
309
  .html( templates.dropdown(selectValues) )
310
310
  .insertBefore($input)
311
311
  ;
312
+ if($input.hasClass(className.multiple) && $input.prop('multiple') === false) {
313
+ module.error(error.missingMultiple);
314
+ $input.prop('multiple', true);
315
+ }
316
+ if($input.is('[multiple]')) {
317
+ module.set.multiple();
318
+ }
312
319
  $input
313
320
  .removeAttr('class')
314
321
  .detach()
315
322
  .prependTo($module)
316
323
  ;
317
324
  }
318
- if($input.is('[multiple]')) {
319
- module.set.multiple();
320
- }
321
325
  module.refresh();
322
326
  },
323
327
  menu: function(values) {
@@ -1449,8 +1453,8 @@ $.fn.dropdown = function(parameters) {
1449
1453
  if(value === '') {
1450
1454
  return '';
1451
1455
  }
1452
- return (!$input.is('select') && module.is.multiple())
1453
- ? typeof value == 'string'
1456
+ return ( !module.has.selectInput() && module.is.multiple() )
1457
+ ? (typeof value == 'string') // delimited string
1454
1458
  ? value.split(settings.delimiter)
1455
1459
  : ''
1456
1460
  : value
@@ -2090,6 +2094,12 @@ $.fn.dropdown = function(parameters) {
2090
2094
  return;
2091
2095
  }
2092
2096
  }
2097
+
2098
+ if( module.is.single() && module.has.selectInput() && module.can.extendSelect() ) {
2099
+ module.debug('Adding user option', value);
2100
+ module.add.optionValue(value);
2101
+ }
2102
+
2093
2103
  module.debug('Updating input value', value, currentValue);
2094
2104
  $input
2095
2105
  .val(value)
@@ -2260,8 +2270,13 @@ $.fn.dropdown = function(parameters) {
2260
2270
  selectObserver.disconnect();
2261
2271
  module.verbose('Temporarily disconnecting mutation observer', value);
2262
2272
  }
2273
+ if( module.is.single() ) {
2274
+ module.verbose('Removing previous user addition');
2275
+ $input.find('option.' + className.addition).remove();
2276
+ }
2263
2277
  $('<option/>')
2264
2278
  .prop('value', value)
2279
+ .addClass(className.addition)
2265
2280
  .html(value)
2266
2281
  .appendTo($input)
2267
2282
  ;
@@ -2342,7 +2357,7 @@ $.fn.dropdown = function(parameters) {
2342
2357
  module.debug('Cannot select blank values from multiselect');
2343
2358
  return;
2344
2359
  }
2345
- // extend currently array
2360
+ // extend current array
2346
2361
  if($.isArray(currentValue)) {
2347
2362
  newValue = currentValue.concat([addedValue]);
2348
2363
  newValue = module.get.uniqueArray(newValue);
@@ -2351,10 +2366,10 @@ $.fn.dropdown = function(parameters) {
2351
2366
  newValue = [addedValue];
2352
2367
  }
2353
2368
  // add values
2354
- if( $input.is('select')) {
2355
- if(settings.allowAdditions) {
2356
- module.add.optionValue(addedValue);
2369
+ if( module.has.selectInput() ) {
2370
+ if(module.can.extendSelect()) {
2357
2371
  module.debug('Adding value to select', addedValue, newValue, $input);
2372
+ module.add.optionValue(addedValue);
2358
2373
  }
2359
2374
  }
2360
2375
  else {
@@ -2407,6 +2422,28 @@ $.fn.dropdown = function(parameters) {
2407
2422
  $item.removeClass(className.filtered);
2408
2423
  }
2409
2424
  },
2425
+ optionValue: function(value) {
2426
+ var
2427
+ $option = $input.find('option[value="' + value + '"]'),
2428
+ hasOption = ($option.length > 0)
2429
+ ;
2430
+ if(!hasOption || !$option.hasClass(className.addition)) {
2431
+ return;
2432
+ }
2433
+ // temporarily disconnect observer
2434
+ if(selectObserver) {
2435
+ selectObserver.disconnect();
2436
+ module.verbose('Temporarily disconnecting mutation observer', value);
2437
+ }
2438
+ $option.remove();
2439
+ module.verbose('Removing user addition as an <option>', value);
2440
+ if(selectObserver) {
2441
+ selectObserver.observe($input[0], {
2442
+ childList : true,
2443
+ subtree : true
2444
+ });
2445
+ }
2446
+ },
2410
2447
  message: function() {
2411
2448
  $menu.children(selector.message).remove();
2412
2449
  },
@@ -2460,16 +2497,16 @@ $.fn.dropdown = function(parameters) {
2460
2497
  },
2461
2498
  value: function(removedValue, removedText, $removedItem) {
2462
2499
  var
2463
- values = $input.val(),
2500
+ values = module.get.values(),
2464
2501
  newValue
2465
2502
  ;
2466
- if( $input.is('select') ) {
2503
+ if( module.has.selectInput() ) {
2467
2504
  module.verbose('Input is <select> removing selected option', removedValue);
2468
2505
  newValue = module.remove.arrayValue(removedValue, values);
2506
+ module.remove.optionValue(removedValue);
2469
2507
  }
2470
2508
  else {
2471
2509
  module.verbose('Removing from delimited values', removedValue);
2472
- values = values.split(settings.delimiter);
2473
2510
  newValue = module.remove.arrayValue(removedValue, values);
2474
2511
  newValue = newValue.join(settings.delimiter);
2475
2512
  }
@@ -2483,6 +2520,9 @@ $.fn.dropdown = function(parameters) {
2483
2520
  module.check.maxSelections();
2484
2521
  },
2485
2522
  arrayValue: function(removedValue, values) {
2523
+ if( !$.isArray(values) ) {
2524
+ values = [values];
2525
+ }
2486
2526
  values = $.grep(values, function(value){
2487
2527
  return (removedValue != value);
2488
2528
  });
@@ -2561,6 +2601,9 @@ $.fn.dropdown = function(parameters) {
2561
2601
  search: function() {
2562
2602
  return ($search.length > 0);
2563
2603
  },
2604
+ selectInput: function() {
2605
+ return ( $input.is('select') );
2606
+ },
2564
2607
  firstLetter: function($item, letter) {
2565
2608
  var
2566
2609
  text,
@@ -2714,7 +2757,7 @@ $.fn.dropdown = function(parameters) {
2714
2757
  return $module.hasClass(className.search);
2715
2758
  },
2716
2759
  searchSelection: function() {
2717
- return ( module.has.search() && $search.closest(selector.menu).length === 0 );
2760
+ return ( module.has.search() && $search.parent(selector.dropdown).length === 1 );
2718
2761
  },
2719
2762
  selection: function() {
2720
2763
  return $module.hasClass(className.selection);
@@ -2738,6 +2781,9 @@ $.fn.dropdown = function(parameters) {
2738
2781
  click: function() {
2739
2782
  return (hasTouch || settings.on == 'click');
2740
2783
  },
2784
+ extendSelect: function() {
2785
+ return settings.allowAdditions || settings.apiSettings;
2786
+ },
2741
2787
  show: function() {
2742
2788
  return !module.is.disabled() && (module.has.items() || module.has.message());
2743
2789
  },
@@ -3141,13 +3187,14 @@ $.fn.dropdown.settings = {
3141
3187
  },
3142
3188
 
3143
3189
  error : {
3144
- action : 'You called a dropdown action that was not defined',
3145
- alreadySetup : 'Once a select has been initialized behaviors must be called on the created ui dropdown',
3146
- labels : 'Allowing user additions currently requires the use of labels.',
3147
- method : 'The method you called is not defined.',
3148
- noAPI : 'The API module is required to load resources remotely',
3149
- noStorage : 'Saving remote data requires session storage',
3150
- noTransition : 'This module requires ui transitions <https://github.com/Semantic-Org/UI-Transition>'
3190
+ action : 'You called a dropdown action that was not defined',
3191
+ alreadySetup : 'Once a select has been initialized behaviors must be called on the created ui dropdown',
3192
+ labels : 'Allowing user additions currently requires the use of labels.',
3193
+ missingMultiple : '<select> requires multiple property to be set to correctly preserve multiple values',
3194
+ method : 'The method you called is not defined.',
3195
+ noAPI : 'The API module is required to load resources remotely',
3196
+ noStorage : 'Saving remote data requires session storage',
3197
+ noTransition : 'This module requires ui transitions <https://github.com/Semantic-Org/UI-Transition>'
3151
3198
  },
3152
3199
 
3153
3200
  regExp : {
@@ -408,10 +408,8 @@ $.fn.modal = function(parameters) {
408
408
  hideDimmer: function() {
409
409
  if( $dimmable.dimmer('is animating') || ($dimmable.dimmer('is active')) ) {
410
410
  $dimmable.dimmer('hide', function() {
411
- if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
412
- module.remove.clickaway();
413
- module.remove.screenHeight();
414
- }
411
+ module.remove.clickaway();
412
+ module.remove.screenHeight();
415
413
  });
416
414
  }
417
415
  else {
@@ -497,14 +495,18 @@ $.fn.modal = function(parameters) {
497
495
  ;
498
496
  }
499
497
  },
500
- screenHeight: function() {
501
- if(module.cache.height > module.cache.pageHeight) {
502
- module.debug('Removing page height');
503
- $body
504
- .css('height', '')
505
- ;
498
+ bodyStyle: function() {
499
+ if($body.attr('style') === '') {
500
+ module.verbose('Removing style attribute');
501
+ $body.removeAttr('style');
506
502
  }
507
503
  },
504
+ screenHeight: function() {
505
+ module.debug('Removing page height');
506
+ $body
507
+ .css('height', '')
508
+ ;
509
+ },
508
510
  keyboardShortcuts: function() {
509
511
  module.verbose('Removing keyboard shortcuts');
510
512
  $document
@@ -120,7 +120,7 @@ $.fn.popup = function(parameters) {
120
120
  : $body
121
121
  ;
122
122
  }
123
- if( $offsetParent.is('html') ) {
123
+ if( $offsetParent.is('html') && $offsetParent[0] !== $body[0] ) {
124
124
  module.debug('Setting page as offset parent');
125
125
  $offsetParent = $body;
126
126
  }
@@ -441,6 +441,9 @@ $.fn.popup = function(parameters) {
441
441
  $module.removeData(metadata.variation);
442
442
  return $module.data(metadata.variation) || settings.variation;
443
443
  },
444
+ popupOffset: function() {
445
+ return $popup.offset();
446
+ },
444
447
  calculations: function() {
445
448
  var
446
449
  targetElement = $target[0],
@@ -481,6 +484,14 @@ $.fn.popup = function(parameters) {
481
484
  }
482
485
  };
483
486
 
487
+ // add in container calcs if fluid
488
+ if( settings.setFluidWidth && module.is.fluid() ) {
489
+ calculations.container = {
490
+ width: $popup.parent().outerWidth()
491
+ };
492
+ calculations.popup.width = calculations.container.width;
493
+ }
494
+
484
495
  // add in margins if inline
485
496
  calculations.target.margin.top = (settings.inline)
486
497
  ? parseInt( window.getComputedStyle(targetElement).getPropertyValue('margin-top'), 10)
@@ -526,6 +537,30 @@ $.fn.popup = function(parameters) {
526
537
  }
527
538
  return false;
528
539
  },
540
+ distanceFromBoundary: function(offset, calculations) {
541
+ var
542
+ distanceFromBoundary = {},
543
+ popup,
544
+ boundary
545
+ ;
546
+ offset = offset || module.get.offset();
547
+ calculations = calculations || module.get.calculations();
548
+
549
+ // shorthand
550
+ popup = calculations.popup;
551
+ boundary = calculations.boundary;
552
+
553
+ if(offset) {
554
+ distanceFromBoundary = {
555
+ top : (offset.top - boundary.top),
556
+ left : (offset.left - boundary.left),
557
+ right : (boundary.right - (offset.left + popup.width) ),
558
+ bottom : (boundary.bottom - (offset.top + popup.height) )
559
+ };
560
+ module.verbose('Distance from boundaries determined', offset, distanceFromBoundary);
561
+ }
562
+ return distanceFromBoundary;
563
+ },
529
564
  offsetParent: function($target) {
530
565
  var
531
566
  element = ($target !== undefined)
@@ -553,40 +588,6 @@ $.fn.popup = function(parameters) {
553
588
  : $()
554
589
  ;
555
590
  },
556
- offstagePosition: function(position, calculations) {
557
- var
558
- offset = $popup.offset(),
559
- offstage = {},
560
- offstagePositions = [],
561
- popup,
562
- boundary
563
- ;
564
- position = position || false;
565
- calculations = calculations || module.get.calculations();
566
- // shorthand
567
- popup = calculations.popup;
568
- boundary = calculations.boundary;
569
-
570
- if(offset && position) {
571
- offstage = {
572
- top : (offset.top < boundary.top),
573
- bottom : (offset.top + popup.height > boundary.bottom),
574
- right : (offset.left + popup.width > boundary.right),
575
- left : (offset.left < boundary.left)
576
- };
577
- module.verbose('Offstage positions determined', offset, offstage);
578
- }
579
- // return only boundaries that have been surpassed
580
- $.each(offstage, function(direction, isOffstage) {
581
- if(isOffstage) {
582
- offstagePositions.push(direction);
583
- }
584
- });
585
- return (offstagePositions.length > 0)
586
- ? offstagePositions.join(' ')
587
- : false
588
- ;
589
- },
590
591
  positions: function() {
591
592
  return {
592
593
  'top left' : false,
@@ -672,10 +673,11 @@ $.fn.popup = function(parameters) {
672
673
  target,
673
674
  popup,
674
675
  parent,
675
- computedPosition,
676
676
  positioning,
677
- offstagePosition
677
+ popupOffset,
678
+ distanceFromBoundary
678
679
  ;
680
+
679
681
  calculations = calculations || module.get.calculations();
680
682
  position = position || $module.data(metadata.position) || settings.position;
681
683
 
@@ -720,8 +722,8 @@ $.fn.popup = function(parameters) {
720
722
  module.debug('RTL: Popup position updated', position);
721
723
  }
722
724
 
723
- if(searchDepth == settings.maxSearchDepth && settings.lastResort) {
724
- module.debug('Using "last resort" position to display', settings.lastResort);
725
+ // if last attempt use specified last resort position
726
+ if(searchDepth == settings.maxSearchDepth && typeof settings.lastResort === 'string') {
725
727
  position = settings.lastResort;
726
728
  }
727
729
 
@@ -804,12 +806,14 @@ $.fn.popup = function(parameters) {
804
806
  .addClass(position)
805
807
  .addClass(className.loading)
806
808
  ;
807
- // check if is offstage
808
- offstagePosition = module.get.offstagePosition(position, calculations);
809
809
 
810
- // recursively find new positioning
811
- if(offstagePosition) {
812
- module.debug('Popup cant fit into viewport', position, offstagePosition);
810
+ popupOffset = module.get.popupOffset();
811
+
812
+ // see if any boundaries are surpassed with this tentative position
813
+ distanceFromBoundary = module.get.distanceFromBoundary(popupOffset, calculations);
814
+
815
+ if( module.is.offstage(distanceFromBoundary, position) ) {
816
+ module.debug('Position is outside viewport', position);
813
817
  if(searchDepth < settings.maxSearchDepth) {
814
818
  searchDepth++;
815
819
  position = module.get.nextPosition(position);
@@ -819,28 +823,33 @@ $.fn.popup = function(parameters) {
819
823
  : false
820
824
  ;
821
825
  }
822
- else if(!settings.lastResort) {
823
- module.debug('Popup could not find a position in view', $popup);
824
- // module.error(error.cannotPlace, element);
825
- module.remove.attempts();
826
- module.remove.loading();
827
- module.reset();
828
- return false;
826
+ else {
827
+ if(settings.lastResort) {
828
+ module.debug('No position found, showing with last position');
829
+ }
830
+ else {
831
+ module.debug('Popup could not find a position to display', $popup);
832
+ module.error(error.cannotPlace, element);
833
+ module.remove.attempts();
834
+ module.remove.loading();
835
+ module.reset();
836
+ return false;
837
+ }
829
838
  }
830
839
  }
831
-
832
840
  module.debug('Position is on stage', position);
833
841
  module.remove.attempts();
834
- module.set.fluidWidth(calculations);
835
842
  module.remove.loading();
843
+ if( settings.setFluidWidth && module.is.fluid() ) {
844
+ module.set.fluidWidth(calculations);
845
+ }
836
846
  return true;
837
847
  },
838
848
 
839
849
  fluidWidth: function(calculations) {
840
850
  calculations = calculations || module.get.calculations();
841
- if( settings.setFluidWidth && $popup.hasClass(className.fluid) ) {
842
- $popup.css('width', calculations.parent.width);
843
- }
851
+ module.debug('Automatically setting element width to parent width', calculations.parent.width);
852
+ $popup.css('width', calculations.container.width);
844
853
  },
845
854
 
846
855
  visible: function() {
@@ -957,12 +966,33 @@ $.fn.popup = function(parameters) {
957
966
  },
958
967
 
959
968
  is: {
969
+ offstage: function(distanceFromBoundary, position) {
970
+ var
971
+ offstage = []
972
+ ;
973
+ // return boundaries that have been surpassed
974
+ $.each(distanceFromBoundary, function(direction, distance) {
975
+ if(distance < -settings.jitter) {
976
+ module.debug('Position exceeds allowable distance from edge', direction, distance, position);
977
+ offstage.push(direction);
978
+ }
979
+ });
980
+ if(offstage.length > 0) {
981
+ return true;
982
+ }
983
+ else {
984
+ return false;
985
+ }
986
+ },
960
987
  active: function() {
961
988
  return $module.hasClass(className.active);
962
989
  },
963
990
  animating: function() {
964
991
  return ( $popup && $popup.hasClass(className.animating) );
965
992
  },
993
+ fluid: function() {
994
+ return ( $popup && $popup.hasClass(className.fluid));
995
+ },
966
996
  visible: function() {
967
997
  return $popup && $popup.hasClass(className.visible);
968
998
  },
@@ -1219,7 +1249,7 @@ $.fn.popup.settings = {
1219
1249
  inline : false,
1220
1250
 
1221
1251
  // popup should be removed from page on hide
1222
- preserve : true,
1252
+ preserve : false,
1223
1253
 
1224
1254
  // popup should not close when being hovered on
1225
1255
  hoverable : false,
@@ -1267,15 +1297,18 @@ $.fn.popup.settings = {
1267
1297
  // distance away from activating element in px
1268
1298
  distanceAway : 0,
1269
1299
 
1300
+ // number of pixels an element is allowed to be "offstage" for a position to be chosen (allows for rounding)
1301
+ jitter : 2,
1302
+
1270
1303
  // offset on aligning axis from calculated position
1271
1304
  offset : 0,
1272
1305
 
1273
1306
  // maximum times to look for a position before failing (9 positions total)
1274
- maxSearchDepth : 20,
1307
+ maxSearchDepth : 15,
1275
1308
 
1276
1309
  error: {
1277
1310
  invalidPosition : 'The position you specified is not a valid position',
1278
- cannotPlace : 'No visible position could be found for the popup',
1311
+ cannotPlace : 'Popup does not fit within the boundaries of the viewport',
1279
1312
  method : 'The method you called is not defined.',
1280
1313
  noTransition : 'This module requires ui transitions <https://github.com/Semantic-Org/UI-Transition>',
1281
1314
  notFound : 'The target or popup you specified does not exist on the page'