| ︙ | | |
826
827
828
829
830
831
832
833
834
835
836
837
838
839
|
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
|
+
+
+
|
document.body.classList.add('wikiedit');
P.base = {tag: E('base'), wikiUrl: F.repoUrl('wiki')};
P.base.originalHref = P.base.tag.href;
P.e = { /* various DOM elements we work with... */
taEditor: E('#wikiedit-content-editor'),
btnReload: E("#wikiedit-tab-content button.wikiedit-content-reload"),
btnSave: E("button.wikiedit-save"),
btnSaveClose: D.attr(E("button.wikiedit-save-close"),
'title',
'Save changes and return to the wiki reader.'),
selectMimetype: E('select[name=mimetype]'),
selectFontSizeWrap: E('#select-font-size'),
// selectDiffWS: E('select[name=diff_ws]'),
cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'),
previewTarget: E('#wikiedit-tab-preview-wrapper'),
diffTarget: E('#wikiedit-tab-diff-wrapper'),
editStatus: E('#wikiedit-edit-status'),
|
| ︙ | | |
859
860
861
862
863
864
865
866
867
868
869
870
871
872
|
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
|
+
|
/* Set up some before-switch-to tab event tasks... */
'before-switch-to', function(ev){
const theTab = ev.detail, btnSlot = theTab.querySelector('.save-button-slot');
if(btnSlot){
/* Several places make sense for a save button, so we'll
move that button around to those tabs where it makes sense. */
btnSlot.parentNode.insertBefore( P.e.btnSave, btnSlot );
btnSlot.parentNode.insertBefore( P.e.btnSaveClose, btnSlot );
P.updateSaveButton();
}
if(theTab===P.e.tabs.preview){
P.baseHrefForWiki();
if(P.previewNeedsUpdate && P.e.cbAutoPreview.checked) P.preview();
}else if(theTab===P.e.tabs.diff){
/* Work around a weird bug where the page gets wider than
|
| ︙ | | |
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
|
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
|
-
+
+
+
+
+
-
+
+
+
|
);
diffButtons.querySelector('button.unified').addEventListener(
"click",(e)=>P.diff(false), false
);
if(0) P.e.btnCommit.addEventListener(
"click",(e)=>P.commit(), false
);
const doSave = function(e){
const doSave = function(alsoClose){
const w = P.winfo;
if(!w){
F.error("No page loaded.");
return;
}
setTimeout(
function(){
if(alsoClose){
P.save(()=>window.location.href=F.repoUrl('wiki',{name: w.name}));
}else{
()=>P.save(), 0
P.save();
}
}, 0
/* timeout is a workaround to allow save() to update the
button's text (per forum feedback). The idea is to force
the call of save() to happen *after* the confirmer
callback returns so that we can change the button label
without the confirmer setting it back to its
pre-confirmed state. This is, however, no guaranty that
save() will actually be called *after* the confirmer
|
| ︙ | | |
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
|
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
|
-
+
+
+
+
+
+
-
+
+
|
});
}else{
P.e.btnReload.addEventListener('click', doReload, false);
}
if(P.config.useConfirmerButtons.save){
F.confirmer(P.e.btnSave, {
confirmText: "Really save changes?",
onconfirm: doSave,
onconfirm: ()=>doSave(),
ticks: F.config.confirmerButtonTicks
});
F.confirmer(P.e.btnSaveClose, {
confirmText: "Really save changes?",
onconfirm: ()=>doSave(true),
ticks: F.config.confirmerButtonTicks
});
}else{
P.e.btnSave.addEventListener('click', doSave, false);
P.e.btnSave.addEventListener('click', ()=>doSave(), false);
P.e.btnSaveClose.addEventListener('click', ()=>doSave(true), false);
}
P.e.taEditor.addEventListener(
'change', ()=>P.stashContentChange(), false
);
P.selectMimetype(false, true);
|
| ︙ | | |
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
|
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
|
-
+
+
|
D.append(f.eName,marker,wi.name);
if(wi.version){
D.append(
f.eLinks,
D.a(F.repoUrl('wiki',{name:wi.name}),"viewer"),
D.a(F.repoUrl('whistory',{name:wi.name}),'history'),
D.a(F.repoUrl('attachlist',{page:wi.name}),"attachments"),
D.a(F.repoUrl('attachadd',{page:wi.name,from: F.repoUrl('wikiedit',{name: wi.name})}), "attach")
D.a(F.repoUrl('attachadd',{page:wi.name,from: F.repoUrl('wikiedit',{name: wi.name})}), "attach"),
D.a(F.repoUrl('wikiedit',{name:wi.name}),"editor permalink")
);
}
};
/**
Update the page title and header based on the state of
this.winfo. A no-op if this.winfo is not set. Returns this.
|
| ︙ | | |
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
|
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
|
+
-
+
+
|
Change the save button depending on whether we have stuff to save
or not.
*/
P.updateSaveButton = function(){
if(!this.winfo || !this.getStashedWinfo(this.winfo)){
D.disable(this.e.btnSave).innerText =
"No changes to save";
D.disable(this.e.btnSaveClose);
}else{
D.enable(this.e.btnSave).innerText = "Save changes";
D.enable(this.e.btnSave).innerText = "Save";
D.enable(this.e.btnSaveClose);
}
return this;
};
/**
Getter (if called with no args) or setter (if passed an arg) for
the current file content.
|
| ︙ | | |
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
|
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
|
-
+
+
+
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
-
+
|
}
});
return this;
};
/**
Saves the current wiki page and re-populates the editor
with the saved state.
with the saved state. If passed an argument, it is
expected to be a function, which is called only if
saving succeeds, after all other post-save processing.
*/
P.save = function callee(){
P.save = function callee(onSuccessCallback){
if(!affirmPageLoaded()) return this;
const content = this.wikiContent();
if(!callee.onload){
const self = this;
callee.onload = function(w){
const oldWinfo = self.winfo;
self.unstashContent(oldWinfo);
self.dispatchEvent('wiki-page-loaded', w);
F.message("Saved page: ["+w.name+"].");
const self = this;
callee.onload = function(w){
const oldWinfo = self.winfo;
self.unstashContent(oldWinfo);
self.dispatchEvent('wiki-page-loaded', w)/* will reset save buttons */;
F.message("Saved page: ["+w.name+"].");
if('function'===typeof onSuccessCallback){
onSuccessCallback();
}
}
};
const fd = new FormData(), w = P.winfo;
fd.append('page',w.name);
fd.append('mimetype', w.mimetype);
fd.append('isnew', w.version ? 0 : 1);
fd.append('content', P.wikiContent());
F.message(
"Saving page..."
).fetch('wikiajax/save',{
payload: fd,
responseType: 'json',
beforesend: function(){
D.disable(P.e.btnSave);
D.disable(P.e.btnSave, P.e.btnSaveClose);
P.e.btnSave.innerText = "Saving...";
F.fetch.beforesend();
},
onload: callee.onload
});
return this;
};
|
| ︙ | | |