riix
3/22/2013 - 3:34 AM

ui.defer.js

ui.defer.js

var deferCount = 0; // 중복 실행 방지

$(window).on('load', function(){

	if(deferCount < 1) defer();
	++deferCount;

});

function defer(){

	// input
	$(':input').each(function(){
		var $this = $(this);
		var type = ( $this.attr('type') ) ? $this.attr('type') : this.tagName.toLowerCase();
		var title = $this.attr('title');
		var color = $this.css('color');
		if (type == 'date' || type == 'tel' || type == 'email' || type == 'url' || type == 'time' || type == 'search' || type == 'number') type = 'text'; // HTML5 Input Types
		if (type == 'password') {
			type = 'text';
			$this.data('type','password').css('ime-mode','disabled'); // password input with placeholder
		}
		if (title) $this.attr('type','text').val(title).css('color','#999'); // placeholder
		$this.addClass(type).on('focusin', function(){
			$this.addClass('focus '+type+'-focus');
			if($this.data('type') == 'password') $this.attr('type','password'); // password input with placeholder
			if(title && $this.val() == title) $this.css('color', color).val(''); // placeholder
		}).on('focusout', function(){
			$this.removeClass('focus '+type+'-focus');
		});
		if(type == 'text' && !$this.attr('maxlength')) $this.attr('maxlength','20'); // maxlength
	});

	// form input
	$('form :input').addClass('form-input');

	// disabled
	$(':disabled').addClass('disabled');

	// accesskey
	$('input:submit:first').attr('accesskey','s');

	// new window
	$('a[target="_blank"]:not([title])').attr('title','새 창으로 이동');
	$('a[href^="mailto"]:not([title])').attr('title','새 창으로 이동 - 이메일 보내기');

	// image placeholder, <img src="" /> or <img />
	$('img:not([src]), img[src=""]').each(function(){
		var $this = $(this);
		var svcSrc1 = 'http://placekitten.com/';
		var svcSrc2 = 'http://placehold.it/';
		var operate1 = '/';
		var operate2 = 'x';
		var w = Math.max(parseInt($this.css('width'), 10), $this.width());
		var h = Math.max(parseInt($this.css('height'), 10), $this.height());
		// 선택하세요
		// $this.attr('src', svcSrc1 + w + operate1 + h);
		$this.attr('src', svcSrc2 + w + operate2 + h);
	});

	// image alt.
	$('img:not([alt])[src]').each(function(el){
		var $this = $(this);
		$this.attr('alt','이미지, ' + $this.attr('src'));
	});

	// jumpmenu
	$(document.body).on('change', '#jumpmenu', function(){ if($(this).val()) window.open($(this).val()); });

	// to the top
	$(document.body).on('click', 'a[href="#top"]', function(e){ e.preventDefault(); $('html, body').animate({ scrollTop: 0}, 'fast'); });

	// label image
	$(document.body).on('click', 'label img' ,function(e) { e.preventDefault(); $(this).parent().click(); });

	// print
	$(document.body).on('click', 'a[href="#print"]', function(e) { e.preventDefault(); window.print(); return null; });

	// skip to contents
	$(document.body).on('click', '#skipToContents a', function(e){
		e.preventDefault(); $(this.hash).find('a').eq(0).focus();
	});

	// blockUI
	if($.blockUI){
		$(document.body).on('click', 'div.blockUI', function(e) { e.preventDefault(); $.unblockUI(); });
	}

}