| author | Simon Descarpentries <sid@sopinspace.com> |
| Mon, 21 Oct 2013 16:37:07 +0200 | |
| changeset 553 | bf26fb47a14c |
| parent 532 | 0bad3613f59d |
| child 562 | 92e8e5aaacde |
| permissions | -rw-r--r-- |
| 0 | 1 |
gICommentForm = null ; |
2 |
||
3 |
instanciateICommentForm = function() { |
|
| 341 | 4 |
gICommentForm = { |
|
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
|
5 |
'position':[CY.WidgetPositionExt.TL, CY.WidgetPositionExt.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) { |
|
|
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
|
50 |
CY.get("#"+gICommentForm['nameInputId']).set('value',gPrefs.get("user","name")) ; |
|
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
|
51 |
CY.get("#"+gICommentForm['emailInputId']).set('value',gPrefs.get("user","email")) ; |
| 341 | 52 |
} |
53 |
|
|
|
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
|
54 |
CY.get("#"+gICommentForm['formTitleId']).set('innerHTML', gettext('New comment')) ; |
|
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
|
55 |
CY.get("#"+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() { |
|
|
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
|
87 |
CY.get("#"+gICommentForm['currentSelIdI']).set('innerHTML', gNoSelectionYet) ; |
| 0 | 88 |
|
89 |
var hostNode = gICommentForm['overlay'].getStdModNode(CY.WidgetStdMod.BODY) ; |
|
|
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
|
90 |
hostNode.queryAll(".comment_input").set('value', "") ; |
| 341 | 91 |
|
|
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
|
92 |
CY.get("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ... |
| 341 | 93 |
|
94 |
if (!sv_loggedIn) { |
|
|
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
|
95 |
hostNode.queryAll(".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) { |
|
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
|
111 |
var name = CY.get("#"+gICommentForm['nameInputId']).get('value') ; |
| 341 | 112 |
gPrefs.persist("user", "name", name) ; |
113 |
|
|
|
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
|
114 |
var email = CY.get("#"+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) { |
|
|
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
|
126 |
var node = CY.Node.get('#'+ids['currentSelIdI']) ; |
| 341 | 127 |
if (node != null) |
128 |
node.set('innerHTML', displayedText) ; |
|
129 |
|
|
|
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
|
130 |
node = CY.get('#'+ids['startWrapperInputId']) ; |
| 341 | 131 |
if (node != null) |
132 |
node.set('value', csStartSelection['elt'].id.substring("sv_".length)) ; |
|
|
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
|
133 |
node = CY.get('#'+ids['startOffsetInputId']) ; |
| 341 | 134 |
if (node != null) |
135 |
node.set('value', csStartSelection['offset']) ; |
|
|
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
|
136 |
node = CY.get('#'+ids['endWrapperInputId']) ; |
| 341 | 137 |
if (node != null) |
138 |
node.set('value', csEndSelection['elt'].id.substring("sv_".length)) ; |
|
|
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
|
139 |
node = CY.get('#'+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) { |
|
|
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
|
169 |
if (CY.get("#"+gICommentForm['nameInputId']).get('value') == '') |
|
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
|
170 |
CY.get("#"+gICommentForm['nameInputId']).set('value', gPrefs.get('user','name')) ; |
|
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
|
171 |
if (CY.get("#"+gICommentForm['emailInputId']).get('value') == '') |
|
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
|
172 |
CY.get("#"+gICommentForm['emailInputId']).set('value', gPrefs.get('user','email')) ; |
| 341 | 173 |
} |
174 |
gIComments.hide() ; |
|
| 421 | 175 |
hideToc(); |
| 341 | 176 |
positionICommentForm() ; |
177 |
gICommentForm['overlay'].show() ; |
|
|
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
|
178 |
CY.get("#"+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 ... : |
|
|
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
|
197 |
pos = [CY.WidgetPositionExt.BL, CY.WidgetPositionExt.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 |
} |