hooch 0.4.1 → 0.4.2
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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/hooch.js +55 -20
- data/jasmine/spec/hoochSpec.js +24 -1
- data/lib/hooch/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4d67b1b958e3b12561ada28c23195172d87206bc
         | 
| 4 | 
            +
              data.tar.gz: 5ff5259338df3bde4f96b7a4885c4cf0eef681cf
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7c869362a248c2f485342e1c74ea027299a6baadd8b4078610bb35744d582175e126af33ef0b9984bfd22c048db269e5d1c95fb29806a3ebc78149515c7484b5
         | 
| 7 | 
            +
              data.tar.gz: d4322ea13fd7dac82374153df36799b3d649959967a7c0de09e9920340d258685eeeea515ba434b700a30ea8875d711d1dd1fde4f6e6b282514b6e6acd129c36
         | 
| @@ -604,11 +604,43 @@ var initHooch = function(){ | |
| 604 604 | 
             
                  },
         | 
| 605 605 | 
             
                  onMousemove: function(e){
         | 
| 606 606 | 
             
                    if(this.dragging_element){
         | 
| 607 | 
            -
                       | 
| 608 | 
            -
             | 
| 609 | 
            -
                      this. | 
| 610 | 
            -
                       | 
| 607 | 
            +
                      this.handleMouseMove(e)
         | 
| 608 | 
            +
                    } else {
         | 
| 609 | 
            +
                      var pressed_element = this.getPressedElement()
         | 
| 610 | 
            +
                      if(pressed_element){
         | 
| 611 | 
            +
                        pressed_element.setDragging()
         | 
| 612 | 
            +
                        this.handleMouseMove(e)
         | 
| 613 | 
            +
                      }
         | 
| 614 | 
            +
                    }
         | 
| 615 | 
            +
                    return true
         | 
| 616 | 
            +
                  },
         | 
| 617 | 
            +
                  handleMouseMove: function(e){
         | 
| 618 | 
            +
                    hooch.pauseEvent(e)
         | 
| 619 | 
            +
                    this.dragging_element.dragging = true
         | 
| 620 | 
            +
                    this.redrawDraggingElement(e);
         | 
| 621 | 
            +
                    this.refreshSequence(e)
         | 
| 622 | 
            +
                    return false
         | 
| 623 | 
            +
                  },
         | 
| 624 | 
            +
                  onMouseup: function(){
         | 
| 625 | 
            +
                    if(this.dragging_element){
         | 
| 626 | 
            +
                      var tmp_dragging_element = this.dragging_element
         | 
| 627 | 
            +
                      this.removeDraggingElement()
         | 
| 628 | 
            +
                      if(tmp_dragging_element.dragging){
         | 
| 629 | 
            +
                        this.sendSort()
         | 
| 630 | 
            +
                      }
         | 
| 631 | 
            +
                      tmp_dragging_element.dragging = false
         | 
| 632 | 
            +
                    }
         | 
| 633 | 
            +
                    var pressed_element = this.getPressedElement()
         | 
| 634 | 
            +
                    if(pressed_element){
         | 
| 635 | 
            +
                      pressed_element.unSetPressed()
         | 
| 636 | 
            +
                    }
         | 
| 637 | 
            +
                  },
         | 
| 638 | 
            +
                  getPressedElement: function(){
         | 
| 639 | 
            +
                    var possible_pressed_element = $.grep(this.sort_elements, function(sort_element,i){return sort_element.pressed})
         | 
| 640 | 
            +
                    if(possible_pressed_element.length > 0){
         | 
| 641 | 
            +
                      return possible_pressed_element[0]
         | 
| 611 642 | 
             
                    }
         | 
| 643 | 
            +
                    return false
         | 
| 612 644 | 
             
                  },
         | 
| 613 645 | 
             
                  getSortElements: function(){
         | 
| 614 646 | 
             
                    this.$sort_elements = this.$sorter.children()
         | 
| @@ -848,10 +880,6 @@ var initHooch = function(){ | |
| 848 880 | 
             
                      this.removeDraggingElement()
         | 
| 849 881 | 
             
                    }
         | 
| 850 882 | 
             
                  },
         | 
| 851 | 
            -
                  onMouseup: function(){
         | 
| 852 | 
            -
                    this.removeDraggingElement()
         | 
| 853 | 
            -
                    this.sendSort()
         | 
| 854 | 
            -
                  },
         | 
| 855 883 | 
             
                  removeDraggingElement: function(){
         | 
| 856 884 | 
             
                    if(this.dragging_element){
         | 
| 857 885 | 
             
                      var placeholder_row = this.removePlaceholder()
         | 
| @@ -901,6 +929,7 @@ var initHooch = function(){ | |
| 901 929 | 
             
                    this.old_position = $sort_element.css('position')
         | 
| 902 930 | 
             
                    this.width = this.$sort_element.width()
         | 
| 903 931 | 
             
                    this.height = this.$sort_element.height()
         | 
| 932 | 
            +
                    this.dragging = false
         | 
| 904 933 | 
             
                    var sort_element = this
         | 
| 905 934 | 
             
                    this.$sort_element.on('dragstart', function(e){
         | 
| 906 935 | 
             
                      hooch.pauseEvent(e)
         | 
| @@ -911,22 +940,28 @@ var initHooch = function(){ | |
| 911 940 | 
             
                  onMousedown: function(e){
         | 
| 912 941 | 
             
                    if(1 == e.which){
         | 
| 913 942 | 
             
                      this.sorter.clearDraggingElement();
         | 
| 914 | 
            -
                       | 
| 943 | 
            +
                      this.pressed = true
         | 
| 915 944 | 
             
                      this.starting_offset = this.getOffset();
         | 
| 916 945 | 
             
                      this.mouse_start = {top: e.originalEvent.pageY, left: e.originalEvent.pageX}
         | 
| 917 | 
            -
                      this.placeholder = new hooch.SortPlaceholder(this.$sort_element.clone().removeAttr('id').css({width: this.width, height: this.height}),this.sorter)
         | 
| 918 | 
            -
                      this.placeholder.css({'visibility': 'hidden'});
         | 
| 919 | 
            -
                      this.placeholder.css({background: 'none', 'background-color': 'pink'});
         | 
| 920 | 
            -
                      $tmp = $('<div style="display: none;"></div>')
         | 
| 921 | 
            -
                      this.$sort_element.before($tmp)
         | 
| 922 | 
            -
                      this.$sort_element
         | 
| 923 | 
            -
                        .css({position: 'absolute', top: this.starting_offset.top, left: this.starting_offset.left})
         | 
| 924 | 
            -
                        .appendTo('body')
         | 
| 925 | 
            -
                      $tmp.replaceWith(this.placeholder.$sort_element)
         | 
| 926 | 
            -
                      this.sorter.setDraggingElement(this,e);
         | 
| 927 | 
            -
                      return false;
         | 
| 928 946 | 
             
                    }
         | 
| 929 947 | 
             
                  },
         | 
| 948 | 
            +
                  unSetPressed: function(){
         | 
| 949 | 
            +
                    this.pressed = false
         | 
| 950 | 
            +
                  },
         | 
| 951 | 
            +
                  setDragging: function(){
         | 
| 952 | 
            +
                    this.sorter.clearDraggingElement();
         | 
| 953 | 
            +
                    this.unSetPressed()
         | 
| 954 | 
            +
                    this.placeholder = new hooch.SortPlaceholder(this.$sort_element.clone().removeAttr('id').css({width: this.width, height: this.height}),this.sorter)
         | 
| 955 | 
            +
                    this.placeholder.css({'visibility': 'hidden'});
         | 
| 956 | 
            +
                    this.placeholder.css({background: 'none', 'background-color': 'pink'});
         | 
| 957 | 
            +
                    $tmp = $('<div style="display: none;"></div>')
         | 
| 958 | 
            +
                    this.$sort_element.before($tmp)
         | 
| 959 | 
            +
                    this.$sort_element
         | 
| 960 | 
            +
                      .css({position: 'absolute', top: this.starting_offset.top, left: this.starting_offset.left})
         | 
| 961 | 
            +
                      .appendTo('body')
         | 
| 962 | 
            +
                    $tmp.replaceWith(this.placeholder.$sort_element)
         | 
| 963 | 
            +
                    this.sorter.setDraggingElement(this);
         | 
| 964 | 
            +
                  },
         | 
| 930 965 | 
             
                  drop: function(){
         | 
| 931 966 | 
             
                    this.css({position: this.old_position, top: '', left: ''})
         | 
| 932 967 | 
             
                    this.placeholder.replaceWith(this.$sort_element);
         | 
    
        data/jasmine/spec/hoochSpec.js
    CHANGED
    
    | @@ -134,10 +134,25 @@ describe("hooch", function() { | |
| 134 134 | 
             
                })
         | 
| 135 135 | 
             
                it('Handles mousedown on a sort element', function(){
         | 
| 136 136 | 
             
                  sort_elem_a.onMousedown({which: 1, originalEvent: {pageY: 10, pageX: 10}})
         | 
| 137 | 
            +
                  //Pressing the left mouse button on a sort element sets the mousestart position
         | 
| 138 | 
            +
                  expect(sort_elem_a.mouse_start.top).toEqual(10)
         | 
| 139 | 
            +
                  expect(sort_elem_a.mouse_start.left).toEqual(10)
         | 
| 140 | 
            +
                  //That initial press should also set the 'pressed' attribute
         | 
| 141 | 
            +
                  expect(sort_elem_a.pressed).toBe(true)
         | 
| 142 | 
            +
                  //There should be no dragging element for the sorter yet
         | 
| 143 | 
            +
                  expect(sorter.dragging_element).toBeUndefined()
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                })
         | 
| 146 | 
            +
                it('Handles the initial mousemove when dragging an element', function(){
         | 
| 147 | 
            +
                  sort_elem_a.onMousedown({which: 1, originalEvent: {pageY: 10, pageX: 10}})
         | 
| 148 | 
            +
                  sorter.onMousemove({originalEvent: {pageY: 10, pageX: 11}})
         | 
| 149 | 
            +
                  //Starting to move the mouse will unset the pressed flag so we don't try to initialize the movement again.
         | 
| 150 | 
            +
                  expect(sort_elem_a.pressed).toBe(false)
         | 
| 137 151 | 
             
                  //We set the dragging element for the sorter to be element 'a'
         | 
| 138 152 | 
             
                  expect(sorter.dragging_element.$sort_element.attr('id')).toEqual('a')
         | 
| 139 153 | 
             
                  //We created a placeholder for element a
         | 
| 140 154 | 
             
                  expect(sort_elem_a.placeholder.is_placeholder).toBe(true)
         | 
| 155 | 
            +
             | 
| 141 156 | 
             
                  var elem_before_b = sort_elem_b.$sort_element.prev()
         | 
| 142 157 | 
             
                  //The dom element for the placeholder had it's id removed to avoid duplication
         | 
| 143 158 | 
             
                  expect(elem_before_b.attr('id')).toBeUndefined()
         | 
| @@ -145,6 +160,7 @@ describe("hooch", function() { | |
| 145 160 | 
             
                  expect(elem_before_b.is(sort_elem_a.placeholder.$sort_element)).toBe(true)
         | 
| 146 161 | 
             
                  //The real element 'a' is now attached directly to the body
         | 
| 147 162 | 
             
                  expect(sort_elem_a.$sort_element.parent()[0].nodeName).toEqual('BODY')
         | 
| 163 | 
            +
             | 
| 148 164 | 
             
                })
         | 
| 149 165 | 
             
                it('Handles mousemove when dragging an element', function(){
         | 
| 150 166 | 
             
                  sort_elem_a.onMousedown({which: 1, originalEvent: {pageY: 10, pageX: 10}})
         | 
| @@ -165,11 +181,18 @@ describe("hooch", function() { | |
| 165 181 | 
             
                it('Handles dropping an element', function(){
         | 
| 166 182 | 
             
                  sort_elem_a.onMousedown({which: 1, originalEvent: {pageY: 10, pageX: 10}})
         | 
| 167 183 | 
             
                  sorter.onMousemove({originalEvent: {pageY: 210, pageX: 10}})
         | 
| 168 | 
            -
                  sorter. | 
| 184 | 
            +
                  sorter.onMouseup()
         | 
| 169 185 | 
             
                  last_elem = sorter.$sorter.children(':last')
         | 
| 170 186 | 
             
                  //Now the real element 'a' is in last place after being dragged below the sorter
         | 
| 171 187 | 
             
                  expect(sort_elem_a.$sort_element.is(last_elem)).toBe(true)
         | 
| 172 188 | 
             
                })
         | 
| 189 | 
            +
                it('Handles a click without a drag', function(){
         | 
| 190 | 
            +
                  sort_elem_a.onMousedown({which: 1, originalEvent: {pageY: 10, pageX: 10}})
         | 
| 191 | 
            +
                  sorter.onMouseup()
         | 
| 192 | 
            +
                  expect(sorter.dragging_element).toBeUndefined()
         | 
| 193 | 
            +
                  var pressed_element = sorter.getPressedElement()
         | 
| 194 | 
            +
                  expect(pressed_element).toBe(false)
         | 
| 195 | 
            +
                })
         | 
| 173 196 | 
             
                it('Builds form data', function(){
         | 
| 174 197 | 
             
                  sorter.$sorter.attr('data-sort-field','my_sort')
         | 
| 175 198 | 
             
                  form_data = sorter.getFormData()
         | 
    
        data/lib/hooch/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: hooch
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.4. | 
| 4 | 
            +
              version: 0.4.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Eric Draut
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-11-02 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |