Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update static JS files #795

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions static/js/analytics.min.js

Large diffs are not rendered by default.

Binary file added static/js/analytics.min.js.gz
Binary file not shown.
7 changes: 7 additions & 0 deletions static/js/bootstrap.bundle.min.js

Large diffs are not rendered by default.

Binary file added static/js/bootstrap.bundle.min.js.gz
Binary file not shown.
1 change: 1 addition & 0 deletions static/js/bootstrap.bundle.min.js.map

Large diffs are not rendered by default.

Binary file modified static/js/bootstrap.min.js.gz
Binary file not shown.
Binary file modified static/js/calendar.js.gz
Binary file not shown.
Binary file modified static/js/canvas2svg.js.gz
Binary file not shown.
10,078 changes: 4 additions & 10,074 deletions static/js/jquery.js

Large diffs are not rendered by default.

Binary file modified static/js/jquery.js.gz
Binary file not shown.
5 changes: 1 addition & 4 deletions static/js/jquery.min.js
100755 → 100644

Large diffs are not rendered by default.

Binary file modified static/js/jquery.min.js.gz
100755 → 100644
Binary file not shown.
Binary file modified static/js/modernizr-2.8.3.min.js.gz
Binary file not shown.
Binary file modified static/js/qrcode.js.gz
Binary file not shown.
Binary file modified static/js/qrcode.min.js.gz
Binary file not shown.
Binary file modified static/js/respond-1.4.2.min.js.gz
Binary file not shown.
Binary file modified static/js/share.js.gz
Binary file not shown.
Binary file modified static/js/web2py-bootstrap3.js.gz
Binary file not shown.
82 changes: 82 additions & 0 deletions static/js/web2py-bootstrap4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
(function($, undefined) {
$.web2py.ajax_fields = function(target) {
/*
*this attaches something to a newly loaded fragment/page
* Ideally all events should be bound to the document, so we can avoid calling
* this over and over... all will be bound to the document
*/
/*adds btn class to buttons*/
$('button:not([class^="btn"])', target).addClass('btn btn-default');
$("p.w2p-autocomplete-widget input").addClass('form-control');
$('form input[type="submit"]:not([class^="btn"]), form input[type="button"]:not([class^="btn"])', target).addClass('btn btn-default');
/* javascript for PasswordWidget*/
$('input[type=password][data-w2p_entropy]', target).each(function() {
$.web2py.validate_entropy($(this));
});
/* javascript for ListWidget*/
$('ul.w2p_list', target).each(function() {
function pe(ul, e) {
var new_line = ml(ul);
rel(ul);
if ($(e.target).closest('li').is(':visible')) {
/* make sure we didn't delete the element before we insert after */
new_line.insertAfter($(e.target).closest('li'));
} else {
/* the line we clicked on was deleted, just add to end of list */
new_line.appendTo(ul);
}
new_line.find(":text").focus();
return false;
}

function rl(ul, e) {
if ($(ul).find('li').length > 1) {
/* only remove if we have more than 1 item so the list is never empty */
$(e.target).closest('li').remove();
}
}

function ml(ul) {
/* clone the first field */
var line = $(ul).find("li:first").clone(true);
line.find(':text').val('');
return line;
}

function rel(ul) {
/* keep only as many as needed*/
$(ul).find("li").each(function() {
var trimmed = $.trim($(this).find(":text").val());
if (trimmed == '') $(this).remove();
else $(this).find(":text").val(trimmed);
});
}
var ul = this;
$(ul).find(":text").addClass('form-control').wrap("<div class='input-group'></div>").after('<div class="input-group-append"><i class="fa fa-plus-circle"></i></div>&nbsp;<div class="input-group-append"><i class="fa fa-minus-circle"></i></div>').keypress(function(e) {
return (e.which == 13) ? pe(ul, e) : true;
}).next().click(function(e) {
pe(ul, e);
e.preventDefault();
}).next().click(function(e) {
rl(ul, e);
e.preventDefault();
});
});
}

$(function() {
$(".nav ul.dropdown-menu").each(function() {
var toggle = jQuery(this).parent();
if (toggle.parent().hasClass("nav")) {
toggle.attr("data-w2pmenulevel", "l0");
toggle.children("a")
.addClass("dropdown-toggle")
.append('<span class="caret"> </span>')
.attr("data-toggle", "dropdown");
} else {
toggle.addClass("dropdown-submenu").removeClass("dropdown");
};
});
});

})(jQuery);
Binary file added static/js/web2py-bootstrap4.js.gz
Binary file not shown.
30 changes: 26 additions & 4 deletions static/js/web2py.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
}
});
/* help preventing double form submission for normal form (not LOADed) */
$(doc).on('submit', 'form:not(.no_disable)', function (e) {
$(doc).on('submit', 'form', function (e) {
var submit_buttons = $(this).find(web2py.formInputClickSelector);
submit_buttons.each(function() {
web2py.disableElement($(this));
Expand All @@ -283,7 +283,11 @@
doc.ajaxSuccess(function (e, xhr) {
var redirect = xhr.getResponseHeader('web2py-redirect-location');
if (redirect !== null) {
window.location = redirect;
if (!redirect.endsWith('#')) {
window.location.href = redirect;
} else {
window.location.reload();
}
}
/* run this here only if this Ajax request is NOT for a web2py component. */
if (xhr.getResponseHeader('web2py-component-content') === null) {
Expand Down Expand Up @@ -335,7 +339,7 @@
} else {
formData = form.serialize(); // Fallback for older browsers.
}
web2py.ajax_page('post', url, formData, target, form);
web2py.ajax_page('post', url, formData, target);

e.preventDefault();
});
Expand Down Expand Up @@ -367,6 +371,24 @@
'data': data,
'processData': !isFormData,
'contentType': contentType,
'xhr': function() {
var xhr = new window.XMLHttpRequest();

xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
web2py.fire(element, 'w2p:uploadProgress', [percentComplete], target);

if (percentComplete === 100) {
web2py.fire(element, 'w2p:uploadComplete', [], target);
}

}
}, false);

return xhr;
},
'beforeSend': function (xhr, settings) {
xhr.setRequestHeader('web2py-component-location', document.location);
xhr.setRequestHeader('web2py-component-element', target);
Expand Down Expand Up @@ -617,7 +639,7 @@
flash: function (message, status) {
var flash = $('.w2p_flash');
web2py.hide_flash();
flash.html(message).addClass(status);
flash.text(message).addClass(status);
if (flash.html()) flash.append('<span id="closeflash"> &times; </span>')[animateIn]();
},
hide_flash: function () {
Expand Down
Binary file modified static/js/web2py.js.gz
Binary file not shown.
13 changes: 12 additions & 1 deletion views/uikit_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,24 @@
<link rel="stylesheet" href="{{=URL('static','uikit-3/css/uikit.min.css')}}" />
<script src="{{=URL('static','uikit-3/js/uikit.min.js')}}"></script>
<script src="{{=URL('static','uikit-3/js/uikit-icons.min.js')}}"></script>
<script src="{{=URL('static','js/web2py.js')}}"></script>
Copy link
Collaborator

@lentinj lentinj Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just include webpy_ajax.html on pages that really need it?

At best this downloads a useless copy of jquery for every page, at worst introduces web2py behaviours which then fight with our JS (the "Working..." message appearing on all buttons I've seen in the past).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. I didn't realise that was the reason we had killed it. I guess we might bung it in on pages that use Ajax then?

<link rel="stylesheet" type="text/css" href="{{=URL('static', 'css/content.css')}}" />

<!-- include the relevant bits of 'web2py_ajax.html' -->
<script type="text/javascript"><!--
// These variables are used by the web2py_ajax_init function in web2py_ajax.js (which is loaded below).
{{=ASSIGNJS(
w2p_ajax_confirm_message = T('Are you sure you want to delete this object?'),
w2p_ajax_disable_with_message = T('Working...'),
w2p_ajax_date_format = T('%Y-%m-%d'),
w2p_ajax_datetime_format = T('%Y-%m-%d %H:%M:%S'),
ajax_error_500 = T.M('An error occured, please [[reload %s]] the page') % URL(args=request.args, vars=request.get_vars)
)}}
//--></script>
{{
response.include_meta()
response.include_files()
}}
<!-- include 'web2py_ajax.html' could be done here, but it performs more than we want so we disect it and keep only the bits we really need -->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems easier to remove calendar.js from views/web2py_ajax.html rather than replicating it all here. Why it was done like this I've no idea, but it was intentional: e4bf707

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Seems easiest to reinstate with the calendar stuff missing. But I think we probably require the include_meta() and include_files() stuff on all pages, so I'm not sure on the best way to only include web2py.js on some of the pages.



{{if is_testing:}}<script>window.is_testing = true;</script>{{pass}}
Expand Down
2 changes: 1 addition & 1 deletion views/web2py_ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)}}
//--></script>
{{
response.files.insert(0,URL('static','js/jquery.min.js'))
response.files.insert(0,URL('static','js/jquery.js'))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an unintentional commit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just to test, as I hadn't minified the jquery lib, but I guess I can revert it now.

response.files.insert(1,URL('static','css/calendar.css'))
response.files.insert(2,URL('static','js/calendar.js'))
response.files.insert(3,URL('static','js/web2py.js'))
Expand Down