JavaScript gadget – load local files into wiki page interactively, like CSS or JavaScript resources.
This avoids to load too many scripts always into every wiki page. If really needed, a particular tool can be used once in a while on particular pages.
Local resource files have some more advantages against user pages on wiki:
A link within tool box of wiki page is offered. Furthermore there are different calls to base functions available ( API).
The tool link gives access to interactive selection of one or more resource files within a pre-selected path, which will be appplied to the current wiki page.
The file name extensions .css
(
CSS) and .js
(
JavaScript) may be used (in capital letters, too).
It must be allowed to use local files from a web based document.
It is necessary to declare the path externally.
Insert these lines into personal common.js:
mw.loader.load("//en.wikipedia.org/?title=User:PerfektesChaos/js/loadResourceFile/r.js&action=raw&ctype=text/javascript&maxage=604800&*",
"text/javascript");
This makes all functions available, including a link within tool box.
It is assumed that all script files and CSS styles assigned for use within wiki pages are concentrated within one directory.
They need to exist within this folder.
.lnk
doesn’t work.The path in effect may be declared by various means:
localStorage
as follows.mw.libs.loadResourceFile.setFolder(
path )
localStorage.setItem( "loadResourceFile.path",
path );
After definition the path is shown within tooltip over tool link.
A slash after base folder is possible but not required. The kind of slash ( \) does not matter.
The starting point of interactive file selection menu cannot be influenced.
It is recommended to store all resource files in UTF-8 encoding.
UTF-8
rather than ANSI
format.UTF-8
ISO-8859-1
– Western Europe (ANSI), alias latin1
UTF-8
There are facilities offered to use all resource files or all subsequent files for this page or just the current file in deviating encoding.
The initial environment and the behaviour can be equipped by each user individually.
Base directory and default character encoding can be set interactively on Special:Gadgets as soon as the script library has been loaded.
The portlet link can be switched on and off only.
When reloading a page the preferences declared here come into effect. This dynamic assignment overrides the static setting by application object.
These user preferences are not visible to other users.
Insert the following lines into common.js etc. (best before mw.loader.load):
if ( typeof mw.libs.loadResourceFile !== "object" ) {
mw.libs.loadResourceFile = { };
}
mw.libs.loadResourceFile.key1 = value1;
See API for more information.
Before script loading an application object may be declared as follows, e.g. within personal common.js page:
if ( ! mw.libs.loadResourceFile ) {
mw.libs.loadResourceFile = { };
}
Subsequently assignments can be made according to the following table. Static assignments of values are to be made before script library was called. Later the functions are to be used for changing the current setting.
After loading the API functions may be used always, whether the application object has been declared by user or not.
Presettings | Meaning | |
Key | Value | |
---|---|---|
portlet
|
|
|
portlet.scope
|
"p-tb "
|
ID of container |
portlet.show
|
"Load CSS/JS file "
|
Link title |
portlet.shortcut
|
Keyboard code | |
portlet.stick
|
null | ID of container element to place ahead |
set
|
"UTF-8 "
|
Different default for encoding. |
store
|
Default for base directory | |
API | The functions yield no return value. | |
find(access)
|
Start an interactive file selection including resource loading into document (using current encoding).
| |
folder(access)
|
Set temporary default for base directory, and retrieve current path.
| |
loadFiles(apply,access,accept)
|
Load one or more resource files.
| |
setCharset(accept)
|
Set default for character encoding.
|
Example:
if ( typeof mw.libs.loadResourceFile !== "object" ) {
mw.libs.loadResourceFile = { };
}
mw.libs.loadResourceFile.portlet = false;
The current implementation may be used with any browser during recent 15 years.
Modern browsers permit a “blob” access. There file names are not disclosed, but file content only, which would enable navigation into arbitrary folders.
However, it is supposed that in a tidy household all files for working on wiki are collected in one directory. So, there is no reason for another approach now, executing file content actively.
This gadget is prepared for multilingual support.
lang.texts
mapping on top of source code.Source code |
|
ResourceLoader |
|
Namespaces | all |
Cookies |
|
mw.libs
|
loadResourceFile
|
JavaScript gadget – load local files into wiki page interactively, like CSS or JavaScript resources.
This avoids to load too many scripts always into every wiki page. If really needed, a particular tool can be used once in a while on particular pages.
Local resource files have some more advantages against user pages on wiki:
A link within tool box of wiki page is offered. Furthermore there are different calls to base functions available ( API).
The tool link gives access to interactive selection of one or more resource files within a pre-selected path, which will be appplied to the current wiki page.
The file name extensions .css
(
CSS) and .js
(
JavaScript) may be used (in capital letters, too).
It must be allowed to use local files from a web based document.
It is necessary to declare the path externally.
Insert these lines into personal common.js:
mw.loader.load("//en.wikipedia.org/?title=User:PerfektesChaos/js/loadResourceFile/r.js&action=raw&ctype=text/javascript&maxage=604800&*",
"text/javascript");
This makes all functions available, including a link within tool box.
It is assumed that all script files and CSS styles assigned for use within wiki pages are concentrated within one directory.
They need to exist within this folder.
.lnk
doesn’t work.The path in effect may be declared by various means:
localStorage
as follows.mw.libs.loadResourceFile.setFolder(
path )
localStorage.setItem( "loadResourceFile.path",
path );
After definition the path is shown within tooltip over tool link.
A slash after base folder is possible but not required. The kind of slash ( \) does not matter.
The starting point of interactive file selection menu cannot be influenced.
It is recommended to store all resource files in UTF-8 encoding.
UTF-8
rather than ANSI
format.UTF-8
ISO-8859-1
– Western Europe (ANSI), alias latin1
UTF-8
There are facilities offered to use all resource files or all subsequent files for this page or just the current file in deviating encoding.
The initial environment and the behaviour can be equipped by each user individually.
Base directory and default character encoding can be set interactively on Special:Gadgets as soon as the script library has been loaded.
The portlet link can be switched on and off only.
When reloading a page the preferences declared here come into effect. This dynamic assignment overrides the static setting by application object.
These user preferences are not visible to other users.
Insert the following lines into common.js etc. (best before mw.loader.load):
if ( typeof mw.libs.loadResourceFile !== "object" ) {
mw.libs.loadResourceFile = { };
}
mw.libs.loadResourceFile.key1 = value1;
See API for more information.
Before script loading an application object may be declared as follows, e.g. within personal common.js page:
if ( ! mw.libs.loadResourceFile ) {
mw.libs.loadResourceFile = { };
}
Subsequently assignments can be made according to the following table. Static assignments of values are to be made before script library was called. Later the functions are to be used for changing the current setting.
After loading the API functions may be used always, whether the application object has been declared by user or not.
Presettings | Meaning | |
Key | Value | |
---|---|---|
portlet
|
|
|
portlet.scope
|
"p-tb "
|
ID of container |
portlet.show
|
"Load CSS/JS file "
|
Link title |
portlet.shortcut
|
Keyboard code | |
portlet.stick
|
null | ID of container element to place ahead |
set
|
"UTF-8 "
|
Different default for encoding. |
store
|
Default for base directory | |
API | The functions yield no return value. | |
find(access)
|
Start an interactive file selection including resource loading into document (using current encoding).
| |
folder(access)
|
Set temporary default for base directory, and retrieve current path.
| |
loadFiles(apply,access,accept)
|
Load one or more resource files.
| |
setCharset(accept)
|
Set default for character encoding.
|
Example:
if ( typeof mw.libs.loadResourceFile !== "object" ) {
mw.libs.loadResourceFile = { };
}
mw.libs.loadResourceFile.portlet = false;
The current implementation may be used with any browser during recent 15 years.
Modern browsers permit a “blob” access. There file names are not disclosed, but file content only, which would enable navigation into arbitrary folders.
However, it is supposed that in a tidy household all files for working on wiki are collected in one directory. So, there is no reason for another approach now, executing file content actively.
This gadget is prepared for multilingual support.
lang.texts
mapping on top of source code.Source code |
|
ResourceLoader |
|
Namespaces | all |
Cookies |
|
mw.libs
|
loadResourceFile
|