-
Notifications
You must be signed in to change notification settings - Fork 20
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
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> <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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
<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 --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems easier to remove calendar.js from There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
)}} | ||
//--></script> | ||
{{ | ||
response.files.insert(0,URL('static','js/jquery.min.js')) | ||
response.files.insert(0,URL('static','js/jquery.js')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an unintentional commit There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')) | ||
|
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?