| author | Simon Descarpentries <sid@sopinspace.com> |
| Wed, 30 Oct 2013 18:08:42 +0100 | |
| changeset 556 | 69503659fe8f |
| parent 553 | bf26fb47a14c |
| child 558 | 5ba711a2bd06 |
| permissions | -rw-r--r-- |
| 0 | 1 |
gShowingAllComments = false ; |
| 466 | 2 |
// indexOf method of Array is unknown by stupid IE. |
3 |
if (!Array.prototype.indexOf) { |
|
4 |
Array.prototype.indexOf = function(obj, start) { |
|
5 |
for (var i = (start || 0), j = this.length; i < j; i++) { |
|
6 |
if (this[i] === obj) { return i; } |
|
7 |
} |
|
8 |
return -1; |
|
9 |
} |
|
10 |
} |
|
| 0 | 11 |
// YUI : queue, overlay |
12 |
Sync = function() { |
|
| 341 | 13 |
// this queue handles both animations and io requests |
14 |
this._q = null ; |
|
15 |
|
|
16 |
this._iPreventClick = false ; // oh really ? |
|
| 0 | 17 |
} |
18 |
||
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
19 |
// Are we on Safari mobile ? |
|
556
69503659fe8f
[c_selection.js] If safari_mobile, get current selection from a previously created global variable
Simon Descarpentries <sid@sopinspace.com>
parents:
553
diff
changeset
|
20 |
// made global to be used in templates/site/text_view_comments.html |
|
69503659fe8f
[c_selection.js] If safari_mobile, get current selection from a previously created global variable
Simon Descarpentries <sid@sopinspace.com>
parents:
553
diff
changeset
|
21 |
// and in media/js/site/c_text_view_comments.js |
|
69503659fe8f
[c_selection.js] If safari_mobile, get current selection from a previously created global variable
Simon Descarpentries <sid@sopinspace.com>
parents:
553
diff
changeset
|
22 |
safari_mobile = /iPhone|iPod|iPad/.test(navigator.userAgent); |
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
23 |
// If so, we must scroll the jQuery UI pane created for Safari mobile instead of the whole document |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
24 |
var the_scrolling_part = safari_mobile ? '#maincontainer' : 'document' ; |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
25 |
|
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
26 |
// "Add comment" height and margin, to offset comments' display |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
27 |
var add_comment_offset = 30; // px |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
28 |
|
| 0 | 29 |
Sync.prototype = { |
| 341 | 30 |
init : function (iComment) { |
31 |
this._q = new CY.AsyncQueue() ; |
|
| 0 | 32 |
// pr2 this._q = new CY.Queue() ; |
| 341 | 33 |
}, |
34 |
|
|
35 |
setPreventClickOn : function () { |
|
36 |
CY.log("setPreventClickOn !") ; |
|
37 |
if (gLayout.isInFrame()) |
|
38 |
parent.f_interfaceFreeze() |
|
39 |
this._iPreventClick = true ; |
|
40 |
}, |
|
| 0 | 41 |
|
| 341 | 42 |
setPreventClickOff : function () { |
43 |
CY.log("setPreventClickOff !") ; |
|
44 |
if (gLayout.isInFrame()) |
|
45 |
parent.f_interfaceUnfreeze() |
|
46 |
this._iPreventClick = false ; |
|
47 |
}, |
|
| 0 | 48 |
|
| 341 | 49 |
removeCommentRet : function(args) { |
50 |
var successfull = args['successfull'] ; |
|
51 |
|
|
52 |
var iComment = (successfull) ? args['failure']['iComment'] : args['success']['iComment'] ; |
|
53 |
|
|
54 |
if (successfull) { |
|
55 |
var filterData = args['returned']['filterData'] ; |
|
56 |
if (gLayout.isInFrame()) { |
|
57 |
parent.f_updateFilterData(filterData) ; |
|
58 |
} |
|
59 |
|
|
60 |
var y = gIComments.getTopPosition()[1] ; |
|
61 |
|
|
62 |
var comment = gDb.getComment(iComment.commentId) ; |
|
63 |
this._q.add( |
|
64 |
function(){ |
|
65 |
|
|
66 |
unpaintCommentScope(comment) ; |
|
67 |
gIComments.close(comment.id) ; |
|
68 |
gIComments.remove(comment.id) ; |
|
69 |
if (comment.reply_to_id != null) |
|
70 |
gIComments.refresh(comment.reply_to_id) ; |
|
71 |
|
|
72 |
gDb.del(comment) ; |
|
73 |
|
|
74 |
if (gLayout.isInFrame()) { |
|
75 |
if (gDb.comments.length == 0 && gDb.allComments.length != 0) { |
|
76 |
parent.f_enqueueMsg(gettext("no filtered comments left")) ; |
|
77 |
parent.resetFilter() ; |
|
78 |
} |
|
79 |
else { |
|
80 |
// just counting here ... |
|
81 |
var filterRes = gDb.computeFilterResults() ; |
|
82 |
updateFilterResultsCount(filterRes['nbDiscussions'], filterRes['nbComments'], filterRes['nbReplies']) ; |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
); |
|
87 |
|
|
88 |
this._animateTo(y) ; |
|
89 |
} |
|
90 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
91 |
this.resume() ; |
|
92 |
}, |
|
93 |
|
|
94 |
moderateCommentRet : function(args) { |
|
95 |
var successfull = args['successfull'] ; |
|
| 0 | 96 |
|
| 341 | 97 |
var iComment = (successfull) ? args['failure']['iComment'] : args['success']['iComment'] ; |
| 0 | 98 |
|
| 341 | 99 |
if (successfull) { |
100 |
var ret = args['returned'] ; |
|
101 |
var comment = ret['comment'] ; |
|
| 0 | 102 |
|
| 341 | 103 |
gDb.upd(comment) ; |
104 |
|
|
105 |
var shouldReset = gLayout.isInFrame() && !parent.f_isFrameFilterFieldsInit() ; |
|
106 |
if (shouldReset){ |
|
107 |
parent.resetFilter() ; |
|
108 |
this._showSingleComment(comment) ; |
|
109 |
} |
|
110 |
else |
|
111 |
iComment.changeModeration(comment) ; |
|
112 |
} |
|
| 0 | 113 |
|
| 341 | 114 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
115 |
this.resume() ; |
|
116 |
}, |
|
117 |
|
|
118 |
saveCommentRet : function(args) { |
|
119 |
var successfull = args['successfull'] ; |
|
120 |
if (successfull) { |
|
121 |
var formId = args['success']['formId'] ; |
|
122 |
var ret = args['returned'] ; |
|
123 |
|
|
124 |
removeFormErrMsg(formId) ; |
|
125 |
|
|
126 |
if ('errors' in ret) { // validation error |
|
127 |
var errors = ret['errors'] ; |
|
128 |
for (var eltName in errors) { |
|
129 |
addFormErrMsg(formId, eltName, errors[eltName]) ; |
|
130 |
} |
|
131 |
this._animateToTop() ; |
|
132 |
} |
|
133 |
else { |
|
134 |
var isReply = function() {return (gNewReply != null) && (formId == gNewReply['ids']['formId']) ;} ; |
|
135 |
var isNewComment = function() {return (gICommentForm != null) && (formId == gICommentForm['formId']) ;} ; |
|
136 |
var isEdit = function() {return (gEdit != null) && (formId == gEdit['ids']['formId']) ;} ; |
|
137 |
|
|
138 |
// doing this here for the a priori moderation case |
|
139 |
if (isNewComment()) |
|
140 |
this.hideICommentForm(cleanICommentForm()) ; |
|
141 |
else if (isEdit()) |
|
142 |
this._hideEditForm() ; |
|
143 |
else if (isReply()) |
|
144 |
this._hideNewReplyForm() ; |
|
145 |
|
|
146 |
if ("ask_for_notification" in ret) { |
|
147 |
if (ret['ask_for_notification']) { |
|
148 |
// TODO ask for notification ...or use AUTO_CONTRIB ? |
|
149 |
parent.f_yesNoDialog(gettext("Do you want to be notified of all replies in all discussions you participated in?"), gettext("Reply notification"), |
|
150 |
function() { // special case : no waiting for the return, no error check, nothing ! |
|
151 |
var cfg = { |
|
152 |
method: "POST", |
|
153 |
data: urlEncode({'fun':'ownNotify', 'key':sv_key, 'version_key':sv_version_key, 'email':ret['email'], 'active':false}) |
|
154 |
} ; |
|
155 |
CY.io(sv_client_url, cfg); |
|
156 |
}, this, null, |
|
157 |
function() { // special case : no waiting for the return, no error check, nothing ! |
|
158 |
var cfg = { |
|
159 |
method: "POST", |
|
160 |
data: urlEncode({'fun':'ownNotify', 'key':sv_key, 'version_key':sv_version_key, 'email':ret['email'], 'active':true}) |
|
161 |
} ; |
|
162 |
CY.io(sv_client_url, cfg); |
|
163 |
}, this, null) ; |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
|
|
168 |
if ("comment" in ret) { // won't be when add with a priori moderation |
|
169 |
var comment = ret['comment'] ; |
|
170 |
|
|
171 |
gDb.upd(comment) ; |
|
172 |
|
|
|
490
57c1ba71f642
Do not reset filters when adding a comment.
Production Moz <dev@sopinspace.com>
parents:
466
diff
changeset
|
173 |
var shouldReset = gLayout.isInFrame() && parent.f_isFrameFilterFieldsInit() ; |
| 341 | 174 |
if (shouldReset) |
175 |
parent.resetFilter() ; |
|
176 |
else { // ASSUMING filter is in init state ! (because when not // TODO $$$$$$$$$$$ this isn't true anymore .... when passing filter arguments in url !! |
|
177 |
// in frame for now data can't be filtered) |
|
178 |
if (comment.reply_to_id == null) { // not a reply |
|
179 |
unpaintCommentScope(comment) ; // for the edit case |
|
180 |
paintCommentScope(comment) ; |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
// UPDATE FILTER DATA // TODO move ???? |
|
185 |
var filterData = ret['filterData'] ; |
|
186 |
if (gLayout.isInFrame()) { |
|
187 |
parent.f_updateFilterData(filterData) ; |
|
188 |
updateResetFilterResultsCount() ; |
|
189 |
} |
|
| 0 | 190 |
|
| 341 | 191 |
if (isReply()) { // add reply case |
192 |
if (!shouldReset) { |
|
193 |
this._insertReply(comment) ; |
|
194 |
} |
|
195 |
} |
|
196 |
else { // edit (reply or comment) or add (comment) case |
|
197 |
this._showSingleComment(comment) ; |
|
198 |
} |
|
199 |
} |
|
200 |
else |
|
201 |
this._animateToTop() ; |
|
202 |
} |
|
| 0 | 203 |
|
| 341 | 204 |
} |
205 |
else { // TODO ? ALL ret-FUNCTIONS ? |
|
206 |
this._q.add({id:"expl", fn:function () {CY.log('in example .........') ;}}) ; |
|
207 |
this._q.promote("expl") ; |
|
208 |
} |
|
| 0 | 209 |
|
| 341 | 210 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
211 |
this.resume() ; |
|
212 |
}, |
|
213 |
|
|
214 |
example : function () { |
|
215 |
CY.log('in example .........') ; |
|
216 |
}, |
|
| 0 | 217 |
|
| 341 | 218 |
moderateComment : function(iComment, state) { |
219 |
var comment = gDb.getComment(iComment['commentId']) ; |
|
| 0 | 220 |
this._q.add( |
| 341 | 221 |
{fn:CY.bind(this.setPreventClickOn, this)}, |
222 |
{autoContinue:false, fn:CY.bind(doExchange, null, "editComment", {'comment_key':comment.key, 'state':state}, null, this.moderateCommentRet, this, {'iComment':iComment}, gettext("could not save comment"))} |
|
223 |
).run(); |
|
224 |
}, |
|
225 |
|
|
226 |
_saveComment : function(serverFun, formId) { |
|
| 0 | 227 |
this._q.add( |
| 341 | 228 |
{fn:CY.bind(this.setPreventClickOn, this)}, |
229 |
{autoContinue:false, fn:CY.bind(doExchange, null, serverFun, {}, formId, this.saveCommentRet, this, {'formId':formId}, gettext("could not save comment"))} |
|
230 |
).run(); |
|
231 |
}, |
|
232 |
|
|
233 |
editComment : function() { |
|
234 |
this._saveComment("editComment", gEdit['ids']['formId']) ; |
|
235 |
}, |
|
236 |
|
|
237 |
saveComment : function(formId) { |
|
|
501
5cd02f32be5e
Prevents sumitting comment several time while waiting for server response.
gibus
parents:
492
diff
changeset
|
238 |
if (readyForAction()) |
|
5cd02f32be5e
Prevents sumitting comment several time while waiting for server response.
gibus
parents:
492
diff
changeset
|
239 |
this._saveComment("addComment", formId) ; |
| 341 | 240 |
}, |
241 |
|
|
242 |
removeComment : function(iComment) { |
|
243 |
checkForOpenedDialog(iComment, function() { |
|
244 |
if (gLayout.isInFrame()) { |
|
245 |
parent.f_yesNoDialog(gettext("Are you sure you want to delete this comment?"), gettext("Warning"), function() { this.animateToTop() ;}, this, null, function() { |
|
246 |
var comment = gDb.getComment(iComment.commentId) ; |
|
247 |
this._q.add( |
|
248 |
{fn:CY.bind(this.setPreventClickOn, this)}, |
|
249 |
{autoContinue:false, fn:CY.bind(doExchange, null, "removeComment", {'comment_key':comment.key}, null, this.removeCommentRet, this, {'iComment':iComment}, gettext("could not remove comment"))} |
|
250 |
).run(); |
|
251 |
}, this, null) ; |
|
252 |
|
|
253 |
} |
|
254 |
// else { |
|
255 |
// alert("TODO : can't yet delete comments when not embed in text_view_frame because can't 'dialog' confirmation") ; |
|
256 |
// } |
|
257 |
|
|
258 |
}, this, null) ; |
|
259 |
}, |
|
260 |
|
|
261 |
resume : function(commentDbIds, mouseXY) { |
|
262 |
this._q.run() ; |
|
263 |
}, |
|
264 |
|
|
265 |
resetAutoContinue : function(callbackId) { |
|
266 |
this._q.getCallback(callbackId).autoContinue = true; |
|
267 |
}, |
|
268 |
|
|
269 |
hideICommentForm : function(funObj) { |
|
270 |
// this._q.add({fn:function() {persistICommentFormValues();}}) ; |
|
271 |
this._q.add({autoContinue:false, fn:CY.bind(gICommentForm['animationHide'].run, gICommentForm['animationHide'])}) ; |
|
272 |
// this._q.add({fn:function() {cleanICommentForm();}}) ; |
|
273 |
if (funObj) |
|
274 |
this._q.add(funObj) ; |
|
275 |
}, |
|
276 |
|
|
277 |
/* ANIMATION DRIVEN INTERFACE CHANGES */ |
|
278 |
|
|
279 |
showCommentForm : function(iComment) { |
|
280 |
checkForOpenedDialog(null, function() { |
|
281 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
|
282 |
this._q.add({fn:function() { |
|
283 |
if (iComment == null) { |
|
284 |
var selection = getSelectionInfo() ; |
|
285 |
updateICommentFormSelection(selection) ; |
|
286 |
} |
|
287 |
showICommentForm(iComment); |
|
288 |
}}) ; |
|
289 |
this._q.add({autoContinue:false, fn:CY.bind(gICommentForm['animationShow'].run, gICommentForm['animationShow'])}, |
|
290 |
{fn:CY.bind(this.setPreventClickOff, this)} |
|
291 |
).run(); |
|
292 |
}, this, null) ; |
|
293 |
}, |
|
294 |
|
|
295 |
showEditForm : function(iComment) { |
|
296 |
checkForOpenedDialog(null, function() { |
|
297 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
|
| 0 | 298 |
|
| 341 | 299 |
this._q.add({fn:function() { |
300 |
showEditForm(iComment) ; |
|
301 |
}}); |
|
302 |
this._animateToTop() ; |
|
303 |
|
|
304 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
|
305 |
this._q.run() ; |
|
306 |
}, this, null) ; |
|
307 |
}, |
|
308 |
|
|
309 |
showReplyForm : function(iComment) { |
|
310 |
checkForOpenedDialog(null, function() { |
|
311 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
|
| 0 | 312 |
|
| 341 | 313 |
this._q.add({fn:function() { |
314 |
instanciateNewReplyForm(iComment) ; |
|
315 |
}}); |
|
316 |
this._animateToTop() ; |
|
317 |
|
|
318 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
|
319 |
this._q.run() ; |
|
320 |
}, this, null) ; |
|
321 |
}, |
|
322 |
|
|
323 |
cancelICommentForm : function() { |
|
| 0 | 324 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
325 |
|
|
| 341 | 326 |
// this._q.add({fn:function() {cleanICommentForm();}}) ; |
327 |
this.hideICommentForm() ; |
|
328 |
|
|
| 0 | 329 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
330 |
this._q.run() ; |
|
| 341 | 331 |
}, |
332 |
cancelEdit : function() { |
|
| 0 | 333 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
334 |
|
|
| 341 | 335 |
this._q.add({fn:function() {cancelEditForm();}}) ; |
336 |
this._animateToTop() ; |
|
337 |
|
|
| 0 | 338 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
339 |
this._q.run() ; |
|
| 341 | 340 |
}, |
341 |
cancelReply : function() { |
|
| 0 | 342 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
343 |
|
|
| 341 | 344 |
this._q.add({fn:function() {cancelNewReplyForm();}}) ; |
345 |
this._animateToTop() ; |
|
346 |
|
|
| 0 | 347 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
348 |
this._q.run() ; |
|
| 341 | 349 |
}, |
350 |
changeScopeFormClick : function() { |
|
| 0 | 351 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
352 |
|
|
| 341 | 353 |
this._q.add({fn:function() {changeScopeFormClick();}}) ; |
354 |
this._animateToTop() ; |
|
355 |
|
|
| 0 | 356 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
357 |
this._q.run() ; |
|
| 341 | 358 |
}, |
359 |
// this is invoked during queue execution |
|
360 |
_hideNewReplyForm : function() { |
|
361 |
this._q.add({fn:function() { |
|
362 |
cleanNewReplyForm() ; |
|
363 |
cancelNewReplyForm() ;}}) ; |
|
364 |
}, |
|
365 |
// this is invoked during queue execution |
|
366 |
_hideEditForm : function() { |
|
367 |
this._q.add({fn:function() { |
|
368 |
cancelEditForm() ;}}) ; |
|
369 |
}, |
|
370 |
// this is invoked during queue execution |
|
371 |
_insertReply : function(comment) { |
|
372 |
this._q.add({fn:function() { |
|
373 |
var parentComment = gDb.getComment(comment.reply_to_id) ; |
|
374 |
var parentThread = gDb.getThreads([parentComment]) ; |
|
375 |
var previousComment = parentThread[parentThread.length - 2] ; // - 2 because now that comment has been added comment is parentThread[parentThread.length - 1] |
|
| 0 | 376 |
|
| 341 | 377 |
var iComment = gIComments.insertAfter(previousComment, comment) ; |
378 |
// iComment CAN'T BE NULL ! (TODO check that there is a |
|
379 |
// check server side that parent exists when adding a reply |
|
380 |
// !) |
|
381 |
|
|
382 |
var parentPosition = gIComments.getPosition(comment.reply_to_id) ; |
|
383 |
iComment.setPosition(parentPosition) ; |
|
384 |
|
|
385 |
// check if activation is necessary (will always be ?) |
|
386 |
var comment_path = gDb.getPath(comment) ; |
|
387 |
var topComment = comment_path[comment_path.length - 1] ; |
|
388 |
if (gIComments.isTopActive(topComment.id)) |
|
389 |
iComment.activate() ; |
|
| 0 | 390 |
|
| 341 | 391 |
iComment.show() ;}}) ; |
392 |
this._animateToTop() ; |
|
393 |
}, |
|
394 |
_showSingleComment : function(comment) { |
|
395 |
if (comment != null) { |
|
396 |
var path = gDb.getPath(comment) ; |
|
397 |
var topAncestorComment = path[path.length - 1] ; |
|
398 |
var topY = 0 ; |
|
399 |
if (comment['start_wrapper'] != -1) |
|
|
532
0bad3613f59d
Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents:
525
diff
changeset
|
400 |
topY = CY.get(".c-id-"+topAncestorComment.id).getY() ; |
| 341 | 401 |
else |
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
402 |
topY = CY.get(the_scrolling_part).get('scrollTop') ; |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
403 |
|
| 341 | 404 |
this._showComments([topAncestorComment.id], topY, false) ; |
405 |
// optim when browsing comments with no reply |
|
406 |
if (topAncestorComment.replies.length > 0) |
|
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
407 |
// SID: let topY param be null to force Y acquisition from comment that |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
408 |
// may have previously been set by showComments |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
409 |
this._animateTo() ; |
| 341 | 410 |
} |
411 |
}, |
|
412 |
_showFocusSingleComment : function(topComment, focusComment, reply) { |
|
413 |
if (topComment != null) { |
|
414 |
var topY = 0 ; |
|
415 |
if (topComment['start_wrapper'] != -1) |
|
|
532
0bad3613f59d
Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents:
525
diff
changeset
|
416 |
topY = CY.get(".c-id-"+topComment.id).getY() ; |
| 341 | 417 |
else |
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
418 |
topY = CY.get(the_scrolling_part).get('scrollTop') ; |
| 341 | 419 |
|
420 |
this._showComments([topComment.id], topY, false) ; |
|
421 |
// optim when browsing comments with no reply |
|
422 |
if (topComment.replies.length > 0 || reply) |
|
423 |
this._animateToAndFocus(topY, focusComment.id, reply) ; |
|
424 |
} |
|
425 |
}, |
|
| 0 | 426 |
|
| 341 | 427 |
showSingleComment : function(comment) { |
428 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
429 |
this._showSingleComment(comment) ; |
|
430 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
431 |
this._q.run(); |
|
432 |
}, |
|
433 |
|
|
434 |
showFocusSingleComment : function(topComment, focusComment, reply) { |
|
435 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
436 |
this._showFocusSingleComment(topComment, focusComment, reply) ; |
|
437 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
438 |
this._q.run(); |
|
439 |
}, |
|
440 |
|
|
441 |
browse : function(order, whereto) { |
|
442 |
var comment = gIComments.browse(order, whereto) ; |
|
443 |
if (comment != null) |
|
444 |
this.showSingleComment(comment) ; |
|
445 |
}, |
|
446 |
|
|
447 |
_showComments : function(commentDbIds, topY, atDocumentTop) { |
|
448 |
this._q.add( |
|
449 |
{fn:function() { |
|
450 |
gShowingAllComments = atDocumentTop ; |
|
451 |
gIComments.hide() ; |
|
| 421 | 452 |
hideToc(); |
| 341 | 453 |
var cs = CY.Array.map(commentDbIds, function(id) { return gDb.getComment(id)Â ; }) ; |
454 |
var comments = gDb.getThreads(cs)Â ; |
|
455 |
gIComments.fetch(comments) ; |
|
456 |
|
|
457 |
if (commentDbIds.length > 0) { |
|
458 |
if (atDocumentTop) { |
|
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
459 |
CY.get(the_scrolling_part).set('scrollTop', 0) ; |
| 341 | 460 |
} |
461 |
else { |
|
462 |
gIComments.activate(commentDbIds[0]) ; |
|
|
532
0bad3613f59d
Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents:
525
diff
changeset
|
463 |
var scopeStart = CY.get(".c-id-"+commentDbIds[0]) ; |
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
464 |
|
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
465 |
// scopeStart could be null when comment has no scope |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
466 |
if (scopeStart && !scopeStart.inViewportRegion()) { |
| 341 | 467 |
scopeStart.scrollIntoView(true) ; |
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
468 |
|
|
491
50eeeb10e960
Since scrollIntoView scroll the embed iframe *and* the parent window, save and restore the position of the toolbar.
Production Moz <dev@sopinspace.com>
parents:
490
diff
changeset
|
469 |
// Since scrollIntoView scroll the embed ifram *and* the parent window |
|
50eeeb10e960
Since scrollIntoView scroll the embed iframe *and* the parent window, save and restore the position of the toolbar.
Production Moz <dev@sopinspace.com>
parents:
490
diff
changeset
|
470 |
// restore the position of the toolbar |
|
492
5b5245f4fe9a
Since scrollIntoView scroll the embed iframe *and* the parent window, restore the position of the toolbar.
Production Moz <dev@sopinspace.com>
parents:
491
diff
changeset
|
471 |
if (parent) |
|
5b5245f4fe9a
Since scrollIntoView scroll the embed iframe *and* the parent window, restore the position of the toolbar.
Production Moz <dev@sopinspace.com>
parents:
491
diff
changeset
|
472 |
parent.document.getElementById('outer-north').scrollIntoView(true) ; |
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
473 |
|
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
474 |
// SID: As we scroll via jQuery UI pane while on Safari mobile, we should base comment |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
475 |
// position on the result of previous scrollIntoView on the pane, so relatively to that |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
476 |
// new top. |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
477 |
// On other cases, it's the right place to add an offset on comment tops in order to |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
478 |
// avoid them to display under the "Add comment" button. |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
479 |
if (safari_mobile) |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
480 |
topY = add_comment_offset; |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
481 |
else |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
482 |
topY += add_comment_offset; |
|
491
50eeeb10e960
Since scrollIntoView scroll the embed iframe *and* the parent window, save and restore the position of the toolbar.
Production Moz <dev@sopinspace.com>
parents:
490
diff
changeset
|
483 |
} |
| 341 | 484 |
} |
485 |
} |
|
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
486 |
|
| 341 | 487 |
gIComments.setPosition([gConf['iCommentLeftPadding'], topY]) ; |
488 |
gIComments.show() ; |
|
489 |
}}) ; |
|
490 |
}, |
|
491 |
|
|
492 |
_animateTo : function(topY) { |
|
493 |
this._q.add({fn:function() { |
|
494 |
gIComments.setAnimationToPositions(topY) ; |
|
495 |
}}, |
|
496 |
{id:"animationRun", autoContinue:false, fn:CY.bind(gIComments.runAnimations, gIComments)} |
|
497 |
) ; |
|
498 |
}, |
|
499 |
|
|
500 |
_animateToAndFocus : function(topY, focusCommentId, reply) { |
|
501 |
this._q.add({fn:function() { |
|
502 |
gIComments.setAnimationToPositionsAndFocus(topY, focusCommentId, reply) ; |
|
503 |
}}, |
|
504 |
{id:"animationRun", autoContinue:false, fn:CY.bind(gIComments.runAnimations, gIComments)} |
|
505 |
) ; |
|
506 |
}, |
|
507 |
|
|
508 |
_animateToTop : function() { |
|
509 |
var topPos = gIComments.getTopPosition() ; |
|
510 |
if (topPos != null) |
|
511 |
this._animateTo(topPos[1]) ; |
|
512 |
}, |
|
513 |
|
|
514 |
animateToTop : function() { |
|
515 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
516 |
this._animateToTop() ; |
|
517 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
518 |
this._q.run(); |
|
519 |
}, |
|
520 |
|
|
521 |
showAllComments : function() { |
|
522 |
checkForOpenedDialog(null, function() { |
|
523 |
gShowingAllComments = true ; |
|
524 |
var allTopComments = CY.Array.map(gDb.comments, function(c){return c.id;}) ; |
|
|
432
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
525 |
// Reorder if by scope. |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
526 |
if (parent.$("#browse_by").val() == 'scope') { |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
527 |
allTopComments.sort(function (a,b) { |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
528 |
if (gDb.ordered_comment_ids['scope'].indexOf(a) < gDb.ordered_comment_ids['scope'].indexOf(b)) |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
529 |
return -1; |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
530 |
if (gDb.ordered_comment_ids['scope'].indexOf(a) > gDb.ordered_comment_ids['scope'].indexOf(b)) |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
531 |
return 1 |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
532 |
return 0 |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
533 |
}); |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
534 |
} |
| 375 | 535 |
// GIB: go down the 'add comment' icon |
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
536 |
this.showComments(allTopComments, [0, add_comment_offset], true); |
| 341 | 537 |
}, this, null) ; |
538 |
}, |
|
| 0 | 539 |
|
| 341 | 540 |
showScopeRemovedComments : function() { |
541 |
checkForOpenedDialog(null, function() { |
|
542 |
gShowingAllComments = true ; |
|
543 |
var scopeRemovedComments = CY.Array.filter(gDb.comments, function(comment) { return (comment.start_wrapper == -1)Â ; }) ; |
|
544 |
var scopeRemovedCommentIds = CY.Array.map(scopeRemovedComments, function(c){return c.id;}) ; |
|
|
432
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
545 |
// Reorder if by scope. |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
546 |
if (parent.$("#browse_by").val() == 'scope') { |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
547 |
scopeRemovedCommentIds.sort(function (a,b) { |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
548 |
if (gDb.ordered_comment_ids['scope'].indexOf(a) < gDb.ordered_comment_ids['scope'].indexOf(b)) |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
549 |
return -1; |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
550 |
if (gDb.ordered_comment_ids['scope'].indexOf(a) > gDb.ordered_comment_ids['scope'].indexOf(b)) |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
551 |
return 1 |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
552 |
return 0 |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
553 |
}); |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
554 |
} |
| 375 | 555 |
// GIB: go down the 'add comment' icon |
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
556 |
this.showComments(scopeRemovedCommentIds, [0, add_comment_offset], true); |
| 341 | 557 |
|
558 |
}, this, null) ; |
|
559 |
}, |
|
| 103 | 560 |
|
| 341 | 561 |
showComments : function(commentDbIds, mouseXY, atDocumentTop) { |
562 |
checkForOpenedDialog(null, function() { |
|
563 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
564 |
this._showComments(commentDbIds, mouseXY[1], atDocumentTop) ; |
|
|
553
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
565 |
// SID: let topY param be null to force Y acquisition from comment that |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
566 |
// may have previously been set by showComments |
|
bf26fb47a14c
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
567 |
this._animateTo() ; |
| 341 | 568 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
569 |
this._q.run(); |
|
570 |
}, this, null) ; |
|
571 |
}, |
|
| 0 | 572 |
|
| 341 | 573 |
openComment : function(iComment) { |
574 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
| 0 | 575 |
|
| 341 | 576 |
var y = gIComments.getTopPosition()[1] ; |
577 |
this._q.add({fn:function() { |
|
578 |
gIComments.open(iComment.commentId) ; |
|
579 |
gIComments.refresh(iComment.commentId) ; |
|
580 |
}}) ; |
|
581 |
this._animateTo(y) ; |
|
582 |
|
|
583 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
584 |
this._q.run(); |
|
585 |
}, |
|
586 |
|
|
587 |
closeComment : function(iComment) { |
|
588 |
checkForOpenedDialog(iComment, function() { |
|
589 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
590 |
|
|
591 |
var y = gIComments.getTopPosition()[1] ; |
|
592 |
this._q.add({fn:function() { |
|
593 |
var comment = gDb.getComment(iComment.commentId) ; |
|
594 |
gIComments.close(iComment.commentId) ; |
|
595 |
if (comment.reply_to_id != null) |
|
596 |
gIComments.refresh(comment.reply_to_id) ; |
|
597 |
}}) ; |
|
598 |
this._animateTo(y) ; |
|
599 |
|
|
600 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
601 |
this._q.run() ; |
|
602 |
}, this, null) ; |
|
603 |
}, |
|
604 |
|
|
605 |
activate : function(iComment) { |
|
606 |
gIComments.activate(iComment.commentId) ; |
|
607 |
} |
|
| 0 | 608 |
} |
| 341 | 609 |
|
| 0 | 610 |
readyForAction = function () { |
| 341 | 611 |
return !gSync._iPreventClick ; |
| 0 | 612 |
}; |