| author | Yves-Marie Haussonne <ymh.work+github@gmail.com> |
| Fri, 09 May 2014 18:35:26 +0200 | |
| changeset 656 | a84519031134 |
| parent 600 | fda73ac53450 |
| permissions | -rw-r--r-- |
| 0 | 1 |
CY = null; |
2 |
gPrefs = null; |
|
3 |
gLayout = null; |
|
4 |
gDb = null; |
|
5 |
gIComments = null; |
|
6 |
gSync = null; |
|
7 |
gGETValues = null; |
|
8 |
||
9 |
gConf = {'iCommentLeftPadding':4, |
|
| 341 | 10 |
'iCommentThreadPadding':12, |
| 0 | 11 |
'defaultCommentFormat':'markdown', |
12 |
'sliderFixedMin':.9, |
|
13 |
'sliderFixedMax':.1, |
|
14 |
'iCommentsInitAlloc':2, |
|
15 |
'defaultPrefs':{'text':{'style':'text-modern-style'}, 'user' : {'name' : '','email' : ''},'general': {'animduration' : '0.4'},'comments': {'threadpad' : '1'},'layout': {'comments_col_width' : '25' /* out of 100 */}} |
|
16 |
}; |
|
17 |
||
18 |
//available text styles in c-text-styles.css |
|
19 |
//classname(key) : will be added to #textcontainer, name(value) : the name to display in style dropdown choice" |
|
| 482 | 20 |
if (sv_custom_font) { |
21 |
gTextStyles = {'custom':gettext('custom'), 'modern':gettext('modern'), 'classic':gettext('classic'), 'code':gettext('code')}; |
|
22 |
} |
|
23 |
else { |
|
24 |
gTextStyles = {'modern':gettext('modern'), 'classic':gettext('classic'), 'code':gettext('code')}; |
|
25 |
} |
|
| 0 | 26 |
|
27 |
YUI( { |
|
| 341 | 28 |
base :sv_media_url + "/js/lib/yui/" + c_yui_base + "/build/", |
29 |
// filter: '{% if CLIENT_DEBUG %}debug{% else %}raw{% endif %}', |
|
30 |
// filter :'raw', |
|
31 |
timeout :10000 |
|
| 0 | 32 |
}).use( |
| 341 | 33 |
"cookie", |
34 |
"json", |
|
35 |
"overlay", |
|
36 |
"io-form", |
|
37 |
"async-queue", |
|
38 |
"event-mouseenter", |
|
39 |
"anim", |
|
40 |
"collection", |
|
41 |
function(Y) { |
|
42 |
CY = Y; |
|
43 |
|
|
| 0 | 44 |
gPrefs = new Preferences() ; |
45 |
gPrefs.init() ; |
|
46 |
|
|
47 |
gLayout = new Layout() ; |
|
48 |
gLayout.init() ; |
|
49 |
||
| 341 | 50 |
if (sv_withComments) { |
51 |
gDb = new Db() ; |
|
52 |
gDb.init() ; |
|
53 |
|
|
54 |
gIComments = new IComments() ; |
|
55 |
gIComments.init() ; |
|
56 |
} |
|
| 0 | 57 |
|
58 |
gSync = new Sync() ; |
|
59 |
gSync.init() ; |
|
60 |
||
| 341 | 61 |
CY.on("domready", onDomReady, this); |
| 0 | 62 |
|
| 341 | 63 |
}); |
| 0 | 64 |
|
65 |
_reinit = function(filterRes) { |
|
| 341 | 66 |
gIComments.hide(); |
67 |
gDb.initComments(filterRes['commentIds']); |
|
| 0 | 68 |
|
| 341 | 69 |
unpaintAllComments(); |
70 |
renderCommentScopes(); |
|
71 |
|
|
72 |
updateFilterResultsCount(filterRes['nbDiscussions'], filterRes['nbComments'], filterRes['nbReplies']); |
|
| 0 | 73 |
}; |
74 |
||
75 |
reinit = function(filterGETValues) { |
|
| 341 | 76 |
var filterRes = gDb.computeFilterResults(filterGETValues); |
77 |
_reinit(filterRes); |
|
| 0 | 78 |
}; |
79 |
||
80 |
hideAll = function() { |
|
| 341 | 81 |
_reinit({'commentIds':[],'nbDiscussions':0, 'nbComments':0, 'nbReplies':0}); |
| 0 | 82 |
}; |
83 |
||
84 |
updateFilterResultsCount = function(nbDiscussions, nbComments, nbReplies) { |
|
| 341 | 85 |
var r = gDb.getCommentsAndRepliesCounts(true); |
86 |
var nbAllComments = r[0], nbAllReplies = r[1]; |
|
87 |
var detailedResults = (nbComments != 0 || nbReplies != 0) && (nbAllComments != nbComments || nbAllReplies != nbReplies) ; |
|
88 |
if (gLayout.isInFrame()) { |
|
89 |
parent.f_updateFilterCountDetailed(detailedResults) ; |
|
90 |
parent.f_updateFilterCountResult(nbDiscussions, nbComments, nbReplies, nbAllComments, nbAllReplies); |
|
91 |
} |
|
| 0 | 92 |
}; |
93 |
||
94 |
updateResetFilterResultsCount = function() { |
|
| 341 | 95 |
var counts = gDb.getCommentsAndRepliesCounts(false) |
96 |
var nbComments = counts[0], nbReplies = counts[1]; |
|
| 0 | 97 |
|
| 341 | 98 |
var nbDiscussions = nbComments; |
99 |
updateFilterResultsCount(nbDiscussions, nbComments, nbReplies); |
|
| 0 | 100 |
}; |
101 |
||
102 |
// TODO MOVE |
|
103 |
renderCommentScopes = function() { |
|
| 341 | 104 |
for (var i = 0 ; i < gDb.comments.length ; i++) { |
105 |
var comment = gDb.comments[i] ; |
|
106 |
paintCommentScope(comment) ; |
|
107 |
} |
|
| 0 | 108 |
} ; |
109 |
||
110 |
onTextMouseUp = function(e) { |
|
| 341 | 111 |
if (readyForAction()) { |
112 |
var selection = getSelectionInfo() ; |
|
113 |
if (selection != null) { |
|
114 |
updateICommentFormSelection(selection) ; |
|
115 |
if (gEditICommentHost != null) { |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
556
diff
changeset
|
116 |
var modifyScope = CY.one("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked') ; |
| 341 | 117 |
if (modifyScope) { |
118 |
gEditICommentHost.scrollIntoView() ; |
|
119 |
} |
|
120 |
} |
|
121 |
} |
|
122 |
else { |
|
123 |
var node = e.target ; |
|
124 |
if (node.hasClass('c-c')) { |
|
125 |
var elt = CY.Node.getDOMNode(node) ; |
|
126 |
var commentIds = getCommentIdsFromClasses(elt) ; |
|
127 |
if (commentIds.length > 0) { |
|
128 |
checkForOpenedDialog(null, function() { // will only check for reply |
|
129 |
gSync.showComments(commentIds, [e.pageX, e.pageY], false) ; |
|
130 |
}) ; |
|
131 |
} |
|
132 |
} |
|
133 |
} |
|
134 |
//// FIRST UPDATE SELECTION IF ANY AND SCROLL TO EDITION IF ANY |
|
135 |
// if (isICommentFormVisible() ||Â gEditICommentHost != null) { |
|
136 |
// CY.log(selection) ; |
|
137 |
// updateICommentFormSelection(selection) ; |
|
138 |
// |
|
139 |
// if (gEditICommentHost != null) { |
|
140 |
// var modifyScope = CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked') ; |
|
141 |
// if (modifyScope) { |
|
142 |
// gEditICommentHost.scrollIntoView() ; |
|
143 |
// didSomething = true ; |
|
144 |
// } |
|
145 |
// } |
|
146 |
// if (isICommentFormVisible()) |
|
147 |
// didSomething = true ; |
|
148 |
// } |
|
149 |
// else { |
|
150 |
// checkForOpenedDialog(null, function() { // will only check for reply |
|
151 |
// var node = e.target ; |
|
152 |
// if (node.hasClass('c-c')) { |
|
153 |
// var elt = CY.Node.getDOMNode(node) ; |
|
154 |
// var commentIds = getCommentIdsFromClasses(elt) ; |
|
155 |
// if (commentIds.length > 0) { |
|
156 |
// //hideOverlay(gICommentForm) ; |
|
157 |
// // gIComments.hide() ;20080814 moved it to gSync._showComments |
|
158 |
// gSync.showComments(commentIds, [e.pageX, e.pageY]) ; |
|
159 |
// } |
|
160 |
// } |
|
161 |
// }) ; |
|
162 |
// } |
|
163 |
} |
|
| 0 | 164 |
} ; |
165 |
||
|
556
69503659fe8f
[c_selection.js] If safari_mobile, get current selection from a previously created global variable
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
166 |
// safari_mobile defined in media/js/client/c_sync.js |
|
69503659fe8f
[c_selection.js] If safari_mobile, get current selection from a previously created global variable
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
167 |
if (safari_mobile) |
|
69503659fe8f
[c_selection.js] If safari_mobile, get current selection from a previously created global variable
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
168 |
onSelectionChange = onTextMouseUp; |
|
69503659fe8f
[c_selection.js] If safari_mobile, get current selection from a previously created global variable
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
169 |
|
| 0 | 170 |
gLastScrollTime = null ; |
171 |
checkForAlignement = function () { |
|
| 341 | 172 |
var now = (new Date()).getTime() ; |
173 |
if ((gLastScrollTime != null) && (now - gLastScrollTime) > 200) { |
|
174 |
positionICommentForm() ; |
|
175 |
gLastScrollTime = null ; |
|
176 |
} |
|
| 0 | 177 |
}; |
178 |
||
179 |
onFrameScroll = function () { |
|
| 341 | 180 |
gLastScrollTime = (new Date()).getTime() ; |
| 0 | 181 |
}; |
182 |
||
183 |
browse = function(order, whereto) { |
|
| 341 | 184 |
gSync.browse(order, whereto) ; |
| 0 | 185 |
}; |
186 |
||
187 |
initialConnect = function() { |
|
| 341 | 188 |
CY.on("mouseup", onTextMouseUp, "#textcontainer"); |
189 |
gTimer = CY.Lang.later(200, this, checkForAlignement, [], true) ; |
|
190 |
CY.on('scroll', onFrameScroll, window, this, true); |
|
191 |
CY.on('resize', onFrameScroll, window, this, true); |
|
| 0 | 192 |
}; |
193 |
||
194 |
preventLinksInText = function() { |
|
| 341 | 195 |
var interceptLink = function(e) { |
196 |
var a = e.target; |
|
197 |
var href = null; |
|
198 |
while (a != null && href == null) { |
|
199 |
a = a.get('parentNode'); |
|
200 |
href = a.get("href"); |
|
201 |
} |
|
202 |
|
|
203 |
if (a != null && href != null) { |
|
204 |
//alert(window.location) ; |
|
205 |
var clean_window_location = window.location.href ; |
|
206 |
|
|
207 |
var ind = clean_window_location.indexOf('#') ; |
|
208 |
if (ind != -1) |
|
209 |
clean_window_location = clean_window_location.substring(0, ind) ; |
|
210 |
|
|
211 |
if (href.indexOf(clean_window_location) == -1 ) { |
|
212 |
window.open(a.get("href")); |
|
213 |
e.preventDefault(); ; |
|
214 |
} |
|
215 |
} |
|
216 |
} ; |
|
| 0 | 217 |
|
| 341 | 218 |
CY.all("#textcontainer a").on("click", interceptLink); |
| 0 | 219 |
}; |
220 |
||
221 |
onDomReady = function(arg1) { |
|
| 341 | 222 |
preventLinksInText(); |
223 |
var q1 = new CY.AsyncQueue(); // |
|
224 |
// doesn't behave like the doc says : |
|
225 |
// no timeout -> seems in blocking mode |
|
226 |
q1.add( { |
|
227 |
fn : function() { |
|
| 0 | 228 |
|
| 341 | 229 |
if (gLayout.isInComentSite()) { |
230 |
parent.toInitialSize(); |
|
231 |
} |
|
232 |
if (sv_withComments) { |
|
233 |
instanciateICommentForm(); |
|
234 |
} |
|
| 421 | 235 |
instanciateToc(); |
| 341 | 236 |
}, |
237 |
timeout :5 |
|
238 |
}, { |
|
239 |
fn : function() { |
|
| 0 | 240 |
|
| 341 | 241 |
gGETValues = CY.JSON.parse(sv_get_params); |
242 |
|
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
556
diff
changeset
|
243 |
CY.one('#maincontainer').setStyle('display', 'block'); |
|
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
556
diff
changeset
|
244 |
CY.one('#textcontainer').setStyle('display', 'block'); |
| 341 | 245 |
|
246 |
var val = (sv_withComments) ? gPrefs.get('layout','comments_col_width') : 0 ; |
|
247 |
var colWidth = sliderValToPx(val) ; |
|
248 |
gLayout.setLeftColumnWidth(colWidth) ; |
|
249 |
|
|
250 |
if (gLayout.isInFrame()) { |
|
251 |
parent.f_initFrame(); |
|
252 |
parent.f_layoutFrames(); |
|
| 0 | 253 |
|
| 341 | 254 |
if (sv_withComments) { |
255 |
parent.f_fillTopToolbar() ; |
|
256 |
if (hasPerm("can_create_comment"))Â |
|
257 |
parent.$("#add_comment_btn").removeClass('initially_hidden'); |
|
258 |
//parent.enqueueLoadingMsg(); // no more loading message ? TODO |
|
259 |
|
|
260 |
parent.f_fillFilterTab() ; |
|
261 |
parent.f_fillPreferencesTab() ; |
|
262 |
|
|
263 |
// parent.f_fillBrowseSection() ; |
|
264 |
|
|
265 |
var firstTimeFilterData = CY.JSON.parse(sv_filter_data); |
|
266 |
parent.f_updateFilterData(firstTimeFilterData); |
|
267 |
|
|
268 |
parent.f_setFilterValue(gGETValues) ; |
|
269 |
} |
|
270 |
parent.f_fillTextPreferencesTab() ; |
|
271 |
} |
|
272 |
|
|
273 |
if (gLayout.isInComentSite()) |
|
274 |
parent.$("#c_fullscreen_btn").show(); |
|
275 |
else { |
|
276 |
parent.$("#c_fullscreen_btn").hide(); |
|
277 |
} |
|
| 0 | 278 |
|
| 422 | 279 |
if (gToc['empty']) |
280 |
parent.$("#c_toc_btn").hide(); |
|
281 |
||
| 341 | 282 |
}, |
283 |
timeout :5 |
|
284 |
}, { |
|
285 |
fn : function() { |
|
286 |
if (sv_withComments) { |
|
287 |
|
|
288 |
reinit(gGETValues); |
|
289 |
initialConnect(); |
|
290 |
} |
|
291 |
}, |
|
292 |
timeout :5 |
|
293 |
}, { |
|
294 |
fn : function() { |
|
295 |
if (gLayout.isInFrame()) { |
|
296 |
parent.f_interfaceUnfreeze() ; |
|
297 |
parent.f_removeLoadingMsg(); |
|
298 |
} |
|
299 |
// if there is a comment id in the url display it |
|
300 |
if ("comment_id_key" in gGETValues) { |
|
301 |
var id_key = gGETValues["comment_id_key"] ; |
|
302 |
var comment = gDb.getCommentByIdKey(id_key) ; |
|
303 |
if (comment != null) { |
|
304 |
var path = gDb.getPath(comment) ; |
|
305 |
var topParentComment = path[path.length - 1] ; |
|
|
329
00df963f91fb
When comment_id_key is passed as URL parameter, focus on this comment, instead of the top comment of the related thread.
gibus
parents:
276
diff
changeset
|
306 |
var focusComment = gDb.getCommentByIdKey(id_key); |
|
337
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
307 |
// if comment_op=reply, show reply form |
|
340
9e2b9e568e42
Be more strict by controlling that value ofcomment_op url parameter is set to "reply"
gibus
parents:
337
diff
changeset
|
308 |
if ("comment_op" in gGETValues && gGETValues["comment_op"] == 'reply') { |
|
337
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
309 |
gSync.showFocusSingleComment(topParentComment, focusComment, true) ; |
|
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
310 |
} |
|
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
311 |
else { |
|
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
312 |
gSync.showFocusSingleComment(topParentComment, focusComment, false) ; |
|
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
313 |
} |
| 341 | 314 |
} |
315 |
} |
|
|
337
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
316 |
|
| 341 | 317 |
// if comment_auto_display: show all comments |
318 |
if ("comments_auto_display" in gGETValues) { |
|
319 |
gSync.showAllComments(); |
|
320 |
} |
|
321 |
|
|
322 |
// else { |
|
323 |
// gSync.showAllComments() ;// show all |
|
324 |
// } |
|
325 |
} |
|
326 |
}); |
|
327 |
q1.run(); |
|
| 0 | 328 |
}; |
329 |