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