|
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, |
|
10 'defaultCommentFormat':'markdown', |
|
11 'sliderFixedMin':.9, |
|
12 'sliderFixedMax':.1, |
|
13 'iCommentsInitAlloc':2, |
|
14 'defaultPrefs':{'text':{'style':'text-modern-style'}, 'user' : {'name' : '','email' : ''},'general': {'animduration' : '0.4'},'comments': {'threadpad' : '1'},'layout': {'comments_col_width' : '25' /* out of 100 */}} |
|
15 }; |
|
16 |
|
17 //available text styles in c-text-styles.css |
|
18 //classname(key) : will be added to #textcontainer, name(value) : the name to display in style dropdown choice" |
|
19 gTextStyles = {'text-modern-style':gettext('modern'), 'text-classic-style':gettext('classic'), 'text-code-style':gettext('code')}; |
|
20 |
|
21 YUI( { |
|
22 base :sv_media_url + "/js/lib/yui/" + c_yui_base + "/build/", |
|
23 // filter: '{% if CLIENT_DEBUG %}debug{% else %}raw{% endif %}', |
|
24 // filter :'raw', |
|
25 timeout :10000 |
|
26 }).use( |
|
27 "text-modern-style", |
|
28 "cookie", |
|
29 "json", |
|
30 "overlay", |
|
31 "io-form", |
|
32 "async-queue", |
|
33 "event-mouseenter", |
|
34 "anim", |
|
35 "collection", |
|
36 function(Y) { |
|
37 CY = Y; |
|
38 |
|
39 gPrefs = new Preferences() ; |
|
40 gPrefs.init() ; |
|
41 |
|
42 gLayout = new Layout() ; |
|
43 gLayout.init() ; |
|
44 |
|
45 if (sv_withComments) { |
|
46 gDb = new Db() ; |
|
47 gDb.init() ; |
|
48 |
|
49 gIComments = new IComments() ; |
|
50 gIComments.init() ; |
|
51 } |
|
52 |
|
53 gSync = new Sync() ; |
|
54 gSync.init() ; |
|
55 |
|
56 CY.on("domready", onDomReady, this); |
|
57 |
|
58 }); |
|
59 |
|
60 _reinit = function(filterRes) { |
|
61 gIComments.hide(); |
|
62 gDb.initComments(filterRes['commentIds']); |
|
63 |
|
64 unpaintAllComments(); |
|
65 renderCommentScopes(); |
|
66 |
|
67 updateFilterResultsCount(filterRes['nbDiscussions'], filterRes['nbComments'], filterRes['nbReplies']); |
|
68 }; |
|
69 |
|
70 reinit = function(filterGETValues) { |
|
71 var filterRes = gDb.computeFilterResults(filterGETValues); |
|
72 _reinit(filterRes); |
|
73 }; |
|
74 |
|
75 hideAll = function() { |
|
76 _reinit({'commentIds':[],'nbDiscussions':0, 'nbComments':0, 'nbReplies':0}); |
|
77 }; |
|
78 |
|
79 updateFilterResultsCount = function(nbDiscussions, nbComments, nbReplies) { |
|
80 var r = gDb.getCommentsAndRepliesCounts(true); |
|
81 var nbAllComments = r[0], nbAllReplies = r[1]; |
|
82 var detailedResults = (nbComments != 0 || nbReplies != 0) && (nbAllComments != nbComments || nbAllReplies != nbReplies) ; |
|
83 if (gLayout.isInFrame()) { |
|
84 parent.f_updateFilterCountDetailed(detailedResults) ; |
|
85 parent.f_updateFilterCountResult(nbDiscussions, nbComments, nbReplies, nbAllComments, nbAllReplies); |
|
86 } |
|
87 }; |
|
88 |
|
89 updateResetFilterResultsCount = function() { |
|
90 var counts = gDb.getCommentsAndRepliesCounts(false) |
|
91 var nbComments = counts[0], nbReplies = counts[1]; |
|
92 |
|
93 var nbDiscussions = nbComments; |
|
94 updateFilterResultsCount(nbDiscussions, nbComments, nbReplies); |
|
95 }; |
|
96 |
|
97 // TODO MOVE |
|
98 renderCommentScopes = function() { |
|
99 for (var i = 0 ; i < gDb.comments.length ; i++) { |
|
100 var comment = gDb.comments[i] ; |
|
101 paintCommentScope(comment) ; |
|
102 } |
|
103 } ; |
|
104 |
|
105 onTextMouseUp = function(e) { |
|
106 if (readyForAction()) { |
|
107 var selection = getSelectionInfo() ; |
|
108 if (selection != null) { |
|
109 updateICommentFormSelection(selection) ; |
|
110 if (gEditICommentHost != null) { |
|
111 var modifyScope = CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked') ; |
|
112 if (modifyScope) { |
|
113 gEditICommentHost.scrollIntoView() ; |
|
114 } |
|
115 } |
|
116 } |
|
117 else { |
|
118 var node = e.target ; |
|
119 if (node.hasClass('c-c')) { |
|
120 var elt = CY.Node.getDOMNode(node) ; |
|
121 var commentIds = getCommentIdsFromClasses(elt) ; |
|
122 if (commentIds.length > 0) { |
|
123 checkForOpenedDialog(null, function() { // will only check for reply |
|
124 gSync.showComments(commentIds, [e.pageX, e.pageY], false) ; |
|
125 }) ; |
|
126 } |
|
127 } |
|
128 } |
|
129 //// FIRST UPDATE SELECTION IF ANY AND SCROLL TO EDITION IF ANY |
|
130 // if (isICommentFormVisible() || gEditICommentHost != null) { |
|
131 // CY.log(selection) ; |
|
132 // updateICommentFormSelection(selection) ; |
|
133 // |
|
134 // if (gEditICommentHost != null) { |
|
135 // var modifyScope = CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked') ; |
|
136 // if (modifyScope) { |
|
137 // gEditICommentHost.scrollIntoView() ; |
|
138 // didSomething = true ; |
|
139 // } |
|
140 // } |
|
141 // if (isICommentFormVisible()) |
|
142 // didSomething = true ; |
|
143 // } |
|
144 // else { |
|
145 // checkForOpenedDialog(null, function() { // will only check for reply |
|
146 // var node = e.target ; |
|
147 // if (node.hasClass('c-c')) { |
|
148 // var elt = CY.Node.getDOMNode(node) ; |
|
149 // var commentIds = getCommentIdsFromClasses(elt) ; |
|
150 // if (commentIds.length > 0) { |
|
151 // //hideOverlay(gICommentForm) ; |
|
152 // // gIComments.hide() ;20080814 moved it to gSync._showComments |
|
153 // gSync.showComments(commentIds, [e.pageX, e.pageY]) ; |
|
154 // } |
|
155 // } |
|
156 // }) ; |
|
157 // } |
|
158 } |
|
159 } ; |
|
160 |
|
161 gLastScrollTime = null ; |
|
162 checkForAlignement = function () { |
|
163 var now = (new Date()).getTime() ; |
|
164 if ((gLastScrollTime != null) && (now - gLastScrollTime) > 200) { |
|
165 positionICommentForm() ; |
|
166 gLastScrollTime = null ; |
|
167 } |
|
168 }; |
|
169 |
|
170 onFrameScroll = function () { |
|
171 gLastScrollTime = (new Date()).getTime() ; |
|
172 }; |
|
173 |
|
174 browse = function(order, whereto) { |
|
175 gSync.browse(order, whereto) ; |
|
176 }; |
|
177 |
|
178 initialConnect = function() { |
|
179 CY.on("mouseup", onTextMouseUp, "#textcontainer"); |
|
180 gTimer = CY.Lang.later(200, this, checkForAlignement, [], true) ; |
|
181 CY.on('scroll', onFrameScroll, window, this, true); |
|
182 CY.on('resize', onFrameScroll, window, this, true); |
|
183 }; |
|
184 |
|
185 // serious tests were made : various browsers + comments on a link. |
|
186 preventLinksInText = function() { |
|
187 var interceptLink = function(e) { |
|
188 e.preventDefault(); |
|
189 |
|
190 var a = e.target; |
|
191 while (a != null && a.get("href") == null) { |
|
192 a = a.get('parentNode'); |
|
193 } |
|
194 |
|
195 if (a != null && a.get("href") != null) { |
|
196 window.open(a.get("href")); |
|
197 } |
|
198 |
|
199 } ; |
|
200 |
|
201 CY.all("#textcontainer a").on("click", interceptLink); |
|
202 }; |
|
203 |
|
204 onDomReady = function(arg1) { |
|
205 preventLinksInText(); |
|
206 var q1 = new CY.AsyncQueue(); // |
|
207 // doesn't behave like the doc says : |
|
208 // no timeout -> seems in blocking mode |
|
209 q1.add( { |
|
210 fn : function() { |
|
211 |
|
212 if (gLayout.isInComentSite()) { |
|
213 top.v_toInitialSize(); |
|
214 } |
|
215 if (sv_withComments) { |
|
216 instanciateICommentForm(); |
|
217 } |
|
218 }, |
|
219 timeout :5 |
|
220 }, { |
|
221 fn : function() { |
|
222 |
|
223 gGETValues = CY.JSON.parse(sv_get_params); |
|
224 |
|
225 CY.get('#maincontainer').setStyle('display', 'block'); |
|
226 CY.get('#textcontainer').setStyle('display', 'block'); |
|
227 |
|
228 var val = (sv_withComments) ? gPrefs.get('layout','comments_col_width') : 0 ; |
|
229 var colWidth = sliderValToPx(val) ; |
|
230 gLayout.setLeftColumnWidth(colWidth) ; |
|
231 |
|
232 if (gLayout.isInFrame()) { |
|
233 parent.f_initFrame(); |
|
234 parent.f_layoutFrames(); |
|
235 |
|
236 if (sv_withComments) { |
|
237 parent.f_fillTopToolbar() ; |
|
238 if (hasPerm("can_create_comment")) |
|
239 parent.$("#add_comment_btn").removeClass('initially_hidden'); |
|
240 //parent.enqueueLoadingMsg(); // no more loading message ? TODO |
|
241 |
|
242 parent.f_fillFilterTab() ; |
|
243 parent.f_fillPreferencesTab() ; |
|
244 |
|
245 // parent.f_fillBrowseSection() ; |
|
246 |
|
247 var firstTimeFilterData = CY.JSON.parse(sv_filter_data); |
|
248 parent.f_updateFilterData(firstTimeFilterData); |
|
249 |
|
250 parent.f_setFilterValue(gGETValues) ; |
|
251 } |
|
252 parent.f_fillTextPreferencesTab() ; |
|
253 } |
|
254 |
|
255 if (gLayout.isInComentSite()) |
|
256 parent.$("#c_fullscreen_btn").show(); |
|
257 else { |
|
258 parent.$("#c_fullscreen_btn").hide(); |
|
259 } |
|
260 |
|
261 }, |
|
262 timeout :5 |
|
263 }, { |
|
264 fn : function() { |
|
265 if (sv_withComments) { |
|
266 |
|
267 reinit(gGETValues); |
|
268 initialConnect(); |
|
269 } |
|
270 }, |
|
271 timeout :5 |
|
272 }, { |
|
273 fn : function() { |
|
274 if (gLayout.isInFrame()) { |
|
275 parent.f_interfaceUnfreeze() ; |
|
276 parent.f_removeLoadingMsg(); |
|
277 } |
|
278 |
|
279 // if there is a comment id in the url display it |
|
280 if ("comment_key" in gGETValues) { |
|
281 var key = gGETValues["comment_key"] ; |
|
282 var comment = gDb.getCommentByKey(key) ; |
|
283 if (comment != null) { |
|
284 var path = gDb.getPath(comment) ; |
|
285 var topParentComment = path[path.length - 1] ; |
|
286 gSync.showSingleComment(topParentComment) ; |
|
287 } |
|
288 } |
|
289 // else show all |
|
290 else { |
|
291 gSync.showAllComments() ; |
|
292 } |
|
293 } |
|
294 }); |
|
295 q1.run(); |
|
296 }; |
|
297 |