Removed global client-side scripts array and refactored page-specific scripts, now that library code is loaded at once

This commit is contained in:
Tobi Schäfer 2015-01-30 23:59:40 +01:00
parent 29175bec5c
commit 6276392100
15 changed files with 26 additions and 32 deletions

View file

@ -9,10 +9,6 @@ require('uikit-bower/js/uikit');
require('uikit-bower/js/components/form-password'); require('uikit-bower/js/components/form-password');
$(function() { $(function() {
for (var i = 0; i < scripts.length; i += 1) {
scripts[i].call();
}
// Extend jQuery with selectText() method. // Extend jQuery with selectText() method.
$.fn.selectText = function() { $.fn.selectText = function() {
var element = this.get(0); var element = this.get(0);

View file

@ -107,7 +107,7 @@
</div> </div>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
scripts.push(function() { $(function() {
$("#creationScope").on('change', function() { $("#creationScope").on('change', function() {
var disabled = $(this).val() === "regular" ? false : true; var disabled = $(this).val() === "regular" ? false : true;
$("#probationPeriod").attr("disabled", disabled); $("#probationPeriod").attr("disabled", disabled);

View file

@ -24,7 +24,7 @@
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
scripts.push(function() { $(function() {
$('#confirmation').hide(); $('#confirmation').hide();
$('#mode').on('click', function() { $('#mode').on('click', function() {
if ($(this).prop('checked')) { if ($(this).prop('checked')) {

View file

@ -64,7 +64,7 @@
</div> </div>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
scripts.push(function() { $(function() {
if ('<% file.name %>') { if ('<% file.name %>') {
$('#name').attr('disabled', true); $('#name').attr('disabled', true);
} }

View file

@ -38,7 +38,7 @@
</div> </div>
</div> </div>
<script> <script>
scripts.push(function () { $(function () {
$('.av-upload input[type="file"]').on('change', function (event) { $('.av-upload input[type="file"]').on('change', function (event) {
$('#<% param.name %>_origin').val($(this).val()); $('#<% param.name %>_origin').val($(this).val());
}); });

View file

@ -102,7 +102,7 @@
</div> </div>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
scripts.push(function() { $(function() {
if ('<% image.name %>') { if ('<% image.name %>') {
$('#name').attr('disabled', true); $('#name').attr('disabled', true);
$('#maxWidth').attr('disabled', true); $('#maxWidth').attr('disabled', true);

View file

@ -36,7 +36,7 @@
</div> </div>
</form> </form>
<script type='text/javascript'> <script type='text/javascript'>
scripts.push(function() { $(function() {
$('#addVariable').on('click', function (event) { $('#addVariable').on('click', function (event) {
event.preventDefault(); event.preventDefault();
var name = prompt('<% gettext "Please enter the name of the new variable:" %>'); var name = prompt('<% gettext "Please enter the name of the new variable:" %>');

View file

@ -68,7 +68,7 @@
</div> </div>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
scripts.push(function() { $(function() {
$("form#login").on('submit', function (event) { $("form#login").on('submit', function (event) {
var name = $("#name").val(); var name = $("#name").val();
$.ajax({ $.ajax({
@ -129,7 +129,7 @@ scripts.push(function() {
</div> </div>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
scripts.push(function() { $(function() {
$("form#register").submit(function() { $("form#register").submit(function() {
var token = "<% session.token %>"; var token = "<% session.token %>";
var password = $("#password").val(); var password = $("#password").val();

View file

@ -120,7 +120,7 @@ else
</div> </div>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
scripts.push(function() { $(function() {
var index = $(".choice").length + 1; var index = $(".choice").length + 1;
$("#add").on('click', function (event) { $("#add").on('click', function (event) {
event.preventDefault(); event.preventDefault();

View file

@ -3,12 +3,17 @@
<% #urlPreview %> <% #urlPreview %>
<a id='av-site-url-preview'></a> <a id='av-site-url-preview'></a>
<script> <script type='text/javascript'>
scripts.push(function () { $(function () {
$('#name').on('keyup', function (event) { $('#name').on('keyup', function (event) {
var url = '<% root.href %>' + $(this).val(); var name = $(this).val();
var html = '<% root.href %>' + '<b>' + $(this).val() + '</b>'; if (name) {
var url = '<% root.href %>' + name;
var html = '<% root.href %>' + '<b>' + name + '</b>';
$('#av-site-url-preview').html(html).attr('href', url); $('#av-site-url-preview').html(html).attr('href', url);
} else {
$('#av-site-url-preview').html(name);
}
}); });
}); });
</script> </script>

View file

@ -79,16 +79,12 @@ document.addEventListener('DOMContentLoaded', function () {
<% site.skin Site#javascript | script %> <% site.skin Site#javascript | script %>
window.scripts = [];
<% #include %> <% #include %>
(function (url) { (function (url) {
//document.writeln("<script type='text/javascript' src='<% param.href %>'></script>");
var script = document.createElement('script'); var script = document.createElement('script');
script.type = 'text/javascript'; script.type = 'text/javascript';
script.src = url; script.src = url;
var scripts = document.head.getElementsByTagName('script'); document.head.appendChild(script);
document.head.insertBefore(script, scripts[0]);
})('<% param.href %>'); })('<% param.href %>');
<% #stylesheet %> <% #stylesheet %>
@ -552,7 +548,7 @@ a.gs-title:hover {
</tbody> </tbody>
</table> </table>
<script type="text/javascript"> <script type="text/javascript">
scripts.push(function () { $(function () {
var query = new Antville.Query(); var query = new Antville.Query();
var spamFilter = new Antville.Filter([<% site.spamfilter %>]); var spamFilter = new Antville.Filter([<% site.spamfilter %>]);
var searchFilter = new Antville.Filter(query.filter); var searchFilter = new Antville.Filter(query.filter);
@ -829,7 +825,7 @@ scripts.push(function () {
</div> </div>
</form> </form>
<script> <script>
scripts.push(function () { $(function () {
$('input#callbackMode').on('click', function(event) { $('input#callbackMode').on('click', function(event) {
$('input#callbackUrl').prop('disabled', !this.checked); $('input#callbackUrl').prop('disabled', !this.checked);
}); });

View file

@ -36,7 +36,7 @@
<% skin.textarea source %> <% skin.textarea source %>
</form> </form>
<script type='text/javascript'> <script type='text/javascript'>
scripts.push(function() { $(function() {
var mode; var mode;
if (location.href.indexOf('stylesheet') > -1) { if (location.href.indexOf('stylesheet') > -1) {
mode = 'text/css'; mode = 'text/css';

View file

@ -63,7 +63,7 @@ else
<% #restore %> <% #restore %>
<script type="text/javascript"> <script type="text/javascript">
scripts.push(function() { $(function() {
var url = "<% site.href backup.js %>"; var url = "<% site.href backup.js %>";
var input = $(".backup :input"); var input = $(".backup :input");

View file

@ -20,7 +20,7 @@
<% list.nextLink text="<i class='uk-icon-arrow-right'></i>" prefix=<li> suffix=</li> default="<li class='uk-disabled'><span><i class='uk-icon-arrow-right'></i></span></li>" %> <% list.nextLink text="<i class='uk-icon-arrow-right'></i>" prefix=<li> suffix=</li> default="<li class='uk-disabled'><span><i class='uk-icon-arrow-right'></i></span></li>" %>
</ul> </ul>
<script type='text/javascript'> <script type='text/javascript'>
scripts.push(function () { $(function () {
$(function() { $(function() {
var resizeTimer = null; var resizeTimer = null;
$('.av-tagged').collageCaption(); $('.av-tagged').collageCaption();

View file

@ -87,9 +87,8 @@
</div> </div>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
scripts.push(function () { $(function () {
$("#submit").click(function (event) { $("#submit").click(function (event) {
//event.preventDefault();
var token = "<% session.token %>"; var token = "<% session.token %>";
var salt = "<% session.salt %>"; var salt = "<% session.salt %>";
var password = $("#password").val(); var password = $("#password").val();
@ -97,9 +96,7 @@ scripts.push(function () {
var hash = $.md5(password + token); var hash = $.md5(password + token);
$("#hash").val(hash); $("#hash").val(hash);
$("#password").val(""); $("#password").val("");
//$("#digest").val($.md5($.md5(password + salt) + token));
} }
return true;
}); });
}); });
</script> </script>