-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made quicksearch JS code a dedicated module
* Moved the needed utility functions to separate modules on the way. * Separated the sidebar JS code from the rest by compiling a dedicated side_min.js out of side_index.js. * Some linter cleanups and minor bug fixes on the way Change-Id: Ia98dbf92ad9385990ddedb2b0aa1bc9955a20350
- Loading branch information
1 parent
31c930e
commit e3e78a9
Showing
12 changed files
with
296 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ | |
"strict": 1, | ||
"indent": [ | ||
"error", | ||
4 | ||
4, | ||
{ "SwitchCase": 1 } | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// +------------------------------------------------------------------+ | ||
// | ____ _ _ __ __ _ __ | | ||
// | / ___| |__ ___ ___| | __ | \/ | |/ / | | ||
// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | | ||
// | | |___| | | | __/ (__| < | | | | . \ | | ||
// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | | ||
// | | | ||
// | Copyright Mathias Kettner 2014 mk@mathias-kettner.de | | ||
// +------------------------------------------------------------------+ | ||
// | ||
// This file is part of Check_MK. | ||
// The official homepage is at http://mathias-kettner.de/check_mk. | ||
// | ||
// check_mk is free software; you can redistribute it and/or modify it | ||
// under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation in version 2. check_mk is distributed | ||
// in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- | ||
// out even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
// PARTICULAR PURPOSE. See the GNU General Public License for more de- | ||
// ails. You should have received a copy of the GNU General Public | ||
// License along with GNU Make; see the file COPYING. If not, write | ||
// to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
// Boston, MA 02110-1301 USA. | ||
|
||
import { merge_args } from "utils"; | ||
|
||
export function get_url(url, handler, data, errorHandler, addAjaxId) | ||
{ | ||
var args = { | ||
response_handler: handler | ||
}; | ||
|
||
if (typeof data !== "undefined") | ||
args.handler_data = data; | ||
|
||
if (typeof errorHandler !== "undefined") | ||
args.error_handler = errorHandler; | ||
|
||
if (typeof addAjaxId !== "undefined") | ||
args.add_ajax_id = addAjaxId; | ||
|
||
call_ajax(url, args); | ||
} | ||
|
||
export function post_url(url, post_params, responseHandler, handler_data, errorHandler) | ||
{ | ||
var args = { | ||
method: "POST", | ||
post_data: post_params | ||
}; | ||
|
||
if (typeof responseHandler !== "undefined") { | ||
args.response_handler = responseHandler; | ||
} | ||
|
||
if (typeof handler_data !== "undefined") | ||
args.handler_data = handler_data; | ||
|
||
if (typeof errorHandler !== "undefined") | ||
args.error_handler = errorHandler; | ||
|
||
call_ajax(url, args); | ||
} | ||
|
||
export function call_ajax(url, optional_args) | ||
{ | ||
var args = merge_args({ | ||
add_ajax_id : true, | ||
plain_error : false, | ||
response_handler : null, | ||
error_handler : null, | ||
handler_data : null, | ||
method : "GET", | ||
post_data : null, | ||
sync : false | ||
}, optional_args); | ||
|
||
var AJAX = window.XMLHttpRequest ? new window.XMLHttpRequest() : new window.ActiveXObject("Microsoft.XMLHTTP"); | ||
if (!AJAX) | ||
return null; | ||
|
||
// Dynamic part to prevent caching | ||
if (args.add_ajax_id) { | ||
url += url.indexOf("?") !== -1 ? "&" : "?"; | ||
url += "_ajaxid="+Math.floor(Date.parse(new Date()) / 1000); | ||
} | ||
|
||
if (args.plain_error) { | ||
url += url.indexOf("?") !== -1 ? "&" : "?"; | ||
url += "_plain_error=1"; | ||
} | ||
|
||
try { | ||
AJAX.open(args.method, url, !args.sync); | ||
} catch (e) { | ||
if (args.error_handler) { | ||
args.error_handler(args.handler_data, null, e); | ||
return null; | ||
} else { | ||
throw e; | ||
} | ||
} | ||
|
||
if (args.method == "POST") { | ||
AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | ||
} | ||
|
||
if (!args.sync) { | ||
AJAX.onreadystatechange = function() { | ||
if (AJAX && AJAX.readyState == 4) { | ||
if (AJAX.status == 200) { | ||
if (args.response_handler) | ||
args.response_handler(args.handler_data, AJAX.responseText); | ||
} | ||
else if (AJAX.status == 401) { | ||
// This is reached when someone is not authenticated anymore | ||
// but has some webservices running which are still fetching | ||
// infos via AJAX. Reload the whole frameset or only the | ||
// single page in that case. | ||
if(top) | ||
top.location.reload(); | ||
else | ||
document.location.reload(); | ||
} | ||
else { | ||
if (args.error_handler) | ||
args.error_handler(args.handler_data, AJAX.status, AJAX.statusText); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
AJAX.send(args.post_data); | ||
return AJAX; | ||
} |
Oops, something went wrong.