Skip to content

Commit

Permalink
Merge pull request #3941 from mitchray/js/relocate-1
Browse files Browse the repository at this point in the history
Next batch of JS extraction
  • Loading branch information
lachlan-00 committed May 6, 2024
2 parents 31088e9 + c48a79b commit 2cad4bc
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 116 deletions.
5 changes: 5 additions & 0 deletions public/templates/js_globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,22 @@
var jsAmpConfigCookieSecure = "<?php echo make_bool(AmpConfig::get('cookie_secure')); ?>";
var jsAmpConfigGeolocation = "<?php echo make_bool(AmpConfig::get('geolocation')); ?>";
var jsAmpConfigLibitemContextmenu = "<?php echo make_bool(AmpConfig::get('libitem_contextmenu')); ?>";
var jsAmpConfigPlayType = "<?php echo AmpConfig::get('play_type'); ?>";
var jsAmpConfigSlideshowTime = "<?php echo make_bool(AmpConfig::get('slideshow_time')); ?>";
var jsAmpConfigSidebarHideSwitcher = "<?php echo make_bool(AmpConfig::get('sidebar_hide_switcher', false)); ?>";

// Preferences
var jsPrefExistsFlickrApiKey = "<?php echo Preference::exists('flickr_api_key'); ?>";

// Misc
var jsAjaxUrl = "<?php echo $ajaxUriRetriever->getAjaxUri(); ?>";
var jsWebPath = "<?php echo $web_path; ?>";
var jsAjaxServer = "<?php echo $ajaxUriRetriever->getAjaxServerUri(); ?>";
var jsSiteTitle = "<?php echo addslashes(AmpConfig::get('site_title', '')); ?>";
var jsCookieString = jsAmpConfigCookieSecure ? "expires: 30, path: '/', secure: true, samesite: 'Strict'" : "expires: 30, path: '/', samesite: 'Strict'";
var jsBasketCount = 0; // updated in rightbar.inc.php after ajax load

// Strings
var jsHomeTitle = "<?php echo addslashes(T_('Home')); ?>";
var jsUploadTitle = "<?php echo addslashes(T_('Upload')); ?>";
var jsLocalplayTitle = "<?php echo addslashes(T_('Localplay')); ?>";
Expand Down
34 changes: 10 additions & 24 deletions public/templates/rightbar.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@
use Ampache\Repository\Model\Video;

$user_id = (Core::get_global('user') instanceof User) ? Core::get_global('user')->id : -1; ?>
<script>
function ToggleRightbarVisibility()
{
if ($("#rightbar").is(":visible")) {
$("#rightbar").slideUp();
} else {
$("#rightbar").slideDown();
}
}
</script>
<ul id="rb_action">
<li>
<?php echo Ajax::button('?page=stream&action=basket', 'play_circle', T_('Play'), 'rightbar_play'); ?>
Expand Down Expand Up @@ -120,20 +110,7 @@ function ToggleRightbarVisibility()
// FIXME :: this is kludgy
if (!defined('NO_SONGS') && Core::get_global('user') instanceof User && Core::get_global('user')->playlist) {
$objects = Core::get_global('user')->playlist->get_items();
} ?>
<script>
<?php if (count($objects) > 0 || (AmpConfig::get('play_type') == 'localplay')) { ?>
$("#content").removeClass("content-right-wild", 500);
$("#footer").removeClass("footer-wild", 500);
$("#rightbar").removeClass("hidden");
$("#rightbar").show("slow");
<?php } else { ?>
$("#content").addClass("content-right-wild", 500);
$("#footer").addClass("footer-wild", 500);
$("#rightbar").hide("slow");
<?php } ?>
</script>
<?php
}
// Limit the number of objects we show here
if (count($objects) > 100) {
$truncated = (count($objects) - 100);
Expand Down Expand Up @@ -175,3 +152,12 @@ function ToggleRightbarVisibility()
if (count($objects)) {
Stream::run_playlist_method();
} ?>

<script>
$(document).ready(function() {
// necessary evils for time being
jsAmpConfigPlayType = "<?php echo AmpConfig::get('play_type'); ?>";
jsBasketCount = <?php echo (Core::get_global('user') instanceof User && Core::get_global('user')->playlist) ? count(Core::get_global('user')->playlist->get_items()) : 0; ?>;
RightbarInit();
});
</script>
8 changes: 0 additions & 8 deletions public/templates/show_recently_played.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,4 @@
} ?>
<a href="<?php echo $web_path; ?>/stats.php?action=recent_song<?php echo $user_id_a; ?>"><?php echo T_('More'); ?></a>
</div>
<script>
$(document).ready(function () {
$("a[rel^='prettyPhoto']").prettyPhoto({
social_tools: false,
deeplinking: false
});
});
</script>
<?php Ui::show_box_bottom(); ?>
8 changes: 0 additions & 8 deletions public/templates/show_recently_played_all.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,4 @@
</tr>
</tfoot>
</table>
<script>
$(document).ready(function () {
$("a[rel^='prettyPhoto']").prettyPhoto({
social_tools: false,
deeplinking: false
});
});
</script>
<?php Ui::show_box_bottom(); ?>
8 changes: 0 additions & 8 deletions public/templates/show_recently_skipped.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,4 @@
</tr>
</tfoot>
</table>
<script>
$(document).ready(function () {
$("a[rel^='prettyPhoto']").prettyPhoto({
social_tools: false,
deeplinking: false
});
});
</script>
<?php Ui::show_box_bottom(); ?>
9 changes: 1 addition & 8 deletions public/templates/show_similar_songs.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
$hide_drag = in_array('cel_drag', $hide_columns);
$show_license = AmpConfig::get('licensing') && AmpConfig::get('show_license');
?>
<table id="top_tracks_<?php echo $artist->id; ?>" class="tabledata striped-rows">
<table id="similar_songs" class="tabledata striped-rows">
<thead>
<tr class="th-top">
<th class="cel_play essential"></th>
Expand Down Expand Up @@ -135,10 +135,3 @@
<?php } ?>
</tbody>
</table>

<script>
var index = 1;
var indexes = $("#similar_songs_<?php echo $artist->id; ?> .cel_play_content").each(function() {
$(this).html(index++);
});
</script>
9 changes: 2 additions & 7 deletions public/templates/show_top_tracks.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
$hide_drag = in_array('cel_drag', $hide_columns);
$show_license = AmpConfig::get('licensing') && AmpConfig::get('show_license');
?>
<table id="top_tracks_<?php echo $artist->id; ?>" class="tabledata striped-rows">
<table id="top_tracks" class="tabledata striped-rows">
<thead>
<tr class="th-top">
<th class="cel_play essential"></th>
Expand Down Expand Up @@ -136,9 +136,4 @@
</tbody>
</table>

<script>
var index = 1;
var indexes = $("#top_tracks_<?php echo $artist->id; ?> .cel_play_content").each(function() {
$(this).html(index++);
});
</script>
<script>topTracksIndexes();</script>
47 changes: 1 addition & 46 deletions public/templates/sidebar.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,49 +134,4 @@
</div>
</li>
<?php } ?>
</ul>

<script>
$(function() {
$(".header").click(function () {

$header = $(this);
// getting the next element
$content = $header.next();
// open up the content needed - toggle the slide- if visible, slide up, if not slidedown.
$content.slideToggle(500, function() {
$header.children(".header-img").toggleClass("expanded collapsed");
var sbstate = "expanded";
if ($header.children(".header-img").hasClass("collapsed")) {
sbstate = "collapsed";
}
Cookies.set('sb_' + $header.children(".header-img").attr('id'), sbstate, {<?php echo $cookie_string; ?>});
});
});
});

$(document).ready(function() {
// Get a string of all the cookies.
var cookieArray = document.cookie.split(";");
var result = new Array();
// Create a key/value array with the individual cookies.
for (var elem in cookieArray) {
var temp = cookieArray[elem].split("=");
// We need to trim whitespaces.
temp[0] = $.trim(temp[0]);
temp[1] = $.trim(temp[1]);
// Only take sb_* cookies (= sidebar cookies)
if (temp[0].substring(0, 3) == "sb_") {
result[temp[0].substring(3)] = temp[1];
}
}
// Finds the elements and if the cookie is collapsed, it collapsed the found element.
for (var key in result) {
if ($("#" + key).length && result[key] == "collapsed") {
$("#" + key).removeClass("expanded");
$("#" + key).addClass("collapsed");
$("#" + key).parent().next().slideToggle(0);
}
}
});
</script>
</ul>
6 changes: 6 additions & 0 deletions src/js/artist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function topTracksIndexes() {
var index = 1;
var indexes = $("#top_tracks .cel_play_content").each(function() {
$(this).html(index++);
});
}
6 changes: 0 additions & 6 deletions src/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,10 @@ $(function() {
});

$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto({
social_tools: false,
deeplinking: false
});
if (jsAmpConfigGeolocation) {
geolocate_user();
}
});

$(document).ready(function(){
if (jsAmpConfigLibitemContextmenu) {
function libitem_action(item, action)
{
Expand Down
4 changes: 4 additions & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import * as Ajax from './ajax.js';
import * as Artist from './artist.js';
import * as Base from './base.js';
import * as Search from './search.js';
import * as Sidebar from './sidebar.js';
import * as Slideshow from './slideshow.js';
import * as Tools from './tools.js';

Object.assign(window, Ajax);
Object.assign(window, Base);
Object.assign(window, Tools);
Object.assign(window, Search);
Object.assign(window, Sidebar);
Object.assign(window, Artist);
Object.assign(window, Slideshow);
68 changes: 67 additions & 1 deletion src/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,70 @@ $('#sidebar-header').click(function(){
});

Cookies.set('sidebar_state', newstate, {jsCookieString});
});
});

$(function() {
$(".header").click(function () {
var $header = $(this);
// getting the next element
var $content = $header.next();
// open up the content needed - toggle the slide- if visible, slide up, if not slidedown.
$content.slideToggle(500, function() {
$header.children(".header-img").toggleClass("expanded collapsed");
var sbstate = "expanded";
if ($header.children(".header-img").hasClass("collapsed")) {
sbstate = "collapsed";
}
Cookies.set('sb_' + $header.children(".header-img").attr('id'), sbstate, {jsCookieString});
});
});
});

$(document).ready(function() {
// Get a string of all the cookies.
var cookieArray = document.cookie.split(";");
var result = new Array();
// Create a key/value array with the individual cookies.
for (var elem in cookieArray) {
var temp = cookieArray[elem].split("=");
// We need to trim whitespaces.
temp[0] = $.trim(temp[0]);
temp[1] = $.trim(temp[1]);
// Only take sb_* cookies (= sidebar cookies)
if (temp[0].substring(0, 3) == "sb_") {
result[temp[0].substring(3)] = temp[1];
}
}
// Finds the elements and if the cookie is collapsed, it collapsed the found element.
for (var key in result) {
if ($("#" + key).length && result[key] == "collapsed") {
$("#" + key).removeClass("expanded");
$("#" + key).addClass("collapsed");
$("#" + key).parent().next().slideToggle(0);
}
}
});

// RIGHTBAR
export function ToggleRightbarVisibility()
{
if ($("#rightbar").is(":visible")) {
$("#rightbar").slideUp();
} else {
$("#rightbar").slideDown();
}
}

// kick off toggling the rightbar when it is loaded
export function RightbarInit() {
if (jsBasketCount > 0 || jsAmpConfigPlayType === "localplay") {
$("#content").removeClass("content-right-wild", 500);
$("#footer").removeClass("footer-wild", 500);
$("#rightbar").removeClass("hidden");
$("#rightbar").show("slow");
} else {
$("#content").addClass("content-right-wild", 500);
$("#footer").addClass("footer-wild", 500);
$("#rightbar").hide("slow");
}
}

0 comments on commit 2cad4bc

Please sign in to comment.