ultimate-base 0.2.1 → 0.2.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.
@@ -1,6 +1,6 @@
1
- Backbone.Ultimate ||= {}
1
+ (@Ultimate ||= {}).Backbone ||= {}
2
2
 
3
- class Backbone.Ultimate.App
3
+ class Ultimate.Backbone.App
4
4
  @App: null
5
5
 
6
6
  name: null
@@ -14,7 +14,7 @@ class Backbone.Ultimate.App
14
14
 
15
15
  constructor: (name = null) ->
16
16
  if @constructor.App
17
- throw new Error("Can't create new Backbone.Ultimate.App because the single instance has already been created");
17
+ throw new Error("Can't create new Ultimate.Backbone.App because the single instance has already been created");
18
18
  else
19
19
  @constructor.App = @
20
20
  @name = name
@@ -22,4 +22,4 @@ class Backbone.Ultimate.App
22
22
 
23
23
 
24
24
 
25
- _.extend Backbone.Ultimate.App::, Backbone.Events
25
+ _.extend Ultimate.Backbone.App::, Backbone.Events
@@ -1,6 +1,6 @@
1
- Backbone.Ultimate ||= {}
1
+ (@Ultimate ||= {}).Backbone ||= {}
2
2
 
3
- class Backbone.Ultimate.Collection extends Backbone.Collection
3
+ class Ultimate.Backbone.Collection extends Backbone.Collection
4
4
 
5
5
  ready: (callback, context = @) ->
6
6
  unless @length
@@ -134,6 +134,9 @@
134
134
 
135
135
  rest = [];
136
136
  events = events.split(eventSplitter);
137
+
138
+ // Fill up `rest` with the callback arguments. Since we're only copying
139
+ // the tail of `arguments`, a loop is much faster than Array#slice.
137
140
  for (i = 1, length = arguments.length; i < length; i++) {
138
141
  rest[i - 1] = arguments[i];
139
142
  }
@@ -1023,6 +1026,9 @@
1023
1026
  var docMode = document.documentMode;
1024
1027
  var oldIE = (isExplorer.exec(navigator.userAgent.toLowerCase()) && (!docMode || docMode <= 7));
1025
1028
 
1029
+ // Normalize root to always include trailing slash
1030
+ if (!trailingSlash.test(this.options.root)) this.options.root += '/';
1031
+
1026
1032
  if (oldIE && this._wantsHashChange) {
1027
1033
  this.iframe = Backbone.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo('body')[0].contentWindow;
1028
1034
  this.navigate(fragment);
@@ -1042,7 +1048,7 @@
1042
1048
  // opened by a non-pushState browser.
1043
1049
  this.fragment = fragment;
1044
1050
  var loc = this.location;
1045
- var atRoot = (loc.pathname === this.options.root) && !loc.search;
1051
+ var atRoot = (loc.pathname.replace(/[^/]$/, '$&/') === this.options.root) && !loc.search;
1046
1052
 
1047
1053
  // If we've started off with a route from a `pushState`-enabled browser,
1048
1054
  // but we're currently in a browser that doesn't support it...
@@ -1284,8 +1290,8 @@
1284
1290
  _ensureElement: function() {
1285
1291
  if (!this.el) {
1286
1292
  var attrs = _.extend({}, getValue(this, 'attributes'));
1287
- if (this.id) attrs.id = this.id;
1288
- if (this.className) attrs['class'] = this.className;
1293
+ if (this.id) attrs.id = getValue(this, 'id');
1294
+ if (this.className) attrs['class'] = getValue(this, 'className');
1289
1295
  this.setElement(this.make(getValue(this, 'tagName'), attrs), false);
1290
1296
  } else {
1291
1297
  this.setElement(this.el, false);
@@ -1,6 +1,6 @@
1
- Backbone.Ultimate ||= {}
1
+ (@Ultimate ||= {}).Backbone ||= {}
2
2
 
3
- class Backbone.Ultimate.Model extends Backbone.Model
3
+ class Ultimate.Backbone.Model extends Backbone.Model
4
4
 
5
5
  ready: (callback, context = @) ->
6
6
  if _.isEmpty(@attributes)
@@ -1,6 +1,6 @@
1
- Backbone.Ultimate ||= {}
1
+ (@Ultimate ||= {}).Backbone ||= {}
2
2
 
3
- class Backbone.Ultimate.Router extends Backbone.Router
3
+ class Ultimate.Backbone.Router extends Backbone.Router
4
4
 
5
5
  namedParam = /:\w+/g
6
6
  splatParam = /\*\w+/g
@@ -1,6 +1,6 @@
1
- Backbone.Ultimate ||= {}
1
+ (@Ultimate ||= {}).Backbone ||= {}
2
2
 
3
- class Backbone.Ultimate.View extends Backbone.View
3
+ class Ultimate.Backbone.View extends Backbone.View
4
4
 
5
5
  viewOptions: []
6
6
 
@@ -0,0 +1,128 @@
1
+ Ultimate.Backbone.Views ||= {}
2
+
3
+ class Ultimate.Backbone.Views.Slider extends Ultimate.Backbone.View
4
+ el: ".g-slider"
5
+
6
+ nodes: ->
7
+ jNavs: ".nav"
8
+ jDisplay:
9
+ selector: ".slide-display"
10
+ jLine:
11
+ selector: ".slide-line"
12
+ jItems: ".item"
13
+
14
+ events: ->
15
+ "click .nav.enabled" : "navClick"
16
+
17
+ viewOptions: ["vertical", "cycling", "interval", "durationPerPixel", "prevItems"]
18
+
19
+ vertical: false
20
+ cycling: false
21
+ interval: 0
22
+ durationPerPixel: 2
23
+
24
+ totalItems: 0
25
+ itemSize: 0
26
+ displayItems: 0
27
+ moveItems: 0
28
+ overItems: 0
29
+ prevItems: 0 # can as setting
30
+
31
+ timeoutId: null # for cycling == true
32
+ startSide: "left" # set by @vertical
33
+ sizeAttr: "width" # set by @vertical
34
+
35
+ initialize: (options) ->
36
+ @startSide = if @vertical then "top" else "left"
37
+ @sizeAttr = if @vertical then "height" else "width"
38
+ @totalItems = @jItems.length
39
+ if @totalItems
40
+ @jItems.each (index) -> $(@).attr "data-slide-index", index
41
+ jFirstItem = @jItems.first()
42
+ @itemSize = jFirstItem[_.camelize("outer-#{@sizeAttr}")](true)
43
+ needSize = @totalItems * @itemSize
44
+ @jLine[@sizeAttr](needSize) if @jLine[@sizeAttr]() < needSize
45
+ @displayItems = Math.round(@jDisplay[@sizeAttr]() / @itemSize)
46
+ @moveItems = Math.round(@displayItems / 2)
47
+ @overItems = @totalItems - @displayItems
48
+ if @overItems
49
+ if @prevItems
50
+ @jLine.css @startSide, (- @prevItems * @itemSize)
51
+ else
52
+ @prevItems = Math.round(- @jLine.position()[@startSide] / @itemSize)
53
+ @refreshNavs()
54
+ @setTimeout() if @interval
55
+ else
56
+ @prevItems = 0
57
+ #@bus().trigger "slider:slide", 0, @prevItems, jItems.eq(@prevItems)
58
+
59
+ currentIndex: ->
60
+ @jLine.find(".item:eq(#{@prevItems})").data("slideIndex")
61
+
62
+ trySlide: (move = 1, moveItems = move * @moveItems) ->
63
+ if @totalItems and @overItems
64
+ newPrevItems = @prevItems + moveItems
65
+ needFlip = false
66
+ flipItems = 0
67
+ animatedOverItems = 0
68
+ if newPrevItems < 0
69
+ if @cycling
70
+ needFlip = true
71
+ flipItems = newPrevItems
72
+ animatedOverItems = Math.ceil(- @jLine.position()[@startSide] / @itemSize)
73
+ newPrevItems = 0
74
+ else if newPrevItems > @overItems
75
+ if @cycling
76
+ needFlip = true
77
+ flipItems = newPrevItems - @overItems
78
+ animatedOverItems = @overItems - Math.floor(- @jLine.position()[@startSide] / @itemSize)
79
+ newPrevItems = @overItems
80
+ if needFlip
81
+ if flipItems and animatedOverItems < @overItems
82
+ @prevItems -= flipItems
83
+ if flipItems < 0
84
+ @jLine.prepend @jLine.find(".item").slice(flipItems)
85
+ else
86
+ @jLine.append @jLine.find(".item").slice(0, flipItems)
87
+ props = {}
88
+ props[@startSide] = "+=#{flipItems * @itemSize}"
89
+ @jLine.css props
90
+ @slideTo newPrevItems
91
+ else
92
+ @slideTo newPrevItems
93
+
94
+ trySlideToStart: ->
95
+ if @totalItems and @overItems
96
+ @slideTo 0
97
+
98
+ _duration: (deltaItems) ->
99
+ Math.sqrt(Math.abs(deltaItems) * @itemSize * 500) * @durationPerPixel
100
+
101
+ # TODO protect bounds, mb trySlideTo() and _slideTo()
102
+ slideTo: (newPrevItems) ->
103
+ deltaItems = newPrevItems - @prevItems
104
+ if deltaItems
105
+ #@bus().trigger "slider:slide", deltaItems, newPrevItems, jLine.find(".item:eq(#{newPrevItems})")
106
+ props = {}
107
+ props[@startSide] = (- newPrevItems * @itemSize)
108
+ @jLine.stop(true).animate props, @_duration(deltaItems)
109
+ @prevItems = newPrevItems
110
+ @refreshNavs()
111
+ @setTimeout() if @interval
112
+ deltaItems
113
+
114
+ refreshNavs: ->
115
+ @jNavs.filter(".prev").toggleClass "enabled", @cycling or @prevItems > 0
116
+ @jNavs.filter(".next").toggleClass "enabled", @cycling or (@overItems - @prevItems) > 0
117
+
118
+ setTimeout: ->
119
+ if @timeoutId?
120
+ clearTimeout @timeoutId
121
+ @timeoutId = null
122
+ @timeoutId = setTimeout =>
123
+ @trySlide()
124
+ , @interval
125
+
126
+ navClick: (event) ->
127
+ @trySlide if $(event.currentTarget).hasClass("prev") then -1 else 1
128
+ false
@@ -70,7 +70,11 @@
70
70
  .change()
71
71
  @
72
72
 
73
+ #class Backbone.Ultimate.
74
+
73
75
  $.fn.observeTypedFields = (selector = 'input:text[data-data-type], input:text[data-regexp-mask]') ->
76
+
77
+
74
78
  return @ unless @length
75
79
 
76
80
  @on 'keypress', selector, (event) ->
@@ -1,5 +1,5 @@
1
1
  module Ultimate
2
2
  module Base
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultimate-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-10 00:00:00.000000000 Z
12
+ date: 2012-08-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Ultimate UI core, base helpers and improves for Ruby on Rails Front-end
15
15
  email:
@@ -26,12 +26,13 @@ files:
26
26
  - LICENSE
27
27
  - README.md
28
28
  - Rakefile
29
- - app/assets/javascripts/backbone/backbone.js
30
- - app/assets/javascripts/backbone/ultimate/app.js.coffee
31
- - app/assets/javascripts/backbone/ultimate/collection.js.coffee
32
- - app/assets/javascripts/backbone/ultimate/model.js.coffee
33
- - app/assets/javascripts/backbone/ultimate/router.js.coffee
34
- - app/assets/javascripts/backbone/ultimate/view.js.coffee
29
+ - app/assets/javascripts/ultimate/backbone/app.js.coffee
30
+ - app/assets/javascripts/ultimate/backbone/collection.js.coffee
31
+ - app/assets/javascripts/ultimate/backbone/lib/backbone.js
32
+ - app/assets/javascripts/ultimate/backbone/model.js.coffee
33
+ - app/assets/javascripts/ultimate/backbone/router.js.coffee
34
+ - app/assets/javascripts/ultimate/backbone/view.js.coffee
35
+ - app/assets/javascripts/ultimate/backbone/views/slider.js.coffee
35
36
  - app/assets/javascripts/ultimate/base.js.coffee
36
37
  - app/assets/javascripts/ultimate/bus.js.coffee
37
38
  - app/assets/javascripts/ultimate/devise.js.coffee