Skip to content
Open
Show file tree
Hide file tree
Changes from 16 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.

4 changes: 0 additions & 4 deletions core/modules/utils/dom/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,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
44 changes: 13 additions & 31 deletions core/modules/utils/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,11 @@ 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);
};
// Deprecated: Use compareDocumentPosition instead
exports.domContains = (a,b) => a.compareDocumentPosition(b) & 16;

exports.domMatchesSelector = function(node,selector) {
return node.matches ? node.matches(selector) : node.msMatchesSelector(selector);
};
// Deprecated: Use matches instead
exports.domMatchesSelector = (node,selector) => node.matches(selector);

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

exports.hasClass = function(el,className) {
return el && el.hasAttribute && el.hasAttribute("class") && el.getAttribute("class").split(" ").indexOf(className) !== -1;
};
// Deprecated: Use element.classList.contains instead
exports.hasClass = (el,className) => el.classList && el.classList.contains(className);

// Deprecated: Use element.classList.add instead
exports.addClass = function(el,className) {
var c = (el.getAttribute("class") || "").split(" ");
if(c.indexOf(className) === -1) {
c.push(className);
el.setAttribute("class",c.join(" "));
}
el.classList && el.classList.add(className);
};

// Deprecated: Use element.classList.remove instead
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(" "));
}
el.classList && el.classList.remove(className);
};

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

Expand Down
18 changes: 2 additions & 16 deletions core/modules/utils/linked-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function LinkedList() {

LinkedList.prototype.clear = function() {
// LinkedList performs the duty of both the head and tail node
this.next = new LLMap();
this.prev = new LLMap();
this.next = new Map();
this.prev = new Map();
// Linked list head initially points to itself
this.next.set(null, null);
this.prev.set(null, null);
Expand Down Expand Up @@ -190,18 +190,4 @@ function _assertString(value) {
}
};

var LLMap = function() {
this.map = Object.create(null);
};

// Just a wrapper so our object map can also accept null.
LLMap.prototype = {
set: function(key,val) {
(key === null) ? (this.null = val) : (this.map[key] = val);
},
get: function(key) {
return (key === null) ? this.null : this.map[key];
}
};

exports.LinkedList = LinkedList;
71 changes: 14 additions & 57 deletions core/modules/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,9 @@ exports.warning = function(text) {
};

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

/*
Return the integer represented by the str (string).
Expand All @@ -82,37 +74,26 @@ exports.replaceString = function(text,search,replace) {
};

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

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

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

/*
Trim whitespace from the start and end of a string
Thanks to Steven Levithan, http://blog.stevenlevithan.com/archives/faster-trim-javascript
Deprecated: Use str.trim instead
*/
exports.trim = function(str) {
if(typeof str === "string") {
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
return str.trim();
} else {
return str;
}
Expand Down Expand Up @@ -925,32 +906,9 @@ 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;
};
exports.sign = Math.sign;

/*
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;
}
};
exports.strEndsWith = (str,ending,position) => str.endsWith(ending,position);

/*
Return system information useful for debugging
Expand Down Expand Up @@ -978,9 +936,8 @@ exports.parseInt = function(str) {
return parseInt(str,10) || 0;
};

exports.stringifyNumber = function(num) {
return num + "";
};
// Use Number.toString instead
exports.stringifyNumber = num => num.toString();

exports.makeCompareFunction = function(type,options) {
options = options || {};
Expand Down