first iteration on bs3 cleanup
This commit is contained in:
@@ -1,134 +1,82 @@
|
||||
/*!
|
||||
* part of the package to convert web2py elements to bootstrap3 theme
|
||||
* Developed by Paolo Caruccio ( paolo.caruccio66@gmail.com )
|
||||
* Released under MIT license
|
||||
* version 1 rev.201402261600
|
||||
*
|
||||
* Supported version of bootstrap framework: 3.0.2+
|
||||
|
||||
* The full package includes:
|
||||
* - bootstrap3.py python module
|
||||
* - web2py-bootstrap3.css
|
||||
* - this js file
|
||||
* - example of layout.html
|
||||
|
||||
*/
|
||||
|
||||
jQuery(function(){
|
||||
// bootstrap3 classes for elements of horizontal form - calculations
|
||||
var fh_label_class = 'col-md-4',
|
||||
fh_offest_class = 'col-md-offset-4',
|
||||
fh_control_class = 'col-md-8';
|
||||
|
||||
// functions
|
||||
function menu_is_collapsed() {
|
||||
return !jQuery('.navbar-toggle').is(':hidden');
|
||||
};
|
||||
|
||||
function closeSubmenu() {
|
||||
jQuery(".dropdown-submenu > a.active").each(function(){
|
||||
var o = jQuery(this);
|
||||
o.parent().children("ul")
|
||||
.toggleClass('open').data('phase', null);
|
||||
o.toggleClass('active');
|
||||
});
|
||||
};
|
||||
|
||||
jQuery.fn.center = function (options) {
|
||||
var defaults = {'parent': false, 'mode': "both"};
|
||||
var settings = jQuery.extend(defaults, options);
|
||||
var parent;
|
||||
if (settings.parent)
|
||||
parent = this.parent();
|
||||
else
|
||||
parent = window;
|
||||
if (settings.mode != "horizontally") {
|
||||
this.css("top", Math.max
|
||||
(0, ((jQuery(parent).height() - jQuery(this).outerHeight()) / 2) + jQuery(parent).scrollTop()) + "px");
|
||||
}
|
||||
if (settings.mode != "vertically") {
|
||||
this.css("left", Math.max
|
||||
(0, ((jQuery(parent).width() - jQuery(this).outerWidth()) / 2) + jQuery(parent).scrollLeft()) + "px");
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
// alert centering
|
||||
jQuery('.flash.alert.centered').center({'mode': "horizontally"});
|
||||
|
||||
// navs
|
||||
jQuery(".nav ul.dropdown-menu").not("#w2p-auth-bar").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('.navbar-nav a.dropdown-toggle').click(function(e) {
|
||||
if (menu_is_collapsed())
|
||||
e.preventDefault();
|
||||
else
|
||||
window.location=jQuery(this).attr('href');
|
||||
});
|
||||
|
||||
jQuery(".dropdown-submenu>a").click(function(event) {
|
||||
if (menu_is_collapsed()) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
var submenu = jQuery(this).parent().children("ul");
|
||||
submenu.data('phase','opening');
|
||||
var dropdownOfThis = jQuery(this).parent().parent();
|
||||
var actives = dropdownOfThis.find('ul.dropdown-menu.open');
|
||||
if (actives && actives.length) {
|
||||
var hasData = actives.data('phase');
|
||||
if (hasData && hasData=='opened') {
|
||||
actives.removeClass('open');
|
||||
actives.siblings('a.active').removeClass('active');
|
||||
hasData || actives.data('phase', null);
|
||||
};
|
||||
};
|
||||
submenu.toggleClass('open').data('phase','opened');
|
||||
jQuery(this).toggleClass('active');
|
||||
}else{
|
||||
window.location=jQuery(this).attr('href');
|
||||
};
|
||||
});
|
||||
|
||||
jQuery(".nav-tabs .web2py-menu-active").addClass('active');
|
||||
jQuery(".nav-tabs a").not(".dropdown-toggle").attr("data-toggle", "tab");
|
||||
// button fixes
|
||||
jQuery("button:not(.btn),input[type=button]:not(.btn),.w2p_list a").addClass('btn btn-default');
|
||||
// form fixes
|
||||
jQuery("form.bs3-form p.w2p-autocomplete-widget input").addClass('form-control');
|
||||
|
||||
// on page load
|
||||
function adjust_maxheight_of_collapsed_nav() {
|
||||
var cn = jQuery('div.navbar-collapse');
|
||||
var sh = jQuery(window).height();
|
||||
if (cn.get(0)) {
|
||||
if (sh<320)
|
||||
cn.addClass('short-screen');
|
||||
else if(cn.hasClass('short-screen'))
|
||||
cn.removeClass('short-screen');
|
||||
}
|
||||
};
|
||||
|
||||
adjust_maxheight_of_collapsed_nav();
|
||||
|
||||
// resize and orientation change events
|
||||
jQuery(window).on('orientationchange resize', function(event) {
|
||||
adjust_maxheight_of_collapsed_nav();
|
||||
jQuery('.flash.alert').center({'mode':"horizontally"});
|
||||
if (menu_is_collapsed() === false) {
|
||||
closeSubmenu();
|
||||
jQuery('.navbar-nav .dropdown.open a.dropdown-toggle').dropdown('toggle');
|
||||
jQuery('#main-menu.in, #login-menu.in').collapse('hide');
|
||||
};
|
||||
});
|
||||
(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', target).addClass('btn btn-default');
|
||||
$("p.w2p-autocomplete-widget input").addClass('form-control');
|
||||
$('form input[type="submit"], form input[type="button"]', 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).parent().is(':visible')) {
|
||||
/* make sure we didn't delete the element before we insert after */
|
||||
new_line.insertAfter($(e.target).parent());
|
||||
} 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).children().length > 1) {
|
||||
/* only remove if we have more than 1 item so the list is never empty */
|
||||
$(e.target).parent().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.firstChild).val());
|
||||
if (trimmed == '') $(this).remove();
|
||||
else $(this.firstChild).val(trimmed);
|
||||
});
|
||||
}
|
||||
var ul = this;
|
||||
$(ul).find(":text").after('<a class="btn btn-default" href="#">+</a> <a class="btn btn-default" href="#">-</a>').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);
|
||||
Reference in New Issue
Block a user