| author | gibus |
| Wed, 11 Sep 2013 23:13:01 +0200 | |
| changeset 532 | 0bad3613f59d |
| parent 525 | 89ef5ed3c48b |
| child 556 | 69503659fe8f |
| 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 |
"text-modern-style", |
34 |
"cookie", |
|
35 |
"json", |
|
36 |
"overlay", |
|
37 |
"io-form", |
|
38 |
"async-queue", |
|
39 |
"event-mouseenter", |
|
40 |
"anim", |
|
41 |
"collection", |
|
42 |
function(Y) { |
|
43 |
CY = Y; |
|
44 |
|
|
| 0 | 45 |
gPrefs = new Preferences() ; |
46 |
gPrefs.init() ; |
|
47 |
|
|
48 |
gLayout = new Layout() ; |
|
49 |
gLayout.init() ; |
|
50 |
||
| 341 | 51 |
if (sv_withComments) { |
52 |
gDb = new Db() ; |
|
53 |
gDb.init() ; |
|
54 |
|
|
55 |
gIComments = new IComments() ; |
|
56 |
gIComments.init() ; |
|
57 |
} |
|
| 0 | 58 |
|
59 |
gSync = new Sync() ; |
|
60 |
gSync.init() ; |
|
61 |
||
| 341 | 62 |
CY.on("domready", onDomReady, this); |
| 0 | 63 |
|
| 341 | 64 |
}); |
| 0 | 65 |
|
66 |
_reinit = function(filterRes) { |
|
| 341 | 67 |
gIComments.hide(); |
68 |
gDb.initComments(filterRes['commentIds']); |
|
| 0 | 69 |
|
| 341 | 70 |
unpaintAllComments(); |
71 |
renderCommentScopes(); |
|
72 |
|
|
73 |
updateFilterResultsCount(filterRes['nbDiscussions'], filterRes['nbComments'], filterRes['nbReplies']); |
|
| 0 | 74 |
}; |
75 |
||
76 |
reinit = function(filterGETValues) { |
|
| 341 | 77 |
var filterRes = gDb.computeFilterResults(filterGETValues); |
78 |
_reinit(filterRes); |
|
| 0 | 79 |
}; |
80 |
||
81 |
hideAll = function() { |
|
| 341 | 82 |
_reinit({'commentIds':[],'nbDiscussions':0, 'nbComments':0, 'nbReplies':0}); |
| 0 | 83 |
}; |
84 |
||
85 |
updateFilterResultsCount = function(nbDiscussions, nbComments, nbReplies) { |
|
| 341 | 86 |
var r = gDb.getCommentsAndRepliesCounts(true); |
87 |
var nbAllComments = r[0], nbAllReplies = r[1]; |
|
88 |
var detailedResults = (nbComments != 0 || nbReplies != 0) && (nbAllComments != nbComments || nbAllReplies != nbReplies) ; |
|
89 |
if (gLayout.isInFrame()) { |
|
90 |
parent.f_updateFilterCountDetailed(detailedResults) ; |
|
91 |
parent.f_updateFilterCountResult(nbDiscussions, nbComments, nbReplies, nbAllComments, nbAllReplies); |
|
92 |
} |
|
| 0 | 93 |
}; |
94 |
||
95 |
updateResetFilterResultsCount = function() { |
|
| 341 | 96 |
var counts = gDb.getCommentsAndRepliesCounts(false) |
97 |
var nbComments = counts[0], nbReplies = counts[1]; |
|
| 0 | 98 |
|
| 341 | 99 |
var nbDiscussions = nbComments; |
100 |
updateFilterResultsCount(nbDiscussions, nbComments, nbReplies); |
|
| 0 | 101 |
}; |
102 |
||
103 |
// TODO MOVE |
|
104 |
renderCommentScopes = function() { |
|
| 341 | 105 |
for (var i = 0 ; i < gDb.comments.length ; i++) { |
106 |
var comment = gDb.comments[i] ; |
|
107 |
paintCommentScope(comment) ; |
|
108 |
} |
|
| 0 | 109 |
} ; |
110 |
||
111 |
onTextMouseUp = function(e) { |
|
| 341 | 112 |
if (readyForAction()) { |
113 |
var selection = getSelectionInfo() ; |
|
114 |
if (selection != null) { |
|
115 |
updateICommentFormSelection(selection) ; |
|
116 |
if (gEditICommentHost != null) { |
|
|
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
|
117 |
var modifyScope = CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked') ; |
| 341 | 118 |
if (modifyScope) { |
119 |
gEditICommentHost.scrollIntoView() ; |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
else { |
|
124 |
var node = e.target ; |
|
125 |
if (node.hasClass('c-c')) { |
|
126 |
var elt = CY.Node.getDOMNode(node) ; |
|
127 |
var commentIds = getCommentIdsFromClasses(elt) ; |
|
128 |
if (commentIds.length > 0) { |
|
129 |
checkForOpenedDialog(null, function() { // will only check for reply |
|
130 |
gSync.showComments(commentIds, [e.pageX, e.pageY], false) ; |
|
131 |
}) ; |
|
132 |
} |
|
133 |
} |
|
134 |
} |
|
135 |
//// FIRST UPDATE SELECTION IF ANY AND SCROLL TO EDITION IF ANY |
|
136 |
// if (isICommentFormVisible() ||Â gEditICommentHost != null) { |
|
137 |
// CY.log(selection) ; |
|
138 |
// updateICommentFormSelection(selection) ; |
|
139 |
// |
|
140 |
// if (gEditICommentHost != null) { |
|
141 |
// var modifyScope = CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked') ; |
|
142 |
// if (modifyScope) { |
|
143 |
// gEditICommentHost.scrollIntoView() ; |
|
144 |
// didSomething = true ; |
|
145 |
// } |
|
146 |
// } |
|
147 |
// if (isICommentFormVisible()) |
|
148 |
// didSomething = true ; |
|
149 |
// } |
|
150 |
// else { |
|
151 |
// checkForOpenedDialog(null, function() { // will only check for reply |
|
152 |
// var node = e.target ; |
|
153 |
// if (node.hasClass('c-c')) { |
|
154 |
// var elt = CY.Node.getDOMNode(node) ; |
|
155 |
// var commentIds = getCommentIdsFromClasses(elt) ; |
|
156 |
// if (commentIds.length > 0) { |
|
157 |
// //hideOverlay(gICommentForm) ; |
|
158 |
// // gIComments.hide() ;20080814 moved it to gSync._showComments |
|
159 |
// gSync.showComments(commentIds, [e.pageX, e.pageY]) ; |
|
160 |
// } |
|
161 |
// } |
|
162 |
// }) ; |
|
163 |
// } |
|
164 |
} |
|
| 0 | 165 |
} ; |
166 |
||
167 |
gLastScrollTime = null ; |
|
168 |
checkForAlignement = function () { |
|
| 341 | 169 |
var now = (new Date()).getTime() ; |
170 |
if ((gLastScrollTime != null) && (now - gLastScrollTime) > 200) { |
|
171 |
positionICommentForm() ; |
|
172 |
gLastScrollTime = null ; |
|
173 |
} |
|
| 0 | 174 |
}; |
175 |
||
176 |
onFrameScroll = function () { |
|
| 341 | 177 |
gLastScrollTime = (new Date()).getTime() ; |
| 0 | 178 |
}; |
179 |
||
180 |
browse = function(order, whereto) { |
|
| 341 | 181 |
gSync.browse(order, whereto) ; |
| 0 | 182 |
}; |
183 |
||
184 |
initialConnect = function() { |
|
| 341 | 185 |
CY.on("mouseup", onTextMouseUp, "#textcontainer"); |
186 |
gTimer = CY.Lang.later(200, this, checkForAlignement, [], true) ; |
|
187 |
CY.on('scroll', onFrameScroll, window, this, true); |
|
188 |
CY.on('resize', onFrameScroll, window, this, true); |
|
| 0 | 189 |
}; |
190 |
||
191 |
preventLinksInText = function() { |
|
| 341 | 192 |
var interceptLink = function(e) { |
193 |
var a = e.target; |
|
194 |
var href = null; |
|
195 |
while (a != null && href == null) { |
|
196 |
a = a.get('parentNode'); |
|
197 |
href = a.get("href"); |
|
198 |
} |
|
199 |
|
|
200 |
if (a != null && href != null) { |
|
201 |
//alert(window.location) ; |
|
202 |
var clean_window_location = window.location.href ; |
|
203 |
|
|
204 |
var ind = clean_window_location.indexOf('#') ; |
|
205 |
if (ind != -1) |
|
206 |
clean_window_location = clean_window_location.substring(0, ind) ; |
|
207 |
|
|
208 |
if (href.indexOf(clean_window_location) == -1 ) { |
|
209 |
window.open(a.get("href")); |
|
210 |
e.preventDefault(); ; |
|
211 |
} |
|
212 |
} |
|
213 |
} ; |
|
| 0 | 214 |
|
| 341 | 215 |
CY.all("#textcontainer a").on("click", interceptLink); |
| 0 | 216 |
}; |
217 |
||
218 |
onDomReady = function(arg1) { |
|
| 341 | 219 |
preventLinksInText(); |
220 |
var q1 = new CY.AsyncQueue(); // |
|
221 |
// doesn't behave like the doc says : |
|
222 |
// no timeout -> seems in blocking mode |
|
223 |
q1.add( { |
|
224 |
fn : function() { |
|
| 0 | 225 |
|
| 341 | 226 |
if (gLayout.isInComentSite()) { |
227 |
parent.toInitialSize(); |
|
228 |
} |
|
229 |
if (sv_withComments) { |
|
230 |
instanciateICommentForm(); |
|
231 |
} |
|
| 421 | 232 |
instanciateToc(); |
| 341 | 233 |
}, |
234 |
timeout :5 |
|
235 |
}, { |
|
236 |
fn : function() { |
|
| 0 | 237 |
|
| 341 | 238 |
gGETValues = CY.JSON.parse(sv_get_params); |
239 |
|
|
|
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
|
240 |
CY.get('#maincontainer').setStyle('display', 'block'); |
|
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
|
241 |
CY.get('#textcontainer').setStyle('display', 'block'); |
| 341 | 242 |
|
243 |
var val = (sv_withComments) ? gPrefs.get('layout','comments_col_width') : 0 ; |
|
244 |
var colWidth = sliderValToPx(val) ; |
|
245 |
gLayout.setLeftColumnWidth(colWidth) ; |
|
246 |
|
|
247 |
if (gLayout.isInFrame()) { |
|
248 |
parent.f_initFrame(); |
|
249 |
parent.f_layoutFrames(); |
|
| 0 | 250 |
|
| 341 | 251 |
if (sv_withComments) { |
252 |
parent.f_fillTopToolbar() ; |
|
253 |
if (hasPerm("can_create_comment"))Â |
|
254 |
parent.$("#add_comment_btn").removeClass('initially_hidden'); |
|
255 |
//parent.enqueueLoadingMsg(); // no more loading message ? TODO |
|
256 |
|
|
257 |
parent.f_fillFilterTab() ; |
|
258 |
parent.f_fillPreferencesTab() ; |
|
259 |
|
|
260 |
// parent.f_fillBrowseSection() ; |
|
261 |
|
|
262 |
var firstTimeFilterData = CY.JSON.parse(sv_filter_data); |
|
263 |
parent.f_updateFilterData(firstTimeFilterData); |
|
264 |
|
|
265 |
parent.f_setFilterValue(gGETValues) ; |
|
266 |
} |
|
267 |
parent.f_fillTextPreferencesTab() ; |
|
268 |
} |
|
269 |
|
|
270 |
if (gLayout.isInComentSite()) |
|
271 |
parent.$("#c_fullscreen_btn").show(); |
|
272 |
else { |
|
273 |
parent.$("#c_fullscreen_btn").hide(); |
|
274 |
} |
|
| 0 | 275 |
|
| 422 | 276 |
if (gToc['empty']) |
277 |
parent.$("#c_toc_btn").hide(); |
|
278 |
||
| 341 | 279 |
}, |
280 |
timeout :5 |
|
281 |
}, { |
|
282 |
fn : function() { |
|
283 |
if (sv_withComments) { |
|
284 |
|
|
285 |
reinit(gGETValues); |
|
286 |
initialConnect(); |
|
287 |
} |
|
288 |
}, |
|
289 |
timeout :5 |
|
290 |
}, { |
|
291 |
fn : function() { |
|
292 |
if (gLayout.isInFrame()) { |
|
293 |
parent.f_interfaceUnfreeze() ; |
|
294 |
parent.f_removeLoadingMsg(); |
|
295 |
} |
|
296 |
// if there is a comment id in the url display it |
|
297 |
if ("comment_id_key" in gGETValues) { |
|
298 |
var id_key = gGETValues["comment_id_key"] ; |
|
299 |
var comment = gDb.getCommentByIdKey(id_key) ; |
|
300 |
if (comment != null) { |
|
301 |
var path = gDb.getPath(comment) ; |
|
302 |
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
|
303 |
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
|
304 |
// 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
|
305 |
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
|
306 |
gSync.showFocusSingleComment(topParentComment, focusComment, true) ; |
|
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
307 |
} |
|
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
308 |
else { |
|
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
309 |
gSync.showFocusSingleComment(topParentComment, focusComment, false) ; |
|
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
310 |
} |
| 341 | 311 |
} |
312 |
} |
|
|
337
614669e0e313
Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents:
329
diff
changeset
|
313 |
|
| 341 | 314 |
// if comment_auto_display: show all comments |
315 |
if ("comments_auto_display" in gGETValues) { |
|
316 |
gSync.showAllComments(); |
|
317 |
} |
|
318 |
|
|
319 |
// else { |
|
320 |
// gSync.showAllComments() ;// show all |
|
321 |
// } |
|
322 |
} |
|
323 |
}); |
|
324 |
q1.run(); |
|
| 0 | 325 |
}; |
326 |