corn_js 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/corn.js +2 -1
- data/app/assets/javascripts/corn_js/corn.js +367 -229
- data/app/assets/javascripts/corn_js/fileuploader.js +1307 -0
- data/app/assets/stylesheets/corn.css +13 -0
- data/app/assets/stylesheets/corn_js/23states.css +10 -4
- data/app/assets/stylesheets/corn_js/corn.css +108 -8
- data/app/assets/stylesheets/corn_js/fileuploader.css +63 -0
- data/lib/corn_js/version.rb +1 -1
- metadata +11 -8
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
//= require_tree .
|
@@ -1,236 +1,368 @@
|
|
1
|
-
var Popcorn = function($element, defaults) {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
var Popcorn = function($element, defaults) {
|
2
|
+
this.$element = $element;
|
3
|
+
this.$anchor = null;
|
4
|
+
this.defaults = defaults;
|
5
|
+
};
|
6
|
+
|
7
|
+
Popcorn.prototype.decorateContainerWithHtml = function() {
|
8
|
+
if (this.positionType) {
|
9
|
+
throw "inferPositionType must be called after decorateContainerWithHtml";
|
10
|
+
}
|
11
|
+
this.containerOf().hide().addClass('popcorn');
|
12
|
+
this.containerOf().contents().wrap("<div class='popcorn-body'/>");
|
13
|
+
this.containerOf().append("<div class='popcorn-tail'></div>");
|
14
|
+
};
|
15
|
+
|
16
|
+
Popcorn.prototype.inferPositionType = function() {
|
17
|
+
var self = this;
|
18
|
+
self.$anchor = self.$element;
|
19
|
+
|
20
|
+
function _createPositionType(defaults) {
|
21
|
+
if(self.$element.offset().left < 1){
|
22
|
+
self.$anchor = self.$element.parent();
|
23
|
+
}
|
24
|
+
if (self.collideLeft()) { return new LeftPosition(self); }
|
25
|
+
else if (self.collideRight()) { return new RightPosition(self); }
|
26
|
+
return new CenterPosition(self);
|
27
|
+
}
|
28
|
+
|
29
|
+
self.positionType = _createPositionType(self.defaults);
|
30
|
+
};
|
31
|
+
|
32
|
+
Popcorn.prototype.decorateContainerWithArrow = function() {
|
33
|
+
if (this.positionType == undefined) { throw "inferPositionType must be called in order to set up the arrows"; }
|
34
|
+
|
35
|
+
this.containerOf().find('.popcorn-tail').css('left', this.positionType.leftOffset());
|
36
|
+
};
|
37
|
+
|
38
|
+
var LeftPosition = function(popcorn) {
|
39
|
+
// TODO centrare la freccia sull'elemento puntato da fatpopcorn
|
40
|
+
// this.leftOffset = function() {return popcorn.$element.offset().left + (popcorn.$element.width() - popcorn.defaults.arrowWidth) / 2; }
|
41
|
+
this.leftOffset = function() { return popcorn.defaults.marginArrow; }
|
42
|
+
this.left = function() { return popcorn.defaults.marginBorder; }
|
43
|
+
this.top = function() { return popcorn.$anchor.offset().top + popcorn.defaults.verticalOffsetFromElement };
|
44
|
+
};
|
45
|
+
|
46
|
+
var RightPosition = function(popcorn) {
|
47
|
+
this.leftOffset = function() { return popcorn.containerOf().width() - (popcorn.defaults.arrowWidth + popcorn.defaults.marginArrow); }
|
48
|
+
this.left = function() { return $('html').width() - popcorn.defaults.marginBorder - popcorn.containerOf().width(); }
|
49
|
+
this.top = function() { return popcorn.$anchor.offset().top + popcorn.defaults.verticalOffsetFromElement };
|
50
|
+
};
|
51
|
+
|
52
|
+
var CenterPosition = function(popcorn) {
|
53
|
+
this.leftOffset = function() { return popcorn.containerOf().width() / 2 - Math.floor(popcorn.defaults.arrowWidth / 2); }
|
54
|
+
this.left = function() {
|
55
|
+
var middleOfElement = Popcorn.calculateMiddle(popcorn.$anchor.offset().left, popcorn.$anchor.width());
|
56
|
+
return Popcorn.calculateLeftOffset(middleOfElement, popcorn.containerOf().width());
|
57
|
+
}
|
58
|
+
this.top = function() { return popcorn.$anchor.offset().top + popcorn.defaults.verticalOffsetFromElement };
|
59
|
+
};
|
60
|
+
|
61
|
+
Popcorn.containerOf = function($element) {
|
62
|
+
return $element.next();
|
9
63
|
}
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
};
|
14
|
-
|
15
|
-
Popcorn.prototype.inferPositionType = function() {
|
16
|
-
var self = this;
|
17
|
-
|
18
|
-
function _createPositionType(defaults) {
|
19
|
-
if (self.collideLeft()) { return new LeftPosition(self); }
|
20
|
-
else if (self.collideRight()) { return new RightPosition(self); }
|
21
|
-
return new CenterPosition(self);
|
64
|
+
|
65
|
+
Popcorn.prototype.containerOf = function() {
|
66
|
+
return Popcorn.containerOf(this.$element);
|
22
67
|
}
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
var LeftPosition = function(popcorn) {
|
34
|
-
// TODO centrare la freccia sull'elemento puntato da fatpopcorn
|
35
|
-
// this.leftOffset = function() {return popcorn.$element.offset().left + (popcorn.$element.width() - popcorn.defaults.arrowWidth) / 2; }
|
36
|
-
this.leftOffset = function() { return popcorn.defaults.marginArrow; }
|
37
|
-
this.left = function() { return popcorn.defaults.marginBorder; }
|
38
|
-
this.top = function() { return popcorn.$element.offset().top + popcorn.defaults.verticalOffsetFromElement };
|
39
|
-
};
|
40
|
-
|
41
|
-
var RightPosition = function(popcorn) {
|
42
|
-
this.leftOffset = function() { return popcorn.containerOf().width() - (popcorn.defaults.arrowWidth + popcorn.defaults.marginArrow); }
|
43
|
-
this.left = function() { return $('html').width() - popcorn.defaults.marginBorder - popcorn.containerOf().width(); }
|
44
|
-
this.top = function() { return popcorn.$element.offset().top + popcorn.defaults.verticalOffsetFromElement };
|
45
|
-
};
|
46
|
-
|
47
|
-
var CenterPosition = function(popcorn) {
|
48
|
-
this.leftOffset = function() { return popcorn.containerOf().width() / 2 - Math.floor(popcorn.defaults.arrowWidth / 2); }
|
49
|
-
this.left = function() {
|
50
|
-
var middleOfElement = Popcorn.calculateMiddle(popcorn.$element.offset().left, popcorn.$element.width());
|
51
|
-
return Popcorn.calculateLeftOffset(middleOfElement, popcorn.containerOf().width());
|
68
|
+
|
69
|
+
Popcorn.prototype.setContainerPosition = function() {
|
70
|
+
this.containerOf().css('top', this.positionType.top());
|
71
|
+
this.containerOf().css('left', this.positionType.left());
|
72
|
+
}
|
73
|
+
|
74
|
+
Popcorn.prototype.collideRight = function() {
|
75
|
+
var middleOfElement = Popcorn.calculateMiddle(this.$anchor.offset().left, this.$anchor.width());
|
76
|
+
var rightOffset = middleOfElement + this.containerOf().width() / 2;
|
77
|
+
return ($('html').width() - (rightOffset + this.defaults.marginBorder)) < 0;
|
52
78
|
}
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
Popcorn.containerOf = function($element) {
|
57
|
-
return $element.next();
|
58
|
-
}
|
59
|
-
|
60
|
-
Popcorn.prototype.containerOf = function() {
|
61
|
-
return Popcorn.containerOf(this.$element);
|
62
|
-
}
|
63
|
-
|
64
|
-
Popcorn.prototype.setContainerPosition = function() {
|
65
|
-
this.containerOf().css('top', this.positionType.top());
|
66
|
-
this.containerOf().css('left', this.positionType.left());
|
67
|
-
}
|
68
|
-
|
69
|
-
Popcorn.prototype.collideRight = function() {
|
70
|
-
var middleOfElement = Popcorn.calculateMiddle(this.$element.offset().left, this.$element.width());
|
71
|
-
var rightOffset = middleOfElement + this.containerOf().width() / 2;
|
72
|
-
return ($('html').width() - (rightOffset + this.defaults.marginBorder)) < 0;
|
73
|
-
}
|
74
|
-
|
75
|
-
Popcorn.prototype.collideLeft = function() {
|
76
|
-
return (Popcorn.calculateLeftOffset(this.middleOf(), this.containerOf().width()) - this.defaults.marginBorder) < 0;
|
77
|
-
}
|
78
|
-
|
79
|
-
Popcorn.prototype.middleOf = function() {
|
80
|
-
return Popcorn.calculateMiddle(this.$element.offset().left, this.$element.width());
|
81
|
-
}
|
82
|
-
|
83
|
-
Popcorn.calculateMiddle = function(left, width) {
|
84
|
-
return left + width / 2;
|
85
|
-
}
|
86
|
-
|
87
|
-
Popcorn.calculateRightOffset = function(middlePoint, width) {
|
88
|
-
return middlePoint + width / 2;
|
89
|
-
}
|
90
|
-
Popcorn.calculateLeftOffset = function(middlePoint, width) {
|
91
|
-
return middlePoint - width / 2;
|
92
|
-
}
|
93
|
-
Popcorn.containerOf = function(element) {
|
94
|
-
return $(element).next();
|
95
|
-
}
|
96
|
-
Popcorn.hideAllContainers = function($elements) {
|
97
|
-
$elements.each(function() {
|
98
|
-
Popcorn.containerOf(this).hide();
|
99
|
-
});
|
100
|
-
}
|
101
|
-
Popcorn.hideAllContainersExcept = function($elements, element) {
|
102
|
-
$elements.not(element).each(function() {
|
103
|
-
Popcorn.containerOf(this).hide()
|
104
|
-
});
|
105
|
-
};
|
106
|
-
|
107
|
-
var FatPopcorn = function($element, defaults) {
|
108
|
-
function _checkOptions(options) {
|
109
|
-
return typeof options.modelName === undefined ||
|
110
|
-
options.modelId === undefined ||
|
111
|
-
options.token === undefined ||
|
112
|
-
options.current_user === undefined;
|
113
|
-
};
|
114
|
-
var self = this;
|
115
|
-
|
116
|
-
self.$element = $element;
|
117
|
-
self.defaults = defaults;
|
118
|
-
self.attributes = defaults;
|
119
|
-
this.get = function(option) {
|
120
|
-
return self.defaults[option];
|
79
|
+
|
80
|
+
Popcorn.prototype.collideLeft = function() {
|
81
|
+
return (Popcorn.calculateLeftOffset(this.middleOf(), this.containerOf().width()) - this.defaults.marginBorder) < 0;
|
121
82
|
}
|
122
|
-
|
123
|
-
|
124
|
-
|
83
|
+
|
84
|
+
Popcorn.prototype.middleOf = function() {
|
85
|
+
return Popcorn.calculateMiddle(this.$anchor.offset().left, this.$anchor.width());
|
125
86
|
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
};
|
151
|
-
FatPopcorn.prototype.actionUrl = function() {
|
152
|
-
return '/active_metadata/' + this.get('modelName') + '/' + this.get('modelId') + '/' + this.currentLabel() + '/notes';
|
153
|
-
};
|
154
|
-
FatPopcorn.prototype.setupFormAction = function() {
|
155
|
-
$('.fatpopcorn #notes_form').attr('action', this.actionUrl());
|
156
|
-
};
|
157
|
-
FatPopcorn.prototype.setupFormToken = function() {
|
158
|
-
$('.fatpopcorn #notes_form input[name="authenticity_token"]').val(this.get('token'));
|
159
|
-
};
|
160
|
-
FatPopcorn.prototype.currentLabel = function() {
|
161
|
-
return this.$element.attr('data-label');
|
162
|
-
};
|
163
|
-
FatPopcorn.hideContainer = function() {
|
164
|
-
$(window).off('resize');
|
165
|
-
return FatPopcorn.container().hide();
|
166
|
-
}
|
167
|
-
FatPopcorn.container = function() {
|
168
|
-
return $('.fatpopcorn').first();
|
169
|
-
}
|
170
|
-
FatPopcorn.prototype.containerOf = function() {
|
171
|
-
return $('.fatpopcorn').first();
|
172
|
-
}
|
173
|
-
|
174
|
-
FatPopcorn.decorateContainerWithHtml = function() {
|
175
|
-
var self = this;
|
176
|
-
function _html() {
|
177
|
-
return '<div class="fatpopcorn"><div class="popcorn-body"><div class="header"><ul><li class="stream-tab active"><div>stream</div></li>' +
|
178
|
-
'<li class="edit-tab"><div>edit</div></li><li class="history-tab"><div>history</div></li></ul></div>' +
|
179
|
-
'<div class="stream"><div class="content"></div></div><div class="history"><div class="content"></div></div>' +
|
180
|
-
'<div class="edit"><div class="watchlist"><h1>Watchlist</h1><div class="on-off _23states"><input type="radio" ' +
|
181
|
-
'name="on" value="on" id="on"><label for="on" class="true"><span class="true">On</span></label><input type="radio" name="off" value="off" id="off"><label for="off" class="false">' +
|
182
|
-
'<span class="false">Off</span></label></div></div><hr/><div class="note"><h1>Nota</h1><form form action="" method="post" id="notes_form"><div style="margin:0;padding:0;display:inline"><input type="hidden" value="✓" name="utf8"><input type="hidden" value="' + self['token'] + '" name="authenticity_token"></div>' +
|
183
|
-
'<textarea name="note" rows="4"></textarea><a id="send_note" href="#">Inserisci</a></form></div><hr/>' +
|
184
|
-
'<div class="attachment"><h1>Allegati</h1><a href="#">Inserisci</a></div><div class="info"><h1>Info</h1><p>Lorem ipsum...</p></div></div></div><div class="popcorn-tail"></div><span class="loader"></span></div>';
|
87
|
+
|
88
|
+
Popcorn.calculateMiddle = function(left, width) {
|
89
|
+
return left + width / 2;
|
90
|
+
}
|
91
|
+
|
92
|
+
Popcorn.calculateRightOffset = function(middlePoint, width) {
|
93
|
+
return middlePoint + width / 2;
|
94
|
+
}
|
95
|
+
Popcorn.calculateLeftOffset = function(middlePoint, width) {
|
96
|
+
return middlePoint - width / 2;
|
97
|
+
}
|
98
|
+
Popcorn.containerOf = function(element) {
|
99
|
+
return $(element).next();
|
100
|
+
}
|
101
|
+
Popcorn.hideAllContainers = function($elements) {
|
102
|
+
$elements.each(function() {
|
103
|
+
Popcorn.containerOf(this).hide();
|
104
|
+
});
|
105
|
+
}
|
106
|
+
Popcorn.hideAllContainersExcept = function($elements, element) {
|
107
|
+
$elements.not(element).each(function() {
|
108
|
+
Popcorn.containerOf(this).hide()
|
109
|
+
});
|
185
110
|
};
|
186
|
-
|
187
|
-
|
188
|
-
|
111
|
+
|
112
|
+
var FatPopcorn = function($element, defaults) {
|
113
|
+
function _checkOptions(options) {
|
114
|
+
return typeof options.modelId === undefined ||
|
115
|
+
options.token === undefined ||
|
116
|
+
options.current_user === undefined;
|
117
|
+
};
|
118
|
+
var self = this;
|
119
|
+
|
120
|
+
self.$element = $element;
|
121
|
+
|
122
|
+
self.defaults = defaults;
|
123
|
+
self.attributes = defaults;
|
124
|
+
this.get = function(option) {
|
125
|
+
return self.defaults[option];
|
126
|
+
}
|
127
|
+
|
128
|
+
self.defaults['modelName'] = self.$element.attr('data-model');
|
129
|
+
|
130
|
+
if (_checkOptions(self.defaults)){
|
131
|
+
throw("parameters [modelId], [token], [current_user] are required");
|
132
|
+
}
|
133
|
+
};
|
134
|
+
FatPopcorn.prototype = new Popcorn();
|
135
|
+
|
136
|
+
FatPopcorn.prototype.init = function() {
|
137
|
+
this.setupFormAction();
|
138
|
+
this.setupFormToken();
|
139
|
+
this.setupStreamUrl();
|
140
|
+
this.setupHistoryUrl();
|
141
|
+
this.setupAttachmentsUrl();
|
142
|
+
this.setupWatchlistUrl();
|
143
|
+
|
144
|
+
if (this.hasStream()) {
|
145
|
+
$('.fatpopcorn .stream-tab').click();
|
146
|
+
}
|
147
|
+
else {
|
148
|
+
$('.fatpopcorn .edit-tab').click();
|
149
|
+
}
|
150
|
+
};
|
151
|
+
|
152
|
+
FatPopcorn.prototype.setupStreamUrl = function() {
|
153
|
+
$('.fatpopcorn .stream').attr('data-url', this.streamUrl());
|
154
|
+
};
|
155
|
+
FatPopcorn.prototype.setupAttachmentsUrl = function() {
|
156
|
+
FatPopcorn.createAttachmentButton(this.attachmentsUrl());
|
157
|
+
$('.fatpopcorn .edit').attr('data-attach-url', this.attachmentsUrl());
|
158
|
+
};
|
159
|
+
FatPopcorn.prototype.setupWatchlistUrl = function() {
|
160
|
+
$('.fatpopcorn .edit').attr('data-url', this.watchlistUrl());
|
161
|
+
};
|
162
|
+
FatPopcorn.prototype.setupHistoryUrl = function() {
|
163
|
+
$('.fatpopcorn .history').attr('data-url', this.historyUrl());
|
164
|
+
};
|
165
|
+
FatPopcorn.prototype.setupFormAction = function() {
|
166
|
+
$('.fatpopcorn #notes_form').attr('action', this.actionUrl());
|
167
|
+
$('.fatpopcorn .edit').attr('data-note-url', this.actionUrl());
|
168
|
+
};
|
169
|
+
FatPopcorn.prototype.setupFormToken = function() {
|
170
|
+
$('.fatpopcorn #notes_form input[name="authenticity_token"]').val(FatPopcorn.formToken());
|
171
|
+
};
|
172
|
+
FatPopcorn.prototype.actionUrl = function() {
|
173
|
+
return this.urlPrefix() + '/notes';
|
174
|
+
};
|
175
|
+
FatPopcorn.prototype.streamUrl = function() {
|
176
|
+
return this.urlPrefix() + '/stream';
|
177
|
+
};
|
178
|
+
FatPopcorn.prototype.attachmentsUrl = function() {
|
179
|
+
return this.urlPrefix() + '/attachments';
|
180
|
+
};
|
181
|
+
FatPopcorn.prototype.watchlistUrl = function() {
|
182
|
+
return this.urlPrefix() + '/watchers/' + this.defaults.current_user;
|
183
|
+
};
|
184
|
+
FatPopcorn.prototype.historyUrl = function() {
|
185
|
+
return this.urlPrefix() + '/histories';
|
186
|
+
};
|
187
|
+
FatPopcorn.prototype.urlPrefix = function() {
|
188
|
+
return '/active_metadata/' + this.get('modelName') + '/' + this.get('modelId') + '/' + this.currentLabel();
|
189
|
+
};
|
190
|
+
FatPopcorn.prototype.currentLabel = function() {
|
191
|
+
return this.$element.attr('data-label');
|
192
|
+
};
|
193
|
+
FatPopcorn.prototype.hasStream = function() {
|
194
|
+
return this.$element.attr('data-stream') === 'true';
|
195
|
+
};
|
196
|
+
FatPopcorn.hideContainer = function() {
|
197
|
+
$(window).off('resize');
|
198
|
+
return FatPopcorn.container().hide();
|
189
199
|
}
|
190
|
-
FatPopcorn.container()
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
FatPopcorn.prototype.
|
200
|
+
FatPopcorn.container = function() {
|
201
|
+
return $('.fatpopcorn').first();
|
202
|
+
}
|
203
|
+
FatPopcorn.prototype.containerOf = function() {
|
204
|
+
return $('.fatpopcorn').first();
|
205
|
+
}
|
206
|
+
FatPopcorn.onCompleteUpload = function(id, fileName, response, qq) {
|
207
|
+
if(qq.getQueue().length == 1) {
|
208
|
+
$('.qq-upload-list').empty();
|
209
|
+
}
|
210
|
+
if(!response.success){
|
211
|
+
K.message.error(K.message.buildListOfErrors(response.errors));
|
212
|
+
return;
|
213
|
+
}
|
214
|
+
|
215
|
+
$('.stream-tab').click();
|
216
|
+
}
|
217
|
+
FatPopcorn.decorateContainerWithHtml = function() {
|
218
|
+
var self = this;
|
219
|
+
function _html() {
|
220
|
+
return '<div class="fatpopcorn"><div class="popcorn-body"><div class="header"><ul><li class="stream-tab"><div>stream</div></li>' +
|
221
|
+
'<li class="edit-tab"><div>edit</div></li><li class="history-tab"><div>history</div></li></ul></div>' +
|
222
|
+
'<div class="stream"><div class="content"></div></div><div class="history"><div class="content"></div></div>' +
|
223
|
+
'<div class="edit"><div class="watchlist"><h1>Watchlist</h1><div class="on-off _23states"><input name="watchlist" id="watchlist_true" value="true" type="radio"><label class="true" for="watchlist_true"><span>On</span></label><input checked="checked" name="watchlist" id="watchlist_false" value="false" type="radio"><label class="false" for="watchlist_false"><span>Off</span></label></div></div><hr/>' +
|
224
|
+
'<div class="note"><h1>Nota</h1><form form action="" method="post" id="notes_form"><div style="margin:0;padding:0;display:inline"><input type="hidden" value="✓" name="utf8"><input type="hidden" value="' + self['token'] + '" name="authenticity_token"></div>' +
|
225
|
+
'<textarea id="note_text" name="note" rows="4"></textarea><a id="send_note" href="#">Inserisci</a></form></div><hr/>' +
|
226
|
+
'<div class="attachment"><h1>Allegati</h1><div id="fatpopcorn_attach"></div><div id="attach_output"></div></div>' +
|
227
|
+
'<div class="info"><h1>Info</h1><p>Lorem ipsum...</p></div></div></div><div class="popcorn-tail"></div><span class="loader"></span></div>';
|
228
|
+
};
|
229
|
+
|
230
|
+
if (FatPopcorn.container().size() == 0) {
|
231
|
+
$('body').append(_html());
|
232
|
+
}
|
233
|
+
FatPopcorn.container().hide();
|
234
|
+
}
|
235
|
+
|
236
|
+
FatPopcorn.prototype.addGripToElement = function($element) {
|
237
|
+
if (!$element.parent().is('span.fatpopcorn_grip') && this.defaults.autoWrap) {
|
238
|
+
$element.wrap('<span class="fatpopcorn_grip"/>')
|
239
|
+
}
|
240
|
+
return $element.parent();
|
241
|
+
};
|
242
|
+
FatPopcorn.prototype.gripOf = function($element) {
|
243
|
+
return $element.parent();
|
244
|
+
};
|
245
|
+
|
246
|
+
FatPopcorn.activateTheClickedTab = function() {
|
247
|
+
$('.fatpopcorn .header > ul > li').click(function(e){
|
248
|
+
var self = this;
|
249
|
+
|
250
|
+
function _tabBodyName(tabName) { return tabName.split('-')[0].trim(); };
|
251
|
+
function _currentTabName() { return _tabBodyName($(self).attr('class')); };
|
252
|
+
function _currentTab() { return $('.' + _currentTabName()); };
|
253
|
+
function _currentTabMethod() { return _currentTabName() + "Event"; }
|
254
|
+
|
255
|
+
e.stopPropagation();
|
256
|
+
e.preventDefault();
|
257
|
+
|
258
|
+
$('.fatpopcorn .active').removeClass('active');
|
259
|
+
$('.fatpopcorn .popcorn-body > div:not(.header)').hide();
|
260
|
+
|
261
|
+
_currentTab().show();
|
233
262
|
|
263
|
+
$(this).addClass('active');
|
264
|
+
|
265
|
+
FatPopcorn[_currentTabMethod()].call();
|
266
|
+
});
|
267
|
+
};
|
268
|
+
FatPopcorn.streamEvent = function() {
|
269
|
+
$.ajax($('.fatpopcorn .stream').attr('data-url'))
|
270
|
+
.success(FatPopcorn.getStreamSuccess);
|
271
|
+
};
|
272
|
+
FatPopcorn.editEvent = function() {
|
273
|
+
// should do something?
|
274
|
+
};
|
275
|
+
FatPopcorn.historyEvent = function() {
|
276
|
+
$.ajax($('.fatpopcorn .history').attr('data-url'))
|
277
|
+
.success(FatPopcorn.getHistorySuccess);
|
278
|
+
};
|
279
|
+
FatPopcorn.containerVisible = function () {
|
280
|
+
return FatPopcorn.container().is(':visible');
|
281
|
+
};
|
282
|
+
FatPopcorn.formToken = function() {
|
283
|
+
return $('meta[name="csrf-token"]').attr('content');
|
284
|
+
};
|
285
|
+
FatPopcorn.createAttachmentButton = function(actionUrl) {
|
286
|
+
delete FatPopcorn.uploader;
|
287
|
+
FatPopcorn.uploader = new qq.FileUploader({
|
288
|
+
element: document.getElementById('fatpopcorn_attach'),
|
289
|
+
allowedExtensions: [],
|
290
|
+
params: { authenticity_token: FatPopcorn.formToken(), target: "attach_output"},
|
291
|
+
uploadButtonText: 'Inserisci',
|
292
|
+
action: actionUrl,
|
293
|
+
multiple: true,
|
294
|
+
onComplete: FatPopcorn.onCompleteUpload
|
295
|
+
});
|
296
|
+
};
|
297
|
+
|
298
|
+
FatPopcorn.bindRemoteEvents = function() {
|
299
|
+
|
300
|
+
function _startWatching() {
|
301
|
+
_callWatchlistService({authenticity_token: FatPopcorn.formToken() });
|
302
|
+
};
|
303
|
+
function _stopWatching() {
|
304
|
+
_callWatchlistService({_method: 'delete', authenticity_token: FatPopcorn.formToken() });
|
305
|
+
};
|
306
|
+
function _callWatchlistService(data) {
|
307
|
+
$.post($('.fatpopcorn .edit').attr('data-url'), data).success(function() {console.log("watchlist success")});
|
308
|
+
};
|
309
|
+
|
310
|
+
$('.fatpopcorn').on('click', function(e) {
|
311
|
+
e.stopPropagation();
|
312
|
+
});
|
313
|
+
$('.fatpopcorn #watchlist_true').click(function() {
|
314
|
+
_startWatching()
|
315
|
+
});
|
316
|
+
$('.fatpopcorn #watchlist_false').click(function() {
|
317
|
+
_stopWatching();
|
318
|
+
});
|
319
|
+
|
320
|
+
$('#send_note').click(function() {
|
321
|
+
if ($('#note_text').val() == '') return false;
|
322
|
+
|
323
|
+
$.post($('form#notes_form').attr('action'), $('form#notes_form').serialize()).success('success.rails', FatPopcorn.newNoteSuccess);
|
324
|
+
});
|
325
|
+
$('.loader').ajaxSend(function(e) { $(this).show(); });
|
326
|
+
$('.loader').ajaxComplete(function() { $(this).hide(); });
|
327
|
+
};
|
328
|
+
|
329
|
+
FatPopcorn.newNoteSuccess = function(data) {
|
330
|
+
$('.fatpopcorn textarea#note_text').val('');
|
331
|
+
$('.fatpopcorn .stream-tab').click();
|
332
|
+
};
|
333
|
+
|
334
|
+
FatPopcorn.getStreamSuccess = function(data) {
|
335
|
+
$('.fatpopcorn .stream .content').empty();
|
336
|
+
$('.fatpopcorn .stream .content').append(data);
|
337
|
+
$('.fatpopcorn .stream .attachment span.delete').click(FatPopcorn.deleteAttachment);
|
338
|
+
$('.fatpopcorn .stream .note span.delete').click(FatPopcorn.deleteNote);
|
339
|
+
};
|
340
|
+
FatPopcorn.deleteAttachment = function(e) {
|
341
|
+
FatPopcorn.deleteStream(e, $('.fatpopcorn .edit').attr('data-attach-url'));
|
342
|
+
};
|
343
|
+
FatPopcorn.deleteNote = function(e) {
|
344
|
+
FatPopcorn.deleteStream(e, $('.fatpopcorn .edit').attr('data-note-url'));
|
345
|
+
};
|
346
|
+
FatPopcorn.deleteStream = function(e, urlPrefix) {
|
347
|
+
function _url() {
|
348
|
+
return urlPrefix + '/' + $(e.target).parent().attr('data-id');
|
349
|
+
}
|
350
|
+
|
351
|
+
$.post(_url(), {_method: 'delete'}).
|
352
|
+
success('success.rails', FatPopcorn.deleteSuccess).
|
353
|
+
fail(FatPopcorn.deleteFailure);
|
354
|
+
};
|
355
|
+
FatPopcorn.deleteSuccess = function() {
|
356
|
+
$('.fatpopcorn .stream-tab').click();
|
357
|
+
console.log('deleted attach success');
|
358
|
+
};
|
359
|
+
FatPopcorn.deleteFailure = function() {
|
360
|
+
console.log('deleted attach failure');
|
361
|
+
};
|
362
|
+
FatPopcorn.getHistorySuccess = function(data) {
|
363
|
+
$('.fatpopcorn .history .content').empty();
|
364
|
+
$('.fatpopcorn .history .content').append(data);
|
365
|
+
};
|
234
366
|
(function($) {
|
235
367
|
$.fn.fatpopcorn = function(options) {
|
236
368
|
|
@@ -252,15 +384,22 @@ FatPopcorn.prototype.newNoteSuccess = function() { $('.stream-tab').click(); };
|
|
252
384
|
FatPopcorn.decorateContainerWithHtml();
|
253
385
|
FatPopcorn.activateTheClickedTab();
|
254
386
|
FatPopcorn.bindRemoteEvents();
|
255
|
-
|
387
|
+
FatPopcorn.createAttachmentButton();
|
388
|
+
|
256
389
|
function _setUpElement() {
|
257
390
|
var $element = $(this), fatpopcorn = new FatPopcorn($element, defaults);
|
258
391
|
fatpopcorn.addGripToElement($element);
|
259
|
-
|
392
|
+
|
393
|
+
fatpopcorn.gripOf($element).children().click(function(e) {
|
394
|
+
$(e.target).data('elementMatched', true);
|
395
|
+
});
|
396
|
+
|
260
397
|
fatpopcorn.gripOf($element).click(function(e) {
|
398
|
+
if ($(e.target).data('elementMatched')) return;
|
399
|
+
|
261
400
|
e.stopPropagation();
|
262
401
|
e.preventDefault();
|
263
|
-
fatpopcorn.
|
402
|
+
fatpopcorn.init();
|
264
403
|
|
265
404
|
if (FatPopcorn.containerVisible()) {
|
266
405
|
FatPopcorn.hideContainer();
|
@@ -272,7 +411,6 @@ FatPopcorn.prototype.newNoteSuccess = function() { $('.stream-tab').click(); };
|
|
272
411
|
fatpopcorn.decorateContainerWithArrow();
|
273
412
|
fatpopcorn.containerOf().show();
|
274
413
|
|
275
|
-
|
276
414
|
$(window).on('resize',function() {
|
277
415
|
if (FatPopcorn.containerVisible()) fatpopcorn.setContainerPosition();
|
278
416
|
});
|