hooch 0.13.2 → 0.14.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c453d5f21e48c17056e5c3016fc9439c447ee9d3
4
- data.tar.gz: 6b52a1b1d79458fbb08146cce8613380edffdf5a
3
+ metadata.gz: fb20ac68cd5d280812465183224f608f8f09ba43
4
+ data.tar.gz: 463a25fee2d56b8432ef99a42aa78e4357c2749c
5
5
  SHA512:
6
- metadata.gz: d452f69a39db675e927a9d1d88f391fb2e0a71dc7baaab14a012732dc89c2cb73ca9cec265e0eef3f842f18a88428efbe1964b8c4cdd339590bda5ac0706a7ee
7
- data.tar.gz: 4221a4d84e1a2489916155acb349d198e67e2fbe2930c25c9c677062f8daa1e346ee81e73d2e3ae586711ac0045f323e99c22087fad59e80ff352441e255577e
6
+ metadata.gz: 4e865332a62301a80b2ea2adcdc58e08e7201b39535e298569e5f41a223b5940ca9809bf795220b8ba39a6ea65ffc2c9d4fdbc8e215dc02c7744b8b069aa1211
7
+ data.tar.gz: 1abebd42f529a8b413df43b3b1f13aee584dc02b5b1cc367dbed4c86fd595ab36b3e38661e0aeeb4ccc34514f5550815738cdeb7b4ed758c4e8f99fc2a8603bd
@@ -586,6 +586,9 @@ var initHooch = function(){
586
586
  },
587
587
  addKeyValue: function(key,value){
588
588
  this.addState(key,value)
589
+ this.setNewParams()
590
+ },
591
+ setNewParams: function(){
589
592
  history['replaceState'](this.state, null, this.toUrl());
590
593
  },
591
594
  replacePath: function(new_path){
@@ -595,16 +598,64 @@ var initHooch = function(){
595
598
  }),
596
599
  HistoryPusher: Class.extend({
597
600
  init: function($history_pusher){
598
- this.key = $history_pusher.data('key')
599
- this.value = $history_pusher.data('value')
601
+ this.$history_pusher = $history_pusher
602
+ this.getPusherType()
603
+ var history_pusher = this
604
+ this.bindPusher()
605
+ },
606
+ bindPusher: function(){
607
+ var bind_method = 'bind' + this.pusher_type
608
+ this[bind_method]()
609
+ },
610
+ bindLink: function(){
600
611
  var history_pusher = this
601
- $history_pusher.on('click', function(){
612
+ this.$history_pusher.on('click apiclick', function(){
602
613
  history_pusher.pushIt()
603
614
  })
604
615
  },
616
+ bindForm: function(){
617
+ var history_pusher = this
618
+ this.$history_pusher.on('submit apisubmit', function(){
619
+ history_pusher.pushIt()
620
+ })
621
+ },
622
+ getPusherType: function(){
623
+ switch(this.$history_pusher.get(0).nodeName.toLowerCase()){
624
+ case 'form':
625
+ this.pusher_type = 'Form'
626
+ break;
627
+ case 'a':
628
+ default:
629
+ this.pusher_type = 'Link'
630
+ break;
631
+ }
632
+ },
633
+ getNewParams: function(){
634
+ var get_params_method = 'get' + this.pusher_type + 'Params'
635
+ this[get_params_method]()
636
+ },
637
+ getFormParams: function(){
638
+ this.new_params = this.$history_pusher.serializeArray().
639
+ reduce(
640
+ function(obj, item) {
641
+ obj[item.name] = item.value;
642
+ return obj;
643
+ },
644
+ {}
645
+ );
646
+ },
647
+ getLinkParams: function(){
648
+ this.new_params = {}
649
+ this.new_params[this.$history_pusher.data('key')] = this.$history_pusher.data('value')
650
+ },
605
651
  pushIt: function(){
606
- this.current_state = new hooch.IhHistoryState(history.state)
607
- this.current_state.addKeyValue(this.key,this.value)
652
+ this.getNewParams()
653
+ var history_pusher = this
654
+ history_pusher.current_state = new hooch.IhHistoryState(history.state)
655
+ $.each(this.new_params,function(new_key,new_value){
656
+ history_pusher.current_state.addState(new_key,new_value)
657
+ })
658
+ history_pusher.current_state.setNewParams()
608
659
  }
609
660
  }),
610
661
  HistoryReplacer: Class.extend({
@@ -170,19 +170,19 @@ module Hooch
170
170
  end
171
171
  end
172
172
 
173
- def history_pusher_attrs(key,value)
173
+ def history_pusher_attrs(key = nil,value = nil)
174
174
  ''.tap do |attrs|
175
175
  attrs.concat 'data-history-pusher=true'
176
- attrs.concat " data-key=#{key}"
177
- attrs.concat " data-value=\"#{value}\""
176
+ attrs.concat " data-key=#{key}" if key
177
+ attrs.concat " data-value=\"#{value}\"" if value
178
178
  end.html_safe
179
179
  end
180
180
 
181
- def history_pusher(key,value)
181
+ def history_pusher(key = nil,value = nil)
182
182
  {}.tap do |params|
183
183
  params['data-history-pusher'] = true
184
- params['data-key'] = key
185
- params['data-value'] = value
184
+ params['data-key'] = key if key
185
+ params['data-value'] = value if value
186
186
  end
187
187
  end
188
188
 
@@ -1,3 +1,3 @@
1
1
  module Hooch
2
- VERSION = "0.13.2"
2
+ VERSION = "0.14.0"
3
3
  end
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.13.2
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Draut
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-03 00:00:00.000000000 Z
11
+ date: 2016-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails