| author | gibus |
| Mon, 10 Mar 2014 13:24:19 +0100 | |
| changeset 600 | fda73ac53450 |
| parent 562 | 92e8e5aaacde |
| permissions | -rw-r--r-- |
| 0 | 1 |
gICommentForm = null ; |
2 |
||
3 |
instanciateICommentForm = function() { |
|
| 341 | 4 |
gICommentForm = { |
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
5 |
'position':[CY.WidgetPositionAlign.TL, CY.WidgetPositionAlign.TL], |
| 341 | 6 |
'formId':CY.guid(), |
7 |
'formTitleId':CY.guid(), |
|
8 |
'titleInputId':CY.guid(), |
|
9 |
'contentInputId':CY.guid(), |
|
10 |
'tagsInputId':CY.guid(), |
|
|
504
b2e0186daa5b
Adds a category to comments, painted with colored vertical bar.
gibus
parents:
421
diff
changeset
|
11 |
'categoryInputId':CY.guid(), |
| 341 | 12 |
'formatInputId':CY.guid(), |
13 |
'startWrapperInputId':CY.guid(), |
|
14 |
'endWrapperInputId':CY.guid(), |
|
15 |
'startOffsetInputId':CY.guid(), |
|
16 |
'endOffsetInputId':CY.guid(), |
|
17 |
'selectionPlaceId':CY.guid(), |
|
18 |
'keyId':CY.guid(), |
|
19 |
'currentSelId':CY.guid(), |
|
20 |
'currentSelIdI':CY.guid(), |
|
21 |
'addBtnId':CY.guid(), |
|
22 |
'cancelBtnId':CY.guid(), |
|
23 |
'closeBtnId':CY.guid() |
|
24 |
} ; |
|
25 |
|
|
26 |
if (!sv_loggedIn) { |
|
27 |
gICommentForm ['nameInputId'] = CY.guid() ; |
|
28 |
gICommentForm ['emailInputId'] = CY.guid() ; |
|
29 |
} |
|
30 |
|
|
31 |
var overlayHtml = getHtml(gICommentForm) ; |
|
32 |
|
|
33 |
var width = gLayout.getTopICommentsWidth() ; |
|
|
562
92e8e5aaacde
Give maximum width for add_comment form and toc.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
34 |
width += gLayout.iCommentsRequiredThreadPadding (); // SID: use max available space as there is no indentation on that box |
| 341 | 35 |
|
36 |
var overlay = new CY.Overlay( { |
|
37 |
zIndex :3, |
|
38 |
shim :false, // until we really need it, no shim |
|
39 |
visible :false, |
|
40 |
headerContent :overlayHtml['headerContent'], |
|
41 |
bodyContent :overlayHtml['bodyContent'], |
|
42 |
xy :[10,10], |
|
43 |
width : width |
|
44 |
}); |
|
45 |
overlay.get('contentBox').addClass("c-newcomment") ; |
|
46 |
|
|
47 |
// attach to DOM |
|
48 |
overlay.render('#leftcolumn'); |
|
49 |
|
|
50 |
if (!sv_loggedIn) { |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
51 |
CY.one("#"+gICommentForm['nameInputId']).set('value',gPrefs.get("user","name")) ; |
|
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
52 |
CY.one("#"+gICommentForm['emailInputId']).set('value',gPrefs.get("user","email")) ; |
| 341 | 53 |
} |
54 |
|
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
55 |
CY.one("#"+gICommentForm['formTitleId']).set('innerHTML', gettext('New comment')) ; |
|
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
56 |
CY.one("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ; |
| 341 | 57 |
|
58 |
CY.on("click", onSubmitICommentFormClick, "#"+gICommentForm['addBtnId']); |
|
59 |
CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['cancelBtnId']); |
|
60 |
CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['closeBtnId']); |
|
61 |
|
|
62 |
gICommentForm['overlay'] = overlay ; |
|
63 |
|
|
64 |
var animationHide = null ; |
|
65 |
animationHide = new CY.Anim({ |
|
| 0 | 66 |
node: overlay.get('boundingBox'), |
67 |
duration: .3, //gPrefs['general']['animduration'], |
|
68 |
easing: CY.Easing.easeOut |
|
| 341 | 69 |
}); |
70 |
gICommentForm['animationHide'] = animationHide ; |
|
71 |
animationHide.set('to', { opacity: 0});// height : 0 doesn't work |
|
72 |
gICommentForm['animationHide-handle'] = animationHide.on('end', onICommentFormHideAnimEnd, gICommentForm); |
|
| 0 | 73 |
|
| 341 | 74 |
var animationShow = null ; |
75 |
animationShow = new CY.Anim({ |
|
| 0 | 76 |
node: overlay.get('boundingBox'), |
77 |
duration: .3, //gPrefs['general']['animduration'], |
|
78 |
easing: CY.Easing.easeOut |
|
| 341 | 79 |
}); |
80 |
gICommentForm['animationShow'] = animationShow ; |
|
81 |
animationShow.set('to', { opacity: 1}); |
|
82 |
gICommentForm['animationShow-handle'] = animationShow.on('end', onICommentFormShowAnimEnd, gICommentForm); |
|
83 |
|
|
84 |
changeFormFieldsWidth(gICommentForm['formId'], width) ; |
|
| 0 | 85 |
} |
86 |
||
87 |
cleanICommentForm = function() { |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
88 |
CY.one("#"+gICommentForm['currentSelIdI']).set('innerHTML', gNoSelectionYet) ; |
| 0 | 89 |
|
90 |
var hostNode = gICommentForm['overlay'].getStdModNode(CY.WidgetStdMod.BODY) ; |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
91 |
hostNode.all(".comment_input").set('value', "") ; |
| 341 | 92 |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
93 |
CY.one("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ... |
| 341 | 94 |
|
95 |
if (!sv_loggedIn) { |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
96 |
hostNode.all(".user_input").set('value', "") ; |
| 341 | 97 |
} |
| 0 | 98 |
} |
99 |
||
100 |
onICommentFormHideAnimEnd = function() { |
|
| 341 | 101 |
// iComment['overlay'].blur() ; |
102 |
this.overlay.hide() ; |
|
103 |
gSync.resume() ; |
|
| 0 | 104 |
} |
105 |
||
106 |
onICommentFormShowAnimEnd = function() { |
|
| 341 | 107 |
gSync.resume() ; |
| 0 | 108 |
} |
109 |
||
110 |
onSubmitICommentFormClick = function() { |
|
| 341 | 111 |
if (!sv_loggedIn) { |
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
112 |
var name = CY.one("#"+gICommentForm['nameInputId']).get('value') ; |
| 341 | 113 |
gPrefs.persist("user", "name", name) ; |
114 |
|
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
115 |
var email = CY.one("#"+gICommentForm['emailInputId']).get('value') ; |
| 341 | 116 |
gPrefs.persist("user", "email", email) ; |
117 |
} |
|
118 |
gSync.saveComment(gICommentForm['formId']) ; |
|
| 0 | 119 |
} |
120 |
||
121 |
onCancelICommentFormClick = function() { |
|
| 341 | 122 |
gSync.cancelICommentForm() ; |
| 0 | 123 |
} |
124 |
||
125 |
// record selection info in hidden form fields |
|
126 |
_updateICommentFormSelection = function(ids, displayedText, csStartSelection, csEndSelection) { |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
127 |
var node = CY.Node.one('#'+ids['currentSelIdI']) ; |
| 341 | 128 |
if (node != null) |
129 |
node.set('innerHTML', displayedText) ; |
|
130 |
|
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
131 |
node = CY.one('#'+ids['startWrapperInputId']) ; |
| 341 | 132 |
if (node != null) |
133 |
node.set('value', csStartSelection['elt'].id.substring("sv_".length)) ; |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
134 |
node = CY.one('#'+ids['startOffsetInputId']) ; |
| 341 | 135 |
if (node != null) |
136 |
node.set('value', csStartSelection['offset']) ; |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
137 |
node = CY.one('#'+ids['endWrapperInputId']) ; |
| 341 | 138 |
if (node != null) |
139 |
node.set('value', csEndSelection['elt'].id.substring("sv_".length)) ; |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
140 |
node = CY.one('#'+ids['endOffsetInputId']) ; |
| 341 | 141 |
if (node != null) |
142 |
node.set('value', csEndSelection['offset']) ; |
|
| 0 | 143 |
} |
144 |
||
145 |
updateICommentFormSelection = function(selection) { |
|
| 341 | 146 |
var text = (selection == null) ? "" : selection['text'] ; |
147 |
if (text != "") { |
|
148 |
// display text to be commented |
|
149 |
var displayedText = text ; |
|
150 |
var maxLength = 100 ; // even number only |
|
151 |
if (text.length > maxLength ) { |
|
152 |
var start = text.substring(0, (text.substring(0, maxLength/2)).lastIndexOf(" ")) ; |
|
153 |
var endPart = text.substring(text.length - maxLength/2) ; |
|
154 |
var end = endPart.substring(endPart.indexOf(" ")) ; |
|
155 |
displayedText = start + " ... " + end ; |
|
156 |
} |
|
| 0 | 157 |
var csStartSelection = _convertSelectionFromCCToCS(selection['start']) ; |
158 |
var csEndSelection = _convertSelectionFromCCToCS(selection['end']) ; |
|
159 |
||
160 |
_updateICommentFormSelection(gICommentForm, displayedText, csStartSelection, csEndSelection); |
|
161 |
if (gEdit != null) |
|
| 341 | 162 |
_updateICommentFormSelection(gEdit['ids'], displayedText, csStartSelection, csEndSelection); |
163 |
positionICommentForm() ; |
|
164 |
} |
|
| 0 | 165 |
} |
166 |
||
167 |
showICommentForm= function () { |
|
| 341 | 168 |
removeFormErrMsg(gICommentForm['formId']) ; |
169 |
if (!sv_loggedIn) { |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
170 |
if (CY.one("#"+gICommentForm['nameInputId']).get('value') == '') |
|
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
171 |
CY.one("#"+gICommentForm['nameInputId']).set('value', gPrefs.get('user','name')) ; |
|
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
172 |
if (CY.one("#"+gICommentForm['emailInputId']).get('value') == '') |
|
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
173 |
CY.one("#"+gICommentForm['emailInputId']).set('value', gPrefs.get('user','email')) ; |
| 341 | 174 |
} |
175 |
gIComments.hide() ; |
|
| 421 | 176 |
hideToc(); |
| 341 | 177 |
positionICommentForm() ; |
178 |
gICommentForm['overlay'].show() ; |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
179 |
CY.one("#"+gICommentForm['titleInputId']).focus() ; |
| 0 | 180 |
} |
181 |
||
182 |
isICommentFormVisible = function () { |
|
| 341 | 183 |
if (gICommentForm != null) |
184 |
return gICommentForm['overlay'].get('visible') ; |
|
185 |
return false ; |
|
| 0 | 186 |
} |
187 |
||
188 |
positionICommentForm = function () { |
|
| 341 | 189 |
if (gICommentForm != null) { |
190 |
var overlay = gICommentForm['overlay'] ; |
|
191 |
var boundingBox = overlay.get('boundingBox') ; |
|
| 0 | 192 |
|
| 341 | 193 |
var commentFormHeight = boundingBox.get('offsetHeight') ; |
194 |
var windowHeight = boundingBox.get('winHeight') ; |
|
| 0 | 195 |
|
| 341 | 196 |
var pos = gICommentForm['position'] ; |
197 |
if (commentFormHeight > windowHeight) // trying to have save comment visible ... : |
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
198 |
pos = [CY.WidgetPositionAlign.BL, CY.WidgetPositionAlign.BL] ; |
| 341 | 199 |
|
200 |
overlay.set("align", {points:pos}); |
|
| 382 | 201 |
if (commentFormHeight <= windowHeight) |
202 |
overlay.set("y", overlay.get("y") + 30); |
|
| 341 | 203 |
boundingBox.setX(boundingBox.getX() + gConf['iCommentLeftPadding']); |
204 |
} |
|
205 |
} |