Moved import-style modules back into repository-style modules.
This commit is contained in:
parent
8e973d1a1a
commit
9f213ab7b9
7 changed files with 182 additions and 129 deletions
|
@ -1,41 +0,0 @@
|
|||
var encode = function (str, buffer, encodeNewline) {
|
||||
str = String(str);
|
||||
|
||||
if (str === null || !str.length) return str;
|
||||
if (!buffer) buffer = [];
|
||||
if (typeof encodeNewline === 'undefined') encodeNewline = true;
|
||||
|
||||
for (var i = 0, len = str.length; i < len; i += 1) {
|
||||
var char = str.charAt(i);
|
||||
|
||||
switch (char) {
|
||||
case '<':
|
||||
buffer.push('<');
|
||||
break;
|
||||
|
||||
case '>':
|
||||
buffer.push('>');
|
||||
break;
|
||||
|
||||
case '&':
|
||||
buffer.push('&');
|
||||
break;
|
||||
|
||||
case '"':
|
||||
buffer.push('"');
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
if (encodeNewline) {
|
||||
buffer.push("<br class='helma-format' />");
|
||||
}
|
||||
buffer.push('\n');
|
||||
break;
|
||||
|
||||
default:
|
||||
buffer.push(char);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.join('');
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
// import 'encode';
|
||||
|
||||
var encodeForm = function(str, buffer) {
|
||||
str = String(str);
|
||||
|
||||
if (str === null || !str.length) return str;
|
||||
if (!buffer) buffer = [];
|
||||
|
||||
return encode(str, buffer, false);
|
||||
};
|
|
@ -1,46 +0,0 @@
|
|||
var encodeXml = function(str, buffer) {
|
||||
str = String(str);
|
||||
|
||||
if (str === null || !str.length) return str;
|
||||
if (!buffer) buffer = [];
|
||||
|
||||
for (var i = 0, len = str.length; i < len; i += 1) {
|
||||
var char = str.charAt(i);
|
||||
|
||||
switch (char) {
|
||||
case '<':
|
||||
buffer.push('<');
|
||||
break;
|
||||
|
||||
case '>':
|
||||
buffer.push('>');
|
||||
break;
|
||||
|
||||
case '&':
|
||||
buffer.push('&');
|
||||
break;
|
||||
|
||||
case '"':
|
||||
buffer.push('"');
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
buffer.push(''');
|
||||
break;
|
||||
|
||||
default:
|
||||
var charCode = str.charCodeAt(i);
|
||||
if (charCode < 0x20) {
|
||||
// sort out invalid XML characters below 0x20 - all but 0x9, 0xA and 0xD.
|
||||
// The trick is an adaption of java.lang.Character.isSpace().
|
||||
if (((((1 << 0x9) | (1 << 0xA) | (1 << 0xD)) >> charCode) & 1) !== 0) {
|
||||
buffer.push(char);
|
||||
}
|
||||
} else {
|
||||
buffer.push(char);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.join('');
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
var stripTags = function (str) {
|
||||
if (str === null) return str;
|
||||
|
||||
var chars = String(str).split('');
|
||||
var charCounter = 0;
|
||||
var inTag = false;
|
||||
|
||||
for (var i = 0, len = str.length; i < len; i += 1) {
|
||||
if (chars[i] === '<') inTag = true;
|
||||
|
||||
if (!inTag) {
|
||||
if (i > charCounter) {
|
||||
chars[charCounter] = chars[i];
|
||||
}
|
||||
|
||||
charCounter += 1;
|
||||
}
|
||||
|
||||
if (chars[i] === '>') {
|
||||
inTag = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (i > charCounter) {
|
||||
chars.length = charCounter;
|
||||
return chars.join('');
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
/**
|
||||
* @fileoverview Adds useful global macros.
|
||||
* <br /><br />
|
||||
* To use this optional module, its repository needs to be added to the
|
||||
* To use this optional module, its repository needs to be added to the
|
||||
* application, for example by calling app.addRepository('modules/core/Global.js')
|
||||
*/
|
||||
|
||||
|
@ -77,3 +77,180 @@ var skin_macro = function(param, name) {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a string for HTML output and inserts linebreak tags.
|
||||
*
|
||||
* Performs the following string manipulations:
|
||||
* All line breaks (i.e. line feeds) are replaced with <br/> tags.
|
||||
* All special characters are being replaced with their equivalent HTML entity.
|
||||
* Existing markup tags are being encoded.
|
||||
*
|
||||
* @param {string} text
|
||||
* The string to encode for HTML output.
|
||||
* @param {boolean} [encodeNewLine = true]
|
||||
* If or if not to encode line breaks (i.e. line feeds).
|
||||
* @return {string}
|
||||
* The encoded string.
|
||||
*/
|
||||
function encode(text, encodeNewLine) {
|
||||
text = String(text);
|
||||
|
||||
if (text === null || !text.length) return text;
|
||||
var buffer = [];
|
||||
if (typeof encodeNewline === 'undefined') encodeNewline = true;
|
||||
|
||||
for (var i = 0, len = text.length; i < len; i += 1) {
|
||||
var char = text.charAt(i);
|
||||
|
||||
switch (char) {
|
||||
case '<':
|
||||
buffer.push('<');
|
||||
break;
|
||||
|
||||
case '>':
|
||||
buffer.push('>');
|
||||
break;
|
||||
|
||||
case '&':
|
||||
buffer.push('&');
|
||||
break;
|
||||
|
||||
case '"':
|
||||
buffer.push('"');
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
if (encodeNewline) {
|
||||
buffer.push("<br/>");
|
||||
}
|
||||
buffer.push('\n');
|
||||
break;
|
||||
|
||||
default:
|
||||
buffer.push(char);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a string for XML output.
|
||||
*
|
||||
* Performs the following string manipulations:
|
||||
* All special characters are being replaced with their equivalent HTML entity.
|
||||
* Existing tags, single and double quotes, as well as ampersands are being encoded.
|
||||
* Some invalid XML characters below '0x20' are removed
|
||||
*
|
||||
* @param {string} text
|
||||
* The string to encode for XML output.
|
||||
* @return {string}
|
||||
* The string encoded for XML output.
|
||||
*/
|
||||
function encodeXml(text) {
|
||||
text = String(text);
|
||||
|
||||
if (text === null || !text.length) return text;
|
||||
var buffer = [];
|
||||
|
||||
for (var i = 0, len = text.length; i < len; i += 1) {
|
||||
var char = text.charAt(i);
|
||||
|
||||
switch (char) {
|
||||
case '<':
|
||||
buffer.push('<');
|
||||
break;
|
||||
|
||||
case '>':
|
||||
buffer.push('>');
|
||||
break;
|
||||
|
||||
case '&':
|
||||
buffer.push('&');
|
||||
break;
|
||||
|
||||
case '"':
|
||||
buffer.push('"');
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
buffer.push(''');
|
||||
break;
|
||||
|
||||
default:
|
||||
var charCode = str.charCodeAt(i);
|
||||
if (charCode < 0x20) {
|
||||
// sort out invalid XML characters below 0x20 - all but 0x9, 0xA and 0xD.
|
||||
// The trick is an adaption of java.lang.Character.isSpace().
|
||||
if (((((1 << 0x9) | (1 << 0xA) | (1 << 0xD)) >> charCode) & 1) !== 0) {
|
||||
buffer.push(char);
|
||||
}
|
||||
} else {
|
||||
buffer.push(char);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a string for HTML output, leaving linebreaks untouched.
|
||||
*
|
||||
* Performs the following string manipulations:
|
||||
* Unlike encode, leaves linebreaks untouched. This is what you usually want to do for encoding form content (esp.
|
||||
* with text input values).
|
||||
* All special characters (i.e. non ASCII) are being replaced with their equivalent HTML entity.
|
||||
* Existing markup tags are being encoded.
|
||||
*
|
||||
* @param {string} text
|
||||
* The string to format for HTML output.
|
||||
* @return {string}
|
||||
* The string formatted for HTML output.
|
||||
*/
|
||||
var encodeForm = function(text) {
|
||||
text = String(text);
|
||||
|
||||
if (text === null || !text.length) return text;
|
||||
|
||||
return encode(str, false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes any markup tags contained in the passed string, and returns the modified string.
|
||||
*
|
||||
* @param {string} markup
|
||||
* The text that is to be stripped of tags.
|
||||
* @return {string}
|
||||
* The text with the tags stripped out.
|
||||
*/
|
||||
var stripTags = function (markup) {
|
||||
if (markup === null) return markup;
|
||||
|
||||
var chars = String(markup).split('');
|
||||
var charCounter = 0;
|
||||
var inTag = false;
|
||||
|
||||
for (var i = 0, len = markup.length; i < len; i += 1) {
|
||||
if (chars[i] === '<') inTag = true;
|
||||
|
||||
if (!inTag) {
|
||||
if (i > charCounter) {
|
||||
chars[charCounter] = chars[i];
|
||||
}
|
||||
|
||||
charCounter += 1;
|
||||
}
|
||||
|
||||
if (chars[i] === '>') {
|
||||
inTag = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (i > charCounter) {
|
||||
chars.length = charCounter;
|
||||
return chars.join('');
|
||||
}
|
||||
|
||||
return markup;
|
||||
};
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
* application, for example by calling app.addRepository('modules/core/Object.js')
|
||||
*/
|
||||
|
||||
app.addRepository('modules/core/Global.js');
|
||||
|
||||
/**
|
||||
* Copies the properties of this object into a clone.
|
||||
* @external
|
||||
|
|
|
@ -42,6 +42,8 @@ String.URLPATTERN = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\
|
|||
* application, for example by calling app.addRepository('modules/core/String.js')
|
||||
*/
|
||||
|
||||
app.addRepository('modules/core/Global.js');
|
||||
|
||||
/**
|
||||
* checks if a date format pattern is correct
|
||||
* @external
|
||||
|
|
Loading…
Add table
Reference in a new issue