Created
May 19, 2015 10:00
-
-
Save dstyle0210/f0e96f19ba4c1b896cc7 to your computer and use it in GitHub Desktop.
[jquery] RunQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * jQuery runQuery v0.9b - http://dstyle.raonnet.com/runquery_v2/ | |
| * Release Date : 2011/10/10 (Date-based Korea) | |
| * Last Modified : 2011/10/27 (Date-based Korea) | |
| * | |
| * Open source under the BSD License. | |
| * | |
| * jQuery 1.6.2 이상에서 정상적으로 동작합니다. | |
| * | |
| * 제작자 : 원용봉(dstyle@reflexion.co.kr) by REFLEXION Web Team. | |
| * REFLEXION : http://www.reflexion.co.kr | |
| * | |
| * 미디어쿼리에 필요한 가로해상도(Width)와 디바이스(Device), | |
| * 브라우저(Browser)를 구분하여 함수를 실행하도록 하는 Jquery기반의 미디어쿼리 지원 플러그인 입니다. | |
| * 추가적으로 시간을 가져와 사용할수 있도록 되어있습니다. | |
| * | |
| * API(documentation) : http://dstyle.raonnet.com/runquery_v2/documentation/ | |
| * | |
| * 오류사항 이나 추가되었으면 하는 기능은 메일(dstyle@reflexion.co.kr)로 보내주시면 최대한 반영할수 있도록 노력하겠습니다. | |
| * | |
| * 감사합니다. | |
| * | |
| */ | |
| /* | |
| * Update Note 0.9b Release | |
| * - Runquery의 성공 콜백함수 및 실패 함수가 추가되었습니다. | |
| * - 성공 및 실패 콜백함수를 따로 옵션으로 지정할수 있도록 되었습니다. | |
| * - 사용법은 http://dstyle.raonnet.com/runquery/documentation/ 을 참조해주세요. | |
| */ | |
| (function($){ | |
| $.runQuery = function(opt,cFunc,oFunc){ | |
| if(!opt || opt==""){ | |
| var o = { | |
| width:$.runQuerySize(), | |
| browser:$.runQueryBrowser(), | |
| device:$.runQueryDevice(), | |
| os:$.runQueryOs(), | |
| date:$.runQueryDate() | |
| }; | |
| return o; | |
| }else{ | |
| var o = $.RQopt(opt,cFunc,oFunc); // 체크를 위해 boolean용으로 백업 | |
| $.extend(o,{rqComplete:o.complete,rqOther:o.other,complete:null,other:null}); | |
| var pass = true; | |
| if(pass && (o.startDate || o.endDate)){ | |
| pass = $.runQueryDate(o); | |
| }; | |
| if(pass && (o.minWidth || o.maxWidth)){ | |
| pass = $.runQuerySize(o); | |
| }; | |
| if(pass && o.device){ | |
| pass = $.runQueryDevice(o); | |
| }; | |
| if(pass && o.browser){ | |
| pass = $.runQueryBrowser(o); | |
| }; | |
| if(pass && o.os){ | |
| pass = $.runQueryOs(o); | |
| }; | |
| $.extend(o,{complete:o.rqComplete,other:o.rqOther,value:pass}); // 실행을 위해 원복 | |
| return $.RQreturn(o,'',o.value); | |
| }; | |
| }; | |
| $.rqJSON = function(rq){ | |
| var rq = rq; | |
| var rqText = "{ "; | |
| for(key in rq){ | |
| rqText += key+":"+rq[key]+", "; | |
| }; | |
| rqText = rqText.substring(0,rqText.length-2); | |
| rqText += " }"; | |
| return rqText; | |
| }; | |
| /* | |
| * runQueryDate : 시간을 기준하는 함수. | |
| */ | |
| $.runQueryDate = function(opt,cFunc,oFunc){ | |
| var o = $.RQopt(opt,cFunc,oFunc,{checkDate:new Date(),startDate:null,endDate:null}); | |
| $.extend(o,{ | |
| chkDate:o.checkDate.getTime(), | |
| startDate:(o.startDate) ? o.startDate.getTime() : new Date(1900,1,1).getTime(), | |
| endDate:(o.endDate) ? o.endDate.getTime() : new Date(2200,1,1).getTime() | |
| }); | |
| $.extend(o,{value:(o.startDate<o.chkDate && o.chkDate<o.endDate)}); | |
| return $.RQreturn(o,o.checkDate,o.value); | |
| }; | |
| // 사이즈 처리 함수 | |
| $.runQuerySize = function(opt,cFunc,oFunc){ | |
| var o = $.RQopt(opt,cFunc,oFunc,{ | |
| minWidth:null, | |
| maxWidth:null, | |
| chkWidth:function(){ | |
| var chkWid = $(window).width(); | |
| var ua = (navigator.userAgent).toLowerCase(); | |
| if((ua.indexOf("msie 6.0") != "-1") || (ua.indexOf("msie 7.0") != "-1")){ | |
| chkWid = chkWid+21; | |
| }else if(ua.indexOf("msie 8.0") != "-1"){ | |
| chkWid = chkWid+4+o.scr(); | |
| }else{ | |
| chkWid = chkWid+o.scr(); | |
| }; | |
| return chkWid; | |
| }, | |
| scr:function(){ | |
| return (($(window).height()<$(document.body).height()) ? 17 : 0); | |
| } | |
| }); | |
| $.extend(o,{ | |
| minWidth:(o.minWidth) ? parseInt(o.minWidth,10) : 0, | |
| maxWidth:(o.maxWidth) ? parseInt(o.maxWidth,10) : 100000 | |
| }); | |
| o.value = (o.minWidth<=o.chkWidth() && o.maxWidth>=o.chkWidth()); | |
| return $.RQreturn(o,o.chkWidth(),o.value); | |
| }; | |
| $.runQueryBrowser = function(opt,cFunc,oFunc){ | |
| var ua_code = ["msie 6.0","msie 7.0","msie 8.0","msie 9.0","msie","firefox","chrome","opera","safari"]; | |
| var user_code = ["IE6","IE7","IE8","IE9","IE","FF","CR","OP","SF"]; | |
| var o = $.RQopt(opt,cFunc,oFunc,{ | |
| browser:null, | |
| userBrowser:[], | |
| ua:(navigator.userAgent).toLowerCase() | |
| }); | |
| $(ua_code).each(function(i,item){ | |
| if(o.ua.indexOf(item) != "-1"){ | |
| o.userBrowser.push(user_code[i]); | |
| }; | |
| }); | |
| o.browser = (($.type(o.browser)=="string") ? [o.browser] : o.browser); | |
| o = $.RQeach(o,o.browser,o.userBrowser); | |
| return $.RQreturn(o,o.userBrowser,o.value); | |
| }; | |
| $.runQueryDevice = function(opt,cFunc,oFunc){ | |
| var o = $.RQopt(opt,cFunc,oFunc,{ | |
| device:null, | |
| m:(($.type(window.orientation)=="number") ? true : false), | |
| size:$.runQuerySize(), | |
| userDevice:[] | |
| }); | |
| o.device = ($.type(o.device)=="string") ? [o.device] : o.device; | |
| var c = ["desktop","mobile","phone","tablet"]; | |
| var b = [(!o.m),(o.m),((o.m) && (o.size<768)),((o.m) && (767<o.size))]; | |
| $(c).each(function(k){ | |
| if(b[k]){ | |
| o.userDevice.push(c[k]); | |
| }; | |
| }); | |
| o = $.RQeach(o,o.device,o.userDevice); | |
| return $.RQreturn(o,o.userDevice,o.value); | |
| }; | |
| $.runQueryOs = function(opt,cFunc,oFunc){ | |
| var ua_code = ["windows","linux","mac os","windows ce","android","like mac"]; | |
| var user_code = ["win","linux","mac","wince","android","ios"]; | |
| var o = $.RQopt(opt,cFunc,oFunc,{ | |
| os:null, | |
| userOs:[], | |
| ua:(navigator.userAgent).toLowerCase() | |
| }); | |
| o.os = (($.type(o.os)=="string") ? [o.os] : o.os); | |
| $(ua_code).each(function(i,item){ | |
| if(o.ua.indexOf(item) != "-1"){ | |
| o.userOs.push(user_code[i]); | |
| }; | |
| }); | |
| o = $.RQeach(o,o.os,o.userOs); | |
| return $.RQreturn(o,o.userOs,o.value); | |
| }; | |
| /* Core Method */ | |
| $.RQopt = function(opt,cFunc,oFunc,cpt){ | |
| var o = {type:null,value:null,complete:((cFunc && ($.type(cFunc)=="function")) ? cFunc : null),other:((oFunc && ($.type(oFunc)=="function")) ? oFunc : null)}; | |
| $.extend(o,cpt); | |
| $.extend(o,opt); | |
| if(!opt || opt==""){ | |
| $.extend(o,{type:"value"}); | |
| }else if(($.type(o.complete)=="function") || ($.type(o.other)=="function")){ | |
| $.extend(o,{ | |
| type:"func", | |
| complete:((o.complete) ? o.complete : function(){}), | |
| other:((o.other) ? o.other : function(){}) | |
| }); | |
| }else{ | |
| $.extend(o,{type:"boolean"}); | |
| }; | |
| return o; | |
| }; | |
| $.RQreturn = function(o,data,val){ | |
| if(o.type=="value"){ return data; }; | |
| if(o.type=="boolean"){ return (!o.value) ? false : true; }; | |
| if(o.type=="func"){ | |
| if(val==true){ | |
| o.complete.call(null); | |
| }else{ | |
| o.other.call(null); | |
| }; | |
| }; | |
| return val; | |
| }; | |
| $.RQeach = function(o,arr,uarr){ | |
| $(arr).each(function(i,item){ | |
| $(uarr).each(function(k,ktem){ | |
| if(ktem==item){ | |
| o.value=true; | |
| return false; | |
| } | |
| }); | |
| if(o.value){ return false; }; | |
| }); | |
| return o; | |
| }; | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment