mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-12-09 18:28:07 +00:00
Add the querySelectorSafe() function and replace querySelector() usage (#7380)
* Initial commit * Correct the over-estimation of my abilities * Add fallback and move code to dom.js * Use new function for tm-focus-selector * Replace other uses of querySelector* * Undo rash replacements of querySelector()
This commit is contained in:
@@ -365,5 +365,25 @@ exports.collectDOMVariables = function(selectedNode,domNode,event) {
|
||||
return variables;
|
||||
};
|
||||
|
||||
/*
|
||||
Make sure the CSS selector is not invalid
|
||||
*/
|
||||
exports.querySelectorSafe = function(selector,baseElement) {
|
||||
baseElement = baseElement || document;
|
||||
try {
|
||||
return baseElement.querySelector(selector);
|
||||
} catch(e) {
|
||||
console.log("Invalid selector: ",selector);
|
||||
}
|
||||
};
|
||||
|
||||
exports.querySelectorAllSafe = function(selector,baseElement) {
|
||||
baseElement = baseElement || document;
|
||||
try {
|
||||
return baseElement.querySelectorAll(selector);
|
||||
} catch(e) {
|
||||
console.log("Invalid selector: ",selector);
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
@@ -127,8 +127,8 @@ PageScroller.prototype.scrollIntoView = function(element,callback,options) {
|
||||
};
|
||||
|
||||
PageScroller.prototype.scrollSelectorIntoView = function(baseElement,selector,callback,options) {
|
||||
baseElement = baseElement || document.body;
|
||||
var element = baseElement.querySelector(selector);
|
||||
baseElement = baseElement || document;
|
||||
var element = $tw.utils.querySelectorSafe(selector,baseElement);
|
||||
if(element) {
|
||||
this.scrollIntoView(element,callback,options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user