| commit 60: | 5c3d7e957645 |
| parent 59: | efd5d9f58db6 |
| branch: | default |
Added a way to reorder lists inline
- View ianb's profile
-
ianb's public repos »
- toppcloud
- Tempita
- dtopt
- wsgi-peps
- WebOb
- libcloud-vbox
- pip
- paste-import
- silverlining
- WSGIProxy
- FlatAtomPub
- PageCollector
- WaitForIt
- WebTest
- formencode
- virtualenv
- bbdocs
- bbdocs-lib
- PasteScript
- wave-experiments
- frank-lib
- doctestjs
- referrertrack
- CmdUtils
- silverlog
- silverlog-lib
- wphp
- twilljs
- paster-create-experiment
- INITools
- PickyWiki
- ScriptTest
- PasteDeploy
- silverlining-refactor
- geodns
- geodns-lib
- geoalchemy
- datacatalog
- datacatalog-lib
- dozer
- wikistorage
- Send message
11 months ago
Changed (Δ2.7 KB):
raw changeset »
pickywiki/static/picky.js (67 lines added, 7 lines removed)
Up to file-list pickywiki/static/picky.js:
124 |
124 |
} |
125 |
125 |
target.data('active', true); |
126 |
126 |
target.addClass('hover-edit'); |
127 |
var link = $('<span class="hover-edit-box dynamic"><a href="#" class="add"><img border=0 src="/-static/circular-icons/add.png" title="add item to list" class="icon"></a> <a href="#" class="re |
|
127 |
var link = $('<span class="hover-edit-box dynamic"><a href="#" class="add"><img border=0 src="/-static/circular-icons/add.png" title="add item to list" class="icon"></a> <a href="#" class="reorder" title="reorder an item in the list"><img border=0 src="/-static/circular-icons/arrows_north_south.png"></a> <a href="#" class="remove"><img border=0 src="/-static/circular-icons/minus.png" title="remove an item from the list" class="icon"></a></span>'); |
|
128 |
128 |
target.bind('mouseout', function (event2) { |
129 |
129 |
outTimeout = setTimeout(function () { |
130 |
130 |
link.remove(); |
133 |
133 |
}, 500); |
134 |
134 |
target.data('outTimeout', outTimeout); |
135 |
135 |
}); |
136 |
||
136 |
137 |
$('a.add', link).bind('click', function (event2) { |
137 |
138 |
var newLi = $('<li class="inline-edit dynamic"><textarea class="inline-edit" name="input"></textarea></li>'); |
138 |
139 |
var textarea = $('textarea', newLi); |
159 |
160 |
editor = editorCreated; |
160 |
161 |
}); |
161 |
162 |
}); |
163 |
||
164 |
$('a.reorder', link).bind('click', function (event2) { |
|
165 |
target.addClass('select-to-reorder'); |
|
166 |
var selectedLi = null; |
|
167 |
var lastLi = null; |
|
168 |
var resetReorder = function () { |
|
169 |
target.removeClass('select-to-reorder'); |
|
170 |
target.removeClass('select-to-reorder-target'); |
|
171 |
if (lastLi !== null) { |
|
172 |
lastLi.remove(); |
|
173 |
} |
|
174 |
$(document).unbind('keyup', escapeCatcher); |
|
175 |
$('li', target).unbind('click', liMover); |
|
176 |
}; |
|
177 |
var liMover = function (event3) { |
|
178 |
var selTarget = $(event3.target); |
|
179 |
if (selectedLi === null) { |
|
180 |
selectedLi = selTarget; |
|
181 |
selectedLi.addClass('select-to-reorder-selected'); |
|
182 |
lastLi = $('<li class="select-bottom">(bottom)</li>'); |
|
183 |
target.append(lastLi); |
|
184 |
lastLi.bind('click', liMover); |
|
185 |
target.removeClass('select-to-reorder'); |
|
186 |
target.addClass('select-to-reorder-target'); |
|
187 |
} else { |
|
188 |
console.log('Moving from', liIndex(selectedLi), |
|
189 |
'to', liIndex(selTarget)); |
|
190 |
$.post(_page_inline_edit_url, |
|
191 |
{tagName: target.get(0).tagName, |
|
192 |
position: ""+elPosition, |
|
193 |
moveLi: liIndex(selectedLi), |
|
194 |
newPosition: liIndex(selTarget)}, |
|
195 |
function () { |
|
196 |
selectedLi.removeClass('select-to-reorder-selected'); |
|
197 |
selTarget.before(selectedLi); |
|
198 |
resetReorder(); |
|
199 |
}); |
|
200 |
} |
|
201 |
}; |
|
202 |
var escapeCatcher = function (event3) { |
|
203 |
if (event3.keyCode == 27) { |
|
204 |
resetReorder(); |
|
205 |
} |
|
206 |
}; |
|
207 |
$(document).bind('keyup', escapeCatcher); |
|
208 |
$('li', target).bind('click', liMover); |
|
209 |
}); |
|
210 |
||
162 |
211 |
$('a.remove', link).bind('click', function (event2) { |
163 |
212 |
target.addClass('select-to-remove'); |
164 |
213 |
var cancelRemove = function () { |
176 |
225 |
liToRemove.addClass('checkbox-in-progress'); |
177 |
226 |
var parent = liToRemove.get(0).parentNode; |
178 |
227 |
var children = parent.getElementsByTagName('li'); |
179 |
for (index=0; index<parent.childNodes.length; index++) { |
|
180 |
if (children[index] == liToRemove.get(0)) { |
|
181 |
break; |
|
182 |
} |
|
183 |
|
|
228 |
var index = liIndex(liToRemove); |
|
184 |
229 |
$.post(_page_inline_edit_url, |
185 |
|
|
230 |
{tagName: target.get(0).tagName, |
|
186 |
231 |
position: ""+elPosition, |
187 |
232 |
removeLi: ""+index}, |
188 |
233 |
function () { |
| … | … | @@ -395,6 +440,21 @@ function makePath(title) { |
395 |
440 |
return '/' + path; |
396 |
441 |
} |
397 |
442 |
|
443 |
function liIndex(li) { |
|
444 |
li = li.get(0); |
|
445 |
var index = 0; |
|
446 |
var parent = li.parentNode; |
|
447 |
for (var i=0; i<parent.childNodes.length; i++) { |
|
448 |
if (parent.childNodes[i] == li) { |
|
449 |
return index; |
|
450 |
} |
|
451 |
if (parent.childNodes[i].tagName == 'LI') { |
|
452 |
index++; |
|
453 |
} |
|
454 |
} |
|
455 |
throw("Somehow parent didn't contain child"); |
|
456 |
} |
|
457 |
||
398 |
458 |
// From http://www.quirksmode.org/js/cookies.html |
399 |
459 |
|
400 |
460 |
function createCookie(name, value, days) { |
