Mercurial > wiki
annotate static-files/wiki.js @ 27:a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Thu, 12 Feb 2009 23:00:03 -0800 |
parents | 0aecc756ea18 |
children |
rev | line source |
---|---|
14 | 1 /* ***** BEGIN LICENSE BLOCK ***** |
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | |
3 * | |
4 * The contents of this file are subject to the Mozilla Public License Version | |
5 * 1.1 (the "License"); you may not use this file except in compliance with | |
6 * the License. You may obtain a copy of the License at | |
7 * http://www.mozilla.org/MPL/ | |
8 * | |
9 * Software distributed under the License is distributed on an "AS IS" basis, | |
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
11 * for the specific language governing rights and limitations under the | |
12 * License. | |
13 * | |
14 * The Original Code is Ubiquity. | |
15 * | |
16 * The Initial Developer of the Original Code is Mozilla. | |
17 * Portions created by the Initial Developer are Copyright (C) 2007 | |
18 * the Initial Developer. All Rights Reserved. | |
19 * | |
20 * Contributor(s): | |
21 * Atul Varma <atul@mozilla.com> | |
22 * | |
23 * Alternatively, the contents of this file may be used under the terms of | |
24 * either the GNU General Public License Version 2 or later (the "GPL"), or | |
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | |
26 * in which case the provisions of the GPL or the LGPL are applicable instead | |
27 * of those above. If you wish to allow use of your version of this file only | |
28 * under the terms of either the GPL or the LGPL, and not to allow others to | |
29 * use your version of this file under the terms of the MPL, indicate your | |
30 * decision by deleting the provisions above and replace them with the notice | |
31 * and other provisions required by the GPL or the LGPL. If you do not delete | |
32 * the provisions above, a recipient may use your version of this file under | |
33 * the terms of any one of the MPL, the GPL or the LGPL. | |
34 * | |
35 * ***** END LICENSE BLOCK ***** */ | |
36 | |
4
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
37 var App = { |
13
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
38 PART_SEPARATOR: "\n\n", |
15
c94bd26e0e67
Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
39 creole: null, |
c94bd26e0e67
Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
40 editingElement: null, |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
41 latestPublishedChangeset: null, |
18
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
42 localChanges: [], |
4
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
43 eventHandlers: {} |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
44 }; |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
45 |
5
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
46 App.eventHandlers.editPart = function editPart(aEvt) { |
2
1d3d91674bbe
Users must hold down shift while clicking to edit.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
47 if (!aEvt.shiftKey) |
1d3d91674bbe
Users must hold down shift while clicking to edit.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
48 return; |
1d3d91674bbe
Users must hold down shift while clicking to edit.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
49 |
3
ac7e15dcee69
Activate edits on mousedown instead of click to prevent default selection behavior.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
50 aEvt.preventDefault(); |
ac7e15dcee69
Activate edits on mousedown instead of click to prevent default selection behavior.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
51 |
10
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
52 App.enterEditMode([this], 1); |
8 | 53 }; |
54 | |
12
0158bed7e0c6
Minor refactoring: added App.getMarkup().
Atul Varma <varmaa@toolness.com>
parents:
11
diff
changeset
|
55 App.getMarkup = function getMarkup(parts) { |
10
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
56 var partsMarkup = []; |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
57 $(".creole-markup", parts).each( |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
58 function(i) { partsMarkup.push($(this).text()); } |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
59 ); |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
60 |
13
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
61 return partsMarkup.join(App.PART_SEPARATOR); |
12
0158bed7e0c6
Minor refactoring: added App.getMarkup().
Atul Varma <varmaa@toolness.com>
parents:
11
diff
changeset
|
62 }; |
0158bed7e0c6
Minor refactoring: added App.getMarkup().
Atul Varma <varmaa@toolness.com>
parents:
11
diff
changeset
|
63 |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
64 App.saveChanges = function saveChanges(options) { |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
65 var isUserChange = options.isUserChange; |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
66 var date = options.date ? new Date(options.date) : new Date(); |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
67 var container; |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
68 if (isUserChange) |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
69 container = $('#unpublished-changes'); |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
70 else |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
71 container = $('#published-changes'); |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
72 |
18
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
73 var markup = App.getMarkup($(window.document)); |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
74 var changeset = {date: date, |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
75 content: markup}; |
18
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
76 App.localChanges.push(changeset); |
19
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
77 var changesetElem = $('<div class="changeset selected"></div>'); |
18
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
78 function setText() { |
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
79 changesetElem.text(jQuery.timeago(changeset.date)); |
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
80 } |
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
81 window.setInterval(setText, 60000); |
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
82 setText(); |
19
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
83 changesetElem.mousedown( |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
84 function(aEvt) { |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
85 |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
86 aEvt.preventDefault(); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
87 if (aEvt.shiftKey) { |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
88 $(window.document).find('.changeset').removeClass('diffed'); |
19
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
89 var newerVersion = App.getMarkup($("#content")); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
90 var diff = $('<div class="diff"></div>'); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
91 var markupDiv = $('<div class="creole-markup"></div>'); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
92 markupDiv.text(newerVersion); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
93 diff.html(diffString(changeset.content, newerVersion)); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
94 $("#content").empty(); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
95 $("#content").append(diff); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
96 $("#content").append(markupDiv); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
97 $(this).addClass('diffed'); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
98 } else { |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
99 $(window.document).find('.changeset').removeClass('selected') |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
100 .removeClass('diffed'); |
19
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
101 $(this).addClass('selected'); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
102 $("#content").empty(); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
103 $("#content").append(App.createParts(changeset.content)); |
8ec70abb260d
Allow different local changeset revisions to be diffed.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
104 } |
18
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
105 } |
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
106 ); |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
107 $(window.document).find('.changeset').removeClass('selected') |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
108 .removeClass('diffed'); |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
109 container.find('h1').after(changesetElem); |
25
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
110 if (isUserChange) { |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
111 var maybeNewChangeset = App.latestPublishedChangeset + 1; |
25
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
112 var jsonData = JSON.stringify({date: changeset.date.toString(), |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
113 content: changeset.content}); |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
114 jQuery.ajax({url: '/' + maybeNewChangeset, |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
115 type: 'PUT', |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
116 success: function() { |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
117 // TODO: Because we're running asynchronously, |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
118 // weird things can happen here, e.g. if the user |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
119 // makes another edit while the XHR is being |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
120 // processed. |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
121 App.latestPublishedChangeset = maybeNewChangeset; |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
122 $('#published-changes').find('h1').after(changesetElem); |
25
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
123 }, |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
124 error: function(xhr, textStatus, errorThrown) { |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
125 // TODO: Do something here. |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
126 }, |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
127 dataType: 'text', |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
128 processData: false, |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
129 contentType: 'application/json', |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
130 data: jsonData}); |
0aecc756ea18
The web app now commits to the server, though it doesn't handle any edge cases whatsoever and is therefore extremely fragile.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
131 } |
18
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
132 }; |
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
133 |
13
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
134 App.enterEditMode = function enterEditMode(parts, level, cursorPos) { |
15
c94bd26e0e67
Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
135 if (App.editingElement) { |
c94bd26e0e67
Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
136 $(App.editingElement).blur(); |
c94bd26e0e67
Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
137 App.editingElement = null; |
c94bd26e0e67
Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
138 } |
c94bd26e0e67
Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
139 |
11 | 140 var editablePart = $('<textarea class="wiki-edit"></textarea>').get(0); |
16
20b6dbeb6250
Added sign-in section that shows up on the left side of the page if the user makes changes to the page.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
141 var originalMarkup = App.getMarkup(parts); |
20b6dbeb6250
Added sign-in section that shows up on the left side of the page if the user makes changes to the page.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
142 $(editablePart).attr("value", originalMarkup); |
1
dd457cc7c596
Improved setting of size of textarea.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
143 |
dd457cc7c596
Improved setting of size of textarea.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
144 function setScrollHeight() { |
9
20ed90d10dee
Replaced use of closure variables w/ use of 'this'.
Atul Varma <varmaa@toolness.com>
parents:
8
diff
changeset
|
145 $(this).height(this.scrollHeight); |
1
dd457cc7c596
Improved setting of size of textarea.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
146 } |
dd457cc7c596
Improved setting of size of textarea.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
147 |
10
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
148 function exitEditMode() { |
16
20b6dbeb6250
Added sign-in section that shows up on the left side of the page if the user makes changes to the page.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
149 var markup = $(this).attr("value"); |
20b6dbeb6250
Added sign-in section that shows up on the left side of the page if the user makes changes to the page.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
150 $(this).replaceWith(App.createParts(markup)); |
18
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
151 if (markup != originalMarkup) { |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
152 App.saveChanges({isUserChange: true}); |
18
530941426679
Local changes are now stored and shown on the sidebar.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
153 } |
10
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
154 } |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
155 |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
156 function editSiblings(aEvt) { |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
157 if (!aEvt.shiftKey || level == 0) |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
158 return; |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
159 |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
160 aEvt.preventDefault(); |
1
dd457cc7c596
Improved setting of size of textarea.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
161 |
13
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
162 var prevMarkup = App.getMarkup($(this).prevAll()); |
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
163 var cursorPos = (prevMarkup.length + App.PART_SEPARATOR.length + |
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
164 this.selectionStart); |
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
165 |
10
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
166 var allSiblings = this.parentNode.childNodes; |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
167 exitEditMode.apply(this); |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
168 |
13
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
169 App.enterEditMode(allSiblings, level-1, cursorPos); |
10
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
170 } |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
171 |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
172 $(editablePart).blur(exitEditMode); |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
173 $(editablePart).mousedown(editSiblings); |
5
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
174 $(editablePart).keyup(setScrollHeight); |
10
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
175 $(parts).filter(":not(:first)").remove(); |
ec3ec75a8d16
The user can now 'zoom out' while editing by shift-clicking the edit field.
Atul Varma <varmaa@toolness.com>
parents:
9
diff
changeset
|
176 $(parts).replaceWith(editablePart); |
9
20ed90d10dee
Replaced use of closure variables w/ use of 'this'.
Atul Varma <varmaa@toolness.com>
parents:
8
diff
changeset
|
177 setScrollHeight.apply(editablePart); |
1
dd457cc7c596
Improved setting of size of textarea.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
178 |
13
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
179 if (typeof(cursorPos) != "undefined") { |
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
180 editablePart.selectionStart = cursorPos; |
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
181 editablePart.selectionEnd = cursorPos; |
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
182 } |
15
c94bd26e0e67
Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
183 |
c94bd26e0e67
Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
184 App.editingElement = editablePart; |
5
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
185 $(editablePart).focus(); |
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
186 }; |
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
187 |
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
188 App.createPart = function createPart(markup) { |
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
189 var partDiv = $('<div class="part"></div>'); |
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
190 var markupDiv = $('<div class="creole-markup"></div>'); |
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
191 markupDiv.text(markup); |
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
192 App.creole.parse(partDiv.get(0), markup); |
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
193 partDiv.mousedown(App.eventHandlers.editPart); |
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
194 partDiv.append(markupDiv); |
6
fb233578283c
User can now create new wiki markup parts (i.e., paragraphs).
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
195 return partDiv.get(0); |
4
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
196 }; |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
197 |
6
fb233578283c
User can now create new wiki markup parts (i.e., paragraphs).
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
198 App.createParts = function createParts(text) { |
fb233578283c
User can now create new wiki markup parts (i.e., paragraphs).
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
199 var parts = []; |
fb233578283c
User can now create new wiki markup parts (i.e., paragraphs).
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
200 |
13
c0edd32443a7
Cursor position is now preserved when moving from editing a part to editing the whole document.
Atul Varma <varmaa@toolness.com>
parents:
12
diff
changeset
|
201 var partsMarkup = text.split(App.PART_SEPARATOR); |
4
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
202 jQuery.each( |
6
fb233578283c
User can now create new wiki markup parts (i.e., paragraphs).
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
203 partsMarkup, |
4
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
204 function(i) { |
5
06e8c49e9dec
Wikicreole markup is now editable. Also refactored things a bit so that variables have better names, DRY is preserved better.
Atul Varma <varmaa@toolness.com>
parents:
4
diff
changeset
|
205 var partMarkup = this.toString(); |
6
fb233578283c
User can now create new wiki markup parts (i.e., paragraphs).
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
206 if (partMarkup) |
fb233578283c
User can now create new wiki markup parts (i.e., paragraphs).
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
207 parts.push(App.createPart(partMarkup)); |
4
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
208 } |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
209 ); |
6
fb233578283c
User can now create new wiki markup parts (i.e., paragraphs).
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
210 |
fb233578283c
User can now create new wiki markup parts (i.e., paragraphs).
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
211 return parts; |
4
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
212 }; |
0 | 213 |
4
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
214 App.eventHandlers.onLoad = function onLoad() { |
15
c94bd26e0e67
Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
Atul Varma <varmaa@toolness.com>
parents:
14
diff
changeset
|
215 App.creole = new Parse.Simple.Creole( |
4
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
216 {interwiki: { |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
217 WikiCreole: 'http://www.wikicreole.org/wiki/', |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
218 Wikipedia: 'http://en.wikipedia.org/wiki/' |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
219 }, |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
220 linkFormat: '' |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
221 }); |
0 | 222 |
24
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
223 function onStatus(status) { |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
224 App.latestPublishedChangeset = status.max_changeset; |
24
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
225 jQuery.get("/" + status.max_changeset, |
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
226 {}, |
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
227 function(obj) { |
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
228 var text = obj.content; |
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
229 $("#content").append(App.createParts(text)); |
27
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
230 App.saveChanges({isUserChange: false, |
a42400d52a1e
Changed recent changes heading to two separate 'unpublished changes' and 'published changes' sections.
Atul Varma <varmaa@toolness.com>
parents:
25
diff
changeset
|
231 date: obj.date}); |
24
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
232 }, |
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
233 "json"); |
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
234 } |
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
235 |
b094768c285b
wiki.html now communicates w/ the server instead of the static file.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
236 jQuery.get('/status', {}, onStatus, "json"); |
4
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
237 }; |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
238 |
01313b55ed09
We're now loading from wikicreole markup contained in wiki.txt, though editing fields still edits their HTML, not their wiki markup.
Atul Varma <varmaa@toolness.com>
parents:
3
diff
changeset
|
239 $(window).ready(App.eventHandlers.onLoad); |