stormfront-rails 0.1.0 → 0.2.3

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/lib/stormfront/rails/version.rb +2 -2
  4. data/lib/stormfront/rails.rb +2 -0
  5. data/stormfront-rails.gemspec +3 -3
  6. data/vendor/assets/javascripts/src/handlebars.js +4604 -0
  7. data/vendor/assets/javascripts/src/stormfront.js +1137 -0
  8. data/vendor/assets/javascripts/stormfront.js +3 -32
  9. metadata +24 -47
  10. data/vendor/assets/javascripts/stormfront/Alert.js +0 -17
  11. data/vendor/assets/javascripts/stormfront/Container.js +0 -31
  12. data/vendor/assets/javascripts/stormfront/Entity.js +0 -53
  13. data/vendor/assets/javascripts/stormfront/Errors.js +0 -25
  14. data/vendor/assets/javascripts/stormfront/KeyboardEvents.js +0 -52
  15. data/vendor/assets/javascripts/stormfront/Layout.js +0 -60
  16. data/vendor/assets/javascripts/stormfront/List.js +0 -123
  17. data/vendor/assets/javascripts/stormfront/MouseEvents.js +0 -146
  18. data/vendor/assets/javascripts/stormfront/Namespaces.js +0 -5
  19. data/vendor/assets/javascripts/stormfront/Overlay.js +0 -178
  20. data/vendor/assets/javascripts/stormfront/Reducer.js +0 -9
  21. data/vendor/assets/javascripts/stormfront/Request.js +0 -39
  22. data/vendor/assets/javascripts/stormfront/View.js +0 -55
  23. data/vendor/assets/javascripts/stormfront/ViewBase.js +0 -57
  24. data/vendor/assets/javascripts/stormfront/mixin/Dispatch.js +0 -19
  25. data/vendor/assets/javascripts/stormfront/mixin/Other.js +0 -25
  26. data/vendor/assets/javascripts/stormfront/support/Chaperone.js +0 -69
  27. data/vendor/assets/javascripts/stormfront/support/Template.js +0 -75
  28. data/vendor/assets/javascripts/stormfront/types/Arguments.js +0 -27
  29. data/vendor/assets/javascripts/stormfront/types/Class.js +0 -25
  30. data/vendor/assets/javascripts/stormfront/types/Hash.js +0 -23
  31. data/vendor/assets/javascripts/stormfront/types/Number.js +0 -15
  32. data/vendor/assets/javascripts/stormfront/types/Response.js +0 -31
  33. data/vendor/assets/javascripts/stormfront/types/String.js +0 -44
  34. data/vendor/assets/javascripts/stormfront/types/Time.js +0 -29
@@ -1,123 +0,0 @@
1
- Stormfront.List = Stormfront.View.compose({
2
- base: {
3
- initializing: function(){
4
- this.itemViews = {};
5
- },
6
- rendering: function(){
7
- this.darkness = $('<div></div>').addClass('hidden');
8
- this.getContent().after(this.darkness);
9
- this.base.collection.sync.call(this);
10
- },
11
- collection: {
12
- error: function(collection, xhr){
13
- if (xhr.handled || xhr.status == 401)
14
- return;
15
- function requestAppearsAborted(xhr){
16
- return xhr.readyState != 4;
17
- }
18
- if (requestAppearsAborted(xhr)){
19
- xhr.handled = true;
20
- console.warn('Request appears aborted', xhr);
21
- } else {
22
- try {
23
- var message = JSON.parse(xhr.responseText);
24
- var error = message.error || message.message;
25
- this.alertUser(error);
26
- xhr.handled = true;
27
- }
28
- catch(e) {
29
- console.warn('Unhandled error', xhr, e);
30
- }
31
- }
32
- },
33
- invalid: function(model, error){
34
- this.alertUser(error);
35
- },
36
- add: function(model){
37
- var options = this.getModel(model);
38
- var type = this.getItemType();
39
- var view = new type(options);
40
- this.setView(model, view);
41
- this.observeView(view);
42
- this.appendContent(view.render().$el).and('item:rendered', view);
43
- },
44
- remove: function(model){
45
- var view = this.getView(model);
46
- this.removeView(view);
47
- //Remove has a bug that causes sync not to happen
48
- this.collection.trigger('sync', this.collection);
49
- },
50
- reset: function(){
51
- this.each(this.removeView);
52
- this.collection.each(this.base.collection.add, this);
53
- //This is a handy re-use of other code paths
54
- this.collection.trigger('sync', this.collection);
55
- }
56
- }
57
- },
58
- initialize: function(options){
59
- this.collection = options.collection;
60
- this.register(this.collection, 'collection');
61
- this.subscribe(this.base);
62
- },
63
- removeView: function(view){
64
- this.stopListening(view);
65
- view.close();
66
- delete this.itemViews[view.model.cid];
67
- this.trigger('item:removed', view);
68
- },
69
- observeView: function(view){
70
- this.register(view, 'item');
71
- this.forward(view);
72
- },
73
-
74
- getModel: function(model){
75
- return { model: model };
76
- },
77
- getItemType: function(){
78
- return this.itemView;
79
- },
80
- eject: function(){
81
- this.getContent().children().appendTo(this.darkness);
82
- },
83
-
84
- alertUser: function(error){
85
- this.alerts = this.alerts || [];
86
-
87
- if (!_.contains(this.alerts, error)){
88
- this.alerts.push(error);
89
- alert(error);
90
- this.alerts = _.without(this.alerts, error);
91
- }
92
- },
93
-
94
- appendContent: function(el){
95
- return new CollectionRenderContext(this).append(el);
96
- },
97
- getContent: function(other){
98
- var selector = other ? '.collection > ' + other : '.collection';
99
- return this.$(selector).first();
100
- },
101
-
102
- getView: function(model){
103
- return this.itemViews[model.cid];
104
- },
105
- setView: function(model, view){
106
- this.itemViews[model.cid] = view;
107
- },
108
- each: function(predicate){
109
- _.each(this.itemViews, predicate, this);
110
- }
111
- });
112
-
113
- var CollectionRenderContext = function(root){
114
- this.append = function (el) {
115
- root.getContent().append(el);
116
- return this;
117
- };
118
- this.and = function(state) {
119
- root.transition.apply(root, arguments);
120
- return this;
121
- };
122
- return this;
123
- };
@@ -1,146 +0,0 @@
1
- MouseEvents = Stormfront.Class.extend({
2
- initialize: function(options){
3
- options = _.extend({delay: 175}, options);
4
- this.delay = options.delay ? options.delay : 175;
5
- this.public = _.clone(Backbone.Events);
6
- this.internal = _.clone(Backbone.Events);
7
- },
8
- listen: function(target){
9
- this.$el = target;
10
- this.$el.global = $(document);
11
- this.el = this.$el[0];
12
-
13
- var self = this;
14
- function enterStandardEventMode() {
15
- self.$el.on('wheel.me', handleMouseWheel);
16
- self.$el.on('mousewheel.me', handleMouseWheel);
17
- self.$el.one('mousedown.me', handleFirstMouseDown);
18
-
19
- function handleFirstMouseDown(eventArgs) {
20
- self.$el.one('mousemove.me', enterDraggingMode);
21
-
22
- self.$el.one('mousedown.me', handleSubsequentMouseDown);
23
- self.internal.once("special:single-click:down", function() { handleSpecialMouseDown(eventArgs)});
24
- self.$el.global.one('mouseup.me', handleFirstMouseUp);
25
- delay("special:single-click:down", eventArgs);
26
- }
27
-
28
- function handleFirstMouseUp(eventArgs) {
29
- self.$el.off('mousemove.me');
30
- self.internal.once("special:single-click:up", function() { handleSpecialMouseUp(eventArgs); });
31
- delay("special:single-click:up", eventArgs);
32
- }
33
-
34
- function delay(event, eventArgs){
35
- setTimeout(function() { publishInternalEvent(event, eventArgs);}, self.delay);
36
- }
37
-
38
- function handleSpecialMouseDown(eventArgs) {
39
- self.$el.off('mousedown.me');
40
- self.$el.one('mousedown.me', handleFirstMouseDown);
41
- publishExternalEvent("single-click:down", eventArgs);
42
- }
43
-
44
- function handleSpecialMouseUp(eventArgs) {
45
- publishExternalEvent("single-click:up", eventArgs);
46
- }
47
-
48
- function handleSubsequentMouseDown(eventArgs) {
49
- self.internal.off("special:single-click:down");
50
- self.$el.one('mousedown.me', handleFirstMouseDown);
51
- self.$el.global.one('mouseup.me', handleSubsequentMouseUp);
52
- publishExternalEvent("double-click:down", eventArgs);
53
- }
54
-
55
- function handleSubsequentMouseUp(eventArgs) {
56
- self.internal.off("special:single-click:up");
57
- publishExternalEvent("double-click:up", eventArgs);
58
- }
59
-
60
- function handleMouseWheel(eventArgs) {
61
- publishExternalEvent("mousewheel", eventArgs);
62
- }
63
- }
64
-
65
- function exitStandardEventMode() {
66
- self.$el.off('mousedown.me');
67
- self.$el.global.off('mouseup.me');
68
- self.$el.off('mousemove.me');
69
- self.$el.off('wheel.me');
70
- self.$el.off('mousewheel.me');
71
- self.internal.off("special:single-click:down");
72
- self.internal.off("special:single-click:up");
73
- }
74
-
75
- function enterDraggingMode(eventArgs) {
76
- function handleMouseMove(eventArgs) {
77
- publishExternalEvent("dragging:move", eventArgs);
78
- }
79
-
80
- function handleMouseUp(eventArgs) {
81
- publishExternalEvent("dragging:end", eventArgs);
82
- exitDraggingMode();
83
- enterStandardEventMode();
84
- }
85
-
86
- exitStandardEventMode();
87
- publishExternalEvent("dragging:start", eventArgs);
88
- self.$el.global.on('mousemove.me', handleMouseMove);
89
- self.$el.global.one('mouseup.me', handleMouseUp);
90
- }
91
-
92
- function exitDraggingMode() {
93
- self.$el.off('mouseup.me');
94
- self.$el.global.off('mousemove.me');
95
- self.$el.global.off('mousedown.me');
96
- }
97
-
98
- function disableUnsupportedEvents() {
99
- self.$el.global.on('selectstart.me', function(eventArgs) {
100
- eventArgs.preventDefault();
101
- eventArgs.stopPropagation();
102
- return false; });
103
- self.$el.on("contextmenu.me", function(eventArgs) {
104
- eventArgs.preventDefault();
105
- eventArgs.stopPropagation();
106
- return false; });
107
- }
108
-
109
- function publishInternalEvent(event, eventArgs){
110
- publishEvent(self.internal, event, eventArgs);
111
- }
112
- function publishExternalEvent(event, eventArgs){
113
- publishEvent(self.public, event, eventArgs);
114
- }
115
- function publishEvent(publisher, event, eventArgs){
116
- function getMousePosition(eventArgs) {
117
- var offset = self.$el.offset();
118
- var relativeX = eventArgs.originalEvent.pageX - offset.left;
119
- var relativeY = eventArgs.originalEvent.pageY - offset.top;
120
- eventArgs.preventDefault();
121
- eventArgs.stopPropagation();
122
- return {
123
- x: relativeX,
124
- y: relativeY
125
- };
126
- }
127
- var position = getMousePosition(eventArgs);
128
- publisher.trigger(event, position, eventArgs.originalEvent);
129
- }
130
-
131
- enterStandardEventMode();
132
- disableUnsupportedEvents();
133
- },
134
- on: function(event, callback){
135
- this.public.on(event, callback);
136
- return this;
137
- },
138
- off: function(event ,callback){
139
- this.public.off(event, callback);
140
- return this;
141
- },
142
- stopListening: function(){
143
- this.$el && this.$el.off('.me');
144
- this.$el.global && this.$el.global.off('.me');
145
- }
146
- });
@@ -1,5 +0,0 @@
1
- stormfront = { };
2
-
3
- Stormfront = {
4
- Mixin: { }
5
- };
@@ -1,178 +0,0 @@
1
- Stormfront.Overlay = Stormfront.Class.extend({
2
- initialize: function(options){
3
- var selector = options.selector;
4
-
5
- if (!selector)
6
- this.overlay = new Stormfront.FullScreenOverlay({model: options});
7
- else if (options.saveRequest)
8
- this.overlay = new Stormfront.InlineOverlay();
9
- else
10
- this.overlay = new Stormfront.AnonymousOverlay();
11
-
12
- selector = selector ? selector : document.body;
13
- this.location = selector.size ? selector : $(selector);
14
- this.render();
15
- },
16
- render: function(){
17
- this.location.append(this.overlay.render().$el);
18
- this.overlay.transition('attached');
19
- return this;
20
- },
21
- close: function(){
22
- this.overlay.close();
23
- this.location = null;
24
- },
25
- error: function(){
26
- this.overlay.error.apply(this.overlay, arguments);
27
- }
28
- });
29
-
30
- Stormfront.OverlayBase = Stormfront.View.extend({
31
- className: 'overlay',
32
- activated: false,
33
- PAUSE_DURATION: 0,
34
- MINIMUM_DURATION: 0,
35
- base_css: {
36
- overlay_background: {
37
- top: '0px', left: '0px',
38
- width: '100%', height: '100%'
39
- },
40
- overlay_panel: {
41
- position: 'absolute',
42
- top: '50%', left: '50%'
43
- }
44
- },
45
- base: {
46
- rendering: function(){
47
- function applyCss(value, key){
48
- var selector = '.' + key;
49
- this.$(selector).css(value);
50
- }
51
- this.startTime = stormfront.time().now();
52
- _.each(this.base_css, applyCss, this);
53
- _.each(this.css, applyCss, this);
54
- this.$el.css({opacity: '0', 'pointer-events': 'none'});
55
- },
56
- attached: function(){
57
- var self = this;
58
- function activate(){
59
- self.$el.css({opacity: '1', 'pointer-events': 'auto'});
60
- self.activated = true;
61
- }
62
- function setDimensions(panel){
63
- var content = self.$('.content');
64
- var position = {
65
- 'margin-left': - content.outerWidth() / 2,
66
- 'margin-top': - content.outerHeight() / 2
67
- };
68
- panel.css(position);
69
- }
70
- setDimensions(this.$('.overlay_panel'));
71
- if (this.PAUSE_DURATION)
72
- setTimeout(activate, this.PAUSE_DURATION);
73
- else
74
- activate();
75
- },
76
- closing: function(){
77
- var self = this;
78
- function remove(){
79
- self.remove();
80
- }
81
- if (!this.activated)
82
- this.remove();
83
-
84
- var currentDuration = stormfront.time().now() - this.startTime;
85
- var remainingDuration = this.MINIMUM_DURATION - currentDuration;
86
- if (remainingDuration > 0)
87
- setTimeout(remove, remainingDuration);
88
- else
89
- this.remove();
90
- }
91
- },
92
- initialize: function(){
93
- this.addSubscriber(this.base);
94
- Stormfront.View.prototype.initialize.apply(this, arguments);
95
- },
96
- error: function(){
97
- this.remove();
98
- },
99
- close: function(){
100
- this.transition.apply(this, stormfront.arguments(arguments).prepend('closing').get());
101
- }
102
- });
103
-
104
- Stormfront.FullScreenOverlay = Stormfront.OverlayBase.extend({
105
- MINIMUM_DURATION: 900,
106
- css: {
107
- overlay_background: {
108
- position: 'fixed',
109
- 'z-index': '100000'
110
- },
111
- overlay_panel: {
112
- 'z-index': '100001'
113
- }
114
- },
115
- when: {
116
- rendering: function(){
117
- this.$el.addClass('blocking');
118
- }
119
- }
120
- });
121
-
122
- Stormfront.AnonymousOverlay = Stormfront.OverlayBase.extend({
123
- PAUSE_DURATION: 200,
124
- MINIMUM_DURATION: 450,
125
- css: {
126
- overlay_background: {
127
- position: 'absolute',
128
- 'z-index': 'auto'
129
- },
130
- overlay_panel: {
131
- 'z-index': 'auto'
132
- }
133
- },
134
- when: {
135
- rendering: function(){
136
- this.$el.addClass('anonymous');
137
- }
138
- }
139
- });
140
-
141
- Stormfront.InlineOverlay = Stormfront.OverlayBase.extend({
142
- className: 'input_overlay',
143
- MINIMUM_DURATION: 1500,
144
- MAXIMUM_WIDTH: 1200,
145
- base_css: {
146
- input: {
147
- position: 'absolute',
148
- top: '2px',
149
- right: '10px',
150
- width:'16px',
151
- 'z-index':'10000'
152
- }
153
- },
154
- when: {
155
- rendering: function () {
156
- this.$el.find('.error').hide();
157
- this.$el.find('.confirm').hide();
158
- },
159
- closing: function(){
160
- this.$el.find('.spinner').hide();
161
- this.$el.find('.confirm').show();
162
- }
163
- },
164
- error: function (xhr) {
165
- //TODO: Elevate this code up a level to the Request
166
- try {
167
- var response = JSON.parse(xhr.responseText);
168
- var error = response.error || response.message;
169
- this.$el.find('.spinner').hide();
170
- this.$el.find('.error').show().attr('title', error);
171
- xhr.handled = true;
172
- }
173
- catch (e) {
174
- console.warn('Could not parse error', arguments);
175
- this.remove();
176
- }
177
- }
178
- });