Skip to content

Commit

Permalink
Allow user to configure local or CDN source for JQuery (fixes marekre…
Browse files Browse the repository at this point in the history
  • Loading branch information
SamantazFox committed Jul 17, 2020
1 parent 8f094c8 commit 4d1f55e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 29 deletions.
18 changes: 18 additions & 0 deletions __encode/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,22 @@
//
$_CONFIG['session_name'] = "";

//
// Defines where to find the JQuery file.
// Allowed values:
// * "local": use the locally hosted file (at __encode/static/jquery.min.js)
// * "cdn" : use the CDN url provided by $_CONFIG['jquery_cdn_url']
// * "none" : don't use JQuery (Warning: limited functionnality)
//
$_CONFIG['jquery_source'] = "cdn";

//
// URL to the JQuery javascript file (Usually a CDN).
// You can use the CDN of your choice or any custom URL. See:
// https://jquery.com/download/#using-jquery-with-a-cdn
// Respected only when $_CONFIG['jquery_source'] == "cdn".
// Default: $_CONFIG['session_name'] = "";
//
$_CONFIG['jquery_cdn_url'] = "https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js";

?>
74 changes: 45 additions & 29 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,32 +395,50 @@ function outputHtml()
<!-- <meta charset="<?php print $this->getConfig('charset'); ?>" /> -->

<?php
if(($this->getConfig('log_file') != null && strlen($this->getConfig('log_file')) > 0)
|| ($this->getConfig('thumbnails') != null && $this->getConfig('thumbnails') == true && $this->mobile == false)
|| (GateKeeper::isDeleteAllowed()))
if($this->getConfig('jquery_source') != null && $this->getConfig('jquery_source') != "none")
{
?>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
<?php
if(GateKeeper::isDeleteAllowed())
if(($this->getConfig('log_file') != null && strlen($this->getConfig('log_file')) > 0)
|| ($this->getConfig('thumbnails') != null && $this->getConfig('thumbnails') == true && $this->mobile == false)
|| (GateKeeper::isDeleteAllowed()))
{

echo "
//
// Jquery source selection
//
$jq_src = "";
if ($this->getConfig('jquery_source') == "local")
{
$jq_src = '__encode/static/jquery.min.js';
}
elseif ($this->getConfig('jquery_source') == "cdn")
{
$jq_src = $this->getConfig('jquery_cdn_url');
}
else {} // Do nothing


// begin JS code
echo "<script type=\"text/javascript\" src=\"" . $jq_src . "\"></script>\n";
echo "<script type=\"text/javascript\">\n";
echo "//<![CDATA[\n";
echo "$(document).ready(function() {\n";


if(GateKeeper::isDeleteAllowed())
{

echo "
$('td.del a').click(function(){
var answer = confirm('Are you sure you want to delete : \"' + $(this).attr(\"data-name\") + '\" ?');
return answer;
});
";
";

}
if($this->logging == true)
{
}

echo "
if($this->logging == true)
{
echo "
function logFileClick(path)
{
$.ajax({
Expand All @@ -436,13 +454,12 @@ function logFileClick(path)
logFileClick('" . $this->location->getDir(true, true, false, 0) . "' + $(this).html());
return true;
});
";

}
if(EncodeExplorer::getConfig("thumbnails") == true && $this->mobile == false)
{
";
}

echo "
if(EncodeExplorer::getConfig("thumbnails") == true && $this->mobile == false)
{
echo "
function positionThumbnail(e) {
xOffset = 30;
yOffset = 10;
Expand All @@ -465,14 +482,13 @@ function() { $('#thumb').remove(); });
$('a.thumb').mousemove(function(e) { positionThumbnail(e); });
$('a.thumb').click(function(e) { $('#thumb').remove(); return true;} );
";
";
}


// End of JS code
echo "\n});\n//]]>\n</script>\n";
}
?>
});
//]]>
</script>
<?php
}
?>

Expand Down

0 comments on commit 4d1f55e

Please sign in to comment.