mootools-plus 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ ## 0.2.0
2
+
3
+ * Add namespace creation
4
+ * Update Logger to core.Logger
5
+ * Add mootools-plus JS file
6
+ * Add ui.Dropdown
7
+
1
8
  ## 0.1.6
2
9
 
3
10
  * Fix Array#deleteIf
data/README.md CHANGED
@@ -8,7 +8,7 @@ Add the gem in your `Gemfile`:
8
8
 
9
9
  ```ruby
10
10
  group :assets do
11
- gem 'mootools-plus', '~> 0.1.0'
11
+ gem 'mootools-plus', '~> 0.2.0'
12
12
  end
13
13
  ```
14
14
 
@@ -17,9 +17,7 @@ Then `bundle install` it.
17
17
  Add mootools-plus to the asset pipeline:
18
18
 
19
19
  ```javascript
20
- //= require mootools-plus/logger
21
- //= require mootools-plus/array
22
- //= require mootools-plus/element
20
+ //= require mootools-plus
23
21
  ```
24
22
 
25
23
  Enjoy!
@@ -142,6 +140,45 @@ Alias of Array#filter
142
140
 
143
141
  Alias of Array#filterOne
144
142
 
143
+ ### ui.Dropdown
144
+
145
+ #### Use
146
+
147
+ ```haml
148
+ %div
149
+ %header
150
+ %a= 'Pipo'
151
+ %ol
152
+ %li
153
+ %a= 'item 1'
154
+ %li
155
+ %a= 'item 2'
156
+ %li
157
+ %a= 'item 3'
158
+ %li
159
+ %a= 'item 4'
160
+ %li
161
+ %a= 'item 5'
162
+ %li
163
+ %a= 'item 6'
164
+ ```
165
+
166
+ ```javascript
167
+ new ui.Dropdown($$('div')[0])
168
+ ```
169
+
170
+ [Example](http://jsfiddle.net/9BZw9/)
171
+
172
+ #### Options
173
+
174
+ ```javascript
175
+ {
176
+ panel: {
177
+ openAtStart: false // Set to true to open the dropdown at initialization
178
+ }
179
+ }
180
+ ```
181
+
145
182
  ## Changelog
146
183
 
147
184
  View [CHANGELOG](https://github.com/caedes/mootools-plus/blob/stable/CHANGELOG.md) of the latest stable version.
@@ -1,5 +1,5 @@
1
1
  module MootoolsPlus
2
2
  module Rails
3
- VERSION = '0.1.6'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ //= require_self
2
+ //= require namespace
3
+ //= require_tree .
4
+
5
+ if (!window.MooTools && console && console.error) console.error('Mootools is not yet installed.')
@@ -1,42 +1,37 @@
1
- if (window.MooTools) {
2
- Array.implement({
3
- getFirst: function(n){
4
- return (n || n === 0) ? this.slice(0, n) : this[0]
5
- },
1
+ Array.implement({
2
+ getFirst: function(n){
3
+ return (n || n === 0) ? this.slice(0, n) : this[0]
4
+ },
6
5
 
7
- getLast: function(n){
8
- if (n >= this.length) return this
9
- return (n || n === 0) ? this.slice(this.length - n, this.length) : this[this.length - 1]
10
- },
6
+ getLast: function(n){
7
+ if (n >= this.length) return this
8
+ return (n || n === 0) ? this.slice(this.length - n, this.length) : this[this.length - 1]
9
+ },
11
10
 
12
- deleteIf: function(fn){
13
- for (var i = 0, length = this.length; i < length; i++) {
14
- var el = this.shift()
15
- if (!fn.call(el)) this.push(el)
16
- }
17
- return this
18
- },
11
+ deleteIf: function(fn){
12
+ for (var i = 0, length = this.length; i < length; i++) {
13
+ var el = this.shift()
14
+ if (!fn.call(el)) this.push(el)
15
+ }
16
+ return this
17
+ },
19
18
 
20
- filterOne: function(fn, bind){
21
- return this.filter(fn, bind).getFirst()
22
- },
19
+ filterOne: function(fn, bind){
20
+ return this.filter(fn, bind).getFirst()
21
+ },
23
22
 
24
- isBlank: function(){
25
- return this.length == 0
26
- },
23
+ isBlank: function(){
24
+ return this.length == 0
25
+ },
27
26
 
28
- hasAny: function(){
29
- return !this.isBlank()
30
- }
31
- })
27
+ hasAny: function(){
28
+ return !this.isBlank()
29
+ }
30
+ })
32
31
 
33
- Array.alias('first', 'getFirst')
34
- Array.alias('last', 'getLast')
35
- Array.alias('select', 'filter')
36
- Array.alias('selectOne', 'filterOne')
37
- Array.alias('compact', 'clean')
38
- Array.alias('isEmpty', 'isBlank')
39
- }
40
- else {
41
- if (console && console.error) console.error('Mootools is not yet installed.')
42
- }
32
+ Array.alias('first', 'getFirst')
33
+ Array.alias('last', 'getLast')
34
+ Array.alias('select', 'filter')
35
+ Array.alias('selectOne', 'filterOne')
36
+ Array.alias('compact', 'clean')
37
+ Array.alias('isEmpty', 'isBlank')
@@ -1,5 +1,5 @@
1
- if (window.MooTools) {
2
- var Logger = new Class()
1
+ (function(){
2
+ var Logger = new Class('core.Logger', {})
3
3
 
4
4
  Logger.log = function(param){
5
5
  Logger.trace(param, 'log')
@@ -37,7 +37,4 @@ if (window.MooTools) {
37
37
  }
38
38
  }
39
39
  }
40
- }
41
- else {
42
- if (console && console.error) console.error('Mootools is not yet installed.')
43
- }
40
+ })()
@@ -1,33 +1,28 @@
1
- if (window.MooTools) {
2
- Element.implement({
3
- hasElement: function(tag){
4
- return (tag == undefined) ? (this.getChildren().length > 0) : (this.getElement(tag) != null)
5
- },
1
+ Element.implement({
2
+ hasElement: function(tag){
3
+ return (tag == undefined) ? (this.getChildren().length > 0) : (this.getElement(tag) != null)
4
+ },
6
5
 
7
- hasElements: function(tag){
8
- return (tag == undefined) ? (this.getChildren().length > 0) : (this.getElements(tag).length > 1)
9
- },
6
+ hasElements: function(tag){
7
+ return (tag == undefined) ? (this.getChildren().length > 0) : (this.getElements(tag).length > 1)
8
+ },
10
9
 
11
- hasEvent: function(eventType, fn){
12
- var myEvents = this.retrieve('events')
13
- return myEvents && myEvents[eventType] && (fn == undefined || myEvents[eventType].keys.contains(fn))
14
- },
10
+ hasEvent: function(eventType, fn){
11
+ var myEvents = this.retrieve('events')
12
+ return myEvents && myEvents[eventType] && (fn == undefined || myEvents[eventType].keys.contains(fn))
13
+ },
15
14
 
16
- hasParent: function(tag){
17
- return (tag == undefined) ? (this.getParent().length > 0) : (this.getParent(tag) != null)
18
- },
15
+ hasParent: function(tag){
16
+ return (tag == undefined) ? (this.getParent().length > 0) : (this.getParent(tag) != null)
17
+ },
19
18
 
20
- disable: function(){
21
- this.set('disabled', true)
22
- return this
23
- },
19
+ disable: function(){
20
+ this.set('disabled', true)
21
+ return this
22
+ },
24
23
 
25
- enable: function(){
26
- this.set('disabled', false)
27
- return this
28
- }
29
- })
30
- }
31
- else {
32
- if (console && console.error) console.error('Mootools is not yet installed.')
33
- }
24
+ enable: function(){
25
+ this.set('disabled', false)
26
+ return this
27
+ }
28
+ })
@@ -0,0 +1,116 @@
1
+ (function(){
2
+
3
+ /**
4
+ * DROPDOWN
5
+ */
6
+
7
+ var Dropdown = new Class('ui.Dropdown', {
8
+ Implements: [Options],
9
+
10
+ options: {
11
+ header: {},
12
+ panel: {}
13
+ },
14
+
15
+ initialize: function(element, options){
16
+ this.element = element
17
+ this.options = Object.merge(this.options, options)
18
+ this.build()
19
+ this.addEvents()
20
+ this.element.store('dropdown', this)
21
+ },
22
+
23
+ build: function(){
24
+ this.header = new ui.DropdownHeader(this.element.getElement('header'), this.options.header)
25
+ this.panel = new ui.DropdownPanel(this.element.getElement('ol'), this.options.panel)
26
+ },
27
+
28
+ addEvents: function(){
29
+ this.header.addEvent('onDropdownHeaderEnter', this.panel.show.bind(this.panel))
30
+ this.header.addEvent('onDropdownHeaderLeave', this.panel.hide.bind(this.panel))
31
+ this.panel.addEvent('onDropdownPanelEnter', this.header.killTimer.bind(this.header))
32
+ this.panel.addEvent('onDropdownPanelLeave', this.panel.hide.bind(this.panel))
33
+ }
34
+ })
35
+
36
+ /**
37
+ * DROPDOWN HEADER
38
+ */
39
+
40
+ var DropdownHeader = new Class('ui.DropdownHeader', {
41
+ Implements: [Options, Events],
42
+
43
+ options: {},
44
+
45
+ initialize: function(element, options){
46
+ this.element = element
47
+ this.options = Object.merge(this.options, options)
48
+ this.addEvents()
49
+ this.element.store('dropdown_header', this)
50
+ },
51
+
52
+ addEvents: function(){
53
+ this.element.addEvent('mouseenter', this.onMouseEnter.bind(this))
54
+ this.element.addEvent('mouseleave', this.onMouseLeave.bind(this))
55
+ },
56
+
57
+ onMouseEnter: function(event){
58
+ this.killTimer()
59
+ this.fireEvent('onDropdownHeaderEnter')
60
+ },
61
+
62
+ onMouseLeave: function(event){
63
+ this.timer = this.fireEvent.delay(500, this, 'onDropdownHeaderLeave')
64
+ },
65
+
66
+ killTimer: function(event){
67
+ if (this.timer) clearTimeout(this.timer)
68
+ }
69
+ })
70
+
71
+ /**
72
+ * DROPDOWN PANEL
73
+ */
74
+
75
+ var DropdownPanel = new Class('ui.DropdownPanel', {
76
+ Implements: [Options, Events],
77
+
78
+ options: {
79
+ openAtStart: false
80
+ },
81
+
82
+ initialize: function(element, options){
83
+ this.element = element
84
+ this.options = Object.merge(this.options, options)
85
+ this.build()
86
+ this.addEvents()
87
+ this.element.store('dropdown_panel', this)
88
+ },
89
+
90
+ build: function(){
91
+ this.hide()
92
+ if (this.options.openAtStart) this.show()
93
+ },
94
+
95
+ addEvents: function(){
96
+ this.element.addEvent('mouseenter', this.onMouseEnter.bind(this))
97
+ this.element.addEvent('mouseleave', this.onMouseLeave.bind(this))
98
+ },
99
+
100
+ show: function(event){
101
+ this.element.show()
102
+ },
103
+
104
+ hide: function(event){
105
+ this.element.hide()
106
+ },
107
+
108
+ onMouseEnter: function(event){
109
+ this.fireEvent('onDropdownPanelEnter')
110
+ },
111
+
112
+ onMouseLeave: function(event){
113
+ this.fireEvent('onDropdownPanelLeave')
114
+ }
115
+ })
116
+ })()
@@ -0,0 +1,46 @@
1
+ (function() {
2
+ // Utility method to get and set objects that may or may not exist
3
+ var objectifier = function(splits, create, context) {
4
+ var result = context || window
5
+ for(var i = 0, s; result && (s = splits[i]); i++) {
6
+ result = (s in result ? result[s] : (create ? result[s] = {} : undefined))
7
+ }
8
+ return result
9
+ }
10
+
11
+ // Creates an object if it doesn't already exist
12
+ Object.extend('place', function(name, value, context) {
13
+ var splits = name.split("."), s = splits.pop(), result = objectifier(splits, true, context)
14
+ return result && s ? (result[s] = value) : undefined
15
+ })
16
+
17
+ // Retrieves an object if not already present
18
+ Object.extend('retrieve', function(name, create, context) {
19
+ return objectifier(name.split('.'), create, context)
20
+ })
21
+
22
+ // Checks to see if the object exists
23
+ Object.extend('exists', function(name, context) {
24
+ return Object.retrieve(name, false, context) !== undefined
25
+ })
26
+
27
+ var klass = Class;
28
+
29
+ // Redefine class
30
+ Class = function(name, params, context) {
31
+ // Find out if this is namespaced or the original method
32
+ var namespaced = arguments.length > 1
33
+
34
+ // Add the class name to the param list
35
+ if(namespaced) params.$name = name
36
+
37
+ // Create and get the original class
38
+ var original = new klass(namespaced ? params : name)
39
+
40
+ // If namespaced, set class into namespace
41
+ if(namespaced) Object.place(name, original, context)
42
+
43
+ // Return this newly created class!
44
+ return original
45
+ }
46
+ })()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mootools-plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-06 00:00:00.000000000 Z
12
+ date: 2012-06-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &2156056380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,15 +24,7 @@ dependencies:
24
24
  version: '5.0'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: 3.1.0
33
- - - <
34
- - !ruby/object:Gem::Version
35
- version: '5.0'
27
+ version_requirements: *2156056380
36
28
  description: mootools-plus provides helpers and Ruby-like methods to Javascript MooTools
37
29
  core classes and plus
38
30
  email:
@@ -53,9 +45,12 @@ files:
53
45
  - lib/mootools-plus/rails/engine.rb
54
46
  - lib/mootools-plus/rails/version.rb
55
47
  - mootools-plus.gemspec
48
+ - vendor/assets/javascripts/mootools-plus.js
56
49
  - vendor/assets/javascripts/mootools-plus/array.js
50
+ - vendor/assets/javascripts/mootools-plus/core/logger.js
57
51
  - vendor/assets/javascripts/mootools-plus/element.js
58
- - vendor/assets/javascripts/mootools-plus/logger.js
52
+ - vendor/assets/javascripts/mootools-plus/ui/dropdown.js
53
+ - vendor/assets/javascripts/namespace.js
59
54
  homepage: https://github.com/caedes/mootools-plus
60
55
  licenses: []
61
56
  post_install_message:
@@ -76,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
71
  version: '0'
77
72
  requirements: []
78
73
  rubyforge_project:
79
- rubygems_version: 1.8.23
74
+ rubygems_version: 1.8.6
80
75
  signing_key:
81
76
  specification_version: 3
82
77
  summary: mootools-plus provides helpers and Ruby-like methods to Javascript MooTools