1 | (function($, undefined) { |
---|
2 | $.web2py.ajax_fields = function(target) { |
---|
3 | /* |
---|
4 | *this attaches something to a newly loaded fragment/page |
---|
5 | * Ideally all events should be bound to the document, so we can avoid calling |
---|
6 | * this over and over... all will be bound to the document |
---|
7 | */ |
---|
8 | /*adds btn class to buttons*/ |
---|
9 | $('button:not([class^="btn"])', target).addClass('btn btn-default'); |
---|
10 | $("p.w2p-autocomplete-widget input").addClass('form-control'); |
---|
11 | $('form input[type="submit"]:not([class^="btn"]), form input[type="button"]:not([class^="btn"])', target).addClass('btn btn-default'); |
---|
12 | /* javascript for PasswordWidget*/ |
---|
13 | $('input[type=password][data-w2p_entropy]', target).each(function() { |
---|
14 | $.web2py.validate_entropy($(this)); |
---|
15 | }); |
---|
16 | /* javascript for ListWidget*/ |
---|
17 | $('ul.w2p_list', target).each(function() { |
---|
18 | function pe(ul, e) { |
---|
19 | var new_line = ml(ul); |
---|
20 | rel(ul); |
---|
21 | if ($(e.target).closest('li').is(':visible')) { |
---|
22 | /* make sure we didn't delete the element before we insert after */ |
---|
23 | new_line.insertAfter($(e.target).closest('li')); |
---|
24 | } else { |
---|
25 | /* the line we clicked on was deleted, just add to end of list */ |
---|
26 | new_line.appendTo(ul); |
---|
27 | } |
---|
28 | new_line.find(":text").focus(); |
---|
29 | return false; |
---|
30 | } |
---|
31 | |
---|
32 | function rl(ul, e) { |
---|
33 | if ($(ul).find('li').length > 1) { |
---|
34 | /* only remove if we have more than 1 item so the list is never empty */ |
---|
35 | $(e.target).closest('li').remove(); |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | function ml(ul) { |
---|
40 | /* clone the first field */ |
---|
41 | var line = $(ul).find("li:first").clone(true); |
---|
42 | line.find(':text').val(''); |
---|
43 | return line; |
---|
44 | } |
---|
45 | |
---|
46 | function rel(ul) { |
---|
47 | /* keep only as many as needed*/ |
---|
48 | $(ul).find("li").each(function() { |
---|
49 | var trimmed = $.trim($(this).find(":text").val()); |
---|
50 | if (trimmed == '') $(this).remove(); |
---|
51 | else $(this).find(":text").val(trimmed); |
---|
52 | }); |
---|
53 | } |
---|
54 | var ul = this; |
---|
55 | $(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) { |
---|
56 | return (e.which == 13) ? pe(ul, e) : true; |
---|
57 | }).next().click(function(e) { |
---|
58 | pe(ul, e); |
---|
59 | e.preventDefault(); |
---|
60 | }).next().click(function(e) { |
---|
61 | rl(ul, e); |
---|
62 | e.preventDefault(); |
---|
63 | }); |
---|
64 | }); |
---|
65 | } |
---|
66 | |
---|
67 | $(function() { |
---|
68 | $(".nav ul.dropdown-menu").each(function() { |
---|
69 | var toggle = jQuery(this).parent(); |
---|
70 | if (toggle.parent().hasClass("nav")) { |
---|
71 | toggle.attr("data-w2pmenulevel", "l0"); |
---|
72 | toggle.children("a") |
---|
73 | .addClass("dropdown-toggle") |
---|
74 | .append('<span class="caret"> </span>') |
---|
75 | .attr("data-toggle", "dropdown"); |
---|
76 | } else { |
---|
77 | toggle.addClass("dropdown-submenu").removeClass("dropdown"); |
---|
78 | }; |
---|
79 | }); |
---|
80 | }); |
---|
81 | |
---|
82 | })(jQuery); |
---|