/* Json Sort */ /* DataAry => [ { 'SN' : '1', 'USER' : '5' }, { 'SN' : '2', 'USER' : '6' }, { } ] SortField => Sort欄位,如 USER SortType => 'D' = DESC , 'A' = 'ASC' */ function SortJsonAry( DataAry, SortField, SortType ) { var valueType = 'Num'; for( var N = 0; N < DataAry.length; N++ ) { if( isNaN( DataAry[N][SortField] ) ) { valueType = 'Text'; break; } } function SortByName( x, y ) { if( valueType == 'Num' ) { // 數字 //return ( ( x[SortField] == y[SortField] ) ? 0 : ( ( x[SortField] > y[SortField] ) ? 1 : -1 ) ); return x[SortField] - y[SortField]; } else if( valueType == 'Text' ) { // 文字 return x[SortField].localeCompare( y[SortField] ); } } DataAry.sort( SortByName ); if( SortType == 'D' ) { DataAry.reverse(); } return DataAry; } /*取得物件資訊*/ function GetObjRectInfo( Obj ) { var ObjRectInfoJson = Obj.getBoundingClientRect(); var ReturnJson = {}; ReturnJson['top'] = Math.floor( ObjRectInfoJson['top'] * 100 ) / 100; ReturnJson['left'] = Math.floor( ObjRectInfoJson['left'] * 100 ) / 100; ReturnJson['width'] = Math.floor( ObjRectInfoJson['width'] * 100 ) / 100; ReturnJson['height'] = Math.floor( ObjRectInfoJson['height'] * 100 ) / 100; return ReturnJson; } //某值是否在陣列中 function InArray( Str, Ary ) { if( Ary != null ) { for ( var S = 0; S < Ary.length; S++ ) { THISENTRY = Ary[S].toString(); if( THISENTRY == Str ) { return true; } } } else { return false; } } /*判斷是否為陣列*/ function IsArray( ARY ) { return !!ARY && typeof ARY === 'object' && typeof ARY.length === 'number' && typeof ARY.splice === 'function' && !( ARY.propertyIsEnumerable('length') ); } //移除陣列某值 function DelArrayValue( ARR, DELV ) { for( var i = 0; i < ARR.length; i++ ) { if( ARR[i] == DELV ) { ARR.splice( i, 1 ); } } return ARR; } /* 捲軸位置 */ function GetPageScroll() { var yScroll; if ( self.pageYOffset ) { yScroll = self.pageYOffset; } else if ( document.documentElement && document.documentElement.scrollTop ) { yScroll = document.documentElement.scrollTop; } /* Explorer 6 Strict */ else if ( document.body ) { yScroll = document.body.scrollTop; } /* all other Explorers */ var xScroll; if ( self.pageXOffset ) { xScroll = self.pageXOffset; } else if ( document.documentElement && document.documentElement.scrollLeft ) { xScroll = document.documentElement.scrollLeft; } /* Explorer 6 Strict */ else if ( document.body ) { xScroll = document.body.scrollLeft; } /* all other Explorers */ var ARYPAGESCROLL = new Array( xScroll, yScroll ); return ARYPAGESCROLL; } /*視窗及內容大小*/ function GetPageSizeInfo() { var xScroll, yScroll; if( window.innerHeight && window.scrollMaxY ) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if( document.body.scrollHeight > document.body.offsetHeight ) { /* all but Explorer Mac */ xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { /* Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari */ xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if( self.innerHeight ) { /* all except Explorer */ windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if( document.documentElement && document.documentElement.clientHeight ) { /* Explorer 6 Strict Mode */ windowWidth = document.documentElement.clientWidth + 20; windowHeight = document.documentElement.clientHeight; } else if( document.body ) { /* other Explorers */ windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } /* for small pages with total height less then height of the viewport */ if( yScroll < windowHeight ) { pageHeight = windowHeight; } else { pageHeight = yScroll; } /* for small pages with total width less then width of the viewport */ if( xScroll < windowWidth ) { pageWidth = windowWidth; } else { pageWidth = xScroll; } var ARYPAGESIZE = { 'pageWidth': pageWidth, 'pageHeight': pageHeight, 'windowWidth': windowWidth, 'windowHeight': windowHeight }; return ARYPAGESIZE; } /*開linghtbox*/ function lightbox() { this.ARY_PAGE_SIZE = GetPageSizeInfo(); this.ARY_PAGE_SCROLL = GetPageScroll(); this.objBody = document.getElementsByTagName("body").item(0); this.objOverlay = document.createElement("div"); this.objOverlay_id = 'overlayId'; this.objOverlay_zIndex = '1500'; this.objOverlay_className = 'sys_overlay'; this.objOverlay_backgroundColor = ''; this.objOverlay_innerhtml = ''; this.objLightbox_id = 'lightboxId'; this.objLightbox_zIndex = '1501'; this.objLightbox_width = this.ARY_PAGE_SIZE.windowWidth - 100; this.objLightbox_height = this.ARY_PAGE_SIZE.windowHeight - 100; this.objLightbox_className = 'sys_lightbox'; this.showOverLay = function() { this.lightbox_id_ary = new Array(); this.lightbox_id_ary.push( this.objOverlay_id ); this.lightbox_id_ary.push( this.objLightbox_id ); var LARY = new Array(); LARY = this.lightbox_id_ary; this.objOverlay.setAttribute( 'id', this.objOverlay_id ); this.objOverlay.style.zIndex = this.objOverlay_zIndex; this.objOverlay.className = this.objOverlay_className; this.objOverlay.style.backgroundColor = this.objOverlay_backgroundColor; this.objOverlay.style.height = this.ARY_PAGE_SIZE.pageHeight + 'px'; this.objOverlay.style.left = this.ARY_PAGE_SCROLL[0] + 'px'; this.objOverlay.onclick = function () { CLOSE_LIGHTBOX( LARY ) }; this.objBody.insertBefore(this.objOverlay, this.objBody.firstChild); this.objOverlay.style.display = 'block'; this.objBody.style.overflow = 'hidden'; for( var N = 0; N < this.objBody.childNodes.length; N++ ) { if( this.objBody.childNodes[N].nodeType == 1 ) { for( var NN = 0; NN < this.objBody.childNodes[N].attributes.length; NN++ ) { if( this.objBody.childNodes[N].nodeName == 'DIV' && this.objBody.childNodes[N].attributes[NN].name == 'id' && this.objBody.childNodes[N].attributes[NN].value == this.objOverlay_id ) { this.objBody.childNodes[N].innerHTML = this.objOverlay_innerhtml; break; } else if( this.objBody.childNodes[N].nodeName == 'SELECT' ) { this.objBody.childNodes[N].style.visibility = "hidden"; } } } } }; this.showLightBox = function() { var ARY_PAGE_SIZE = GetPageSizeInfo(); var objLightbox = document.createElement("div"); objLightbox.setAttribute( 'id', this.objLightbox_id ); objLightbox.style.zIndex = this.objLightbox_zIndex; objLightbox.style.width = ( this.objLightbox_width == "100%" ) ? this.objLightbox_width : this.objLightbox_width + 'px'; objLightbox.style.height = ( this.objLightbox_height == "100%" ) ? this.objLightbox_height : this.objLightbox_height + 'px'; objLightbox.style.marginTop = '-'+this.objLightbox_height / 2 +'px'; objLightbox.style.marginLeft = '-'+this.objLightbox_width / 2 +'px'; if( this.objLightbox_width != "100%" ) { if( ARY_PAGE_SIZE.windowWidth - 20 <= this.objLightbox_width ) { objLightbox.style.width = '100%'; objLightbox.style.height = '100%'; objLightbox.style.marginTop = 'auto'; objLightbox.style.marginLeft = 'auto'; objLightbox.style.top = 'auto'; objLightbox.style.left = 'auto'; } } objLightbox.className = this.objLightbox_className; this.objBody.insertBefore(objLightbox, this.objOverlay.nextSibling); objLightbox.style.display = 'block'; for( var N = 0; N < this.objBody.childNodes.length; N++ ) { if( this.objBody.childNodes[N].nodeType == 1 && this.objBody.childNodes[N].nodeName == 'DIV' ) { for( var NN = 0; NN < this.objBody.childNodes[N].attributes.length; NN++ ) { if( this.objBody.childNodes[N].attributes[NN].name == 'id' && this.objBody.childNodes[N].attributes[NN].value == this.objLightbox_id ) { this.objBody.childNodes[N].innerHTML = this.objLightbox_innerhtml; break; break; } } } } } } /*關lightbox*/ function CLOSE_LIGHTBOX( LARY ) { if( ! LARY ) { LARY = new Array( 'overlayId', 'lightboxId' ); } if( IsArray( LARY ) ) { if( document.getElementsByTagName( 'select' ) ) { var SELECTS = document.getElementsByTagName( 'select' ); for ( var i = 0; i < SELECTS.length; i++ ) { SELECTS[i].style.visibility = "visible"; } } if( parent.document.getElementsByTagName( 'select' ) ) { var SELECTS = parent.document.getElementsByTagName( 'select' ); for ( var i = 0; i < SELECTS.length; i++ ) { SELECTS[i].style.visibility = "visible"; } } for( var N = 0; N < LARY.length; N++ ) { if( document.getElementById( LARY[N] ) ) { document.body.style.overflow = ''; document.documentElement.style.overflow = ''; /*IE6,7*/ document.body.removeChild( document.getElementById( LARY[N] ) ); } else if( parent.document.getElementById( LARY[N] ) ) { parent.document.body.style.overflow = ''; parent.document.documentElement.style.overflow = ''; /*IE6,7*/ parent.document.body.removeChild( parent.document.getElementById( LARY[N] ) ); } } } else { top.location.href = LARY; } } /*開linghtbox function*/ function LIGHTBOX_WINDOW( SEND_GET, W, H ) { var LIGHTBOX = new lightbox(); if( W ) { LIGHTBOX.objLightbox_width = W; } if( H ) { LIGHTBOX.objLightbox_height = H; } LIGHTBOX.showOverLay(); LIGHTBOX.showLightBox(); LIGHTBOX_OBJ = document.getElementById( LIGHTBOX.objLightbox_id ); LIGHTBOX_OBJ.innerHTML = ""; } /*開Linghtbox*/ function LinghtboxDiv( W, H ) { var LIGHTBOX = new lightbox(); if( W ) { LIGHTBOX.objLightbox_width = W; } if( H ) { LIGHTBOX.objLightbox_height = H; } LIGHTBOX.showOverLay(); LIGHTBOX.showLightBox(); LIGHTBOX_OBJ = document.getElementById( LIGHTBOX.objLightbox_id ); return LIGHTBOX_OBJ; } /* //數字跑動 var countToNumber = function ( DfJson ) { //DfJson = { element : 物件, number : 開始數字, suffix : 結尾文字, duration : 結束數字 } $({count: parseInt(element.text().split("+")[0].replace(/\,/g, ''))}).animate({count: number}, { duration: duration ? duration : 1000, easing: 'swing', step: function (now) { element.text((Math.floor(now) + suffix).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); }, complete: function () { countingFromZero = false; } }); } countToNumber($('.images'), 500, '', 200); function setNum(){ countToNumber($('.images'), $("#txt_start").val(), '', $("#txt_end").val()); } */