wiselinks 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 640b50447668efc0f447459335b7185aa86e537b
4
- data.tar.gz: 3dddc36480d89af712d2fff418106e3648605932
3
+ metadata.gz: 8313c2988ca0762699bbcf8e44231232e36b6801
4
+ data.tar.gz: 0a4c39841d2b4a78eacc51a3034d6ebfe8e56ee1
5
5
  SHA512:
6
- metadata.gz: 98244f0449e962e5811cb59b9c0f39a8cbdfe5b52785d280008625c220b9f9cd536b502d7aa197bb5d9ec256a63c4a36f504558804504e7b5986aa5ef64e7654
7
- data.tar.gz: 49b5c6353973b12a65de5e9dba24e081d9ad7e2321969556f6a0bb9ee4aebf62f4abb424fb4584ca790b5fea5c2c7721cebde1b8ee68bbd1ab12c3ee298411a1
6
+ metadata.gz: 9382f1337e30d590fd1116803e74ba1018edea5f43ef24f2451c4726f7a9cf936b393e667971e5d69b0186c28f85cf4c88632a8e032c5b372e0a0744f5d0ad45
7
+ data.tar.gz: e97f40694511b91fd29e497c452731c0a98d9a52440b89c408b8c541d24e23f798ee26619547be6647c4dff7d3fa4eb294736c65a99c7594f6b4bb471c3a88d7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wiselinks (1.1.4)
4
+ wiselinks (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -462,9 +462,9 @@ We crafted example application that uses nearly all features of Wiselinks so you
462
462
 
463
463
  ## Credits
464
464
 
465
- ![JetRockets](http://www.jetrockets.ru/public/logo.png)
465
+ ![JetRockets](http://www.jetrockets.ru/jetrockets.png)
466
466
 
467
- Wiselinks is maintained by [JetRockets](http://www.jetrockets.ru/en).
467
+ Wiselinks is maintained by [JetRockets](http://www.jetrockets.ru).
468
468
 
469
469
  Contributors:
470
470
 
@@ -0,0 +1,50 @@
1
+ class DOMParser
2
+ parse: (html) ->
3
+ @_get_parser()(html)
4
+
5
+ _get_parser: ->
6
+ @_document_parser ?= @_parser_factory()
7
+
8
+ # fully taken from Turbolinks (https://github.com/rails/turbolinks)
9
+ # and changed function names style
10
+ # by @igor-alexandrov request :)
11
+ _parser_factory: ->
12
+ create_document_using_parser = (html) ->
13
+ (new DOMParser).parseFromString html, 'text/html'
14
+
15
+ create_document_using_DOM = (html) ->
16
+ doc = document.implementation.createHTMLDocument ''
17
+ doc.documentElement.innerHTML = html
18
+ doc
19
+
20
+ create_document_using_write = (html) ->
21
+ doc = document.implementation.createHTMLDocument ''
22
+ doc.open 'replace'
23
+ doc.write html
24
+ doc.close()
25
+ doc
26
+
27
+ # Use create_document_using_parser if DOMParser is defined and natively
28
+ # supports 'text/html' parsing (Firefox 12+, IE 10)
29
+ #
30
+ # Use create_document_using_DOM if create_document_using_parser throws an exception
31
+ # due to unsupported type 'text/html' (Firefox < 12, Opera)
32
+ #
33
+ # Use create_document_using_write if:
34
+ # - DOMParser isn't defined
35
+ # - create_document_using_parser returns null due to unsupported type 'text/html' (Chrome, Safari)
36
+ # - create_document_using_DOM doesn't create a valid HTML document (safeguarding against potential edge cases)
37
+ try
38
+ if window.DOMParser
39
+ testDoc = create_document_using_parser '<html><body><p>test'
40
+ create_document_using_parser
41
+ catch e
42
+ testDoc = create_document_using_DOM '<html><body><p>test'
43
+ create_document_using_DOM
44
+ finally
45
+ unless testDoc?.body?.childNodes.length is 1
46
+ return create_document_using_write
47
+
48
+
49
+ window._Wiselinks ?= {}
50
+ window._Wiselinks.DOMParser = DOMParser
@@ -1,3 +1,5 @@
1
+ #= require _response
2
+
1
3
  class RequestManager
2
4
  constructor: (@options = {}) ->
3
5
 
@@ -25,22 +27,7 @@ class RequestManager
25
27
  dataType: "html"
26
28
  ).done(
27
29
  (data, status, xhr) ->
28
- url = self._normalize(xhr.getResponseHeader('X-Wiselinks-Url'))
29
- assets_digest = xhr.getResponseHeader('X-Wiselinks-Assets-Digest')
30
-
31
- if self._assets_changed(assets_digest)
32
- window.location.reload(true)
33
- else
34
- state = History.getState()
35
- if url? && (url != self._normalize(state.url))
36
- self._redirect_to(url, $target, state, xhr)
37
-
38
- $target.html(data).promise().done(
39
- ->
40
- self._title(xhr.getResponseHeader('X-Wiselinks-Title'))
41
- self._done($target, status, state, data)
42
- )
43
-
30
+ self._html_loaded($target, data, status, xhr)
44
31
  ).fail(
45
32
  (xhr, status, error) ->
46
33
  self._fail($target, status, state, error, xhr.status)
@@ -77,6 +64,25 @@ class RequestManager
77
64
  [$target, status, decodeURI(state.url), data]
78
65
  )
79
66
 
67
+ _html_loaded: ($target, data, status, xhr) ->
68
+ response = new window._Wiselinks.Response(data, xhr, $target)
69
+
70
+ url = @_normalize(response.url())
71
+ assets_digest = response.assets_digest()
72
+
73
+ if @_assets_changed(assets_digest)
74
+ window.location.reload(true)
75
+ else
76
+ state = History.getState()
77
+ if url? && (url != @_normalize(state.url))
78
+ @_redirect_to(url, $target, state, xhr)
79
+
80
+ $target.html(response.content()).promise().done(
81
+ =>
82
+ @_title(response.title())
83
+ @_done($target, status, state, response.content())
84
+ )
85
+
80
86
  _fail: ($target, status, state, error, code) ->
81
87
  $(document).trigger('page:fail'
82
88
  [$target, status, decodeURI(state.url), error, code]
@@ -0,0 +1,54 @@
1
+ #= require _dom_parser
2
+
3
+ # if server responds with 304, sometimes you may get
4
+ # full page source instead of just wiselinks part, so
5
+ # you need to use different content extract strategies
6
+ class Response
7
+ @_document_parser: null
8
+
9
+ @_get_document_parser: ->
10
+ Response._document_parser ?= new window._Wiselinks.DOMParser
11
+
12
+
13
+ constructor: (@html, @xhr, @$target) ->
14
+
15
+ url: ->
16
+ @xhr.getResponseHeader('X-Wiselinks-Url')
17
+
18
+ assets_digest: ->
19
+ if @_is_full_document_response()
20
+ $('meta[name="assets-digest"]', @_get_doc()).attr('content')
21
+ else
22
+ @xhr.getResponseHeader('X-Wiselinks-Assets-Digest')
23
+
24
+ content: ->
25
+ @_content ?= @_extract_content()
26
+
27
+ title: ->
28
+ @_title ?= @_extract_title()
29
+
30
+ _extract_title: ->
31
+ if @_is_full_document_response()
32
+ $('title', @_get_doc()).text()
33
+ else
34
+ @xhr.getResponseHeader('X-Wiselinks-Title')
35
+
36
+ _extract_content: ->
37
+ if @_is_full_document_response()
38
+ @_get_doc_target_node().html()
39
+ else
40
+ @html
41
+
42
+ _is_full_document_response: ->
43
+ @_get_doc_target_node().length is 1
44
+
45
+ _get_doc_target_node: ->
46
+ @$doc_target_node ?= $(@$target.selector, @_get_doc())
47
+
48
+ _get_doc: ->
49
+ @_doc ?= Response._get_document_parser().parse(@html)
50
+
51
+
52
+
53
+ window._Wiselinks ?= {}
54
+ window._Wiselinks.Response = Response
@@ -3,8 +3,8 @@
3
3
  module Wiselinks
4
4
  module Version
5
5
  MAJOR = 1
6
- MINOR = 1
7
- PATCH = 4
6
+ MINOR = 2
7
+ PATCH = 0
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wiselinks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Alexandrov
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-01-14 00:00:00.000000000 Z
14
+ date: 2014-03-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -268,10 +268,12 @@ files:
268
268
  - Rakefile
269
269
  - app/views/layouts/wiselinks.html.erb
270
270
  - compiler.jar
271
+ - lib/assets/javascripts/_dom_parser.js.coffee
271
272
  - lib/assets/javascripts/_form.js.coffee
272
273
  - lib/assets/javascripts/_link.js.coffee
273
274
  - lib/assets/javascripts/_page.js.coffee
274
275
  - lib/assets/javascripts/_request_manager.js.coffee
276
+ - lib/assets/javascripts/_response.js.coffee
275
277
  - lib/assets/javascripts/lib/native.history.js
276
278
  - lib/assets/javascripts/wiselinks.js.coffee
277
279
  - lib/wiselinks.rb