User:Cacycle/wikEd dev.js: Difference between revisions

Content deleted Content added
test3
test4
Line 1,643:
// various
if (typeof(wikEd.gotGlobalsHook) == 'undefined') { wikEd.gotGlobalsHook = []; }
if (typeof(wikEd.getGlobalsCounter) == 'undefined') { wikEd.getGlobalsCounter = 0; }
if (typeof(wikEd.loadingTranslation) == 'undefined') { wikEd.loadingTranslation = false; }
if (typeof(wikEd.webStorage) == 'undefined') { wikEd.webStorage = false; }
Line 14,704 ⟶ 14,705:
formData += '--' + boundary + '--\r\n';
// headers['Content-length'] = formData.length;///?
}
WED('formData string', formData);
}
 
// use FormData object
else {
formData = new FormData();
for (var fieldName in postFields) {
if (postFields.hasOwnProperty(fieldName) == true) {
formData.append(fieldName, postFields[fieldName]);
}
}
}
Line 14,823 ⟶ 14,824:
//
// wikEd.GetGlobals: copy global context variables into Greasemonkey context (code copied to wikEdDiff.js)
// uses Greasemonkey postMessage, ___locationhead hackscript, and JSON encoding
 
wikEd.GetGlobals = function(names, gotGlobalsHook) {
Line 14,831 ⟶ 14,832:
}
 
// setprepare ___location hrefcode to executebe codeexecuted in global context
var locationHackCodeglobalScopeCode = 'var globalObj = {};';
if (gotGlobalsHook != null) {
wikEd.gotGlobalsHook.push(gotGlobalsHook);
locationHackCodeglobalScopeCode += 'globalObj.hookNumber = ' + (wikEd.gotGlobalsHook.length - 1) + ';';
}
locationHackCodeglobalScopeCode += 'globalObj.wikEdGetGlobalsscriptId = {}\'wikEdGetGlobalScript' + wikEd.getGlobalsCounter + '\';';
globalScopeCode += 'globalObj.wikEdGetGlobals = {};';
 
// add global scope variables
for (var i = 0; i < names.length; i ++) {
locationHackCodeglobalScopeCode += ''
+ 'if (typeof(' + names[i] + ') != \'undefined\') {'
+ ' globalObj.wikEdGetGlobals.[\'' + names[i] + '\'] = ' + names[i] + ';'
+ '}';
}
locationHackCodeglobalScopeCode += 'var globalObjStr = JSON.stringify(globalObj);';
if (window.___location.host != '') {
locationHackCodeglobalScopeCode += 'window.postMessage(globalObjStr, \'' + window.___location.protocol + '//' + window.___location.host + '\');'
}
else {
locationHackCodeglobalScopeCode += 'window.postMessage(globalObjStr, \'*\');';
}
 
locationHackCode += 'void(0);';
// create head script to execute the code
___location.href = 'javascript:' + locationHackCode;
var script = document.createElement('script');
script.id = 'wikEdGetGlobalScript' + wikEd.getGlobalsCounter;
wikEd.getGlobalsCounter ++;
script.innerHTML = globalScopeCode;
document.getElementsByTagName('head')[0].appendChild(script);
 
return;
Line 14,884 ⟶ 14,893:
wikEd.ExecuteHook(wikEd.gotGlobalsHook[globalObj.hookNumber], true);
}
 
// clean up head script
var script = document.getElementById(globalObj.scriptId);
document.getElementsByTagName('head')[0].removeChild(script);
var script = document.getElementById(globalObj.scriptId);
}
}