twitter-flight-rails 0.0.2 → 1.0.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.
- data/README.md +23 -12
- data/lib/twitter-flight-rails/version.rb +1 -1
- data/twitter-flight-rails.gemspec +2 -4
- data/vendor/assets/javascripts/twitter/flight/component.js +48 -23
- data/vendor/assets/javascripts/twitter/flight/compose.js +1 -1
- data/vendor/assets/javascripts/twitter/flight/tools/debug/debug.js +125 -0
- data/vendor/assets/javascripts/twitter/flight.js +1 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Twitter Flight framework for Rails
|
2
2
|
|
3
|
-
This asset gem packages the [twitter flight](https://github.com/twitter/flight/) framework for
|
3
|
+
This asset gem packages the [twitter flight](https://github.com/twitter/flight/) framework for Rails.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -12,34 +12,45 @@ Add this line to your application's Gemfile:
|
|
12
12
|
|
13
13
|
gem 'twitter-flight-rails', :git => "git@github.com:yourabi/twitter-flight-rails.git"
|
14
14
|
|
15
|
+
You'll also want to add the following dependencies to your Gemfile (see the dependencies section for more details)
|
16
|
+
|
17
|
+
gem 'requirejs-rails'
|
18
|
+
|
19
|
+
gem 'es5-shim-rails'
|
15
20
|
|
16
21
|
And then execute:
|
17
22
|
|
18
23
|
$ bundle
|
19
24
|
|
20
|
-
|
25
|
+
## Dependencies
|
21
26
|
|
22
|
-
|
27
|
+
Twitter flight depdends on ES5-shim, jQuery and an AMD implementation like require.js.
|
23
28
|
|
24
|
-
|
29
|
+
One possible Rails/Require.js integration is [requirejs-rails](https://github.com/jwhitley/requirejs-rails) ... you'll probably want to read their documentation and follow their initial setup instructions.
|
25
30
|
|
26
|
-
|
31
|
+
[ES5-shim](https://github.com/kriskowal/es5-shim) is used to polyfill ES5 support for older browsers and [JQuery](http://jquery.com) for DOM manipulation API. This is provided by the [es5-shim-rails](https://github.com/yourabi/es5-shim-rails) gem.
|
27
32
|
|
28
|
-
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
Eventually you'll end up using require.js to include jquery, es5-shim, flight and your own compnents using something like this
|
29
36
|
|
30
37
|
```js
|
38
|
+
// here "root" is a file that contains your own components under app/assets/javascripts/root.js and accessed at /assets/root.js
|
39
|
+
require(['jquery', 'es5-shim/shims/es5-shim', 'es5-shim/shims/es5-sham', 'twitter/flight/', 'root'], function($) {
|
31
40
|
|
32
|
-
|
41
|
+
// this is your own boot.js file in app/assets/javascripts/boot.js accessed at /assets/boot.js
|
42
|
+
require(['boot'], function(initialize) {
|
43
|
+
initialize();
|
44
|
+
});
|
33
45
|
|
34
|
-
|
46
|
+
});
|
35
47
|
|
36
|
-
|
48
|
+
```
|
37
49
|
|
38
|
-
##
|
50
|
+
## Changelog
|
39
51
|
|
40
|
-
|
52
|
+
Currently this version tracks [flight v1.0.2](https://github.com/twitter/flight/tree/v1.0.2) with a few bugs backported from master ($.browser reference in jQuery 1.9) and paths tweaked slightly.
|
41
53
|
|
42
|
-
Note: as of version 0.0.2 the es5-shim dependency is not handled.
|
43
54
|
|
44
55
|
## Contributing
|
45
56
|
|
@@ -14,12 +14,10 @@ Gem::Specification.new do |gem|
|
|
14
14
|
|
15
15
|
gem.add_dependency 'railties', '>= 3.1'
|
16
16
|
gem.add_dependency 'actionpack', '>= 3.1'
|
17
|
-
gem.add_dependency 'jquery-rails'
|
18
|
-
|
17
|
+
gem.add_dependency 'jquery-rails', '>= 2.2.1'
|
18
|
+
|
19
19
|
gem.add_development_dependency 'rails', '>= 3.1'
|
20
20
|
|
21
21
|
gem.files = `git ls-files`.split($/)
|
22
|
-
# gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
23
|
-
# gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
24
22
|
gem.require_paths = ["lib"]
|
25
23
|
end
|
@@ -17,6 +17,9 @@ define(
|
|
17
17
|
|
18
18
|
function(advice, utils, compose, registry) {
|
19
19
|
|
20
|
+
var functionNameRegEx = /function (.*?)\s?\(/;
|
21
|
+
var spaceCommaRegEx = /\s\,/g;
|
22
|
+
|
20
23
|
function teardownInstance(instanceInfo){
|
21
24
|
instanceInfo.events.slice().forEach(function(event) {
|
22
25
|
var args = [event.type];
|
@@ -43,6 +46,17 @@ define(
|
|
43
46
|
});
|
44
47
|
}
|
45
48
|
|
49
|
+
function checkSerializable(type, data) {
|
50
|
+
try {
|
51
|
+
window.postMessage(data, '*');
|
52
|
+
} catch(e) {
|
53
|
+
console.log('unserializable data for event',type,':',data);
|
54
|
+
throw new Error(
|
55
|
+
["The event", type, "on component", this.describe, "was triggered with non-serializable data"].join(" ")
|
56
|
+
);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
46
60
|
//common mixin allocates basic functionality - used by all component prototypes
|
47
61
|
//callback context is bound to component
|
48
62
|
function withBaseComponent() {
|
@@ -50,33 +64,43 @@ define(
|
|
50
64
|
// delegate trigger, bind and unbind to an element
|
51
65
|
// if $element not supplied, use component's node
|
52
66
|
// other arguments are passed on
|
67
|
+
// event can be either a string specifying the type
|
68
|
+
// of the event, or a hash specifying both the type
|
69
|
+
// and a default function to be called.
|
53
70
|
this.trigger = function() {
|
54
|
-
var $element, type, data;
|
71
|
+
var $element, type, data, event, defaultFn;
|
55
72
|
var args = utils.toArray(arguments);
|
73
|
+
var lastArg = args[args.length - 1];
|
56
74
|
|
57
|
-
if (typeof
|
75
|
+
if (typeof lastArg != "string" && !(lastArg && lastArg.defaultBehavior)) {
|
58
76
|
data = args.pop();
|
59
77
|
}
|
60
78
|
|
61
79
|
$element = (args.length == 2) ? $(args.shift()) : this.$node;
|
62
|
-
|
80
|
+
event = args[0];
|
81
|
+
|
82
|
+
if (event.defaultBehavior) {
|
83
|
+
defaultFn = event.defaultBehavior;
|
84
|
+
event = $.Event(event.type);
|
85
|
+
}
|
86
|
+
|
87
|
+
type = event.type || event;
|
63
88
|
|
64
89
|
if (window.DEBUG && window.postMessage) {
|
65
|
-
|
66
|
-
window.postMessage(data, '*');
|
67
|
-
} catch(e) {
|
68
|
-
console.log('unserializable data for event',type,':',data);
|
69
|
-
throw new Error(
|
70
|
-
["The event", event.type, "on component", this.describe, "was triggered with non-serializable data"].join(" ")
|
71
|
-
);
|
72
|
-
}
|
90
|
+
checkSerializable.call(this, type, data);
|
73
91
|
}
|
74
92
|
|
75
93
|
if (typeof this.attr.eventData === 'object') {
|
76
94
|
data = $.extend(true, {}, this.attr.eventData, data);
|
77
95
|
}
|
78
96
|
|
79
|
-
|
97
|
+
var returnVal = $element.trigger((event || type), data);
|
98
|
+
|
99
|
+
if (defaultFn && !event.isDefaultPrevented()) {
|
100
|
+
(this[defaultFn] || defaultFn).call(this);
|
101
|
+
}
|
102
|
+
|
103
|
+
return returnVal;
|
80
104
|
};
|
81
105
|
|
82
106
|
this.on = function() {
|
@@ -92,7 +116,14 @@ define(
|
|
92
116
|
originalCb = args.pop();
|
93
117
|
}
|
94
118
|
|
95
|
-
|
119
|
+
$element = (args.length == 2) ? $(args.shift()) : this.$node;
|
120
|
+
type = args[0];
|
121
|
+
|
122
|
+
if (typeof originalCb != 'function' && typeof originalCb != 'object') {
|
123
|
+
throw new Error("Unable to bind to '" + type + "' because the given callback is not a function or an object");
|
124
|
+
}
|
125
|
+
|
126
|
+
callback = originalCb.bind(this);
|
96
127
|
callback.target = originalCb;
|
97
128
|
|
98
129
|
// if the original callback is already branded by jQuery's guid, copy it to the context-bound version
|
@@ -100,13 +131,6 @@ define(
|
|
100
131
|
callback.guid = originalCb.guid;
|
101
132
|
}
|
102
133
|
|
103
|
-
$element = (args.length == 2) ? $(args.shift()) : this.$node;
|
104
|
-
type = args[0];
|
105
|
-
|
106
|
-
if (typeof callback == 'undefined') {
|
107
|
-
throw new Error("Unable to bind to '" + type + "' because the given callback is undefined");
|
108
|
-
}
|
109
|
-
|
110
134
|
$element.on(type, callback);
|
111
135
|
|
112
136
|
// get jquery's guid from our bound fn, so unbinding will work
|
@@ -177,13 +201,14 @@ define(
|
|
177
201
|
|
178
202
|
Component.toString = function() {
|
179
203
|
var prettyPrintMixins = mixins.map(function(mixin) {
|
180
|
-
if (
|
181
|
-
|
204
|
+
if (mixin.name == null) {
|
205
|
+
//function name property not supported by this browser, use regex
|
206
|
+
var m = mixin.toString().match(functionNameRegEx);
|
182
207
|
return (m && m[1]) ? m[1] : "";
|
183
208
|
} else {
|
184
209
|
return mixin.name;
|
185
210
|
}
|
186
|
-
}).join(', ').replace(
|
211
|
+
}).join(', ').replace(spaceCommaRegEx,'');//weed out no-named mixins
|
187
212
|
|
188
213
|
return prettyPrintMixins;
|
189
214
|
};
|
@@ -0,0 +1,125 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
define(
|
4
|
+
|
5
|
+
[
|
6
|
+
'../../registry',
|
7
|
+
'../../utils'
|
8
|
+
],
|
9
|
+
|
10
|
+
function(registry, utils) {
|
11
|
+
|
12
|
+
var logFilter;
|
13
|
+
|
14
|
+
//******************************************************************************************
|
15
|
+
// Search object model
|
16
|
+
//******************************************************************************************
|
17
|
+
|
18
|
+
function traverse(util, searchTerm, options) {
|
19
|
+
var options = options || {};
|
20
|
+
var obj = options.obj || window;
|
21
|
+
var path = options.path || ((obj==window) ? "window" : "");
|
22
|
+
var props = Object.keys(obj);
|
23
|
+
props.forEach(function(prop) {
|
24
|
+
if ((tests[util] || util)(searchTerm, obj, prop)){
|
25
|
+
console.log([path, ".", prop].join(""), "->",["(", typeof obj[prop], ")"].join(""), obj[prop]);
|
26
|
+
}
|
27
|
+
if(Object.prototype.toString.call(obj[prop])=="[object Object]" && (obj[prop] != obj) && path.split(".").indexOf(prop) == -1) {
|
28
|
+
traverse(util, searchTerm, {obj: obj[prop], path: [path,prop].join(".")});
|
29
|
+
}
|
30
|
+
});
|
31
|
+
}
|
32
|
+
|
33
|
+
function search(util, expected, searchTerm, options) {
|
34
|
+
if (!expected || typeof searchTerm == expected) {
|
35
|
+
traverse(util, searchTerm, options);
|
36
|
+
} else {
|
37
|
+
console.error([searchTerm, 'must be', expected].join(' '))
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
var tests = {
|
42
|
+
'name': function(searchTerm, obj, prop) {return searchTerm == prop},
|
43
|
+
'nameContains': function(searchTerm, obj, prop) {return prop.indexOf(searchTerm)>-1},
|
44
|
+
'type': function(searchTerm, obj, prop) {return obj[prop] instanceof searchTerm},
|
45
|
+
'value': function(searchTerm, obj, prop) {return obj[prop] === searchTerm},
|
46
|
+
'valueCoerced': function(searchTerm, obj, prop) {return obj[prop] == searchTerm}
|
47
|
+
}
|
48
|
+
|
49
|
+
function byName(searchTerm, options) {search('name', 'string', searchTerm, options);};
|
50
|
+
function byNameContains(searchTerm, options) {search('nameContains', 'string', searchTerm, options);};
|
51
|
+
function byType(searchTerm, options) {search('type', 'function', searchTerm, options);};
|
52
|
+
function byValue(searchTerm, options) {search('value', null, searchTerm, options);};
|
53
|
+
function byValueCoerced(searchTerm, options) {search('valueCoerced', null, searchTerm, options);};
|
54
|
+
function custom(fn, options) {traverse(fn, null, options);};
|
55
|
+
|
56
|
+
//******************************************************************************************
|
57
|
+
// Event logging
|
58
|
+
//******************************************************************************************
|
59
|
+
var logLevel = 'all';
|
60
|
+
logFilter = {actions: logLevel, eventNames: logLevel}; //no filter by default
|
61
|
+
|
62
|
+
function filterEventLogsByAction(/*actions*/) {
|
63
|
+
var actions = [].slice.call(arguments, 0);
|
64
|
+
|
65
|
+
logFilter.eventNames.length || (logFilter.eventNames = 'all');
|
66
|
+
logFilter.actions = actions.length ? actions : 'all';
|
67
|
+
}
|
68
|
+
|
69
|
+
function filterEventLogsByName(/*eventNames*/) {
|
70
|
+
var eventNames = [].slice.call(arguments, 0);
|
71
|
+
|
72
|
+
logFilter.actions.length || (logFilter.actions = 'all');
|
73
|
+
logFilter.eventNames = eventNames.length ? eventNames : 'all';
|
74
|
+
}
|
75
|
+
|
76
|
+
function hideAllEventLogs() {
|
77
|
+
logFilter.actions = [];
|
78
|
+
logFilter.eventNames = [];
|
79
|
+
}
|
80
|
+
|
81
|
+
function showAllEventLogs() {
|
82
|
+
logFilter.actions = 'all';
|
83
|
+
logFilter.eventNames = 'all';
|
84
|
+
}
|
85
|
+
|
86
|
+
return {
|
87
|
+
|
88
|
+
enable: function(enable) {
|
89
|
+
this.enabled = !!enable;
|
90
|
+
|
91
|
+
if (enable && window.console) {
|
92
|
+
console.info('Booting in DEBUG mode');
|
93
|
+
console.info('You can filter event logging with DEBUG.events.logAll/logNone/logByName/logByAction');
|
94
|
+
}
|
95
|
+
|
96
|
+
window.DEBUG = this;
|
97
|
+
},
|
98
|
+
|
99
|
+
find: {
|
100
|
+
byName: byName,
|
101
|
+
byNameContains: byNameContains,
|
102
|
+
byType: byType,
|
103
|
+
byValue: byValue,
|
104
|
+
byValueCoerced: byValueCoerced,
|
105
|
+
custom: custom
|
106
|
+
},
|
107
|
+
|
108
|
+
events: {
|
109
|
+
logFilter: logFilter,
|
110
|
+
|
111
|
+
// Accepts any number of action args
|
112
|
+
// e.g. DEBUG.events.logByAction("on", "off")
|
113
|
+
logByAction: filterEventLogsByAction,
|
114
|
+
|
115
|
+
// Accepts any number of event name args (inc. regex or wildcards)
|
116
|
+
// e.g. DEBUG.events.logByName(/ui.*/, "*Thread*");
|
117
|
+
logByName: filterEventLogsByName,
|
118
|
+
|
119
|
+
logAll: showAllEventLogs,
|
120
|
+
logNone: hideAllEventLogs
|
121
|
+
}
|
122
|
+
};
|
123
|
+
}
|
124
|
+
);
|
125
|
+
|
@@ -1 +1 @@
|
|
1
|
-
//=
|
1
|
+
//=require_directory ./flight
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter-flight-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.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: 2013-02-
|
12
|
+
date: 2013-02-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 2.2.1
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.2.1
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: rails
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- vendor/assets/javascripts/twitter/flight/index.js
|
99
99
|
- vendor/assets/javascripts/twitter/flight/logger.js
|
100
100
|
- vendor/assets/javascripts/twitter/flight/registry.js
|
101
|
+
- vendor/assets/javascripts/twitter/flight/tools/debug/debug.js
|
101
102
|
- vendor/assets/javascripts/twitter/flight/utils.js
|
102
103
|
homepage: https://github.com/yourabi/twitter-flight-rails
|
103
104
|
licenses: []
|