Skip to content

Commit

Permalink
move more js to dedicated files
Browse files Browse the repository at this point in the history
  • Loading branch information
live627 committed Dec 17, 2024
1 parent 70a5392 commit 97af823
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 202 deletions.
1 change: 1 addition & 0 deletions Sources/Actions/Admin/Subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ public function modifyUser(): void
// Setup the template.
Utils::$context['sub_template'] = 'modify_user_subscription';
Utils::$context['page_title'] = Lang::$txt[Utils::$context['action_type'] . '_subscriber'];
Theme::loadJavaScriptFile('paidsubs.js', ['defer' => true, 'minimize' => true], 'smf_paidsubs');

// If we haven't been passed the subscription ID get it.
if (Utils::$context['log_id'] && !Utils::$context['sub_id']) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Actions/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function prepareDisplayContext(): array|bool
'label' => Lang::$txt['quick_edit'],
'class' => 'quick_edit',
'id' => 'modify_button_' . $output['id'],
'custom' => 'onclick="oQuickModify.modifyMsg(\'' . $output['id'] . '\', \'' . !empty(Config::$modSettings['toggle_subject']) . '\')"',
'custom' => 'hidden',
'icon' => 'quick_edit_button',
'show' => $output['can_modify'],
],
Expand Down Expand Up @@ -1002,7 +1002,7 @@ protected function setupTemplate(): void
}

// topic.js
Theme::loadJavaScriptFile('topic.js', ['defer' => false, 'minimize' => true], 'smf_topic');
Theme::loadJavaScriptFile('topic.js', ['defer' => true, 'minimize' => true], 'smf_topic');

// quotedText.js
Theme::loadJavaScriptFile('quotedText.js', ['defer' => true, 'minimize' => true], 'smf_quotedText');
Expand Down
34 changes: 3 additions & 31 deletions Themes/default/Admin.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ function template_not_done()
<form action="', Config::$scripturl, Utils::$context['continue_get_data'], '" method="post" accept-charset="', Utils::$context['character_set'], '" name="autoSubmit" id="autoSubmit">';

// Do we have a token?
if (isset(Utils::$context['not_done_token']) && isset(Utils::$context[Utils::$context['not_done_token'] . '_token'], Utils::$context[Utils::$context['not_done_token'] . '_token_var']))
if (isset(Utils::$context['not_done_token'], Utils::$context[Utils::$context['not_done_token'] . '_token'], Utils::$context[Utils::$context['not_done_token'] . '_token_var']))
echo '
<input type="hidden" name="', Utils::$context[Utils::$context['not_done_token'] . '_token_var'], '" value="', Utils::$context[Utils::$context['not_done_token'] . '_token'], '">';

Expand All @@ -735,21 +735,7 @@ function template_not_done()
</form>
</div><!-- .windowbg -->
<script>
var countdown = ', Utils::$context['continue_countdown'], ';
doAutoSubmit();
function doAutoSubmit()
{
if (countdown == 0)
document.forms.autoSubmit.submit();
else if (countdown == -1)
return;
document.forms.autoSubmit.cont.value = "', Lang::$txt['not_done_continue'], ' (" + countdown + ")";
countdown--;
setTimeout(doAutoSubmit, 1000);
}
doAutoSubmit(', Utils::$context['continue_countdown'], ', ', Lang::$txt['not_done_continue'], ');
</script>';
}

Expand Down Expand Up @@ -1526,21 +1512,7 @@ function template_repair_boards()
{
echo '
<script>
var countdown = 5;
doAutoSubmit();
function doAutoSubmit()
{
if (countdown == 0)
document.forms.recount_form.submit();
else if (countdown == -1)
return;
document.forms.recount_form.recount_now.value = "', Lang::$txt['errors_recount_now'], ' (" + countdown + ")";
countdown--;
setTimeout(doAutoSubmit, 1000);
}
doAutoSubmit(5, ', Utils::escapeJavaScript(Lang::$txt['errors_recount_now']), ', "recount_form", "recount_now");
</script>';
}
}
Expand Down
128 changes: 64 additions & 64 deletions Themes/default/Display.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function template_main()
// Show the topic information - icon, subject, etc.
echo '
<div id="forumposts">
<form action="', Config::$scripturl, '?action=quickmod2;topic=', Utils::$context['current_topic'], '.', Utils::$context['start'], '" method="post" accept-charset="', Utils::$context['character_set'], '" name="quickModForm" id="quickModForm" onsubmit="return oQuickModify.bInEditMode ? oQuickModify.modifySave(\'' . Utils::$context['session_id'] . '\', \'' . Utils::$context['session_var'] . '\') : false">';
<form action="', Config::$scripturl, '?action=quickmod2;topic=', Utils::$context['current_topic'], '.', Utils::$context['start'], '" method="post" accept-charset="', Utils::$context['character_set'], '" id="quickModForm">';

Utils::$context['ignoredMsgs'] = array();
Utils::$context['removableMessageIDs'] = array();
Expand Down Expand Up @@ -286,63 +286,62 @@ function template_main()
</div>';

echo '
<script>';
<script>
window.addEventListener("DOMContentLoaded", function() {';

if (!empty(Theme::$current->options['display_quick_mod']) && Theme::$current->options['display_quick_mod'] == 1 && Utils::$context['can_remove_post'])
{
echo '
var oInTopicModeration = new InTopicModeration({
sCheckboxContainerMask: \'in_topic_mod_check_\',
aMessageIds: [\'', implode('\', \'', Utils::$context['removableMessageIDs']), '\'],
sSessionId: smf_session_id,
sSessionVar: smf_session_var,
sButtonStrip: \'moderationbuttons\',
sButtonStripDisplay: \'moderationbuttons_strip\',
bUseImageButton: false,
bCanRemove: ', Utils::$context['can_remove_post'] ? 'true' : 'false', ',
sRemoveButtonLabel: \'', Lang::$txt['quickmod_delete_selected'], '\',
sRemoveButtonImage: \'delete_selected.png\',
sRemoveButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
bCanRestore: ', Utils::$context['can_restore_msg'] ? 'true' : 'false', ',
sRestoreButtonLabel: \'', Lang::$txt['quick_mod_restore'], '\',
sRestoreButtonImage: \'restore_selected.png\',
sRestoreButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
bCanSplit: ', Utils::$context['can_split'] ? 'true' : 'false', ',
sSplitButtonLabel: \'', Lang::$txt['quickmod_split_selected'], '\',
sSplitButtonImage: \'split_selected.png\',
sSplitButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
sFormId: \'quickModForm\'
});';
var oInTopicModeration = new InTopicModeration({
sCheckboxContainerMask: \'in_topic_mod_check_\',
aMessageIds: [\'', implode('\', \'', Utils::$context['removableMessageIDs']), '\'],
sSessionId: smf_session_id,
sSessionVar: smf_session_var,
sButtonStrip: \'moderationbuttons\',
sButtonStripDisplay: \'moderationbuttons_strip\',
bUseImageButton: false,
bCanRemove: ', Utils::$context['can_remove_post'] ? 'true' : 'false', ',
sRemoveButtonLabel: \'', Lang::$txt['quickmod_delete_selected'], '\',
sRemoveButtonImage: \'delete_selected.png\',
sRemoveButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
bCanRestore: ', Utils::$context['can_restore_msg'] ? 'true' : 'false', ',
sRestoreButtonLabel: \'', Lang::$txt['quick_mod_restore'], '\',
sRestoreButtonImage: \'restore_selected.png\',
sRestoreButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
bCanSplit: ', Utils::$context['can_split'] ? 'true' : 'false', ',
sSplitButtonLabel: \'', Lang::$txt['quickmod_split_selected'], '\',
sSplitButtonImage: \'split_selected.png\',
sSplitButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
sFormId: \'quickModForm\'
});';

// Add it to the mobile button strip as well
echo '
var oInTopicModerationMobile = new InTopicModeration({
sCheckboxContainerMask: \'in_topic_mod_check_\',
aMessageIds: [\'', implode('\', \'', Utils::$context['removableMessageIDs']), '\'],
sSessionId: smf_session_id,
sSessionVar: smf_session_var,
sButtonStrip: \'moderationbuttons_mobile\',
sButtonStripDisplay: \'moderationbuttons_strip_mobile\',
bUseImageButton: false,
bCanRemove: ', Utils::$context['can_remove_post'] ? 'true' : 'false', ',
sRemoveButtonLabel: \'', Lang::$txt['quickmod_delete_selected'], '\',
sRemoveButtonImage: \'delete_selected.png\',
sRemoveButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
bCanRestore: ', Utils::$context['can_restore_msg'] ? 'true' : 'false', ',
sRestoreButtonLabel: \'', Lang::$txt['quick_mod_restore'], '\',
sRestoreButtonImage: \'restore_selected.png\',
sRestoreButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
bCanSplit: ', Utils::$context['can_split'] ? 'true' : 'false', ',
sSplitButtonLabel: \'', Lang::$txt['quickmod_split_selected'], '\',
sSplitButtonImage: \'split_selected.png\',
sSplitButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
sFormId: \'quickModForm\'
});';
var oInTopicModerationMobile = new InTopicModeration({
sCheckboxContainerMask: \'in_topic_mod_check_\',
aMessageIds: [\'', implode('\', \'', Utils::$context['removableMessageIDs']), '\'],
sSessionId: smf_session_id,
sSessionVar: smf_session_var,
sButtonStrip: \'moderationbuttons_mobile\',
sButtonStripDisplay: \'moderationbuttons_strip_mobile\',
bUseImageButton: false,
bCanRemove: ', Utils::$context['can_remove_post'] ? 'true' : 'false', ',
sRemoveButtonLabel: \'', Lang::$txt['quickmod_delete_selected'], '\',
sRemoveButtonImage: \'delete_selected.png\',
sRemoveButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
bCanRestore: ', Utils::$context['can_restore_msg'] ? 'true' : 'false', ',
sRestoreButtonLabel: \'', Lang::$txt['quick_mod_restore'], '\',
sRestoreButtonImage: \'restore_selected.png\',
sRestoreButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
bCanSplit: ', Utils::$context['can_split'] ? 'true' : 'false', ',
sSplitButtonLabel: \'', Lang::$txt['quickmod_split_selected'], '\',
sSplitButtonImage: \'split_selected.png\',
sSplitButtonConfirm: \'', Lang::$txt['quickmod_confirm'], '\',
sFormId: \'quickModForm\'
});';
}

echo '
if (\'XMLHttpRequest\' in window)
{
var oQuickModify = new QuickModify({
sScriptUrl: smf_scripturl,
sClassName: \'quick_edit\',
Expand Down Expand Up @@ -387,14 +386,14 @@ function template_main()
sItemBorderHover: "1px dotted gray",
sItemBackground: "transparent",
sItemBackgroundHover: "#e0e0f0"
});
}';
});';

if (!empty(Utils::$context['ignoredMsgs']))
echo '
ignore_toggles([', implode(', ', Utils::$context['ignoredMsgs']), '], ', Utils::escapeJavaScript(Lang::$txt['show_ignore_user_post']), ');';
ignore_toggles([', implode(', ', Utils::$context['ignoredMsgs']), '], ', Utils::escapeJavaScript(Lang::$txt['show_ignore_user_post']), ');';

echo '
});
</script>';
}

Expand Down Expand Up @@ -967,21 +966,22 @@ function insertQuoteFast(messageid)

echo '
<script>
var oQuickReply = new QuickReply({
bDefaultCollapsed: false,
iTopicId: ', Utils::$context['current_topic'], ',
iStart: ', Utils::$context['start'], ',
sScriptUrl: smf_scripturl,
sImagesUrl: smf_images_url,
sContainerId: "quickreply_options",
sImageId: "quickReplyExpand",
sClassCollapsed: "toggle_up",
sClassExpanded: "toggle_down",
sJumpAnchor: "quickreply_anchor",
bIsFull: true
window.addEventListener("DOMContentLoaded", function() {
var oQuickReply = new QuickReply({
bDefaultCollapsed: false,
iTopicId: ', Utils::$context['current_topic'], ',
iStart: ', Utils::$context['start'], ',
sScriptUrl: smf_scripturl,
sImagesUrl: smf_images_url,
sContainerId: "quickreply_options",
sImageId: "quickReplyExpand",
sClassCollapsed: "toggle_up",
sClassExpanded: "toggle_down",
sJumpAnchor: "quickreply_anchor",
bIsFull: true
});
});
var oEditorID = "', Utils::$context['post_box_name'], '";
var oJumpAnchor = "quickreply_anchor";
</script>';
}

Expand Down
22 changes: 4 additions & 18 deletions Themes/default/ManageNews.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ function template_email_members_send()
<div class="bar" style="width: ', Utils::$context['percentage_done'], '%;"></div>
</div>
<hr>
<input type="submit" name="b" value="', Lang::$txt['email_continue'], '" class="button">
<input type="submit" name="cont" value="', Lang::$txt['email_continue'], '" class="button">
<input type="hidden" name="', Utils::$context['session_var'], '" value="', Utils::$context['session_id'], '">
<input type="hidden" name="subject" value="', Utils::$context['subject'], '">
<input type="hidden" name="message" value="', Utils::$context['message'], '">
Expand All @@ -404,23 +404,9 @@ function template_email_members_send()
</div><!-- .windowbg -->
</form>
<script>
var countdown = 2;
doAutoSubmit();
function doAutoSubmit()
{
if (countdown == 0)
document.forms.autoSubmit.submit();
else if (countdown == -1)
return;
document.forms.autoSubmit.b.value = "', Lang::$txt['email_continue'], ' (" + countdown + ")";
countdown--;
setTimeout("doAutoSubmit();", 1000);
}
</script>';
<script>
doAutoSubmit(2, ', Utils::escapeJavaScript(Lang::$txt['email_continue']), ');
</script>';
}

/**
Expand Down
18 changes: 8 additions & 10 deletions Themes/default/ManagePaid.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ function template_delete_subscription()
*/
function template_modify_user_subscription()
{
// Some quickly stolen javascript from Post, could do with being more efficient :)
echo '
<script>
var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
</script>';

echo '
<form action="', Config::$scripturl, '?action=admin;area=paidsubscribe;sa=modifyuser;sid=', Utils::$context['sub_id'], ';lid=', Utils::$context['log_id'], '" method="post">
<div class="cat_bar">
Expand Down Expand Up @@ -257,7 +251,7 @@ function template_modify_user_subscription()
</dl>
<fieldset>
<legend>', Lang::$txt['start_date_and_time'], '</legend>
<select name="year" id="year" onchange="generateDays();">';
<select name="year" id="year">';

// Show a list of all the years we allow...
for ($year = 2005; $year <= 2030; $year++)
Expand All @@ -266,7 +260,7 @@ function template_modify_user_subscription()

echo '
</select>
<select name="month" id="month" onchange="generateDays();">';
<select name="month" id="month">';

// There are 12 months per year - ensure that they all get listed.
for ($month = 1; $month <= 12; $month++)
Expand All @@ -291,7 +285,7 @@ function template_modify_user_subscription()
</fieldset>
<fieldset>
<legend>', Lang::$txt['end_date_and_time'], '</legend>
<select name="yearend" id="yearend" onchange="generateDays(\'end\');">';
<select name="yearend" id="yearend">';

// Show a list of all the years we allow...
for ($year = 2005; $year <= 2030; $year++)
Expand All @@ -300,7 +294,7 @@ function template_modify_user_subscription()

echo '
</select>
<select name="monthend" id="monthend" onchange="generateDays(\'end\');">';
<select name="monthend" id="monthend">';

// There are 12 months per year - ensure that they all get listed.
for ($month = 1; $month <= 12; $month++)
Expand Down Expand Up @@ -336,6 +330,10 @@ function template_modify_user_subscription()
sSearchType: \'member\',
sTextDeleteItem: \'', Lang::$txt['autosuggest_delete_item'], '\',
});
document.getElementById("year").addEventListener("change", generateDays);
document.getElementById("month").addEventListener("change", generateDays);
document.getElementById("yearend").addEventListener("change", generateDays.bind(null, "end"));
document.getElementById("monthend").addEventListener("change", generateDays.bind(null, "end"));
</script>';

if (!empty(Utils::$context['pending_payments']))
Expand Down
19 changes: 2 additions & 17 deletions Themes/default/ManageSearch.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,31 +310,16 @@ function template_create_index_progress()
</div>
</div>
<hr>
<input type="submit" name="b" value="', Lang::$txt['search_create_index_continue'], '" class="button">
<input type="submit" name="cont" value="', Lang::$txt['search_create_index_continue'], '" class="button">
</div>
<input type="hidden" name="step" value="', Utils::$context['step'], '">
<input type="hidden" name="start" value="', Utils::$context['start'], '">
<input type="hidden" name="bytes_per_word" value="', Utils::$context['index_settings']['bytes_per_word'], '">
<input type="hidden" name="', Utils::$context['session_var'], '" value="', Utils::$context['session_id'], '">
</form>
<script>
var countdown = 10;
doAutoSubmit();
function doAutoSubmit()
{
if (countdown == 0)
document.forms.autoSubmit.submit();
else if (countdown == -1)
return;
document.forms.autoSubmit.b.value = "', Lang::$txt['search_create_index_continue'], ' (" + countdown + ")";
countdown--;
setTimeout(doAutoSubmit, 1000);
}
doAutoSubmit(10, ', Utils::escapeJavaScript(Lang::$txt['search_create_index_continue']), ');
</script>';

}

/**
Expand Down
Loading

0 comments on commit 97af823

Please sign in to comment.