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