20130628-面向对象-backToTop-on-valiationRules

$(function () {

	Application.init ();

});

var Application = function () {

	var validationRules = getValidationRules ();

	return { init: init, validationRules: validationRules };

	function init () {

		enableBackToTop ();
		enableLightbox ();
		enableCirque ();
		enableEnhancedAccordion ();

	}

	function enableCirque () {
		if ($.fn.lightbox) {
			$('.ui-lightbox').lightbox ();
		}
	}

	function enableLightbox () {
		if ($.fn.cirque) {
			$('.ui-cirque').cirque ({  });
		}
	}

	function enableBackToTop () {
		var backToTop = $('<a>', { id: 'back-to-top', href: '#top' });
		var icon = $('<i>', { class: 'icon-chevron-up' });

		backToTop.appendTo ('body');
		icon.appendTo (backToTop);

	    backToTop.hide();

	    $(window).scroll(function () {
	        if ($(this).scrollTop() > 150) {
	            backToTop.fadeIn ();
	        } else {
	            backToTop.fadeOut ();
	        }
	    });

	    backToTop.click (function (e) {
	    	e.preventDefault ();

	        $('body, html').animate({
	            scrollTop: 0
	        }, 600);
	    });
	}

	function enableEnhancedAccordion () {
		$('.accordion').on('show', function (e) {
	         $(e.target).prev('.accordion-heading').parent ().addClass('open');
	    });

	    $('.accordion').on('hide', function (e) {
	        $(this).find('.accordion-toggle').not($(e.target)).parents ('.accordion-group').removeClass('open');
	    });

	    $('.accordion').each (function () {	    	
	    	$(this).find ('.accordion-body.in').parent ().addClass ('open');
	    });
	}

	function getValidationRules () {
		var custom = {
	    	focusCleanup: false,

			wrapper: 'div',
			errorElement: 'span',

			highlight: function(element) {
				$(element).parents ('.control-group').removeClass ('success').addClass('error');
			},
			success: function(element) {
				$(element).parents ('.control-group').removeClass ('error').addClass('success');
				$(element).parents ('.controls:not(:has(.clean))').find ('div:last').before ('<div></div>');
			},
			errorPlacement: function(error, element) {
				error.appendTo(element.parents ('.controls'));
			}

	    };

	    return custom;
	}

}();

view code

这个作者的代码写得真是漂亮:http://jumpstartuidemo.com/themes/base/index.html

个人网站:http://jumpstartui.com/

原文链接:20130628-面向对象-backToTop-on-valiationRules 版权所有,转载时请注明出处,违者必究。
注明出处格式:前端开发博客 (http://caibaojian.com/443.html)

发表评论

请登录后发表评论: