Skip to content

Instantly share code, notes, and snippets.

@riix
Created July 23, 2012 04:37
Show Gist options
  • Save riix/3161978 to your computer and use it in GitHub Desktop.
Save riix/3161978 to your computer and use it in GitHub Desktop.
defer.js Skullbone Code
/*
* Defer Function Snipplet
* by Riix
*/
// http://ajaxian.com/archives/no-more-ie6-background-flicker
if (typeof document.body.style.maxHeight == "undefined") {
try {
document.execCommand('BackgroundImageCache', false, true);
} catch(e) { }
}
/* ------------------------------
Browser Check
------------------------------ */
var isIE7 = false;
if($.browser.msie && $.browser.version < 7) {
isIE7 = true;
}
/* ------------------------------
일반 함수
------------------------------ */
// User Agent 를 반환함
function getUserAgent(){
var userAgent = 'chrome';
if (navigator.userAgent.toUpperCase().indexOf("MOBILE")!=-1){ userAgent = 'mobile';
} else if($.browser.msie && $.browser.version < 7) {
userAgent = 'ie ie6';
} else if($.browser.msie && $.browser.version < 8) {
userAgent = 'ie ie7';
} else if($.browser.msie && $.browser.version < 9) {
userAgent = 'ie ie9';
} else if($.browser.msie) { userAgent = 'ie';
} else if($.browser.mozilla) { userAgent = 'firefox';
} else if($.browser.safari) { userAgent = 'safari';
} else if($.browser.opera) { userAgent = 'opera';
} else {
userAgent = 'other';
}
return userAgent;
}
/* ------------------------------
사용자정의 함수
------------------------------ */
(function($) {
// 이미지 경로 바꾸기
// img.imgSrcToggle({ orgSrc: 'on.gif', newSrc:'off.gif' });
$.fn.imgSrcToggle = function(settings) {
var config = {
orgSrc : '_off', newSrc : '_on'
};
if (settings) $.extend(config, settings);
this.each(function() {
if($(this).attr('src')){
$(this).attr('src',$(this).attr('src').replace(config.orgSrc, config.newSrc));
}
});
};
// 이미지 롤 오버
// img.imgRollOver({ orgSrc: '_off', newSrc:'_on' });
$.fn.imgRollOver = function(settings) {
var config = {
orgSrc : '_off', newSrc : '_on'
};
if (settings) $.extend(config, settings);
this.each(function() {
$(this).bind('mouseenter',function() {
if ($(this).attr('src') && $(this).attr('src').match(config.orgSrc)) {
$(this).attr('src', $(this).attr('src').replace(config.orgSrc, config.newSrc));
$(this).bind('mouseleave',function() {
$(this).attr('src', $(this).attr('src').replace(config.newSrc, config.orgSrc));
});
}
});
});
};
// 일반 팝업 리사이즈
$.fn.resizePopUp = function(settings) {
var config = {
width : '400',
height : '400',
type: 'window'
};
if (settings) $.extend(config, settings);
this.each(function() {
$('#popupContainer').css({
// 'left' : '50%',
// 'margin-left' : -parseInt(config.width/2),
'position' : 'absolute',
'z-index' : '200',
'width' : config.width,
'left' : '0px',
'margin-left' : '0px'
});
$('#popupContents').height(parseInt(config.height) - ( parseInt($('#popupHeader').height()) + parseInt($('#popupFooter').height()) ));
// console.log('#popupContents' + $('#popupContents').height());
// console.log('#innerContents' + $('#innerContents').height());
});
};
})(jQuery);
/* ------------------------------
로드시 실행
------------------------------ */
$(function(){
// png fix
// if (isIE7) { $('img.png, .png img').ifixpng(); }
// User Agent
// if(userAgent.match('ie6')==null && userAgent.match('ie7')==null) 등으로 사용
var userAgent = getUserAgent();
$('html').addClass(userAgent).addClass('js').removeClass('no-js');
$('#quicklaunch img').imgRollOver({ orgSrc: '_off', newSrc:'_on' });
// 현재 스크롤 위치
var scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0;
var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;
// 관련사이트 점프메뉴
$('#jumpmenu').change(function(){ if($(this).val()!=null) window.open($(this).val()); });
// input box 스타일링
$('input[type="text"], input[type=password]').addClass('txt');
$('input[type="password"]').addClass('password').css('ime-mode','disabled');
$('input[type="file"]').addClass('file');
$('input[type="image"]').addClass('image');
$('input[type="submit"]').addClass('button');
$('input:checkbox').addClass('check');
$('input[type="radio"]').addClass('radio');
$('textarea').addClass('textarea');
// 새 창 링크
$('a[target="_blank"]').attr('title','새 창을 띄웁니다.');
$('a[href^="mailto"]').attr('title','이메일을 보냅니다.');
// 페이지 처음으로
$('a[href="#top"]').click(function(event){ event.preventDefault(); $('html, body').animate({scrollTop:0}, 'fast'); });
// 라벨 이미지 처리
$('label img').click(function(event) { event.preventDefault(); $(this).parent().click(); });
// 인쇄
$('a[href="#print"]').click(function(event) { event.preventDefault(); window.print(); return false; });
// 팝업창일때
if ($('body').attr('class').match('popup')){
// doctitle
document.title = $('h1').text() + ' < epass 학점';
// popup closer
$('div.popup a[href="#close"]').bind('click', function(event){
event.preventDefault();
window.close();
});
}
// title 표시
$('#contents input[title]').each(function(){
var strTitle = $(this).attr('title');
var scolor = $(this).css('color');
$(this).css('color','#999999').val(strTitle);
$(this).bind('click',function(event){
if($(this).val() == strTitle){
$(this).css('color', scolor).val('');
}
});
});
// skip to contents
$('#skipToContents > ol > li > a').bind('click', function(event){
event.preventDefault();
var temp = $(this).attr('href');
$(temp).find('a').eq(0).focus();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment