corn_js 0.1.3 → 0.1.4
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/app/assets/javascripts/corn_js/corn.js +453 -346
- data/app/assets/stylesheets/corn_js/corn.css +5 -1
- data/lib/corn_js/version.rb +1 -1
- metadata +8 -8
@@ -1,368 +1,461 @@
|
|
1
|
-
|
1
|
+
var Popcorn = function ($element, defaults) {
|
2
2
|
this.$element = $element;
|
3
3
|
this.$anchor = this.$element;
|
4
|
-
this.defaults =
|
5
|
-
|
4
|
+
this.defaults = defaults;
|
5
|
+
};
|
6
6
|
|
7
|
-
|
7
|
+
Popcorn.prototype.decorateContainerWithHtml = function () {
|
8
8
|
if (this.positionType) {
|
9
|
-
|
9
|
+
throw "inferPositionType must be called after decorateContainerWithHtml";
|
10
10
|
}
|
11
11
|
this.containerOf().hide().addClass('popcorn');
|
12
|
-
if(!this.containerOf().find('.popcorn-body').length){
|
12
|
+
if (!this.containerOf().find('.popcorn-body').length) {
|
13
13
|
this.containerOf().contents().wrap("<div class='popcorn-body'/>");
|
14
14
|
}
|
15
15
|
this.containerOf().append("<div class='popcorn-tail'></div>");
|
16
|
-
|
16
|
+
};
|
17
17
|
|
18
|
-
|
18
|
+
Popcorn.prototype.inferPositionType = function () {
|
19
19
|
var self = this;
|
20
20
|
this.$anchor = this.$element;
|
21
|
-
|
21
|
+
|
22
22
|
function _createPositionType(defaults) {
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
if (self.$element.offset().left < 1) {
|
25
|
+
self.$anchor = self.$element.parent();
|
26
|
+
}
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
if (self.collideLeft()) {
|
29
|
+
return new LeftPosition(self);
|
30
|
+
}
|
31
|
+
else if (self.collideRight()) {
|
32
|
+
return new RightPosition(self);
|
33
|
+
}
|
34
|
+
return new CenterPosition(self);
|
31
35
|
}
|
32
|
-
|
36
|
+
|
33
37
|
self.positionType = _createPositionType(self.defaults);
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if (this.positionType == undefined) {
|
38
|
+
};
|
39
|
+
|
40
|
+
Popcorn.prototype.decorateContainerWithArrow = function () {
|
41
|
+
if (this.positionType == undefined) {
|
42
|
+
throw "inferPositionType must be called in order to set up the arrows";
|
43
|
+
}
|
38
44
|
|
39
45
|
this.containerOf().find('.popcorn-tail').css('left', this.positionType.leftOffset());
|
40
|
-
|
46
|
+
};
|
41
47
|
|
42
|
-
|
48
|
+
var LeftPosition = function (popcorn) {
|
43
49
|
// TODO centrare la freccia sull'elemento puntato da fatpopcorn
|
44
50
|
// this.leftOffset = function() {return popcorn.$element.offset().left + (popcorn.$element.width() - popcorn.defaults.arrowWidth) / 2; }
|
45
|
-
this.leftOffset = function() {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
this.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
this.leftOffset = function() {
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
this.leftOffset = function () {
|
52
|
+
return popcorn.defaults.marginArrow;
|
53
|
+
}
|
54
|
+
this.left = function () {
|
55
|
+
return popcorn.defaults.marginBorder;
|
56
|
+
}
|
57
|
+
this.top = function () {
|
58
|
+
return popcorn.$anchor.offset().top + popcorn.defaults.verticalOffsetFromElement
|
59
|
+
};
|
60
|
+
};
|
61
|
+
|
62
|
+
var RightPosition = function (popcorn) {
|
63
|
+
this.leftOffset = function () {
|
64
|
+
return popcorn.containerOf().width() - (popcorn.defaults.arrowWidth + popcorn.defaults.marginArrow);
|
65
|
+
}
|
66
|
+
this.left = function () {
|
67
|
+
return $('html').width() - popcorn.defaults.marginBorder - popcorn.containerOf().width();
|
61
68
|
}
|
62
|
-
this.top = function() {
|
63
|
-
|
69
|
+
this.top = function () {
|
70
|
+
return popcorn.$anchor.offset().top + popcorn.defaults.verticalOffsetFromElement
|
71
|
+
};
|
72
|
+
};
|
73
|
+
|
74
|
+
var CenterPosition = function (popcorn) {
|
75
|
+
this.leftOffset = function () {
|
76
|
+
return popcorn.containerOf().width() / 2 - Math.floor(popcorn.defaults.arrowWidth / 2);
|
77
|
+
}
|
78
|
+
this.left = function () {
|
79
|
+
var middleOfElement = Popcorn.calculateMiddle(popcorn.$anchor.offset().left, popcorn.$anchor.width());
|
80
|
+
return Popcorn.calculateLeftOffset(middleOfElement, popcorn.containerOf().width());
|
81
|
+
}
|
82
|
+
this.top = function () {
|
83
|
+
return popcorn.$anchor.offset().top + popcorn.defaults.verticalOffsetFromElement
|
84
|
+
};
|
85
|
+
};
|
64
86
|
|
65
|
-
|
87
|
+
Popcorn.containerOf = function ($element) {
|
66
88
|
return $element.next();
|
67
|
-
|
89
|
+
}
|
68
90
|
|
69
|
-
|
91
|
+
Popcorn.prototype.containerOf = function () {
|
70
92
|
return Popcorn.containerOf(this.$element);
|
71
|
-
|
93
|
+
}
|
72
94
|
|
73
|
-
|
95
|
+
Popcorn.prototype.setContainerPosition = function () {
|
74
96
|
this.containerOf().css('top', this.positionType.top());
|
75
97
|
this.containerOf().css('left', this.positionType.left());
|
76
|
-
|
98
|
+
}
|
77
99
|
|
78
|
-
|
100
|
+
Popcorn.prototype.collideRight = function () {
|
79
101
|
var middleOfElement = Popcorn.calculateMiddle(this.$anchor.offset().left, this.$anchor.width());
|
80
102
|
var rightOffset = middleOfElement + this.containerOf().width() / 2;
|
81
103
|
return ($('html').width() - (rightOffset + this.defaults.marginBorder)) < 0;
|
82
|
-
|
104
|
+
}
|
83
105
|
|
84
|
-
|
106
|
+
Popcorn.prototype.collideLeft = function () {
|
85
107
|
return (Popcorn.calculateLeftOffset(this.middleOf(), this.containerOf().width()) - this.defaults.marginBorder) < 0;
|
86
|
-
|
108
|
+
}
|
87
109
|
|
88
|
-
|
110
|
+
Popcorn.prototype.middleOf = function () {
|
89
111
|
return Popcorn.calculateMiddle(this.$anchor.offset().left, this.$anchor.width());
|
90
|
-
|
112
|
+
}
|
91
113
|
|
92
|
-
|
114
|
+
Popcorn.calculateMiddle = function (left, width) {
|
93
115
|
return left + width / 2;
|
94
|
-
|
116
|
+
}
|
95
117
|
|
96
|
-
|
118
|
+
Popcorn.calculateRightOffset = function (middlePoint, width) {
|
97
119
|
return middlePoint + width / 2;
|
98
|
-
|
99
|
-
|
120
|
+
}
|
121
|
+
Popcorn.calculateLeftOffset = function (middlePoint, width) {
|
100
122
|
return middlePoint - width / 2;
|
101
|
-
|
102
|
-
|
123
|
+
}
|
124
|
+
Popcorn.containerOf = function (element) {
|
103
125
|
return $(element).next();
|
104
|
-
|
105
|
-
|
106
|
-
$elements.each(function() {
|
107
|
-
|
126
|
+
}
|
127
|
+
Popcorn.hideAllContainers = function ($elements) {
|
128
|
+
$elements.each(function () {
|
129
|
+
Popcorn.containerOf(this).hide();
|
108
130
|
});
|
109
|
-
|
110
|
-
|
111
|
-
$elements.not(element).each(function() {
|
112
|
-
|
131
|
+
}
|
132
|
+
Popcorn.hideAllContainersExcept = function ($elements, element) {
|
133
|
+
$elements.not(element).each(function () {
|
134
|
+
Popcorn.containerOf(this).hide()
|
113
135
|
});
|
114
|
-
|
136
|
+
};
|
115
137
|
|
116
|
-
|
138
|
+
var FatPopcorn = function ($element, defaults) {
|
117
139
|
function _checkOptions(options) {
|
118
|
-
|
140
|
+
if (!options.autoWrap) options.autoWrap = false;
|
119
141
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
}
|
142
|
+
return typeof options.modelId === undefined ||
|
143
|
+
options.token === undefined ||
|
144
|
+
options.current_user === undefined;
|
145
|
+
}
|
146
|
+
|
147
|
+
;
|
124
148
|
var self = this;
|
125
149
|
|
126
150
|
if (_checkOptions(defaults)) throw("parameters [token], [current_user] are required");
|
127
151
|
|
128
152
|
self.$element = $element;
|
129
153
|
self.defaults = defaults;
|
130
|
-
|
154
|
+
|
131
155
|
|
132
156
|
self.defaults.modelName = "#"
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
157
|
+
};
|
158
|
+
FatPopcorn.prototype = new Popcorn();
|
159
|
+
|
160
|
+
FatPopcorn.prototype.init = function () {
|
137
161
|
this.setupFormAction();
|
138
162
|
this.setupFormToken();
|
139
163
|
this.setupStreamUrl();
|
140
164
|
this.setupHistoryUrl();
|
141
165
|
this.setupEditForm();
|
142
166
|
this.setupWatchlistUrl();
|
143
|
-
|
167
|
+
|
144
168
|
if (this.hasStream()) {
|
145
|
-
|
169
|
+
$('.fatpopcorn .stream-tab').click();
|
146
170
|
}
|
147
171
|
else {
|
148
|
-
|
172
|
+
$('.fatpopcorn .edit-tab').click();
|
149
173
|
}
|
150
|
-
|
151
|
-
|
152
|
-
|
174
|
+
};
|
175
|
+
|
176
|
+
FatPopcorn.prototype.setupStreamUrl = function () {
|
153
177
|
$('.fatpopcorn .stream').attr('data-url', this.streamUrl());
|
154
|
-
|
155
|
-
|
178
|
+
};
|
179
|
+
FatPopcorn.prototype.setupEditForm = function () {
|
156
180
|
FatPopcorn.createAttachmentButton(this.attachmentsUrl());
|
157
|
-
$('.fatpopcorn .edit').attr('data-attach-url', this.attachmentsUrl());
|
181
|
+
$('.fatpopcorn .edit').attr('data-attach-url', this.attachmentsUrl());
|
158
182
|
$('.on-off label.' + this.$element.attr('data-watching')).click();
|
159
|
-
|
160
|
-
|
183
|
+
};
|
184
|
+
FatPopcorn.prototype.setupWatchlistUrl = function () {
|
161
185
|
$('.fatpopcorn .edit').attr('data-url', this.watchlistUrl());
|
162
|
-
|
163
|
-
|
186
|
+
};
|
187
|
+
FatPopcorn.prototype.setupHistoryUrl = function () {
|
164
188
|
$('.fatpopcorn .history').attr('data-url', this.historyUrl());
|
165
|
-
|
166
|
-
|
189
|
+
};
|
190
|
+
FatPopcorn.prototype.setupFormAction = function () {
|
167
191
|
$('.fatpopcorn #notes_form').attr('action', this.actionUrl());
|
168
192
|
$('.fatpopcorn .edit').attr('data-note-url', this.actionUrl());
|
169
|
-
|
170
|
-
|
193
|
+
};
|
194
|
+
FatPopcorn.prototype.setupFormToken = function () {
|
171
195
|
$('.fatpopcorn #notes_form input[name="authenticity_token"]').val(FatPopcorn.formToken());
|
172
|
-
|
173
|
-
|
196
|
+
};
|
197
|
+
FatPopcorn.prototype.actionUrl = function () {
|
174
198
|
return this.urlPrefix() + '/notes';
|
175
|
-
|
176
|
-
|
199
|
+
};
|
200
|
+
FatPopcorn.prototype.streamUrl = function () {
|
177
201
|
return this.urlPrefix() + '/stream';
|
178
|
-
|
179
|
-
|
202
|
+
};
|
203
|
+
FatPopcorn.prototype.attachmentsUrl = function () {
|
180
204
|
return this.urlPrefix() + '/attachments';
|
181
|
-
|
182
|
-
|
205
|
+
};
|
206
|
+
FatPopcorn.prototype.watchlistUrl = function () {
|
183
207
|
return this.urlPrefix() + '/watchers/' + this.defaults.current_user;
|
184
|
-
|
185
|
-
|
208
|
+
};
|
209
|
+
FatPopcorn.prototype.historyUrl = function () {
|
186
210
|
return this.urlPrefix() + '/histories';
|
187
|
-
|
188
|
-
|
211
|
+
};
|
212
|
+
FatPopcorn.prototype.urlPrefix = function () {
|
189
213
|
return '/active_metadata/' + this.$element.attr('data-model') + '/' + this.$element.attr('data-model-id') + '/' + this.$element.attr('data-label');
|
190
|
-
|
191
|
-
|
214
|
+
};
|
215
|
+
FatPopcorn.prototype.currentLabel = function () {
|
192
216
|
return this.$element.attr('data-label');
|
193
|
-
|
194
|
-
|
217
|
+
};
|
218
|
+
FatPopcorn.prototype.hasStream = function () {
|
195
219
|
return parseInt(this.$element.attr('data-stream')) > 0;
|
196
|
-
|
197
|
-
|
220
|
+
};
|
221
|
+
FatPopcorn.hideContainer = function () {
|
198
222
|
$(window).off('resize');
|
199
223
|
return FatPopcorn.container().hide();
|
200
|
-
|
201
|
-
|
224
|
+
}
|
225
|
+
FatPopcorn.container = function () {
|
202
226
|
return $('.fatpopcorn').first();
|
203
|
-
|
204
|
-
|
227
|
+
}
|
228
|
+
FatPopcorn.prototype.containerOf = function () {
|
205
229
|
return $('.fatpopcorn').first();
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
230
|
+
}
|
231
|
+
FatPopcorn.onCompleteUpload = function (id, fileName, response, qq) {
|
232
|
+
console.log('FatPopcorn.onCompleteUpload');
|
233
|
+
if (qq.getQueue().length == 1) {
|
234
|
+
$('.qq-upload-list').empty();
|
235
|
+
}
|
236
|
+
if (!response.success) {
|
213
237
|
console.log(response);
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
238
|
+
FatPopcorn.displayFailure("Si è verificato un errore.");
|
239
|
+
return;
|
240
|
+
}
|
241
|
+
FatPopcorn.newNoteOrAttachmentSuccess(response);
|
242
|
+
}
|
243
|
+
FatPopcorn.decorateContainerWithHtml = function () {
|
220
244
|
var self = this;
|
245
|
+
|
221
246
|
function _html() {
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
}
|
231
|
-
|
247
|
+
return '<div class="fatpopcorn"><div class="popcorn-body"><div class="header"><ul><li class="stream-tab"><div>stream</div></li>' +
|
248
|
+
'<li class="edit-tab"><div>edit</div></li><li class="history-tab"><div>history</div></li></ul></div>' +
|
249
|
+
'<div class="stream"><div class="content"></div></div><div class="history"><div class="content"></div></div>' +
|
250
|
+
'<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/>' +
|
251
|
+
'<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>' +
|
252
|
+
'<textarea id="note_text" name="note" rows="4"></textarea><a id="send_note">Inserisci</a></form></div><hr/>' +
|
253
|
+
'<div class="attachment"><h1>Allegati</h1><div id="fatpopcorn_attach"></div><div id="attach_output"></div></div>' +
|
254
|
+
'<div class="info"><h1>Info</h1><p>Lorem ipsum...</p></div></div></div><div class="popcorn-tail"></div><span class="loader"></span></div>';
|
255
|
+
}
|
256
|
+
|
257
|
+
;
|
258
|
+
|
232
259
|
if (FatPopcorn.container().size() == 0) {
|
233
|
-
|
260
|
+
$('body').append(_html());
|
234
261
|
}
|
235
262
|
FatPopcorn.container().hide();
|
236
|
-
|
263
|
+
}
|
237
264
|
|
238
|
-
|
265
|
+
FatPopcorn.prototype.addGripToElement = function ($element) {
|
239
266
|
if (!$element.parent().is('span.fatpopcorn_grip') && this.defaults.autoWrap) {
|
240
|
-
|
267
|
+
$element.wrap('<span class="fatpopcorn_grip"/>')
|
241
268
|
}
|
242
269
|
return $element.parent();
|
243
|
-
|
244
|
-
|
270
|
+
};
|
271
|
+
FatPopcorn.prototype.gripOf = function ($element) {
|
245
272
|
return $element.parent();
|
246
|
-
|
273
|
+
};
|
274
|
+
|
275
|
+
FatPopcorn.activateTheClickedTab = function () {
|
276
|
+
$('.fatpopcorn .header > ul > li').unbind('click').click(function (e) {
|
277
|
+
var self = this;
|
278
|
+
|
279
|
+
function _tabBodyName(tabName) {
|
280
|
+
return tabName.split('-')[0].trim();
|
281
|
+
}
|
282
|
+
|
283
|
+
;
|
284
|
+
function _currentTabName() {
|
285
|
+
return _tabBodyName($(self).attr('class'));
|
286
|
+
}
|
247
287
|
|
248
|
-
|
249
|
-
|
250
|
-
|
288
|
+
;
|
289
|
+
function _currentTab() {
|
290
|
+
return $('.' + _currentTabName());
|
291
|
+
}
|
292
|
+
|
293
|
+
;
|
294
|
+
function _currentTabMethod() {
|
295
|
+
return _currentTabName() + "Event";
|
296
|
+
}
|
251
297
|
|
252
|
-
|
253
|
-
|
254
|
-
function _currentTab() { return $('.' + _currentTabName()); };
|
255
|
-
function _currentTabMethod() { return _currentTabName() + "Event"; }
|
298
|
+
e.stopPropagation();
|
299
|
+
e.preventDefault();
|
256
300
|
|
257
|
-
|
258
|
-
|
301
|
+
$('.fatpopcorn .active').removeClass('active');
|
302
|
+
$('.fatpopcorn .popcorn-body > div:not(.header)').hide();
|
259
303
|
|
260
|
-
|
261
|
-
$('.fatpopcorn .popcorn-body > div:not(.header)').hide();
|
262
|
-
|
263
|
-
_currentTab().show();
|
304
|
+
_currentTab().show();
|
264
305
|
|
265
|
-
|
306
|
+
$(this).addClass('active');
|
266
307
|
|
267
|
-
|
308
|
+
FatPopcorn[_currentTabMethod()].call();
|
268
309
|
});
|
269
|
-
|
270
|
-
|
310
|
+
};
|
311
|
+
FatPopcorn.streamEvent = function () {
|
271
312
|
$.ajax($('.fatpopcorn .stream').attr('data-url'))
|
272
|
-
|
273
|
-
|
274
|
-
|
313
|
+
.success(FatPopcorn.getStreamSuccess);
|
314
|
+
};
|
315
|
+
FatPopcorn.editEvent = function () {
|
275
316
|
// should do something?
|
276
|
-
|
277
|
-
|
317
|
+
};
|
318
|
+
FatPopcorn.historyEvent = function () {
|
278
319
|
$.ajax($('.fatpopcorn .history').attr('data-url'))
|
279
|
-
|
280
|
-
|
281
|
-
|
320
|
+
.success(FatPopcorn.getHistorySuccess);
|
321
|
+
};
|
322
|
+
FatPopcorn.containerVisible = function () {
|
282
323
|
return FatPopcorn.container().is(':visible');
|
283
|
-
|
284
|
-
|
324
|
+
};
|
325
|
+
FatPopcorn.formToken = function () {
|
285
326
|
return $('meta[name="csrf-token"]').attr('content');
|
286
|
-
|
287
|
-
|
327
|
+
};
|
328
|
+
FatPopcorn.createAttachmentButton = function (actionUrl) {
|
288
329
|
delete FatPopcorn.uploader;
|
289
330
|
FatPopcorn.uploader = new qq.FileUploader({
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
function _startWatching() {
|
303
|
-
|
304
|
-
}
|
331
|
+
element:document.getElementById('fatpopcorn_attach'),
|
332
|
+
allowedExtensions:[],
|
333
|
+
params:{ authenticity_token:FatPopcorn.formToken(), target:"attach_output"},
|
334
|
+
uploadButtonText:'Inserisci',
|
335
|
+
action:actionUrl,
|
336
|
+
multiple:true,
|
337
|
+
onComplete:FatPopcorn.onCompleteUpload
|
338
|
+
});
|
339
|
+
};
|
340
|
+
|
341
|
+
FatPopcorn.bindRemoteEvents = function () {
|
342
|
+
|
343
|
+
function _startWatching() {
|
344
|
+
_callWatchlistService({authenticity_token:FatPopcorn.formToken() });
|
345
|
+
}
|
346
|
+
|
347
|
+
;
|
305
348
|
function _stopWatching() {
|
306
|
-
|
307
|
-
}
|
349
|
+
_callWatchlistService({_method:'delete', authenticity_token:FatPopcorn.formToken() });
|
350
|
+
}
|
351
|
+
|
352
|
+
;
|
308
353
|
function _callWatchlistService(data) {
|
309
|
-
|
354
|
+
var url = $('.fatpopcorn .edit').attr('data-url');
|
355
|
+
$.post(url, data, {dataType:'script'}).done(FatPopcorn.watchingServiceSuccess).error(FatPopcorn.watchingServiceFail);
|
356
|
+
}
|
310
357
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
e.stopPropagation();
|
358
|
+
;
|
359
|
+
$('.fatpopcorn').unbind('click').click(function (e) {
|
360
|
+
e.stopPropagation();
|
315
361
|
});
|
316
|
-
$('.fatpopcorn #watchlist_true').unbind('click').click(function() {
|
317
|
-
|
362
|
+
$('.fatpopcorn #watchlist_true').unbind('click').click(function () {
|
363
|
+
_startWatching()
|
318
364
|
});
|
319
|
-
$('.fatpopcorn #watchlist_false').unbind('click').click(function() {
|
320
|
-
|
365
|
+
$('.fatpopcorn #watchlist_false').unbind('click').click(function () {
|
366
|
+
_stopWatching();
|
321
367
|
});
|
322
368
|
|
323
|
-
$('#send_note').unbind('click').click(function() {
|
324
|
-
|
369
|
+
$('#send_note').unbind('click').click(function () {
|
370
|
+
if ($('#note_text').val() == '') return false;
|
325
371
|
|
326
|
-
|
327
|
-
|
328
|
-
|
372
|
+
$.post($('form#notes_form').attr('action'), $('form#notes_form').serialize())
|
373
|
+
.success('success.rails', FatPopcorn.newNoteOrAttachmentSuccess)
|
374
|
+
.fail(function () {
|
375
|
+
FatPopcorn.displayFailure("Si è verificato un errore.")
|
376
|
+
});
|
377
|
+
});
|
378
|
+
$('.loader').ajaxSend(function (e) {
|
379
|
+
$(this).show();
|
329
380
|
});
|
330
|
-
$('.loader').
|
331
|
-
|
332
|
-
|
381
|
+
$('.loader').ajaxComplete(function () {
|
382
|
+
$(this).hide();
|
383
|
+
});
|
384
|
+
};
|
385
|
+
|
386
|
+
/******
|
387
|
+
Notifier
|
388
|
+
*******/
|
389
|
+
FatPopcorn.notifier = {
|
390
|
+
|
391
|
+
notify: function (type, message) {
|
392
|
+
type = type || "notice";
|
393
|
+
this.removeBox();
|
394
|
+
var $messageBox = $('.fatpopcorn .info h1').after('<p class="' + type + ' messageBox">' + message + '</p>').next();
|
395
|
+
var self = this;
|
396
|
+
$messageBox.bind('click', function () {
|
397
|
+
self.removeBox();
|
398
|
+
});
|
399
|
+
},
|
400
|
+
|
401
|
+
notice : function(message){
|
402
|
+
this.notify("notice",message);
|
403
|
+
},
|
404
|
+
|
405
|
+
error : function(message){
|
406
|
+
this.notify("error",message);
|
407
|
+
},
|
408
|
+
|
409
|
+
removeBox : function(){
|
410
|
+
$('.fatpopcorn .info p.messageBox').remove();
|
411
|
+
}
|
333
412
|
|
334
|
-
|
335
|
-
|
413
|
+
};
|
414
|
+
|
415
|
+
/*****
|
416
|
+
* Error Handling
|
417
|
+
*****/
|
418
|
+
FatPopcorn.displayFailure = function (message) {
|
419
|
+
FatPopcorn.notifier.error(message);
|
420
|
+
};
|
421
|
+
|
422
|
+
/* ajax callbacks */
|
423
|
+
FatPopcorn.watchingServiceSuccess = function (jqxhr) {
|
336
424
|
var data = eval(jqxhr);
|
425
|
+
//remove the error/notice messageBox
|
426
|
+
FatPopcorn.notifier.removeBox();
|
337
427
|
FatPopcorn.item(data).attr('data-watching', data.watching);
|
338
|
-
|
339
|
-
|
428
|
+
}
|
429
|
+
FatPopcorn.watchingServiceFail = function (data) {
|
430
|
+
FatPopcorn.displayFailure("Si è verificato un errore.")
|
340
431
|
console.log('Watchlist service request failed');
|
341
432
|
console.log(data);
|
342
433
|
console.log(data.state());
|
343
434
|
console.log(data.statusCode());
|
344
435
|
console.log(data.getAllResponseHeaders());
|
345
|
-
|
346
|
-
}
|
347
436
|
|
348
|
-
|
437
|
+
}
|
438
|
+
|
439
|
+
FatPopcorn.item = function (data) {
|
349
440
|
return $('[data-model="' + data.modelName + '"][data-label="' + data.fieldName + '"]');
|
350
|
-
|
441
|
+
}
|
351
442
|
|
352
|
-
|
443
|
+
FatPopcorn.newNoteOrAttachmentSuccess = function (dataString) {
|
353
444
|
var data = eval(dataString)
|
445
|
+
//remove the error/notice messageBox
|
446
|
+
FatPopcorn.notifier.removeBox();
|
354
447
|
FatPopcorn.item(data).attr('data-stream', data.streamItemsCount);
|
355
|
-
|
448
|
+
|
356
449
|
if (data.streamItemsCount > 0) {
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
450
|
+
FatPopcorn.item(data).parents('.fatpopcorn_grip').addClass('has-stream');
|
451
|
+
FatPopcorn.item(data).siblings('.stream-items-count').text(data.streamItemsCount);
|
452
|
+
if (data.streamItemsCount > 9)
|
453
|
+
FatPopcorn.item(data).siblings('.stream-items-count').addClass('two-digits')
|
454
|
+
else
|
455
|
+
FatPopcorn.item(data).siblings('.stream-items-count').removeClass('two-digits')
|
363
456
|
} else {
|
364
|
-
|
365
|
-
|
457
|
+
FatPopcorn.item(data).parents('.fatpopcorn_grip').removeClass('has-stream');
|
458
|
+
FatPopcorn.item(data).siblings('.stream-items-count').empty();
|
366
459
|
}
|
367
460
|
$('.fatpopcorn textarea#note_text').val('');
|
368
461
|
$('.fatpopcorn .active').removeClass('active');
|
@@ -371,147 +464,161 @@
|
|
371
464
|
$(".fatpopcorn .stream-tab").addClass('active');
|
372
465
|
FatPopcorn.getStreamSuccess(data.streamBody);
|
373
466
|
|
374
|
-
|
467
|
+
};
|
375
468
|
|
376
|
-
|
469
|
+
FatPopcorn.getStreamSuccess = function (data) {
|
377
470
|
$('.fatpopcorn .stream .content').html(data);
|
378
471
|
$('.fatpopcorn .stream .attachment span.delete').click(FatPopcorn.deleteAttachment);
|
379
472
|
$('.fatpopcorn .stream .note span.delete').click(FatPopcorn.deleteNote);
|
380
473
|
$('.fatpopcorn .stream span.star').click(FatPopcorn.starUnstar);
|
381
|
-
|
382
|
-
|
474
|
+
};
|
475
|
+
|
476
|
+
FatPopcorn.deleteAttachment = function (e) {
|
383
477
|
FatPopcorn.deleteStream(e, $('.fatpopcorn .edit').attr('data-attach-url'));
|
384
|
-
|
385
|
-
|
478
|
+
};
|
479
|
+
|
480
|
+
FatPopcorn.deleteNote = function (e) {
|
386
481
|
FatPopcorn.deleteStream(e, $('.fatpopcorn .edit').attr('data-note-url'));
|
387
|
-
|
388
|
-
|
482
|
+
};
|
483
|
+
|
484
|
+
FatPopcorn.deleteStream = function (e, urlPrefix) {
|
389
485
|
function _url() {
|
390
|
-
|
486
|
+
return urlPrefix + '/' + $(e.target).parent().attr('data-id');
|
391
487
|
}
|
392
488
|
|
393
|
-
$.post(_url(), {_method:
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
489
|
+
$.post(_url(), {_method:'delete'}).
|
490
|
+
success('success.rails', FatPopcorn.newNoteOrAttachmentSuccess).
|
491
|
+
fail(FatPopcorn.deleteFailure);
|
492
|
+
};
|
493
|
+
|
494
|
+
FatPopcorn.starUnstar = function (e, urlPrefix) {
|
495
|
+
var url = $(e.target).attr('data-url');
|
496
|
+
$.post(url, {_method:'put'}).
|
497
|
+
success('success.rails',
|
498
|
+
function (data) {
|
499
|
+
FatPopcorn.getStreamSuccess(data.streamBody)
|
500
|
+
}).
|
501
|
+
fail(FatPopcorn.deleteFailure);
|
502
|
+
};
|
503
|
+
|
504
|
+
FatPopcorn.deleteSuccess = function () {
|
407
505
|
$('.fatpopcorn .stream-tab').click();
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
506
|
+
};
|
507
|
+
|
508
|
+
FatPopcorn.deleteFailure = function () {
|
509
|
+
};
|
510
|
+
|
511
|
+
FatPopcorn.getHistorySuccess = function (data) {
|
412
512
|
$('.fatpopcorn .history .content').empty();
|
413
513
|
$('.fatpopcorn .history .content').append(data);
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
514
|
+
};
|
515
|
+
|
516
|
+
(function ($) {
|
517
|
+
$.fn.fatpopcorn = function (options) {
|
518
|
+
|
519
|
+
// plugin default options
|
520
|
+
var self = this, defaults = {
|
521
|
+
marginBorder:4,
|
522
|
+
arrowWidth:24,
|
523
|
+
marginArrow:11,
|
524
|
+
verticalOffsetFromElement:26
|
525
|
+
};
|
526
|
+
|
527
|
+
// extends defaults with options provided
|
528
|
+
if (options) {
|
529
|
+
$.extend(defaults, options);
|
530
|
+
}
|
425
531
|
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
$(window).click(function() { FatPopcorn.hideContainer(); });
|
432
|
-
|
433
|
-
FatPopcorn.decorateContainerWithHtml();
|
434
|
-
FatPopcorn.activateTheClickedTab();
|
435
|
-
FatPopcorn.bindRemoteEvents();
|
436
|
-
FatPopcorn.createAttachmentButton();
|
437
|
-
|
438
|
-
function _setUpElement() {
|
439
|
-
var $element = $(this), fatpopcorn = new FatPopcorn($element, defaults);
|
440
|
-
fatpopcorn.addGripToElement($element);
|
441
|
-
|
442
|
-
fatpopcorn.gripOf($element).children().click(function(e) {
|
443
|
-
$(e.target).data('elementMatched', true);
|
444
|
-
});
|
445
|
-
|
446
|
-
$('.fatpopcorn_grip .stream-items-count').click(function(e) {
|
447
|
-
$(e.target).data('elementMatched', false);
|
448
|
-
});
|
449
|
-
|
450
|
-
fatpopcorn.gripOf($element).click(function(e) {
|
451
|
-
if ($(e.target).data('elementMatched')) return;
|
532
|
+
$(window).click(function () {
|
533
|
+
FatPopcorn.hideContainer();
|
534
|
+
FatPopcorn.notifier.removeBox();
|
535
|
+
});
|
452
536
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
537
|
+
FatPopcorn.decorateContainerWithHtml();
|
538
|
+
FatPopcorn.activateTheClickedTab();
|
539
|
+
FatPopcorn.bindRemoteEvents();
|
540
|
+
FatPopcorn.createAttachmentButton();
|
541
|
+
|
542
|
+
function _setUpElement() {
|
543
|
+
var $element = $(this), fatpopcorn = new FatPopcorn($element, defaults);
|
544
|
+
fatpopcorn.addGripToElement($element);
|
545
|
+
|
546
|
+
fatpopcorn.gripOf($element).children().click(function (e) {
|
547
|
+
$(e.target).data('elementMatched', true);
|
548
|
+
});
|
549
|
+
|
550
|
+
$('.fatpopcorn_grip .stream-items-count').click(function (e) {
|
551
|
+
$(e.target).data('elementMatched', false);
|
552
|
+
});
|
553
|
+
|
554
|
+
fatpopcorn.gripOf($element).click(function (e) {
|
555
|
+
if ($(e.target).data('elementMatched')) return;
|
556
|
+
|
557
|
+
e.stopPropagation();
|
558
|
+
e.preventDefault();
|
559
|
+
fatpopcorn.init();
|
560
|
+
|
561
|
+
if (FatPopcorn.containerVisible()) {
|
562
|
+
FatPopcorn.hideContainer();
|
563
|
+
return;
|
564
|
+
}
|
565
|
+
|
566
|
+
fatpopcorn.inferPositionType();
|
567
|
+
fatpopcorn.setContainerPosition();
|
568
|
+
fatpopcorn.decorateContainerWithArrow();
|
569
|
+
fatpopcorn.containerOf().show();
|
570
|
+
|
571
|
+
$(window).on('resize', function () {
|
572
|
+
if (FatPopcorn.containerVisible()) fatpopcorn.setContainerPosition();
|
573
|
+
});
|
574
|
+
});
|
575
|
+
|
576
|
+
return this;
|
460
577
|
}
|
461
578
|
|
462
|
-
|
463
|
-
fatpopcorn.setContainerPosition();
|
464
|
-
fatpopcorn.decorateContainerWithArrow();
|
465
|
-
fatpopcorn.containerOf().show();
|
466
|
-
|
467
|
-
$(window).on('resize',function() {
|
468
|
-
if (FatPopcorn.containerVisible()) fatpopcorn.setContainerPosition();
|
469
|
-
});
|
470
|
-
});
|
471
|
-
|
472
|
-
return this;
|
579
|
+
return self.each(_setUpElement);
|
473
580
|
}
|
474
|
-
return self.each(_setUpElement);
|
475
|
-
}
|
476
|
-
|
477
|
-
$.fn.popcorn = function(options) {
|
478
|
-
|
479
|
-
// plugin default options
|
480
|
-
var elements = this, defaults = {
|
481
|
-
marginBorder: 4,
|
482
|
-
arrowWidth: 19,
|
483
|
-
marginArrow: 10,
|
484
|
-
verticalOffsetFromElement: 20
|
485
|
-
};
|
486
581
|
|
487
|
-
|
488
|
-
if (options) {
|
489
|
-
$.extend(delfaults, options);
|
490
|
-
}
|
582
|
+
$.fn.popcorn = function (options) {
|
491
583
|
|
492
|
-
|
584
|
+
// plugin default options
|
585
|
+
var elements = this, defaults = {
|
586
|
+
marginBorder:4,
|
587
|
+
arrowWidth:19,
|
588
|
+
marginArrow:10,
|
589
|
+
verticalOffsetFromElement:20
|
590
|
+
};
|
493
591
|
|
494
|
-
|
495
|
-
|
592
|
+
// extends defaults with options provided
|
593
|
+
if (options) {
|
594
|
+
$.extend(delfaults, options);
|
595
|
+
}
|
496
596
|
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
popcorn.setContainerPosition();
|
597
|
+
$(window).unbind('click').click(function () {
|
598
|
+
Popcorn.hideAllContainers(elements);
|
599
|
+
});
|
501
600
|
|
502
|
-
|
503
|
-
|
504
|
-
e.preventDefault();
|
505
|
-
Popcorn.hideAllContainersExcept(elements, this);
|
506
|
-
Popcorn.containerOf($element).show();
|
507
|
-
});
|
601
|
+
function _setUpElement() {
|
602
|
+
var $element = $(this), popcorn = new Popcorn($element, defaults);
|
508
603
|
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
604
|
+
popcorn.decorateContainerWithHtml();
|
605
|
+
popcorn.inferPositionType();
|
606
|
+
popcorn.decorateContainerWithArrow();
|
607
|
+
popcorn.setContainerPosition();
|
608
|
+
|
609
|
+
$element.click(function (e) {
|
610
|
+
e.stopPropagation();
|
611
|
+
e.preventDefault();
|
612
|
+
Popcorn.hideAllContainersExcept(elements, this);
|
613
|
+
Popcorn.containerOf($element).show();
|
614
|
+
});
|
513
615
|
|
514
|
-
|
616
|
+
$(window).resize(function () {
|
617
|
+
popcorn.setContainerPosition();
|
618
|
+
});
|
619
|
+
}
|
620
|
+
|
621
|
+
return this.each(_setUpElement);
|
515
622
|
|
516
|
-
|
623
|
+
};
|
517
624
|
})(jQuery);
|
@@ -281,6 +281,7 @@ div > h1 > span.delete:hover {
|
|
281
281
|
}
|
282
282
|
.fatpopcorn .edit #send_note {
|
283
283
|
padding-right: 6px;
|
284
|
+
cursor: pointer;
|
284
285
|
}
|
285
286
|
.fatpopcorn .edit .attachment {
|
286
287
|
margin: 10px 10px 26px 10px;
|
@@ -322,11 +323,14 @@ div > h1 > span.delete:hover {
|
|
322
323
|
}
|
323
324
|
.fatpopcorn .edit .info p {
|
324
325
|
color: #626262;
|
325
|
-
display: table-cell;
|
326
326
|
padding-left: 10px;
|
327
327
|
/* overflow: hidden; TODO Controllare cosa succede quando il testo va in overflow
|
328
328
|
text-overflow: ellipsis;*/
|
329
329
|
}
|
330
|
+
.fatpopcorn .edit .info p.error {
|
331
|
+
color: red;
|
332
|
+
}
|
333
|
+
|
330
334
|
.fatpopcorn .edit textarea {
|
331
335
|
width: 98%;
|
332
336
|
margin-left: 2px;
|
data/lib/corn_js/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corn_js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
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-03-
|
12
|
+
date: 2012-03-30 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70109275728320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.2.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70109275728320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: jquery-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70109275727160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70109275727160
|
36
36
|
description: It's possible to use the generic popcorn and the app specific fat popcorn
|
37
37
|
plugin
|
38
38
|
email:
|
@@ -69,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: '0'
|
70
70
|
segments:
|
71
71
|
- 0
|
72
|
-
hash:
|
72
|
+
hash: 597681471737756081
|
73
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
segments:
|
80
80
|
- 0
|
81
|
-
hash:
|
81
|
+
hash: 597681471737756081
|
82
82
|
requirements: []
|
83
83
|
rubyforge_project:
|
84
84
|
rubygems_version: 1.8.10
|