wiselinks-artirix 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +51 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +7 -0
  7. data/Gemfile.lock +184 -0
  8. data/LICENSE +20 -0
  9. data/README.md +479 -0
  10. data/Rakefile +10 -0
  11. data/app/views/layouts/wiselinks.html.erb +1 -0
  12. data/compiler.jar +0 -0
  13. data/lib/assets/javascripts/_dom_parser.js.coffee +50 -0
  14. data/lib/assets/javascripts/_form.js.coffee +74 -0
  15. data/lib/assets/javascripts/_link.js.coffee +44 -0
  16. data/lib/assets/javascripts/_page.js.coffee +108 -0
  17. data/lib/assets/javascripts/_request_manager.js.coffee +132 -0
  18. data/lib/assets/javascripts/_response.js.coffee +101 -0
  19. data/lib/assets/javascripts/lib/native.history.js +3337 -0
  20. data/lib/assets/javascripts/wiselinks.js.coffee +37 -0
  21. data/lib/wiselinks-artirix.rb +1 -0
  22. data/lib/wiselinks.rb +27 -0
  23. data/lib/wiselinks/controller_methods.rb +67 -0
  24. data/lib/wiselinks/helpers.rb +9 -0
  25. data/lib/wiselinks/logger.rb +11 -0
  26. data/lib/wiselinks/rails.rb +22 -0
  27. data/lib/wiselinks/rendering.rb +37 -0
  28. data/lib/wiselinks/request.rb +29 -0
  29. data/lib/wiselinks/version.rb +12 -0
  30. data/spec/cases/helpers_spec.rb +8 -0
  31. data/spec/cases/request_spec.rb +113 -0
  32. data/spec/dummy/README.rdoc +261 -0
  33. data/spec/dummy/Rakefile +7 -0
  34. data/spec/dummy/app/assets/javascripts/application.js.coffee +1 -0
  35. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  36. data/spec/dummy/app/controllers/application_controller.rb +9 -0
  37. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  38. data/spec/dummy/app/mailers/.gitkeep +0 -0
  39. data/spec/dummy/app/models/.gitkeep +0 -0
  40. data/spec/dummy/app/views/application/index.html.erb +1 -0
  41. data/spec/dummy/app/views/application/no_slash.html.erb +0 -0
  42. data/spec/dummy/app/views/application/trailing_slash.html.erb +0 -0
  43. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  44. data/spec/dummy/config.ru +4 -0
  45. data/spec/dummy/config/application.rb +59 -0
  46. data/spec/dummy/config/boot.rb +10 -0
  47. data/spec/dummy/config/database.yml +7 -0
  48. data/spec/dummy/config/environment.rb +5 -0
  49. data/spec/dummy/config/environments/development.rb +37 -0
  50. data/spec/dummy/config/environments/production.rb +67 -0
  51. data/spec/dummy/config/environments/test.rb +40 -0
  52. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  53. data/spec/dummy/config/initializers/inflections.rb +15 -0
  54. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  55. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  56. data/spec/dummy/config/initializers/session_store.rb +8 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/en.yml +5 -0
  59. data/spec/dummy/config/routes.rb +7 -0
  60. data/spec/dummy/lib/assets/.gitkeep +0 -0
  61. data/spec/dummy/log/.gitkeep +0 -0
  62. data/spec/dummy/log/development.log +27917 -0
  63. data/spec/dummy/public/404.html +26 -0
  64. data/spec/dummy/public/422.html +26 -0
  65. data/spec/dummy/public/500.html +25 -0
  66. data/spec/dummy/public/assets/application-a98e47eb93026a340a766faf55214702.js +2830 -0
  67. data/spec/dummy/public/assets/application-a98e47eb93026a340a766faf55214702.js.gz +0 -0
  68. data/spec/dummy/public/assets/application-ecf5beebe0b79251c8be40f0443074f2.css +14 -0
  69. data/spec/dummy/public/assets/application-ecf5beebe0b79251c8be40f0443074f2.css.gz +0 -0
  70. data/spec/dummy/public/assets/application.css +14 -0
  71. data/spec/dummy/public/assets/application.css.gz +0 -0
  72. data/spec/dummy/public/assets/application.js +2830 -0
  73. data/spec/dummy/public/assets/application.js.gz +0 -0
  74. data/spec/dummy/public/assets/manifest.yml +5 -0
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/dummy/public/javascripts/wisepdf.js +1 -0
  77. data/spec/dummy/public/stylesheets/wisepdf.css +1 -0
  78. data/spec/dummy/script/rails +6 -0
  79. data/spec/dummy/tmp/cache/assets/C26/0A0/sprockets%2F52456508a38f02f4559064b24980c87a +0 -0
  80. data/spec/dummy/tmp/cache/assets/C5E/890/sprockets%2Ffb6525457b6873e6905e2d522548091f +0 -0
  81. data/spec/dummy/tmp/cache/assets/C80/150/sprockets%2F0d3881005b0646df783d5c24683d34f5 +0 -0
  82. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  83. data/spec/dummy/tmp/cache/assets/CF3/250/sprockets%2F7edb1809ce839a3d290508f935c89f42 +0 -0
  84. data/spec/dummy/tmp/cache/assets/D09/C40/sprockets%2Fcf317b95ed0500b7277e950a9c0c82e0 +0 -0
  85. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  86. data/spec/dummy/tmp/cache/assets/D45/760/sprockets%2Fbc659a6e09b5025e8be539b0b68f71f2 +0 -0
  87. data/spec/dummy/tmp/cache/assets/D4E/D00/sprockets%2F1a6846f0a837ae2524e2f9ec89e6ef43 +0 -0
  88. data/spec/dummy/tmp/cache/assets/D55/090/sprockets%2F4a21bc343a4696b7603ea4cc25c3c3ba +0 -0
  89. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  90. data/spec/dummy/tmp/cache/assets/DC2/EB0/sprockets%2F75b4716f479a2acfac51b258fba0c2bd +0 -0
  91. data/spec/dummy/tmp/cache/assets/DF1/B80/sprockets%2Fcd0ee4f742908cb7223a1e7be4a4ccbc +0 -0
  92. data/spec/dummy/tmp/cache/assets/E11/4E0/sprockets%2F86e145a39f85cceeaffdff91ebb61449 +0 -0
  93. data/spec/factories/requests.rb +30 -0
  94. data/spec/helper.rb +26 -0
  95. data/spec/requests/trailing_slash_spec.rb +17 -0
  96. data/wiselinks-artirix.gemspec +40 -0
  97. metadata +432 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5d1c19dda93dd6246e051028014a9b2d332150d
4
+ data.tar.gz: 4925057deeea5b143c1603845d6bb4c182d55a07
5
+ SHA512:
6
+ metadata.gz: 8bce94811c1e2467724656dd4d29bb3165a05ae9ab32945b1515e215d4bfafb36ab804b2791404de6cd8d5d2dfe84c8ea94537150e3d8147ebf59f679d61f13c
7
+ data.tar.gz: 1064045c52ca69342348acfc7641fec2cb64a0aaaae9e696ec16b3b88f38c955fe9fe5f27c2947703772014637a4c05ac6c0e4f38f96a2465092a992625ad327
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,51 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ spec/dummy/log/test.log
19
+
20
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
21
+ #
22
+ # * Create a file at ~/.gitignore
23
+ # * Include files you want ignored
24
+ # * Run: git config --global core.excludesfile ~/.gitignore
25
+ #
26
+ # After doing this, these files will be ignored in all your git projects,
27
+ # saving you from having to 'pollute' every project you touch with them
28
+ #
29
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
30
+ #
31
+ # For MacOS:
32
+ #
33
+ #.DS_Store
34
+
35
+ # For TextMate
36
+ #*.tmproj
37
+ #tmtags
38
+
39
+ # For emacs:
40
+ #*~
41
+ #\#*
42
+ #.\#*
43
+
44
+ # For vim:
45
+ #*.swp
46
+
47
+ # For redcar:
48
+ #.redcar
49
+
50
+ # For rubinius:
51
+ #*.rbc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format nested
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ if system('ping -c1 gemcache.ldn.uk.office.artirix.com >/dev/null 2>&1')
2
+ source 'http://gemcache.ldn.uk.office.artirix.com'
3
+ else
4
+ source 'https://rubygems.org'
5
+ end
6
+
7
+ gemspec name: 'wiselinks-artirix'
data/Gemfile.lock ADDED
@@ -0,0 +1,184 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wiselinks-artirix (1.3.0)
5
+
6
+ GEM
7
+ remote: http://gemcache.ldn.uk.office.artirix.com/
8
+ specs:
9
+ actionmailer (3.2.16)
10
+ actionpack (= 3.2.16)
11
+ mail (~> 2.5.4)
12
+ actionpack (3.2.16)
13
+ activemodel (= 3.2.16)
14
+ activesupport (= 3.2.16)
15
+ builder (~> 3.0.0)
16
+ erubis (~> 2.7.0)
17
+ journey (~> 1.0.4)
18
+ rack (~> 1.4.5)
19
+ rack-cache (~> 1.2)
20
+ rack-test (~> 0.6.1)
21
+ sprockets (~> 2.2.1)
22
+ activemodel (3.2.16)
23
+ activesupport (= 3.2.16)
24
+ builder (~> 3.0.0)
25
+ activerecord (3.2.16)
26
+ activemodel (= 3.2.16)
27
+ activesupport (= 3.2.16)
28
+ arel (~> 3.0.2)
29
+ tzinfo (~> 0.3.29)
30
+ activeresource (3.2.16)
31
+ activemodel (= 3.2.16)
32
+ activesupport (= 3.2.16)
33
+ activesupport (3.2.16)
34
+ i18n (~> 0.6, >= 0.6.4)
35
+ multi_json (~> 1.0)
36
+ addressable (2.3.5)
37
+ arel (3.0.3)
38
+ builder (3.0.4)
39
+ capybara (2.2.1)
40
+ mime-types (>= 1.16)
41
+ nokogiri (>= 1.3.3)
42
+ rack (>= 1.0.0)
43
+ rack-test (>= 0.5.4)
44
+ xpath (~> 2.0)
45
+ closure-compiler (1.1.10)
46
+ coffee-rails (3.2.2)
47
+ coffee-script (>= 2.2.0)
48
+ railties (~> 3.2.0)
49
+ coffee-script (2.2.0)
50
+ coffee-script-source
51
+ execjs
52
+ coffee-script-source (1.6.3)
53
+ coffeelint (0.1.3)
54
+ coffee-script
55
+ json
56
+ coveralls (0.7.0)
57
+ multi_json (~> 1.3)
58
+ rest-client
59
+ simplecov (>= 0.7)
60
+ term-ansicolor
61
+ thor
62
+ crack (0.4.1)
63
+ safe_yaml (~> 0.9.0)
64
+ diff-lcs (1.2.5)
65
+ docile (1.1.2)
66
+ erubis (2.7.0)
67
+ execjs (2.0.2)
68
+ factory_girl (4.3.0)
69
+ activesupport (>= 3.0.0)
70
+ faker (1.2.0)
71
+ i18n (~> 0.5)
72
+ hike (1.2.3)
73
+ i18n (0.6.9)
74
+ journey (1.0.4)
75
+ json (1.8.1)
76
+ mail (2.5.4)
77
+ mime-types (~> 1.16)
78
+ treetop (~> 1.4.8)
79
+ mime-types (1.25.1)
80
+ mini_portile (0.5.2)
81
+ multi_json (1.8.4)
82
+ nokogiri (1.6.1)
83
+ mini_portile (~> 0.5.0)
84
+ polyglot (0.3.3)
85
+ rack (1.4.5)
86
+ rack-cache (1.2)
87
+ rack (>= 0.4)
88
+ rack-ssl (1.3.3)
89
+ rack
90
+ rack-test (0.6.2)
91
+ rack (>= 1.0)
92
+ rails (3.2.16)
93
+ actionmailer (= 3.2.16)
94
+ actionpack (= 3.2.16)
95
+ activerecord (= 3.2.16)
96
+ activeresource (= 3.2.16)
97
+ activesupport (= 3.2.16)
98
+ bundler (~> 1.0)
99
+ railties (= 3.2.16)
100
+ railties (3.2.16)
101
+ actionpack (= 3.2.16)
102
+ activesupport (= 3.2.16)
103
+ rack-ssl (~> 1.3.2)
104
+ rake (>= 0.8.7)
105
+ rdoc (~> 3.4)
106
+ thor (>= 0.14.6, < 2.0)
107
+ rake (10.1.1)
108
+ rdoc (3.12.2)
109
+ json (~> 1.4)
110
+ rest-client (1.6.7)
111
+ mime-types (>= 1.16)
112
+ rspec (2.14.1)
113
+ rspec-core (~> 2.14.0)
114
+ rspec-expectations (~> 2.14.0)
115
+ rspec-mocks (~> 2.14.0)
116
+ rspec-core (2.14.7)
117
+ rspec-expectations (2.14.4)
118
+ diff-lcs (>= 1.1.3, < 2.0)
119
+ rspec-mocks (2.14.4)
120
+ rspec-rails (2.14.1)
121
+ actionpack (>= 3.0)
122
+ activemodel (>= 3.0)
123
+ activesupport (>= 3.0)
124
+ railties (>= 3.0)
125
+ rspec-core (~> 2.14.0)
126
+ rspec-expectations (~> 2.14.0)
127
+ rspec-mocks (~> 2.14.0)
128
+ safe_yaml (0.9.7)
129
+ shoulda (3.5.0)
130
+ shoulda-context (~> 1.0, >= 1.0.1)
131
+ shoulda-matchers (>= 1.4.1, < 3.0)
132
+ shoulda-context (1.1.6)
133
+ shoulda-matchers (2.5.0)
134
+ activesupport (>= 3.0.0)
135
+ simplecov (0.8.2)
136
+ docile (~> 1.1.0)
137
+ multi_json
138
+ simplecov-html (~> 0.8.0)
139
+ simplecov-html (0.8.0)
140
+ sprockets (2.2.2)
141
+ hike (~> 1.2)
142
+ multi_json (~> 1.0)
143
+ rack (~> 1.0)
144
+ tilt (~> 1.1, != 1.3.0)
145
+ sqlite3 (1.3.8)
146
+ term-ansicolor (1.2.2)
147
+ tins (~> 0.8)
148
+ thor (0.18.1)
149
+ tilt (1.4.1)
150
+ tins (0.13.1)
151
+ treetop (1.4.15)
152
+ polyglot
153
+ polyglot (>= 0.3.1)
154
+ tzinfo (0.3.38)
155
+ webmock (1.9.3)
156
+ addressable (>= 2.2.7)
157
+ crack (>= 0.3.2)
158
+ xpath (2.0.0)
159
+ nokogiri (~> 1.3)
160
+
161
+ PLATFORMS
162
+ ruby
163
+
164
+ DEPENDENCIES
165
+ bundler
166
+ capybara
167
+ closure-compiler
168
+ coffee-rails
169
+ coffeelint
170
+ coveralls
171
+ factory_girl
172
+ faker
173
+ rails (~> 3.2.13)
174
+ rake
175
+ rspec
176
+ rspec-rails
177
+ shoulda
178
+ simplecov
179
+ sqlite3
180
+ webmock (~> 1.9.0)
181
+ wiselinks-artirix!
182
+
183
+ BUNDLED WITH
184
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Igor Alexandrov, Alexey Solilin and Julia Egorova
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,479 @@
1
+ [![Build Status](https://travis-ci.org/igor-alexandrov/wiselinks.png)](https://travis-ci.org/igor-alexandrov/wiselinks)
2
+ [![Code Climate](https://codeclimate.com/github/igor-alexandrov/wiselinks.png)](https://codeclimate.com/github/igor-alexandrov/wiselinks)
3
+ [![Coverage Status](https://coveralls.io/repos/igor-alexandrov/wiselinks/badge.png)](https://coveralls.io/r/igor-alexandrov/wiselinks)
4
+ [![Dependency Status](https://gemnasium.com/igor-alexandrov/wiselinks.png)](https://gemnasium.com/igor-alexandrov/wiselinks)
5
+ [![Gem Version](https://badge.fury.io/rb/wiselinks.png)](http://badge.fury.io/rb/wiselinks)
6
+
7
+
8
+ #Wiselinks
9
+
10
+ Wiselinks makes following links and submitting forms in your web application faster.
11
+
12
+ You may find Wiselinks similar to [Turbolinks](https://github.com/rails/turbolinks) or [Pjax](https://github.com/defunkt/jquery-pjax), but Wiselinks works as a whitelist rather than blacklist. We tried to make Wiselinks as easy to use as Turbolinks are but also as configurable as Pjax.
13
+
14
+ Try Wiselinks online in our **demo application**:
15
+
16
+ * [http://wiselinks.herokuapp.com/](http://wiselinks.herokuapp.com/)
17
+
18
+ ## Compatibility
19
+
20
+ **Please be advised that Javascript events in wiselinks-0.5.0 are not backward compatible.**
21
+
22
+ Wiselinks uses [History.js](https://github.com/balupton/History.js/) library to perform requests.
23
+
24
+ Wiselinks works in all major browsers including browsers that do not support HTML History API out of the box.
25
+
26
+ ## In Comparison to Turbolinks and PJAX
27
+
28
+ <table>
29
+ <thead>
30
+ <tr>
31
+ <th></th>
32
+ <th>Wiselinks</th>
33
+ <th>Turbolinks</th>
34
+ <th>PJAX</th>
35
+ </tr>
36
+ </thead>
37
+ <tbody>
38
+ <tr>
39
+ <td>Work in HTML5 browsers</td>
40
+ <td><strong>Yes</strong></td>
41
+ <td>Yes</td>
42
+ <td>Yes</td>
43
+ </tr>
44
+ <tr>
45
+ <td>Work in browsers without History API</td>
46
+ <td><strong>Yes</strong>, with hashbang (can be switched off)</td>
47
+ <td>No, degrades to normal request processing</td>
48
+ <td>No, degrades to normal request processing</td>
49
+ </tr>
50
+ <tr>
51
+ <td>Work without JavaScript</td>
52
+ <td>No, degrades to normal request processing</td>
53
+ <td>No, degrades to normal request processing</td>
54
+ <td>No, degrades to normal request processing</td>
55
+ </tr>
56
+ <tr>
57
+ <td>Form processing</td>
58
+ <td><strong>Yes</strong></td>
59
+ <td>No</td>
60
+ <td>Yes (experimental feature)</td>
61
+ </tr>
62
+ <tr>
63
+ <td>Form blank values exclusion</td>
64
+ <td><strong>Yes</strong> (optional)</td>
65
+ <td>No</td>
66
+ <td>No</td>
67
+ </tr>
68
+ <tr>
69
+ <td>Form values optimization</td>
70
+ <td><strong>Yes</strong></td>
71
+ <td>No</td>
72
+ <td>No</td>
73
+ </tr>
74
+ <tr>
75
+ <td>Assets change detection</td>
76
+ <td><strong>Yes</strong>, by calculating assets MD5 hash on boot</td>
77
+ <td>Yes, by parsing document head on every request</td>
78
+ <td>Yes, manually</td>
79
+ </tr>
80
+ <tr>
81
+ <td>30x HTTP redirects processing</td>
82
+ <td><strong>Yes</strong></td>
83
+ <td>No</td>
84
+ <td>Yes</td>
85
+ </tr>
86
+ </tbody>
87
+ </table>
88
+
89
+ ##Installation
90
+
91
+ ### Rails
92
+
93
+ Add this to your Gemfile:
94
+
95
+ ```ruby
96
+ gem 'wiselinks'
97
+ ```
98
+
99
+ Then do:
100
+
101
+ bundle install
102
+
103
+ Restart your server and you're now using wiselinks!
104
+
105
+ ### All others
106
+
107
+ Copy `wiselinks-x.y.z.js` or `wiselinks-x.y.z.min.js` from `build` folder in this project to your project.
108
+
109
+ ## How does it work?
110
+
111
+ ### CoffeeScript
112
+
113
+ Create Wiselinks object in your `application.js.coffee`:
114
+
115
+ ```coffeescript
116
+ #= require jquery
117
+ #= require wiselinks
118
+
119
+ $(document).ready ->
120
+ window.wiselinks = new Wiselinks()
121
+ ```
122
+
123
+ You can disable HTML4 browsers support easily:
124
+
125
+ ```coffeescript
126
+ #= require jquery
127
+ #= require wiselinks
128
+
129
+ $(document).ready ->
130
+ window.wiselinks = new Wiselinks($('body'), html4: false )
131
+ ```
132
+
133
+
134
+ Or you can add some more options, if you want:
135
+
136
+ ```coffeescript
137
+ #= require jquery
138
+ #= require jquery.role
139
+ #= require wiselinks
140
+
141
+ $(document).ready ->
142
+ # DOM element with id = "content" will be replaced after data load.
143
+ window.wiselinks = new Wiselinks($('#content'))
144
+
145
+ $(document).off('page:loading').on(
146
+ 'page:loading'
147
+ (event, $target, render, url) ->
148
+ console.log("Loading: #{url} to #{$target.selector} within '#{render}'")
149
+ # code to start loading animation
150
+ )
151
+
152
+ $(document).off('page:redirected').on(
153
+ 'page:redirected'
154
+ (event, $target, render, url) ->
155
+ console.log("Redirected to: #{url}")
156
+ # code to start loading animation
157
+ )
158
+
159
+ $(document).off('page:always').on(
160
+ 'page:always'
161
+ (event, xhr, settings) ->
162
+ console.log("Wiselinks page loading completed")
163
+ # code to stop loading animation
164
+ )
165
+
166
+ $(document).off('page:done').on(
167
+ 'page:done'
168
+ (event, $target, status, url, data) ->
169
+ console.log("Wiselinks status: '#{status}'")
170
+ )
171
+
172
+ $(document).off('page:fail').on(
173
+ 'page:fail'
174
+ (event, $target, status, url, error, code) ->
175
+ console.log("Wiselinks status: '#{status}'")
176
+ # code to show error message
177
+ )
178
+ ```
179
+
180
+ ### HTML
181
+
182
+ Click on links with `data-push` attribute will fire History.pushState() event.
183
+ Data from the request will replace content of the container that was passed to Wiselinks (default is `$('body')`)
184
+
185
+
186
+ ```html
187
+ <ul class="menu">
188
+ <li>
189
+ <a href="/" data-push="true">Home</a>
190
+ </li>
191
+ <li>
192
+ <a href="/contacts" data-push="true">Contacts</a>
193
+ </li>
194
+ </ul>
195
+ ```
196
+
197
+ Click on links with `data-replace` will fire History.replaceState() event.
198
+ Data from the request will replace content of the container that was passed to Wiselinks (default is "body")
199
+
200
+ ```html
201
+ <div class="dialog">
202
+ <a href="/step2" data-replace="true">Proceed to the next step</a>
203
+ </div>
204
+ ```
205
+
206
+ Click on following links will fire History.pushState() event.
207
+ Data from the request will be pasted into `<div id="catalog">`. This configuration is widely when you have list of items that are paginated, sorted or maybe grouped by some attributes and you want to update only these items and nothing more on page.
208
+
209
+ ```html
210
+ <ul class="pagination">
211
+ <li>
212
+ <span>1</span>
213
+ </li>
214
+ <li>
215
+ <a href="/?page=2" data-push="true" data-target="#catalog">2</a>
216
+ </li>
217
+ <li>
218
+ <a href="/?page=3" data-push="true" data-target="#catalog">3</a>
219
+ </li>
220
+ <li>
221
+ <a href="/?page=4" data-push="true" data-target="#catalog">4</a>
222
+ </li>
223
+ </ul>
224
+
225
+ <ul class="sort">
226
+ <li>
227
+ <a href="/?sort=title" data-push="true" data-target="#catalog">Sort by Title</a>
228
+ </li>
229
+ <li>
230
+ <a href="/?sort=price" data-push="true" data-target="#catalog">Sort by Price</a>
231
+ </li>
232
+ </ul>
233
+
234
+ <div id="catalog">
235
+ <!-- the list of your items -->
236
+ ...
237
+ </div>
238
+ ```
239
+
240
+ **Form processing**
241
+
242
+ Wiselinks can process forms. After submit button is clicked, Wiselinks will perform a request to form url with form attributes serialized to a string. Wiselinks always performs a HTTP GET request.
243
+
244
+ ```html
245
+ <div class="filter">
246
+ <form action="/" method="get" data-push="true" data-target="@catalog">
247
+ <input type="text" size="30" name="title" id="title">
248
+
249
+ <select name="scope" id="scope">
250
+ <option value="">All Tax Liens</option>
251
+ <option value="accruing">Accruing Interest</option>
252
+ <option value="awaiting_payment">Awaiting Payment</option>
253
+ <option value="closed">Closed</option>
254
+ <option value="trashed">Trash</option>
255
+ </select>
256
+
257
+ <input type="submit" value="Find" name="commit">
258
+ </form>
259
+ </div>
260
+
261
+ <div role="catalog">
262
+ <!-- the list of your items -->
263
+ ...
264
+ </div>
265
+ ```
266
+ **data-include-blank-url-params**
267
+
268
+ During form submit Wiselinks excludes blank parameters to make your URLs cleaner. You can disable this behaviour with ```data-include-blank-url-params``` attribute.
269
+
270
+ ```html
271
+ <div class="filter">
272
+ <form action="/" method="get" data-push="true" data-target="@catalog" data-include-blank-url-params="true">
273
+ <input type="text" size="30" name="title" id="title">
274
+ <input type="submit" value="Find" name="commit">
275
+ </form>
276
+ </div>
277
+ ```
278
+
279
+ **data-optimize-url-params**
280
+
281
+ Array parameters ```category_ids[]=1&category_ids[]=2&category_ids[]=3``` are optimized to more human readable ```category_ids=1,2,3```. To changed this behaviour use ```data-optimize-url-params``` attribute.
282
+
283
+ ```html
284
+ <div class="filter">
285
+ <form action="/" method="get" data-push="true" data-target="@catalog" data-optimize-url-params="false">
286
+ <input type="text" size="30" name="title" id="title">
287
+ <input type="submit" value="Find" name="commit">
288
+ </form>
289
+ </div>
290
+ ```
291
+
292
+
293
+ ### Server processing
294
+
295
+ The idea of Wiselinks is that you should render only content that you need in current request. Usually you don't need to reload your stylesheets and javascripts on every request.
296
+
297
+ `X-Wiselinks` header is passed with every Wiselinks request. Server should respond with content that should be inserted into `$target`.
298
+
299
+ In Rails after installing Wiselinks gem, all requests that have `X-Wiselinks` header will be automatically processed within 'app/views/layouts/wiselinks' layout, that basically has only `yield` operator. Of course you can override layout name by redefining `wiselinks_layout` method in your controller.
300
+
301
+ ### Javascript Events
302
+
303
+ While using Wiselinks you **can rely** on `DOMContentLoaded` or `jQuery.ready()` to trigger your JavaScript code, but Wiselinks gives you some additional useful event to deal with the lifecycle of the page:
304
+
305
+ **page:loading ($target, render, url)**
306
+
307
+ Event is triggered before the `XMLHttpRequest` is initialised and performed.
308
+ * *$target* – JQuery object in which result of the request will be inserted;
309
+
310
+ * *url* - URL of the request that will be performed;
311
+
312
+ * *render* – what should be rendered; can be 'template' or 'partial';
313
+
314
+ **page:redirected ($target, render, url)**
315
+
316
+ Event is triggered when you were redirected during `XMLHttpRequest` (with HTTP 30x status).
317
+ * *$target* – jQuery object in which result of the request will be inserted;
318
+
319
+ * *url* - URL where you have been redirected to;
320
+
321
+ * *render* – what should be rendered; can be 'template' or 'partial';
322
+
323
+ **page:done ($target, status, url, data)**
324
+
325
+ Event is triggered if the request succeeds.
326
+ * *$target* – jQuery object that was updated with the request;
327
+
328
+ * *status* – a string describing the status;
329
+
330
+ * *url* – url of the request;
331
+
332
+ * *data* – content of the request;
333
+
334
+ **page:fail ($target, status, url, error, code)**
335
+
336
+ Event is triggered if the request fails.
337
+
338
+ * *$target* – jQuery object that had to be updated with the request;
339
+
340
+ * *status* – a string describing the status;
341
+
342
+ * *url* – url of the request;
343
+
344
+ * *error* – a string describing the type of error that occurred;
345
+
346
+ * *code* – HTTP response status code
347
+
348
+ **page:always ($target, status, url)**
349
+
350
+ Event is triggered after each request.
351
+
352
+ * *$target* – jQuery object that had to be updated with the request;
353
+
354
+ * *status* – a string describing the status;
355
+
356
+ * *url* – url of the request;
357
+
358
+ So if you want to show a client-side loading spinner, you could listen for `page:loading` to start it and `page:always` to stop it.
359
+
360
+ ### ActionDispatch::Request extensions
361
+
362
+ Wiselinks adds a couple of methods to `ActionDispatch::Request`. These methods are mostly syntax sugar and don't have any complex logic, so you can use them or not.
363
+
364
+ #### #wiselinks? ###
365
+ Method returns `true` if current request is initiated by Wiselinks (has `X-Wiselinks` header), `false` otherwise.
366
+
367
+ #### #wiselinks_template? ###
368
+ Method returns `true` if current request is initiated by Wiselinks and client want to render template (`X-Wiselinks != 'partial'`), `false` otherwise.
369
+
370
+ #### #wiselinks_partial? ###
371
+ Method returns `true` if current request is initiated by Wiselinks and client want to render partial (`X-Wiselinks == 'partial'`), `false` otherwise.
372
+
373
+ ### Assets change detection
374
+
375
+ You can enable assets change detection with Wiselinks. To do this you have to enable assets digests by adding this to you environment file:
376
+
377
+ ```ruby
378
+ config.assets.digest = true
379
+ ```
380
+
381
+ Then you should append your layout by adding this to head section:
382
+
383
+ ```erb
384
+ <%= wiselinks_meta_tag %>
385
+ ```
386
+
387
+ Now Wiselinks will track changes of your assets and if anything will change, your page will be reloaded completely.
388
+
389
+ ### Title handling
390
+
391
+ Wiselinks handles page titles by passing `X-Wiselinks-Title` header with response. To set this header you can use `wiselinks_title` helper (in Rails).
392
+
393
+ ```html
394
+ <% wiselinks_title("Wiselinks is awesome") %>
395
+
396
+ <div>
397
+ <!-- your content -->
398
+ ...
399
+ </div>
400
+ ```
401
+
402
+ Of course you can use `wiselinks_title` helper in your own helpers too.
403
+
404
+ ### Redirect handling
405
+
406
+ Wiselinks follows 30x HTTP redirects. Location is updated in browser with `X-Wiselinks-Url` header that is setting up automatically (in Rails) on every wiselinks request.
407
+
408
+ ### Target missing handling
409
+
410
+ By default, if Wiselinks cannot find target that you specified during initialization, it will fail silently. But you can override this behaviour:
411
+
412
+ ```coffeescript
413
+ #= require jquery
414
+ #= require wiselinks
415
+
416
+ $(document).ready ->
417
+ window.wiselinks = new Wiselinks(
418
+ $('something that does not exist'),
419
+ target_missing: 'exception'
420
+ )
421
+ ```
422
+
423
+ `[Wiselinks] Target missing` exception will be thrown. This also works for `data-target` attributes.
424
+
425
+
426
+ ### Google Analytics and Yandex Metrika
427
+
428
+ If you want to handle these analytics tools, then you should add handler to `page:done` event.
429
+
430
+ Let's say, that you have two objects, first is `_gaq` – instance of Google Analytics, second is `_metrika` – instance of Yandex Metrika. Then you have to add the following code somewhere in your `application.js.coffee`.
431
+
432
+ ```coffeescript
433
+ $(document).off('page:done').on(
434
+ 'page:done'
435
+ (event, $target, status, url, data) ->
436
+ _gaq.push(['_trackPageview', url])
437
+ _metrika.hit(url)
438
+ )
439
+ ```
440
+
441
+ After this, you will have correct page view statistics in your analytics tools.
442
+
443
+
444
+ ## Example
445
+
446
+ We crafted example application that uses nearly all features of Wiselinks so you can see it in action.
447
+
448
+ * GitHub Repository: [https://github.com/igor-alexandrov/wiselinks_example](https://github.com/igor-alexandrov/wiselinks_example)
449
+
450
+ * Live Example: [http://wiselinks.herokuapp.com/](http://wiselinks.herokuapp.com/)
451
+
452
+ ## Note on Patches / Pull Requests
453
+
454
+ * Fork the project.
455
+ * Make your feature addition or bug fix.
456
+ * Add tests for it. This is important so I don't break it in a
457
+ future version unintentionally.
458
+ * Commit, do not mess with rakefile, version, or history.
459
+ (if you want to have your own version, that is fine but
460
+ bump version in a commit by itself I can ignore when I pull)
461
+ * Send me a pull request. Bonus points for topic branches.
462
+
463
+ ## Credits
464
+
465
+ ![JetRockets](http://www.jetrockets.ru/jetrockets.png)
466
+
467
+ Wiselinks is maintained by [JetRockets](http://www.jetrockets.ru).
468
+
469
+ Contributors:
470
+
471
+ * [Igor Alexandrov](http://igor-alexandrov.github.com/)
472
+ * [Alexey Solilin](https://github.com/solilin)
473
+ * [Julia Egorova](https://github.com/vankiru)
474
+ * [Alexandr Borisov](https://github.com/aishek)
475
+
476
+ ## License
477
+
478
+ It is free software, and may be redistributed under the terms specified in the LICENSE file.
479
+