hooch 0.3.0 → 0.4.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/hooch.js +395 -1
  3. data/jasmine/jasmine-fixture.js +433 -0
  4. data/jasmine/node_modules/karma-chrome-launcher/CHANGELOG.md +108 -0
  5. data/jasmine/node_modules/karma-chrome-launcher/LICENSE +20 -0
  6. data/jasmine/node_modules/karma-chrome-launcher/README.md +49 -0
  7. data/jasmine/node_modules/karma-chrome-launcher/examples/simple/index.spec.js +5 -0
  8. data/jasmine/node_modules/karma-chrome-launcher/examples/simple/karma.conf.js +32 -0
  9. data/jasmine/node_modules/karma-chrome-launcher/gruntfile.js +63 -0
  10. data/jasmine/node_modules/karma-chrome-launcher/index.js +181 -0
  11. data/jasmine/node_modules/karma-chrome-launcher/node_modules/.bin/which +14 -0
  12. data/jasmine/node_modules/karma-chrome-launcher/node_modules/fs-access/index.js +41 -0
  13. data/jasmine/node_modules/karma-chrome-launcher/node_modules/fs-access/license +21 -0
  14. data/jasmine/node_modules/karma-chrome-launcher/node_modules/fs-access/node_modules/null-check/index.js +19 -0
  15. data/jasmine/node_modules/karma-chrome-launcher/node_modules/fs-access/node_modules/null-check/license +21 -0
  16. data/jasmine/node_modules/karma-chrome-launcher/node_modules/fs-access/node_modules/null-check/package.json +65 -0
  17. data/jasmine/node_modules/karma-chrome-launcher/node_modules/fs-access/node_modules/null-check/readme.md +34 -0
  18. data/jasmine/node_modules/karma-chrome-launcher/node_modules/fs-access/package.json +71 -0
  19. data/jasmine/node_modules/karma-chrome-launcher/node_modules/fs-access/readme.md +53 -0
  20. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/.travis.yml +8 -0
  21. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/LICENSE +15 -0
  22. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/README.md +34 -0
  23. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/bin/which +14 -0
  24. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/node_modules/is-absolute/LICENSE +21 -0
  25. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/node_modules/is-absolute/README.md +53 -0
  26. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/node_modules/is-absolute/index.js +27 -0
  27. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/node_modules/is-absolute/node_modules/is-relative/LICENSE-MIT +21 -0
  28. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/node_modules/is-absolute/node_modules/is-relative/README.md +38 -0
  29. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/node_modules/is-absolute/node_modules/is-relative/index.js +21 -0
  30. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/node_modules/is-absolute/node_modules/is-relative/package.json +75 -0
  31. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/node_modules/is-absolute/package.json +75 -0
  32. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/package.json +56 -0
  33. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/test/basic.js +99 -0
  34. data/jasmine/node_modules/karma-chrome-launcher/node_modules/which/which.js +111 -0
  35. data/jasmine/node_modules/karma-chrome-launcher/package.json +142 -0
  36. data/jasmine/node_modules/karma-chrome-launcher/test/jsflags.spec.js +53 -0
  37. data/jasmine/spec/hoochSpec.js +66 -0
  38. data/lib/hooch/version.rb +1 -1
  39. metadata +37 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 075938e121455aeb850d8794770df4c194edb6fe
4
- data.tar.gz: 690ab05a9d8a2ba37d3fbf3425790b3e36750f3c
3
+ metadata.gz: 843365c8223492ada4139655788204be1eb66f92
4
+ data.tar.gz: abe4e60a98085d46d3ce61ff963ffefc9a63ca25
5
5
  SHA512:
6
- metadata.gz: cce71ebf2f5b2b04213c0ed762360fde8e1f759d1375aaf5c4ad6a0bda28cd931c6b8f2e87d76acf5e45a9bf82f6bb7e34dee14c3dad65cc5f8de139fef33b1e
7
- data.tar.gz: 800b30b97ee0b5173243c0034ccaa0fc312ffd26009982a34c91cbe73ebdddbd09bbd70fc97641d17ac0a4c205d51fc906cb33229207993542ffe26bb5639662
6
+ metadata.gz: 455c26c52f1d3120ecfa8089ce23cbda9df48016316550f3cb2520c7289b2aa0979d2afd8fb8905de2c960a14b9de56147b2185f853b49481966eb9d321b7604
7
+ data.tar.gz: c017a3036d9a74516d4def1f3a6d84d975fd92d5e5b2b25683887714aa904efc9238002edcf6e0c79674fc36d9b4458f1dfd8309b86aa3b696609ac54e34db74
@@ -588,8 +588,395 @@ var initHooch = function(){
588
588
  $fake_select.select(fake_option)
589
589
  })
590
590
  }
591
+ }),
592
+ Sorter: Class.extend({
593
+ init: function($sorter){
594
+ this.$sorter = $sorter;
595
+ this.width = $sorter.width();
596
+ this.getSortElements();
597
+ var sorter = this
598
+ $(window).on('mouseup', function(e){
599
+ sorter.onMouseup();
600
+ });
601
+ $(window).on('mousemove', function(e){
602
+ sorter.onMousemove(e)
603
+ })
604
+ },
605
+ onMousemove: function(e){
606
+ if(this.dragging_element){
607
+ hooch.pauseEvent(e)
608
+ this.redrawDraggingElement(e);
609
+ this.refreshSequence(e)
610
+ return false
611
+ }
612
+ },
613
+ getSortElements: function(){
614
+ this.$sort_elements = this.$sorter.children()
615
+ this.sort_elements = []
616
+ var sorter = this;
617
+ this.$sort_elements.each(function(){
618
+ var sort_element = new hooch.SortElement($(this),sorter)
619
+ sorter.sort_elements.push(sort_element)
620
+ })
621
+ this.row_height = this.sort_elements[0].height;
622
+ var elem_widths = this.sort_elements.map(function(sort_element,i,arr){return sort_element.width})
623
+ this.min_elem_width = Math.min.apply(null,elem_widths);
624
+ this.refreshGrid();
625
+ if((this.min_elem_width * 2) <= this.width){
626
+ this.mode = 'Grid'
627
+ } else {
628
+ this.mode = 'Vertical'
629
+ }
630
+ },
631
+ refreshGrid: function(){
632
+ this.rows = {}
633
+ var sorter = this
634
+ $.each(this.sort_elements,function(i,sort_element){
635
+ if(sort_element != sorter.dragging_element){
636
+ this_element = sort_element
637
+ } else {
638
+ this_element = sort_element.placeholder
639
+ }
640
+ var elem_top = this_element.getOffset().top;
641
+ if(!sorter.rows[elem_top]){
642
+ sorter.rows[elem_top] = []
643
+ }
644
+ sorter.rows[elem_top].push(this_element)
645
+ })
646
+ this.row_keys = Object.keys(this.rows).map(function(val,i){return parseInt(val)}).sort(sorter.numberSort)
647
+ $.each(this.rows, function(row_key,row){row.sort(sorter.elementHorizontalSort)})
648
+ },
649
+ redrawDraggingElement: function(e){
650
+ this.dragging_element.setPosition(e);
651
+ },
652
+ refreshSequence: function(){
653
+ var target_location = this.dragging_element.getCenter()
654
+ var refresh_method = this['refreshSequence' + this.mode]
655
+ refresh_method.call(this, target_location)
656
+ },
657
+ refreshSequenceGrid: function(target_location){
658
+ var dragging_element = this.dragging_element
659
+ if(!this.withinCurrentRow(target_location.y)){
660
+ this.seekCurrentRow(target_location)
661
+ }
662
+ if('end' == this.current_row_key){
663
+ var last_element = this.getLastElement();
664
+ if(!last_element.is_placeholder){
665
+ last_element.$sort_element.after(dragging_element.placeholder.$sort_element)
666
+ this.refreshGrid()
667
+ }
668
+ } else if('begin' == this.current_row_key){
669
+ var first_element = this.getFirstElement();
670
+ if(!first_element.is_placeholder){
671
+ first_element.$sort_element.before(dragging_element.placeholder.$sort_element)
672
+ this.refreshGrid()
673
+ }
674
+ } else {
675
+ var hovered_element = this.getHoveredElementHorizontal(target_location);
676
+ if(hovered_element){
677
+ if('leftmost' == hovered_element){
678
+ var leftmost_element = this.current_row[0]
679
+ leftmost_element.$sort_element.before(dragging_element.placeholder.$sort_element)
680
+ this.refreshGrid()
681
+ } else {
682
+ hovered_element.$sort_element.after(dragging_element.placeholder.$sort_element);
683
+ this.refreshGrid()
684
+ }
685
+ }
686
+ }
687
+ },
688
+ refreshSequenceVertical: function(target_location){
689
+ var dragging_element = this.dragging_element
690
+ var hovered_element = this.getHoveredElementVertical(target_location)
691
+
692
+ if(hovered_element){
693
+ if('first' == hovered_element){
694
+ var first_key = this.row_keys[0]
695
+ var first_element = this.rows[first_key][0]
696
+ first_element.$sort_element.before(dragging_element.placeholder.$sort_element)
697
+ this.refreshGrid()
698
+ } else {
699
+ hovered_element.$sort_element.after(dragging_element.placeholder.$sort_element)
700
+ this.refreshGrid()
701
+ }
702
+ }
703
+ },
704
+ rowAfter: function(row){
705
+ return this.row_keys[this.row_keys.indexOf[row] + 1]
706
+ },
707
+ elemAfter: function(row, elem){
708
+ return row[row.indexOf(elem) + 1]
709
+ },
710
+ seekCurrentRow: function(target_location){
711
+ var sorter = this
712
+ var row_key = $.grep(this.row_keys,function(rowY,i){
713
+ var nextRowY = sorter.rowAfter(rowY)
714
+ var below_top_edge = target_location.y >= rowY
715
+ if(nextRowY){
716
+ var above_bottom_edge = target_location.y < nextRowY
717
+ } else {
718
+ var above_bottom_edge = target_location.y < (rowY + sorter.row_height)
719
+ }
720
+ return (below_top_edge && above_bottom_edge)
721
+ })[0]
722
+ if(row_key){
723
+ this.current_row_key = row_key;
724
+ this.current_row = this.rows[row_key];
725
+ } else if(target_location.y > this.rows[Math.max.apply(null,this.row_keys)][0].getOffset().top) {
726
+ this.current_row_key = 'end';
727
+ this.current_row = undefined;
728
+ } else {
729
+ this.current_row_key = 'begin';
730
+ this.current_row = undefined;
731
+ }
732
+ },
733
+ getHoveredElementHorizontal: function(target_location){
734
+ var current_element = false;
735
+ var sorter = this
736
+ current_element = $.grep(this.current_row, function(sort_element,i){
737
+ if(!sort_element.is_placeholder){
738
+ var elem_center = sort_element.getCenter();
739
+ var slot_left = elem_center.x;
740
+ var past_left_edge = target_location.x >= slot_left
741
+
742
+ var next_elem = sorter.elemAfter(sorter.current_row, sort_element)
743
+ var before_right_edge
744
+ if(next_elem){
745
+ if(!next_elem.is_placeholder){
746
+ var next_elem_center = next_elem.getCenter();
747
+ before_right_edge = target_location.x < next_elem_center.x
748
+ }
749
+ } else {
750
+ before_right_edge = past_left_edge
751
+ }
752
+ return (past_left_edge && before_right_edge)
753
+ }
754
+ return false
755
+ })[0]
756
+ if(current_element){
757
+ return current_element
758
+ } else {
759
+ var first_elem = this.current_row[0]
760
+ if(first_elem && !first_elem.is_placeholder && first_elem.getCenter().x > target_location.x){
761
+ return 'leftmost'
762
+ }
763
+ }
764
+ },
765
+ getHoveredElementVertical: function(target_location){
766
+ var sorter = this
767
+ current_element_key = $.grep(sorter.row_keys, function(row_key,i){
768
+ var this_elem = sorter.rows[row_key][0]
769
+ if(!this_elem.is_placeholder){
770
+ var elem_center = this_elem.getCenter()
771
+ var slot_top = elem_center.y
772
+ var below_top_edge = target_location.y >= slot_top
773
+ var next_row = sorter.rows[sorter.row_keys[i+1]]
774
+ var above_bottom_edge
775
+ var next_elem
776
+ if(next_row){
777
+ next_elem = next_row[0]
778
+ if(next_elem && !next_elem.is_placeholder){
779
+ var next_elem_center = next_elem.getCenter()
780
+ above_bottom_edge = target_location.y < next_elem_center.y
781
+ }
782
+ }
783
+ if(!next_elem){
784
+ above_bottom_edge = below_top_edge
785
+ }
786
+ return(below_top_edge && above_bottom_edge)
787
+ }
788
+ return false
789
+ })[0]
790
+ if(current_element_key){
791
+ return this.rows[current_element_key][0]
792
+ } else {
793
+ var first_key = this.row_keys[0]
794
+ var first_elem = this.rows[first_key][0]
795
+ if(first_elem && !first_elem.is_placeholder && first_elem.getCenter().y > target_location.y){
796
+ return 'first'
797
+ }
798
+ }
799
+ },
800
+ getLastElement: function(){
801
+ var last_row_key = this.row_keys[this.row_keys.length-1]
802
+ var last_row = this.rows[last_row_key];
803
+ return last_row[last_row.length-1]
804
+ },
805
+ getFirstElement: function(){
806
+ var first_row_key = this.row_keys[0]
807
+ var first_row = this.rows[first_row_key]
808
+ return first_row[0]
809
+ },
810
+ elementHorizontalSort: function(a,b){
811
+ if(a.getOffset().left < b.getOffset().left){
812
+ return -1
813
+ }
814
+ if(b.getOffset().left < a.getOffset().left){
815
+ return 1
816
+ }
817
+ return 0
818
+ },
819
+ numberSort: function(a,b){
820
+ if(parseInt(a) < parseInt(b)){return -1}
821
+ if(parseInt(b) < parseInt(a)){return 1}
822
+ return 0
823
+ },
824
+ withinCurrentRow: function(y_value){
825
+ if(this.current_row_key){
826
+ var top_edge = this.current_row_key
827
+ var bottom_edge = top_edge + this.row_height;
828
+ var in_current_row = (top_edge < y_value) && (y_value < bottom_edge)
829
+ if(in_current_row){
830
+ this.current_row = this.rows[this.current_row_key]
831
+ }
832
+ return in_current_row
833
+ }
834
+ return false
835
+ },
836
+ setDraggingElement: function(sort_element){
837
+ this.dragging_element = sort_element;
838
+ var current_row = this.rows[this.dragging_element.starting_offset.top]
839
+ drag_index = current_row.indexOf(sort_element)
840
+ if(drag_index > -1){
841
+ current_row.splice(drag_index, 1)
842
+ }
843
+ current_row.push(this.dragging_element.placeholder)
844
+ this.refreshGrid();
845
+ },
846
+ clearDraggingElement: function(){
847
+ if(this.dragging_element){
848
+ this.removeDraggingElement()
849
+ }
850
+ },
851
+ onMouseup: function(){
852
+ this.removeDraggingElement()
853
+ this.sendSort()
854
+ },
855
+ removeDraggingElement: function(){
856
+ if(this.dragging_element){
857
+ var placeholder_row = this.removePlaceholder()
858
+ this.rows[placeholder_row].push(this.dragging_element)
859
+ this.dragging_element.drop()
860
+ this.dragging_element = undefined;
861
+ this.refreshGrid();
862
+ }
863
+ },
864
+ sendSort: function(){
865
+ $.ajax({
866
+ url: this.$sorter.attr('href'),
867
+ method: 'PATCH',
868
+ data: this.getFormData()
869
+ })
870
+ },
871
+ getFormData: function(){
872
+ var id_array = $.map(this.$sorter.children(),function(e,i){return $(e).attr('id')})
873
+ var first_id = id_array[0]
874
+ var last_underscore_location = first_id.lastIndexOf('_')
875
+ var array_name = first_id.slice(0,last_underscore_location)
876
+ var form_data = {}
877
+ form_data[array_name] = id_array.map(function(id){
878
+ return id.slice((last_underscore_location + 1))
879
+ })
880
+ return form_data
881
+ },
882
+ removePlaceholder: function(){
883
+ var sorter = this
884
+ return $.grep(this.row_keys, function(row_key,i){
885
+ var placeholder_index = sorter.rows[row_key].indexOf(sorter.dragging_element.placeholder)
886
+ if(placeholder_index > -1){
887
+ sorter.rows[row_key].slice(placeholder_index,1)
888
+ return true
889
+ }
890
+ return false
891
+ })[0]
892
+ }
893
+ }),
894
+ SortElement: Class.extend({
895
+ init: function($sort_element,sorter){
896
+ this.sorter = sorter;
897
+ this.$sort_element = $sort_element;
898
+ this.old_position = $sort_element.css('position')
899
+ this.width = this.$sort_element.width()
900
+ this.height = this.$sort_element.height()
901
+ var sort_element = this
902
+ this.$sort_element.on('dragstart', function(e){
903
+ hooch.pauseEvent(e)
904
+ return false
905
+ })
906
+ this.$sort_element.on('mousedown', $.proxy(sort_element.onMousedown, sort_element))
907
+ },
908
+ onMousedown: function(e){
909
+ if(1 == e.which){
910
+ this.sorter.clearDraggingElement();
911
+ hooch.pauseEvent(e)
912
+ this.starting_offset = this.getOffset();
913
+ this.mouse_start = {top: e.originalEvent.pageY, left: e.originalEvent.pageX}
914
+ this.placeholder = new hooch.SortPlaceholder(this.$sort_element.clone().removeAttr('id').css({width: this.width, height: this.height}),this.sorter)
915
+ this.placeholder.css({'visibility': 'hidden'});
916
+ this.placeholder.css({background: 'none', 'background-color': 'pink'});
917
+ $tmp = $('<div style="display: none;"></div>')
918
+ this.$sort_element.before($tmp)
919
+ this.$sort_element
920
+ .css({position: 'absolute', top: this.starting_offset.top, left: this.starting_offset.left})
921
+ .appendTo('body')
922
+ $tmp.replaceWith(this.placeholder.$sort_element)
923
+ this.sorter.setDraggingElement(this,e);
924
+ return false;
925
+ }
926
+ },
927
+ drop: function(){
928
+ this.css({position: this.old_position, top: '', left: ''})
929
+ this.placeholder.replaceWith(this.$sort_element);
930
+ this.placeholder = undefined
931
+ },
932
+ getOffset: function(){
933
+ return this.$sort_element.offset();
934
+ },
935
+ setPosition: function(e){
936
+ var delta = this.getDelta(e)
937
+ var new_position = this.getNewPosition(delta);
938
+ this.$sort_element.css(new_position);
939
+ },
940
+ getDelta: function(e){
941
+ return {
942
+ top: (e.originalEvent.pageY - this.mouse_start.top),
943
+ left: (e.originalEvent.pageX - this.mouse_start.left)
944
+ }
945
+ },
946
+ getNewPosition: function(delta){
947
+ return {top: (this.starting_offset.top + delta.top), left: (this.starting_offset.left + delta.left)}
948
+ },
949
+ getCenter: function(){
950
+ var new_offset = this.getOffset()
951
+ var newX = new_offset.left
952
+ var newY = new_offset.top
953
+ var width = this.width
954
+ var height = this.height
955
+ var centerX = newX + (width / 2)
956
+ var centerY = newY + (height / 2)
957
+ var center = {x: centerX, y: centerY}
958
+ return center
959
+ },
960
+ clone: function(){
961
+ return this.$sort_element.clone();
962
+ },
963
+ css: function(css_obj){
964
+ this.$sort_element.css(css_obj);
965
+ },
966
+ replaceWith: function($jq_obj){
967
+ this.$sort_element.replaceWith($jq_obj)
968
+ }
591
969
  })
592
970
  };
971
+ hooch.SortPlaceholder = hooch.SortElement.extend({
972
+ init: function($sort_element,sorter){
973
+ this.sorter = sorter;
974
+ this.is_placeholder = true;
975
+ this.$sort_element = $sort_element;
976
+ this.width = this.$sort_element.width()
977
+ this.height = this.$sort_element.height()
978
+ }
979
+ })
593
980
  hooch.AjaxExpandable = hooch.Expandable.extend({
594
981
  expand: function(){
595
982
  if(!this.ajax_loaded){
@@ -703,9 +1090,16 @@ var initHooch = function(){
703
1090
  window.any_time_manager.registerList(
704
1091
  ['hover_overflow','hidey_button','submit-proxy','click-proxy','field-filler','revealer',
705
1092
  'checkbox-hidden-proxy','prevent-double-submit','prevent-double-link-click', 'tab-group',
706
- 'hover-reveal', 'emptier', 'remover', 'checkbox-proxy', 'fake-select', 'select-action-changer'],'hooch');
1093
+ 'hover-reveal', 'emptier', 'remover', 'checkbox-proxy', 'fake-select', 'select-action-changer',
1094
+ 'sorter'],'hooch');
707
1095
  window.any_time_manager.load();
708
1096
  };
1097
+ hooch.pauseEvent = function(e){
1098
+ if(e.stopPropagation) e.stopPropagation();
1099
+ if(e.preventDefault) e.preventDefault();
1100
+ e.cancelBubble=true;
1101
+ e.returnValue=false;
1102
+ }
709
1103
  $(document).ready(function(){
710
1104
  if(typeof window.any_time_manager === "undefined" && typeof window.loading_any_time_manager === "undefined"){
711
1105
  window.loading_any_time_manager = true;