mirror of
https://github.com/unraid/webgui.git
synced 2026-03-01 05:41:08 -06:00
refactor: simplify browser detection and search functionality in gui_search.page
- Removed the browser detection logic for improved code clarity and maintainability. - Updated the search functionality to use 'fragmentDirective' for better compatibility. - Eliminated the jQuery.mark.js file as it is no longer needed, streamlining the search implementation.
This commit is contained in:
@@ -18,19 +18,6 @@ $guiSearchBoxSpan = "<span id='guiSearchBoxSpan'><input type='text' id='guiSear
|
||||
var languageVisible;
|
||||
var guiSearchSuggestions;
|
||||
|
||||
var browserName = (function(agent){
|
||||
switch (true) {
|
||||
case agent.indexOf('edge') >= 0: return 'Edge'; // Edge
|
||||
case agent.indexOf('edg/') >= 0: return 'Edge'; // Edge Chromium Based
|
||||
case agent.indexOf('opr') >= 0 && !!window.opr: return 'Opera';
|
||||
case agent.indexOf('chrome') >= 0 && !!window.chrome: return 'Chrome';
|
||||
case agent.indexOf('trident') >= 0: return 'MS IE';
|
||||
case agent.indexOf('firefox') >= 0: return 'Mozilla Firefox';
|
||||
case agent.indexOf('safari') >= 0: return 'Safari';
|
||||
default: return 'other';
|
||||
}
|
||||
})(window.navigator.userAgent.toLowerCase());
|
||||
|
||||
$(function(){
|
||||
<?if ($themeHelper->isSidebarTheme()):?>
|
||||
$('.nav-item.gui_search').hover(function(){gui_search();},function(e){closeSearchBox(e);});
|
||||
@@ -56,10 +43,6 @@ function setupGUIsearch() {
|
||||
<?endif;?>
|
||||
}
|
||||
});
|
||||
if (browserName != 'Chrome' && browserName != 'Edge') {
|
||||
var hashTag = (window.location.hash||'').substr(1).replace('%20',' ').replace('%2d','-');
|
||||
if (hashTag.length) $('body').mark(hashTag,{'accuracy': {'value': 'exactly','limiters': ['.',':','?']},'separateWordSearch': false});
|
||||
}
|
||||
}
|
||||
|
||||
function gui_search() {
|
||||
@@ -97,19 +80,12 @@ function closeSearchBox(e) {
|
||||
|
||||
function guiSearch() {
|
||||
var searchInfo = $('#guiSearchBox').val().split('**');
|
||||
var separator = (browserName == 'Chrome' || browserName == 'Edge') ? '#:~:text=' : '#';
|
||||
var separator = ('fragmentDirective' in document) ? '#:~:text=' : '#';
|
||||
var scrollText = (typeof searchInfo[1] != 'undefined') ? separator+searchInfo[1].replace(' ','%20').replace('-','%2d') : '';
|
||||
var newPage = "<?=$currentUnraidPage?>/Settings/Tools".replace(searchInfo[0]+'/','');
|
||||
|
||||
closeSearchBox(event);
|
||||
if (newPage == 'Dashboard/Settings/Tools') newPage = 'Settings';
|
||||
location.replace('/'+newPage+'/'+searchInfo[0]+scrollText);
|
||||
}
|
||||
|
||||
if (browserName != 'Chrome' && browserName != 'Edge') {
|
||||
var script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = '<?autov('/plugins/dynamix.gui.search/javascript/jquery.mark.js')?>';
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
location.assign('/'+newPage+'/'+searchInfo[0]+scrollText);
|
||||
}
|
||||
</script>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user