Skip to content

Commit

Permalink
Merge pull request #16 from fabriceci/File_exists-fix
Browse files Browse the repository at this point in the history
fix : Uncaught TypeError: file_exists is not a function when you pass the url param :  "langCode"
  • Loading branch information
Pavel Solomienko authored Aug 4, 2016
2 parents 3f1cc1f + 9174893 commit 93c397b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
44 changes: 22 additions & 22 deletions scripts/filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ var loadTemplate = function(id, data) {
return template;
};

// Test if a given url exists
var file_exists = function(url) {
// http://kevin.vanzonneveld.net
// + original by: Enrique Gonzalez
// + input by: Jani Hartikainen
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// % note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
// % note 1: Synchronous so may lock up browser, mainly here for study purposes.
// * example 1: file_exists('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
// * returns 1: '123'
var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
if (!req) {
throw new Error('XMLHttpRequest not supported');
}

// HEAD Results are usually shorter (faster) than GET
req.open('HEAD', url, false);
req.send(null);

return (req.status == 200);
};

// Common variables
var $fileinfo = $('#fileinfo'),
$filetree = $('#filetree'),
Expand Down Expand Up @@ -272,28 +294,6 @@ var setViewButtonsFor = function(viewMode) {
}
};

// Test if a given url exists
var file_exists = function(url) {
// http://kevin.vanzonneveld.net
// + original by: Enrique Gonzalez
// + input by: Jani Hartikainen
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// % note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
// % note 1: Synchronous so may lock up browser, mainly here for study purposes.
// * example 1: file_exists('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
// * returns 1: '123'
var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
if (!req) {
throw new Error('XMLHttpRequest not supported');
}

// HEAD Results are usually shorter (faster) than GET
req.open('HEAD', url, false);
req.send(null);

return (req.status == 200);
};

// Sanitize and transliterate file/folder name as server side (connector) way
var cleanString = function(string, allowed) {
if(config.security.normalizeFilename) {
Expand Down
Loading

0 comments on commit 93c397b

Please sign in to comment.