Modify Javascript to improve page loading times
1. Add template category 'end' that places content right before final </body> tag 2. Move most Javascript from tpl files into one cacheable file, theme.js 3. Load scripts at end of the HTML document instead of in the header 4. Minify several Javascript files Note that the second and third things were only done for Frost and Frost Mobile. Doing it for every theme means going through every .tpl for every theme and rearranging the Javascript, which is tedious.
This commit is contained in:
parent
3f39e29e6e
commit
1f09e7ad23
132 changed files with 3300 additions and 1917 deletions
|
@ -45,22 +45,16 @@ function contacts_init(&$a) {
|
|||
$a->page['aside'] .= networks_widget('contacts',$_GET['nets']);
|
||||
$base = $a->get_baseurl();
|
||||
|
||||
$a->page['htmlhead'] .= '<script src="' . $a->get_baseurl(true) . '/library/jquery_ac/friendica.complete.js" ></script>';
|
||||
$a->page['htmlhead'] .= <<< EOT
|
||||
|
||||
<script>$(document).ready(function() {
|
||||
var a;
|
||||
a = $("#contacts-search").autocomplete({
|
||||
serviceUrl: '$base/acl',
|
||||
minChars: 2,
|
||||
width: 350,
|
||||
});
|
||||
a.setOptions({ params: { type: 'a' }});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
EOT;
|
||||
$tpl = get_markup_template("contacts-head.tpl");
|
||||
$a->page['htmlhead'] .= replace_macros($tpl,array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$base' => $base
|
||||
));
|
||||
$tpl = get_markup_template("contacts-end.tpl");
|
||||
$a->page['end'] .= replace_macros($tpl,array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$base' => $base
|
||||
));
|
||||
|
||||
|
||||
}
|
||||
|
@ -247,6 +241,10 @@ function contacts_content(&$a) {
|
|||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$editselect' => $editselect,
|
||||
));
|
||||
$a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$editselect' => $editselect,
|
||||
));
|
||||
|
||||
require_once('include/contact_selectors.php');
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ function editpost_content(&$a) {
|
|||
$o .= '<h2>' . t('Edit post') . '</h2>';
|
||||
|
||||
$tpl = get_markup_template('jot-header.tpl');
|
||||
|
||||
$a->page['htmlhead'] .= replace_macros($tpl, array(
|
||||
'$baseurl' => $a->get_baseurl(),
|
||||
'$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
|
||||
|
@ -45,6 +44,15 @@ function editpost_content(&$a) {
|
|||
'$nickname' => $a->user['nickname']
|
||||
));
|
||||
|
||||
$tpl = get_markup_template('jot-end.tpl');
|
||||
$a->page['end'] .= replace_macros($tpl, array(
|
||||
'$baseurl' => $a->get_baseurl(),
|
||||
'$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
|
||||
'$ispublic' => ' ', // t('Visible to <strong>everybody</strong>'),
|
||||
'$geotag' => $geotag,
|
||||
'$nickname' => $a->user['nickname']
|
||||
));
|
||||
|
||||
|
||||
$tpl = get_markup_template("jot.tpl");
|
||||
|
||||
|
|
|
@ -145,6 +145,9 @@ function events_content(&$a) {
|
|||
$htpl = get_markup_template('event_head.tpl');
|
||||
$a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl()));
|
||||
|
||||
$etpl = get_markup_template('event_end.tpl');
|
||||
$a->page['end'] .= replace_macros($etpl,array('$baseurl' => $a->get_baseurl()));
|
||||
|
||||
$o ="";
|
||||
// tabs
|
||||
$tabs = profile_tabs($a, True);
|
||||
|
|
|
@ -18,24 +18,17 @@ function message_init(&$a) {
|
|||
));
|
||||
$base = $a->get_baseurl();
|
||||
|
||||
$a->page['htmlhead'] .= '<script src="' . $a->get_baseurl(true) . '/library/jquery_ac/friendica.complete.js" ></script>';
|
||||
$a->page['htmlhead'] .= <<< EOT
|
||||
$head_tpl = get_markup_template('message-head.tpl');
|
||||
$a->page['htmlhead'] .= replace_macros($head_tpl,array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$base' => $base
|
||||
));
|
||||
|
||||
<script>$(document).ready(function() {
|
||||
var a;
|
||||
a = $("#recip").autocomplete({
|
||||
serviceUrl: '$base/acl',
|
||||
minChars: 2,
|
||||
width: 350,
|
||||
onSelect: function(value,data) {
|
||||
$("#recip-complete").val(data);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
EOT;
|
||||
$end_tpl = get_markup_template('message-end.tpl');
|
||||
$a->page['end'] .= replace_macros($end_tpl,array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$base' => $base
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
@ -242,7 +235,6 @@ function message_content(&$a) {
|
|||
|
||||
|
||||
$tpl = get_markup_template('msg-header.tpl');
|
||||
|
||||
$a->page['htmlhead'] .= replace_macros($tpl, array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
|
||||
|
@ -250,6 +242,14 @@ function message_content(&$a) {
|
|||
'$linkurl' => t('Please enter a link URL:')
|
||||
));
|
||||
|
||||
$tpl = get_markup_template('msg-end.tpl');
|
||||
$a->page['end'] .= replace_macros($tpl, array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
|
||||
'$nickname' => $a->user['nickname'],
|
||||
'$linkurl' => t('Please enter a link URL:')
|
||||
));
|
||||
|
||||
$preselect = (isset($a->argv[2])?array($a->argv[2]):false);
|
||||
|
||||
|
||||
|
@ -399,12 +399,17 @@ function message_content(&$a) {
|
|||
require_once("include/bbcode.php");
|
||||
|
||||
$tpl = get_markup_template('msg-header.tpl');
|
||||
|
||||
$a->page['htmlhead'] .= replace_macros($tpl, array(
|
||||
'$nickname' => $a->user['nickname'],
|
||||
'$baseurl' => $a->get_baseurl(true)
|
||||
));
|
||||
|
||||
$tpl = get_markup_template('msg-end.tpl');
|
||||
$a->page['end'] .= replace_macros($tpl, array(
|
||||
'$nickname' => $a->user['nickname'],
|
||||
'$baseurl' => $a->get_baseurl(true)
|
||||
));
|
||||
|
||||
|
||||
$mails = array();
|
||||
$seen = 0;
|
||||
|
|
|
@ -69,30 +69,11 @@ function photos_init(&$a) {
|
|||
$a->page['aside'] .= $o;
|
||||
|
||||
|
||||
$a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';" ;
|
||||
$tpl = get_markup_template("photos_head.tpl");
|
||||
$a->page['htmlhead'] .= replace_macros($tpl,array(
|
||||
'$ispublic' => t('everybody')
|
||||
));
|
||||
|
||||
$a->page['htmlhead'] .= <<< EOT
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
$('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
|
||||
var selstr;
|
||||
$('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
|
||||
selstr = $(this).text();
|
||||
$('#jot-perms-icon').removeClass('unlock').addClass('lock');
|
||||
$('#jot-public').hide();
|
||||
});
|
||||
if(selstr == null) {
|
||||
$('#jot-perms-icon').removeClass('lock').addClass('unlock');
|
||||
$('#jot-public').show();
|
||||
}
|
||||
|
||||
}).trigger('change');
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
EOT;
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -962,7 +943,7 @@ function photos_content(&$a) {
|
|||
$selname = (($datum) ? hex2bin($datum) : '');
|
||||
|
||||
|
||||
$albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
|
||||
$albumselect = '';
|
||||
|
||||
|
||||
$albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
|
||||
|
@ -977,8 +958,6 @@ function photos_content(&$a) {
|
|||
|
||||
$celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
|
||||
|
||||
$albumselect .= '</select>';
|
||||
|
||||
$uploader = '';
|
||||
|
||||
$ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
|
||||
|
@ -1195,15 +1174,12 @@ function photos_content(&$a) {
|
|||
|
||||
}
|
||||
|
||||
if(! $cmd !== 'edit') {
|
||||
$a->page['htmlhead'] .= '<script>
|
||||
$(document).keydown(function(event) {' . "\n";
|
||||
|
||||
if($prevlink)
|
||||
$a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n";
|
||||
if($nextlink)
|
||||
$a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n";
|
||||
$a->page['htmlhead'] .= '});</script>';
|
||||
if( $cmd === 'edit') {
|
||||
$tpl = get_markup_template('photo_edit_head.tpl');
|
||||
$a->page['htmlhead'] .= replace_macros($tpl,array(
|
||||
'$prevlink' => $prevlink,
|
||||
'$nextlink' => $nextlink
|
||||
));
|
||||
}
|
||||
|
||||
if($prevlink)
|
||||
|
|
|
@ -279,6 +279,7 @@ function profile_photo_crop_ui_head(&$a, $ph){
|
|||
$a->config['imagecrop_resolution'] = $smallest;
|
||||
$a->config['imagecrop_ext'] = $ph->getExt();
|
||||
$a->page['htmlhead'] .= get_markup_template("crophead.tpl");
|
||||
$a->page['end'] .= get_markup_template("cropend.tpl");
|
||||
return;
|
||||
}}
|
||||
|
||||
|
|
|
@ -546,6 +546,10 @@ function profiles_content(&$a) {
|
|||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$editselect' => $editselect,
|
||||
));
|
||||
$a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$editselect' => $editselect,
|
||||
));
|
||||
|
||||
|
||||
$opt_tpl = get_markup_template("profile-hide-friends.tpl");
|
||||
|
@ -557,9 +561,6 @@ function profiles_content(&$a) {
|
|||
'$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
|
||||
));
|
||||
|
||||
$a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"js/country.js\" ></script>";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,30 +18,10 @@ function settings_init(&$a) {
|
|||
|
||||
// These lines provide the javascript needed by the acl selector
|
||||
|
||||
$a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';" ;
|
||||
|
||||
$a->page['htmlhead'] .= <<< EOT
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
$('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
|
||||
var selstr;
|
||||
$('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
|
||||
selstr = $(this).text();
|
||||
$('#jot-perms-icon').removeClass('unlock').addClass('lock');
|
||||
$('#jot-public').hide();
|
||||
});
|
||||
if(selstr == null) {
|
||||
$('#jot-perms-icon').removeClass('lock').addClass('unlock');
|
||||
$('#jot-public').show();
|
||||
}
|
||||
|
||||
}).trigger('change');
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
EOT;
|
||||
$tpl = get_markup_template("settings-head.tpl");
|
||||
$a->page['htmlhead'] .= replace_macros($tpl,array(
|
||||
'$ispublic' => t('everybody')
|
||||
));
|
||||
|
||||
|
||||
|
||||
|
@ -781,6 +761,11 @@ function settings_content(&$a) {
|
|||
'$theme_config' => $theme_config,
|
||||
));
|
||||
|
||||
$tpl = get_markup_template("settings_display_end.tpl");
|
||||
$a->page['end'] .= replace_macros($tpl, array(
|
||||
'$theme' => array('theme', t('Display Theme:'), $theme_selected, '', $themes)
|
||||
));
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
|
|
@ -116,34 +116,41 @@ function wallmessage_content(&$a) {
|
|||
|
||||
|
||||
$tpl = get_markup_template('wallmsg-header.tpl');
|
||||
$a->page['htmlhead'] .= replace_macros($tpl, array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$editselect' => '/(profile-jot-text|prvmail-text)/',
|
||||
'$nickname' => $user['nickname'],
|
||||
'$linkurl' => t('Please enter a link URL:')
|
||||
));
|
||||
|
||||
$a->page['htmlhead'] .= replace_macros($tpl, array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$editselect' => '/(profile-jot-text|prvmail-text)/',
|
||||
'$nickname' => $user['nickname'],
|
||||
'$linkurl' => t('Please enter a link URL:')
|
||||
));
|
||||
$tpl = get_markup_template('wallmsg-end.tpl');
|
||||
$a->page['end'] .= replace_macros($tpl, array(
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
'$editselect' => '/(profile-jot-text|prvmail-text)/',
|
||||
'$nickname' => $user['nickname'],
|
||||
'$linkurl' => t('Please enter a link URL:')
|
||||
));
|
||||
|
||||
|
||||
|
||||
$tpl = get_markup_template('wallmessage.tpl');
|
||||
$o .= replace_macros($tpl,array(
|
||||
'$header' => t('Send Private Message'),
|
||||
'$subheader' => sprintf( t('If you wish for %s to respond, please check that the privacy settings on your site allow private mail from unknown senders.'), $user['username']),
|
||||
'$to' => t('To:'),
|
||||
'$subject' => t('Subject:'),
|
||||
'$recipname' => $user['username'],
|
||||
'$nickname' => $user['nickname'],
|
||||
'$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
|
||||
'$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
|
||||
'$readonly' => '',
|
||||
'$yourmessage' => t('Your message:'),
|
||||
'$select' => $select,
|
||||
'$parent' => '',
|
||||
'$upload' => t('Upload photo'),
|
||||
'$insert' => t('Insert web link'),
|
||||
'$wait' => t('Please wait')
|
||||
));
|
||||
$tpl = get_markup_template('wallmessage.tpl');
|
||||
$o .= replace_macros($tpl,array(
|
||||
'$header' => t('Send Private Message'),
|
||||
'$subheader' => sprintf( t('If you wish for %s to respond, please check that the privacy settings on your site allow private mail from unknown senders.'), $user['username']),
|
||||
'$to' => t('To:'),
|
||||
'$subject' => t('Subject:'),
|
||||
'$recipname' => $user['username'],
|
||||
'$nickname' => $user['nickname'],
|
||||
'$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
|
||||
'$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
|
||||
'$readonly' => '',
|
||||
'$yourmessage' => t('Your message:'),
|
||||
'$select' => $select,
|
||||
'$parent' => '',
|
||||
'$upload' => t('Upload photo'),
|
||||
'$insert' => t('Insert web link'),
|
||||
'$wait' => t('Please wait')
|
||||
));
|
||||
|
||||
return $o;
|
||||
}
|
||||
return $o;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue