|
|
/******************************************** * 函數名稱:$(document).ready * 目的:頁面載入時運行相關JS * 作者:Gary * 時間:2014/06/03 * 參數說明: *********************************************/ $(document).ready(function () { OnloadJs(); //運行JS
resetOnloadJs(); //避免UpdatePannel導致js效果失效,在此重新註冊js效果
}); /******************************************** * 函數名稱:OnloadJs() * 目的:運行需要執行的js檔 * 作者:Gary * 時間:2014/08/14 * 參數說明: *********************************************/ function OnloadJs() { setGridViewClass(); //GridView選擇效果設定
setfloatheader(); //設定浮動的TableHeader
} /******************************************** * 函數名稱:resetOnloadJs() * 目的:避免UpdatePannel導致js效果失效,在此重新註冊js效果 * 作者:Gary * 時間:2014/08/14 * 參數說明: *********************************************/ function resetOnloadJs() { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(OnloadJs); //重新運行JS效果
} /******************************************** * 函數名稱:SelectGridView(ObjGridViewTr, State) * 目的:GridView選擇效果 * 作者:Gary * 時間:2014/05/12 * 參數說明:ObjGridViewTr:所選的TR物件 State:State等於"M"為多選,其餘都是單選 M=Multiple rows :目前欄位 *使用方法:在ObjGridViewTr_RowDataBound部分使用 "SelectGridView('gvSearchResult','S',e.Row.RowIndex.ToString()); " *********************************************/ function SelectGridView(ObjGridViewTr, State) { var haveSelect = $(ObjGridViewTr)[0].className.indexOf("rowSelect"); //尋找是否已有被加入選擇的Class
var thisTable = $(ObjGridViewTr).closest("table").attr("id"); //尋找該table之id
if (State.toLowerCase() != "m") { //如果狀態不為m,清除所有TR的"rowSelect"Class
$("#" + thisTable + " tr").removeClass("rowSelect"); } if (haveSelect < 0) { //如果沒選過則加入"rowSelect"Class
$(ObjGridViewTr).addClass("rowSelect"); } else { $(ObjGridViewTr).removeClass("rowSelect"); //如果選過則清除"rowSelect"Class
} } /******************************************** * 函數名稱:setGridViewClass * 目的:GridView選擇效果設定 * 作者:Gary * 時間:2014/05/12 * 參數說明: *********************************************/ function setGridViewClass() { if ($("table[SelectedRow] tr").length > 0) { $("table[SelectedRow] tr").each(function () { //尋找頁面所有符合條件的Table
var SelectedType = $(this).closest("table").attr("SelectedRow"); //如果是M等於複選,S單選;
var thisClass = $(this).attr('class'); //找到該tr的class
var strOnclick = $(this).attr("onclick"); strOnclick = (strOnclick == null) ? "" : strOnclick; if (thisClass != "table-title" && strOnclick.indexOf("SelectGridView") == -1) { //如果Class不等於table-title
$(this).attr("onclick", strOnclick + "; SelectGridView(this, '" + SelectedType + "')") //SelectedType是M等於複選,S單選
} }); } else if ($("table[id^='gvSelect'] tr").length > 0) { $("table[id^='gvSelect'] tr").each(function () { //尋找頁面所有Table 符合 ID有gvSelect之tr
var thisClass = $(this).attr('class'); //找到該tr的class
var strOnclick = $(this).attr("onclick"); strOnclick = (strOnclick == null) ? "" : strOnclick; if (thisClass != "table-title" && strOnclick.indexOf("SelectGridView") == -1) { //如果Class不等於table-title
$(this).attr("onclick", strOnclick + "; SelectGridView(this, 'S')") } }); } else if ($("table[id^='gvMultiSelect'] tr").length > 0) { $("table[id^='gvMultiSelect'] tr").each(function () { //尋找頁面所有Table 符合 ID有gvMultiSelect之tr
var thisClass = $(this).attr('class'); //找到該tr的class
var strOnclick = $(this).attr("onclick"); strOnclick = (strOnclick == null) ? "" : strOnclick; if (thisClass != "table-title" && strOnclick.indexOf("SelectGridView") == -1) { //如果Class不等於table-title
$(this).attr("onclick", strOnclick + "; SelectGridView(this, 'M')") } }); } }
/******************************************** * 函數名稱:OpenOrClose(objID) * 目的:縮放Div * 作者:Gary * 時間:2014/05/13 * 參數說明:obj:物件 *********************************************/ function OpenOrClose(objID) { var ThisDiv = $(objID).parent().parent(); //找到該物件所屬的Title-Div
var NextDiv = $(ThisDiv).next(); //找到內容的Div
if ($(ThisDiv).attr('class').indexOf('all') == -1) { //判斷是否已經隱藏,如果為非切換Class
$(NextDiv).slideUp(); //Div滑入
checkfloatthead(); $(ThisDiv).attr('class', $(ThisDiv).attr('class').replace('top-rl', 'all')) //替換Title之底部樣式,平底有資料時:radius-top-rl,圓弧底:radius-all
$(objID).attr('class', $(objID).attr('class').replace('shut', 'unfold')) //替換伸縮符號樣式,+:icon-unfold,-:icon-shut
} else { $(NextDiv).slideDown(); //Div滑出
checkfloatthead(); $(ThisDiv).attr('class', $(ThisDiv).attr('class').replace('all', 'top-rl')) //替換Title之底部樣式,平底有資料時:radius-top-rl,圓弧底:radius-all
$(objID).attr('class', $(objID).attr('class').replace('unfold', 'shut')) //替換伸縮符號樣式,+:icon-unfold,-:icon-shut
}
} /******************************************** * 函數名稱:AddTextBoxIcon() * 目的:添加Text圖示 * 作者:Gary * 時間:2014/09/10 * 用法:<input type="text" id="txtSearch" class="w150 " icon="search"> *********************************************/ function AddTextBoxIcon() { $("<i class=\"icon-search top-title-icon\" onclick=\"SearchArea(txtSearch.value)\" style=\"margin-left:-25px;cursor: pointer; \"></i>").insertAfter("input[type=text][icon=search]"); } /******************************************** * 函數名稱:TextToUpper(obj) * 目的:文字變大寫 * 作者:Gary * 時間:2014/06/03 * 用法:<input id="txtText" type="text" onchange="TextToUpper(this)" /> *********************************************/ function TextToUpper(obj) { $(obj).val($(obj).val().toUpperCase()); } /******************************************** * 函數名稱:CheckCanSave() * 目的:判斷是否可以修改 * 作者:Gary * 時間:2014/07/14 * 用法:return CheckCanSave() *********************************************/ function CheckCanSave(strToolbarID) { strToolbarID = (strToolbarID = null) ? "Toolbar1_Save" : strToolbarID;
if ($("#" + strToolbarID).prop("disabled")) { return false; } else { return true; } } /******************************************** * 函數名稱:UpdEnabled() * 目的:判斷是否能新增 * 作者:Gary * 時間:2014/07/24 *********************************************/ function UpdEnabled() { var IsUpd = !$('#Toolbar1_Save').prop('disabled'); //尋找頁面上的儲存按鈕是否"不是"disabled
if (IsUpd) { return true; } else { //回傳false
return false; } }
/******************************************** * 函數名稱:setFloatHeader(txtgridviewID,txtheadID) * 目的:浮動資料表頭 * 作者:Ted * 時間:2014/08/04 *********************************************/ function FloatHeader(txtgridviewID, txtheadID) { var tempHead; if ($.type($('#' + txtgridviewID).html()) != "undefined") { if ($.type($('#' + txtgridviewID).find('.' + txtheadID).html()) != 'undefined') { tempHead = $("#" + txtgridviewID + " thead tr." + txtheadID).html(); ///有thead就不儲存值
if ($.type(tempHead) === 'undefined') { tempHead = $("#" + txtgridviewID + " ." + txtheadID).html(); //紀錄原本table-title裡的表頭資料
$("#" + txtgridviewID + " ." + txtheadID).remove(); //移除原本table-title裡的表頭資料
$('#' + txtgridviewID).prepend("<thead><tr class='table-title'>" + tempHead + "</tr></thead>"); //創建一個thead標籤加入原本table-title值
}
//綁定固定窗格效果
$('#' + txtgridviewID).floatThead('destroy'); $('#' + txtgridviewID).floatThead({ useAbsolutePositioning: false, floatContainerClass: '', zIndex: 5 }); } } }
function setfloatheader() { $('table[id^=gv]').each(function () { if ($.type($(this).attr('nofloathead')) == 'undefined') { var $gvId = $(this).attr('id'); FloatHeader($gvId, $('#' + $gvId).find('th').parent().attr('class')); } }); }
function checkfloatthead() { //var checkThead = DivName.find('table').find('thead').html();
$('.table-box-contenter table[id^="gv"]').each(function () { var checkThead = $(this).find('thead').html(); if (checkThead != 'undefined' || checkThead != '') { $txtTableId = $('#' + $(this).attr('id')); $txtTableId.floatThead('reflow'); } });
}
|