This is an automated email from the ASF dual-hosted git repository.
brushed pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git
The following commit(s) were added to refs/heads/master by this push:
new 311369b minor js refactoring (eslint) - no version bump
311369b is described below
commit 311369bf84870f53a27551d11b536f7210498d9c
Author: brushed <[email protected]>
AuthorDate: Sat Mar 9 21:26:33 2019 +0100
minor js refactoring (eslint) - no version bump
---
jspwiki-war/src/main/scripts/behaviors/AddCSS.js | 20 +++++--
.../src/main/scripts/moo-extend/Element.Extend.js | 21 ++++++-
.../src/main/scripts/moo-extend/HighlightQuery.js | 19 ++-----
jspwiki-war/src/main/scripts/wiki/Prefs.js | 21 ++++++-
jspwiki-war/src/main/scripts/wiki/Wiki.js | 64 ++++++++++++----------
5 files changed, 93 insertions(+), 52 deletions(-)
diff --git a/jspwiki-war/src/main/scripts/behaviors/AddCSS.js
b/jspwiki-war/src/main/scripts/behaviors/AddCSS.js
index c182a7f..2598d4c 100644
--- a/jspwiki-war/src/main/scripts/behaviors/AddCSS.js
+++ b/jspwiki-war/src/main/scripts/behaviors/AddCSS.js
@@ -18,6 +18,12 @@
specific language governing permissions and limitations
under the License.
*/
+
+/*eslint-env browser*/
+/*global $ */
+/*exported AddCSS */
+
+
/* Behavior: Add-CSS
Inject any custom css into a wiki page.
You can either directly insert the css definitions in your page or
@@ -38,24 +44,32 @@ function AddCSS(element) {
item;
//concatenate all css to be inserted
- while (item = elements.shift()) { css += item.innerHTML; }
+ while( (item = elements.shift()) ){ css += item.innerHTML; }
css = css //cascading replaces
//allow google fonts @import
url(https://fonts.googleapis.com/css?family=XXXX);
.replace(/@import
url\(https:\/\/fonts.googleapis.com\/css\?family=/gi, "\xa4")
+ //fixme: allow data:image/svg+xml
+ .replace(/url\("data:image\/svg\+xml/gi,"\xa6")
+
//replace wiki-image links to css url()
//xss protection: remove invalid url's; only allow
url([wiki-attachement])
.replace(/url\(<a class="attachment"
href="([^"]+.woff)".*><\/a>\)/gi, 'url(<\xa5$1")')
.replace(/url\(<a class="attachment"
href="([^"]+.ttf)".*><\/a>\)/gi, 'url(<\xa5$1")')
.replace(/url\(<a class="attachment"
href="([^"]+.otf)".*><\/a>\)/gi, 'url(<\xa5$1")')
+ //remaining unmarked urls are invalid
.replace(/url\(<a[^>]+>\)/gi, "url(invalid)") //remove remaining
url(<a...)
.replace(/url\([^<][^)]+\)/gi, "url(invalid)") //remove remaining
url(xxx)
.replace(/@import/gi, "invalid") //xss protection: remove the
remaining @import statements
+ //restore svg images
+ .replace(/\xa6/g, "url(\"data:image/svg+xml")
+
+ //restore google font urls
.replace(/\xa4/g, "@import
url(https://fonts.googleapis.com/css?family=") //google fonts -part2
.replace(/expression|behavior/gi, "invalid") //xss protection:
remove IE dynamic properties
@@ -90,8 +104,7 @@ function AddCSS(element) {
css.replaces(element);
}
-
- };
+ }
if (element.innerHTML.test(/^\s*<a class="wikipage" href="([^"]+)">/)) {
@@ -109,5 +122,4 @@ function AddCSS(element) {
insertStyle([element]);
}
-
}
diff --git a/jspwiki-war/src/main/scripts/moo-extend/Element.Extend.js
b/jspwiki-war/src/main/scripts/moo-extend/Element.Extend.js
index 2d5595c..3d55bda 100644
--- a/jspwiki-war/src/main/scripts/moo-extend/Element.Extend.js
+++ b/jspwiki-war/src/main/scripts/moo-extend/Element.Extend.js
@@ -155,7 +155,7 @@ Element.implement({
event.preventDefault;
- };
+ }
toggle = this.getParent( toggle );
@@ -477,8 +477,9 @@ Element.implement({
/*
Function: mapTextNodes
-
- Walk all text nodes recursively and map their value via a callback
function.
+ Allows you to search and replace using strings or regular expressions
within HTML documents.
+ Keeps the HTML intact, and only changes text nodes.
+ It walks all text nodes recursively and maps their value via a
callback function.
Arguments:
fn - callback function returning the processed textnodes (string)
@@ -486,6 +487,20 @@ Element.implement({
which contain pre-formatted text
includedEmptyNodes - (bool) skip/process empty text nodes
+ Example:
+ $('#my_div').stringReplace('half empty', 'half full');
+ $('#my_div').mapTextNodes( function(s){
+ return s
+ .replace( /(c)/i, "©" )à
+ .replace( /(tm)/i, "™" )
+ .replace( /(sm)/i, "℠" );
+ );
+
+ */
+ /*
+ nodeReplace: function(findRegExp, replace){
+ this.mapTextNodes( function(s){ return s.replace(findRegExp, replace);
});
+ }
*/
mapTextNodes: function(fn, includePreCodeNodes, includeEmptyNodes){
diff --git a/jspwiki-war/src/main/scripts/moo-extend/HighlightQuery.js
b/jspwiki-war/src/main/scripts/moo-extend/HighlightQuery.js
index 97bc679..e5e82be 100644
--- a/jspwiki-war/src/main/scripts/moo-extend/HighlightQuery.js
+++ b/jspwiki-war/src/main/scripts/moo-extend/HighlightQuery.js
@@ -40,39 +40,30 @@ function HighlightQuery( node, query, template ){
if( query || (query =
(document.referrer.match(/(?:\?|&)(?:q|query)=([^&]*)/)||[,''])[1]) ){
-
try {
var words = decodeURIComponent(query)
.stripScripts() //xss vulnerability
.replace( /\+/g, " " )
.replace( /\s+-\S+/g, "" )
- .replace( /([\(\[\{\\\^\$\|\)\?\*\.\+])/g, "\\$1" ) //escape
metachars
+ .replace( /([([{\\^$|)?*.+])/g, "\\$1" ) //escape metachars
.trim().replace(/\s+/g,'|'),
- hasWords = RegExp( "(" + words + ")" , "gi");
+ matchQuery = RegExp( "(" + words + ")" , "gi");
} catch(e) {
console.error(e);
return;
}
- //console.log("highlight word : ",query, words);
+ //console.log("highlight word : ",query, words, matchQuery);
node.mapTextNodes( function(s){
- var t = s.replace( /</g, "<" ); //pre element may contain xml <
-
- if( hasWords.test(t) ){
-
- s = t.replace( hasWords, template || "<mark>$&</mark>" );
+ return s.replace( /</g, "<" ) //pre elements may contain xml <
+ .replace( matchQuery, template || "<mark>$&</mark>" );
- }
-
- return s;
}, true /* includePreCodeNodes */ );
-
}
-
}
diff --git a/jspwiki-war/src/main/scripts/wiki/Prefs.js
b/jspwiki-war/src/main/scripts/wiki/Prefs.js
index ba87a08..d1e91f8 100644
--- a/jspwiki-war/src/main/scripts/wiki/Prefs.js
+++ b/jspwiki-war/src/main/scripts/wiki/Prefs.js
@@ -18,6 +18,11 @@
specific language governing permissions and limitations
under the License.
*/
+
+/*eslint-env browser*/
+/*global Wiki */
+
+
/*
Javascript routines to support JSPWiki UserPreferences
PreferencesContent.jsp
@@ -67,9 +72,19 @@ Javascript routines to support JSPWiki UserPreferences
form.getElements( datapref ).each( function(el){
- wiki.prefs.set( el.get( "data-pref" ), getValue(el) );
+ if( el.type!="radio" || el.checked ){
+ wiki.prefs.set( el.get( "data-pref" ),
getValue(el) );
+ }
});
+
+ /*
+ var key, formData = new FormData( form );
+ for( key of formData.keys() ){
+ wiki.prefs.set( key, formData.get(key) ); //FFS:
key = the name of input element, not the pref name
+ }
+ */
+
break;
default : //"clearAssertedName"
@@ -77,13 +92,15 @@ Javascript routines to support JSPWiki UserPreferences
//FFS: no need for an AreYouSure dialog ??
wiki.prefs.empty();
- };
+ }
//on normal submit, leave the page without asking confirmation
windowUnload();
};
+ //FFS: add click-triggers to some preferences: prefLayout,
prefOrientation,
+
});
})(Wiki);
\ No newline at end of file
diff --git a/jspwiki-war/src/main/scripts/wiki/Wiki.js
b/jspwiki-war/src/main/scripts/wiki/Wiki.js
index f832b61..fc34542 100644
--- a/jspwiki-war/src/main/scripts/wiki/Wiki.js
+++ b/jspwiki-war/src/main/scripts/wiki/Wiki.js
@@ -56,11 +56,11 @@ Depends on :
/*
Class: Wiki
- Javascript support functions for jspwiki. (singleton)
+ Javascript support functions for jspwiki.
*/
var Wiki = {
- version: "haddock04", //used to validate compatible preference cookies
+ version: "haddock04", //js version, used to validate compatible
preference cookies
initialize: function(){
@@ -71,63 +71,57 @@ var Wiki = {
wiki.once = behavior.once.bind(behavior);
wiki.update = behavior.update.bind(behavior);
-
-
- //jspwiki behaviors; needed to support the haddock template jsp's
+ //add the standard jspwiki behaviors; needed to render the haddock JSP
templates
wiki.add( "body", wiki.caniuse )
.add( "[accesskey]", Accesskey )
- //toggle effect: toggle .active class on this element when
clicking toggle element
.add( "[data-toggle]", function(element){
-
+ //toggle the .active class on this element when clicking the
"data-toggle" element
element.onToggle( element.get("data-toggle"),
function(isActive){
var pref = element.get("data-toggle-pref");
if (pref) {
+ //console.log( pref, isActive );
wiki.prefs.set(pref, isActive ? "active" : "");
}
});
})
- //generate modal confirmation boxes, eg prompting to execute
- //an unrecoverable action such as deleting a page or attachment
.add( "[data-modal]", function(element){
+ //render modal confirmation dialog
+ //prior to executing unrecoverable actions such as deleting a
page or attachment
element.onModal( element.get("data-modal") );
})
- //hover effects: show/hide an element when hovering over the
data-hover-parent element
.add( "[data-hover-parent]", function(element){
+ //show/hide an element when hovering over the
"data-hover-parent" element
element.onHover( element.get("data-hover-parent") );
})
- //resize the "data-resize" elements when dragging this element
- //.add( "[data-resize]", wiki.resizer.bind(wiki) )
.add( "[data-resize]", function(element){
+ //when dragging this element, resize the "data-resize" element
wiki.resizer(element, $$(element.get("data-resize")) );
})
//add header scroll-up/down effect
- .add(".fixed-header > .header", wiki.yoyo)
+ .add( ".fixed-header > .header", wiki.yoyo )
- //sticky toolbar in the editor
.add(".sticky", function (element) {
- element.onSticky();
+ element.onSticky(); //eg used by the sticky toolbar in the
editor
})
- //highlight previous search query retreived from a cookie or
referrer page
+ //highlight previous search query, retreived from a cookie or the
referrer page
.add( ".page-content", function(element){
-
var previousQuery = "PrevQuery";
HighlightQuery( element, wiki.prefs.get(previousQuery) );
wiki.prefs.erase(previousQuery);
-
})
- //activate quick navigation searchbox
+ //searchbox dropdown engines
.add( ".searchbox .dropdown-menu", function(element){
-
- var recentSearch = "RecentSearch", prefs = wiki.prefs;
+ var recentSearch = "RecentSearch",
+ prefs = wiki.prefs;
//activate Recent Searches functionality
new wiki.Recents( element, {
@@ -137,7 +131,7 @@ var Wiki = {
}
});
- //activate Quick Navigation functionality
+ //activate Quick Navigation functionality, with type-ahead
search
new wiki.Findpages(element, {
rpc: function(value, callback){
wiki.jsonrpc("/search/pages", [value, 16], callback);
@@ -187,6 +181,8 @@ var Wiki = {
body.ifClass( !( isIE11 || isIE9or10 ) , "can-flex");
+ //body.ifClass( "ontouchstart" in document.documentElement,
"can-touch" );
+
},
@@ -210,6 +206,7 @@ var Wiki = {
path: wiki.BasePath,
duration: 20
});
+ //console.log(wiki.prefs.hash);
//Object.each(wiki.prefs.hash, function(item,key){ console.log("PREFS
",key,"=>",item); });
@@ -219,7 +216,7 @@ var Wiki = {
}
//The initial Sidebar will be active depending on a cookie state.
- //However, for small screen, the default state will be hidden.
+ //However, for small screens, the sidebar will be hidden by default.
wiki.media("(min-width:768px)", function( screenIsLarge ){
if(!screenIsLarge){
@@ -228,6 +225,13 @@ var Wiki = {
});
+ //FIXME
+ //The default Language is taken from a preference cookie, with
fallback to the browser setting
+ //String.I18N.DEFAULT_LOCAL_LANGUAGE = wiki.prefs.get("Language") ||
navigator.language || "en";
+ //The default Date & Time format is taken for m a preference cookie,
with fallback
+ //String.I18N.DEFAULT_DATE_FORMAT = wiki.prefs.get("DateFormat") ||
"dd mmm yyyy hh:mm";
+
+
//wiki.url = null; //CHECK: why this is needed?
//console.log( wiki.prefs.get("SectionEditing") , wiki.EditPermission
,wiki.Context );
if( wiki.prefs.get("SectionEditing") && wiki.EditPermission &&
(wiki.Context != "preview") ){
@@ -236,17 +240,17 @@ var Wiki = {
}
+ //jump to the right section if the referrer page (previous edit) says
so
//console.log( "section", document.referrer, document.referrer.match(
/\§ion=(\d+)$/ ) );
wiki.scrollTo( ( document.referrer.match( /§ion=(\d+)$/ ) ||
[0,-1])[1] );
- // initialize all registered behaviors
+ // now we are ready to run all the registered behaviors
wiki.update();
- //on page-load, also read the #hash and fire popstate events
+ //read the #hash and fire popstate events
wiki.popstate();
wiki.autofocus();
-
},
@@ -325,7 +329,7 @@ var Wiki = {
/*
Function: popstate
When pressing the back-button, the "popstate" event is fired.
- This popstate function will fire a internal 'popstate' event
+ This popstate function will fire an internal 'popstate' event
on the target DOM element.
Behaviors (such as Tabs or Accordions) can push the ID of their
@@ -374,6 +378,7 @@ var Wiki = {
// find input#query2
els = $$("input[autofocus=autofocus],
textarea[autofocus=autofocus]");
while( els[0] ){
+
element = els.shift();
//console.log("autofocus", element, element.autofocus,
element.isVisible(), element.offsetWidth, element.offsetHeight, "$",
element.getStyle("display"), "$");
if( element.isVisible() ){
@@ -422,7 +427,7 @@ var Wiki = {
/*
Function: dropdowns
- Parse special wikipages such ase MoreMenu, HomeMenu
+ Parse special wikipage parts such ase MoreMenu, HomeMenu
and format them as bootstrap compatible dropdown menus.
*/
dropdowns: function(){
@@ -586,7 +591,8 @@ var Wiki = {
});
//Persist the selected editor type in the pref cookie
- form.getElements("a.editor-type").addEvent("click", function(){
+ //????form.getElements(".dropdown-menu
a[data-cmd=editor]").addEvent("click", ...
+ form.getElements("a.editor-type").addEvent("click", function () {
wiki.prefs.set("editor", this.get("text"));