Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 11 additions & 32 deletions boot/boot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions core/modules/utils/deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*\
title: $:/core/modules/utils/deprecated.js
type: application/javascript
module-type: utils

Deprecated util functions

\*/

exports.logTable = data => console.table(data);

exports.repeat = (str,count) => str.repeat(count);

exports.startsWith = (str,search) => str.startsWith(search);

exports.endsWith = (str,search) => str.endsWith(search);

exports.trim = function(str) {
if(typeof str === "string") {
return str.trim();
} else {
return str;
}
};

exports.sign = Math.sign;

exports.strEndsWith = (str,ending,position) => str.endsWith(ending,position);

exports.stringifyNumber = num => num.toString();

exports.domContains = (a,b) => a.compareDocumentPosition(b) & 16;

// Use matches instead
exports.domMatchesSelector = (node,selector) => node.matches(selector);

// Use element.classList.contains instead
exports.hasClass = (el,className) => el.classList && el.classList.contains(className);

// Use element.classList.add instead
exports.addClass = function(el,className) {
el.classList && el.classList.add(className);
};

// Use element.classList.remove instead
exports.removeClass = function(el,className) {
el.classList && el.classList.remove(className);
};

// Use element.classList.toggle instead
exports.toggleClass = function(el,className,status) {
if(status === undefined) {
el.classList && el.classList.toggle(className);
} else {
el.classList && el.classList.toggle(className, status);
}
};

exports.getLocationPath = () => window.location.origin + window.location.pathname;
12 changes: 1 addition & 11 deletions core/modules/utils/dom/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports.convertStyleNameToPropertyName = function(styleName) {
var propertyName = $tw.utils.unHyphenateCss(styleName);
// Then check if it needs a prefix
if($tw.browser && document.body.style[propertyName] === undefined) {
var prefixes = ["O","MS","Moz","webkit"];
var prefixes = ["Moz","webkit"];
for(var t=0; t<prefixes.length; t++) {
var prefixedName = prefixes[t] + propertyName.substr(0,1).toUpperCase() + propertyName.substr(1);
if(document.body.style[prefixedName] !== undefined) {
Expand All @@ -66,8 +66,6 @@ exports.convertPropertyNameToStyleName = function(propertyName) {
// If there's a webkit prefix, add a dash (other browsers have uppercase prefixes, and so get the dash automatically)
if(styleName.indexOf("webkit") === 0) {
styleName = "-" + styleName;
} else if(styleName.indexOf("-m-s") === 0) {
styleName = "-ms" + styleName.substr(4);
}
return styleName;
};
Expand All @@ -92,8 +90,6 @@ var eventNameMappings = {
correspondingCssProperty: "transition",
mappings: {
transition: "transitionend",
OTransition: "oTransitionEnd",
MSTransition: "msTransitionEnd",
MozTransition: "transitionend",
webkitTransition: "webkitTransitionEnd"
}
Expand All @@ -102,8 +98,6 @@ var eventNameMappings = {
correspondingCssProperty: "animation",
mappings: {
animation: "animationend",
OAnimation: "oAnimationEnd",
MSAnimation: "msAnimationEnd",
MozAnimation: "animationend",
webkitAnimation: "webkitAnimationEnd"
}
Expand Down Expand Up @@ -136,19 +130,15 @@ exports.getFullScreenApis = function() {
result = {
"_requestFullscreen": db.webkitRequestFullscreen !== undefined ? "webkitRequestFullscreen" :
db.mozRequestFullScreen !== undefined ? "mozRequestFullScreen" :
db.msRequestFullscreen !== undefined ? "msRequestFullscreen" :
db.requestFullscreen !== undefined ? "requestFullscreen" : "",
"_exitFullscreen": d.webkitExitFullscreen !== undefined ? "webkitExitFullscreen" :
d.mozCancelFullScreen !== undefined ? "mozCancelFullScreen" :
d.msExitFullscreen !== undefined ? "msExitFullscreen" :
d.exitFullscreen !== undefined ? "exitFullscreen" : "",
"_fullscreenElement": d.webkitFullscreenElement !== undefined ? "webkitFullscreenElement" :
d.mozFullScreenElement !== undefined ? "mozFullScreenElement" :
d.msFullscreenElement !== undefined ? "msFullscreenElement" :
d.fullscreenElement !== undefined ? "fullscreenElement" : "",
"_fullscreenChange": d.webkitFullscreenElement !== undefined ? "webkitfullscreenchange" :
d.mozFullScreenElement !== undefined ? "mozfullscreenchange" :
d.msFullscreenElement !== undefined ? "MSFullscreenChange" :
d.fullscreenElement !== undefined ? "fullscreenchange" : ""
};
if(!result._requestFullscreen || !result._exitFullscreen || !result._fullscreenElement || !result._fullscreenChange) {
Expand Down
49 changes: 0 additions & 49 deletions core/modules/utils/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@ Various static DOM-related utility functions.

var Popup = require("$:/core/modules/utils/dom/popup.js");

/*
Determines whether element 'a' contains element 'b'
Code thanks to John Resig, http://ejohn.org/blog/comparing-document-position/
*/
exports.domContains = function(a,b) {
return a.contains ?
a !== b && a.contains(b) :
!!(a.compareDocumentPosition(b) & 16);
};

exports.domMatchesSelector = function(node,selector) {
return node.matches ? node.matches(selector) : node.msMatchesSelector(selector);
};

/*
Select text in a an input or textarea (setSelectionRange crashes on certain input types)
Expand All @@ -49,38 +36,6 @@ exports.removeChildren = function(node) {
}
};

exports.hasClass = function(el,className) {
return el && el.hasAttribute && el.hasAttribute("class") && el.getAttribute("class").split(" ").indexOf(className) !== -1;
};

exports.addClass = function(el,className) {
var c = (el.getAttribute("class") || "").split(" ");
if(c.indexOf(className) === -1) {
c.push(className);
el.setAttribute("class",c.join(" "));
}
};

exports.removeClass = function(el,className) {
var c = (el.getAttribute("class") || "").split(" "),
p = c.indexOf(className);
if(p !== -1) {
c.splice(p,1);
el.setAttribute("class",c.join(" "));
}
};

exports.toggleClass = function(el,className,status) {
if(status === undefined) {
status = !exports.hasClass(el,className);
}
if(status) {
exports.addClass(el,className);
} else {
exports.removeClass(el,className);
}
};

/*
Get the first parent element that has scrollbars or use the body as fallback.
*/
Expand Down Expand Up @@ -297,10 +252,6 @@ exports.copyToClipboard = function(text,options) {
document.body.removeChild(textArea);
};

exports.getLocationPath = function() {
return window.location.toString().split("#")[0];
};

/*
Collect DOM variables
*/
Expand Down
81 changes: 0 additions & 81 deletions core/modules/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ exports.warning = function(text) {
exports.log(text,"brown/orange");
};

/*
Log a table of name: value pairs
*/
exports.logTable = function(data) {
if(console.table) {
console.table(data);
} else {
$tw.utils.each(data,function(value,name) {
console.log(name + ": " + value);
});
}
}

/*
Return the integer represented by the str (string).
Return the dflt (default) parameter if str is not a base-10 number.
Expand All @@ -81,43 +68,6 @@ exports.replaceString = function(text,search,replace) {
});
};

/*
Repeats a string
*/
exports.repeat = function(str,count) {
var result = "";
for(var t=0;t<count;t++) {
result += str;
}
return result;
};

/*
Check if a string starts with another string
*/
exports.startsWith = function(str,search) {
return str.substring(0, search.length) === search;
};

/*
Check if a string ends with another string
*/
exports.endsWith = function(str,search) {
return str.substring(str.length - search.length) === search;
};

/*
Trim whitespace from the start and end of a string
Thanks to Steven Levithan, http://blog.stevenlevithan.com/archives/faster-trim-javascript
*/
exports.trim = function(str) {
if(typeof str === "string") {
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
} else {
return str;
}
};

exports.trimPrefix = function(str,unwanted) {
if(typeof str === "string" && typeof unwanted === "string") {
if(unwanted === "") {
Expand Down Expand Up @@ -925,33 +875,6 @@ exports.tagToCssSelector = function(tagName) {
});
};

/*
IE does not have sign function
*/
exports.sign = Math.sign || function(x) {
x = +x; // convert to a number
if(x === 0 || isNaN(x)) {
return x;
}
return x > 0 ? 1 : -1;
};

/*
IE does not have an endsWith function
*/
exports.strEndsWith = function(str,ending,position) {
if(str.endsWith) {
return str.endsWith(ending,position);
} else {
if(typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > str.length) {
position = str.length;
}
position -= ending.length;
var lastIndex = str.indexOf(ending, position);
return lastIndex !== -1 && lastIndex === position;
}
};

/*
Return system information useful for debugging
*/
Expand All @@ -978,10 +901,6 @@ exports.parseInt = function(str) {
return parseInt(str,10) || 0;
};

exports.stringifyNumber = function(num) {
return num + "";
};

exports.makeCompareFunction = function(type,options) {
options = options || {};
// set isCaseSensitive to true if not defined in options
Expand Down