You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

225 lines
10 KiB

  1. /********************************************
  2. * 函數名稱$(document).ready
  3. * 目的頁面載入時運行相關JS
  4. * 作者Gary
  5. * 時間2014/06/03
  6. * 參數說明
  7. *********************************************/
  8. $(document).ready(function () {
  9. OnloadJs(); //運行JS
  10. resetOnloadJs(); //避免UpdatePannel導致js效果失效,在此重新註冊js效果
  11. });
  12. /********************************************
  13. * 函數名稱OnloadJs()
  14. * 目的運行需要執行的js檔
  15. * 作者Gary
  16. * 時間2014/08/14
  17. * 參數說明
  18. *********************************************/
  19. function OnloadJs() {
  20. setGridViewClass(); //GridView選擇效果設定
  21. setfloatheader(); //設定浮動的TableHeader
  22. }
  23. /********************************************
  24. * 函數名稱resetOnloadJs()
  25. * 目的避免UpdatePannel導致js效果失效在此重新註冊js效果
  26. * 作者Gary
  27. * 時間2014/08/14
  28. * 參數說明
  29. *********************************************/
  30. function resetOnloadJs() {
  31. Sys.WebForms.PageRequestManager.getInstance().add_endRequest(OnloadJs); //重新運行JS效果
  32. }
  33. /********************************************
  34. * 函數名稱SelectGridView(ObjGridViewTr, State)
  35. * 目的GridView選擇效果
  36. * 作者Gary
  37. * 時間2014/05/12
  38. * 參數說明ObjGridViewTr所選的TR物件
  39. StateState等於"M"為多選其餘都是單選 M=Multiple
  40. rows 目前欄位
  41. *使用方法在ObjGridViewTr_RowDataBound部分使用 "SelectGridView('gvSearchResult','S',e.Row.RowIndex.ToString()); "
  42. *********************************************/
  43. function SelectGridView(ObjGridViewTr, State) {
  44. var haveSelect = $(ObjGridViewTr)[0].className.indexOf("rowSelect"); //尋找是否已有被加入選擇的Class
  45. var thisTable = $(ObjGridViewTr).closest("table").attr("id"); //尋找該table之id
  46. if (State.toLowerCase() != "m") { //如果狀態不為m,清除所有TR的"rowSelect"Class
  47. $("#" + thisTable + " tr").removeClass("rowSelect");
  48. }
  49. if (haveSelect < 0) { //如果沒選過則加入"rowSelect"Class
  50. $(ObjGridViewTr).addClass("rowSelect");
  51. }
  52. else {
  53. $(ObjGridViewTr).removeClass("rowSelect"); //如果選過則清除"rowSelect"Class
  54. }
  55. }
  56. /********************************************
  57. * 函數名稱setGridViewClass
  58. * 目的GridView選擇效果設定
  59. * 作者Gary
  60. * 時間2014/05/12
  61. * 參數說明
  62. *********************************************/
  63. function setGridViewClass() {
  64. if ($("table[SelectedRow] tr").length > 0) {
  65. $("table[SelectedRow] tr").each(function () { //尋找頁面所有符合條件的Table
  66. var SelectedType = $(this).closest("table").attr("SelectedRow"); //如果是M等於複選,S單選;
  67. var thisClass = $(this).attr('class'); //找到該tr的class
  68. var strOnclick = $(this).attr("onclick");
  69. strOnclick = (strOnclick == null) ? "" : strOnclick;
  70. if (thisClass != "table-title" && strOnclick.indexOf("SelectGridView") == -1) { //如果Class不等於table-title
  71. $(this).attr("onclick", strOnclick + "; SelectGridView(this, '" + SelectedType + "')") //SelectedType是M等於複選,S單選
  72. }
  73. });
  74. }
  75. else if ($("table[id^='gvSelect'] tr").length > 0) {
  76. $("table[id^='gvSelect'] tr").each(function () { //尋找頁面所有Table 符合 ID有gvSelect之tr
  77. var thisClass = $(this).attr('class'); //找到該tr的class
  78. var strOnclick = $(this).attr("onclick");
  79. strOnclick = (strOnclick == null) ? "" : strOnclick;
  80. if (thisClass != "table-title" && strOnclick.indexOf("SelectGridView") == -1) { //如果Class不等於table-title
  81. $(this).attr("onclick", strOnclick + "; SelectGridView(this, 'S')")
  82. }
  83. });
  84. }
  85. else if ($("table[id^='gvMultiSelect'] tr").length > 0) {
  86. $("table[id^='gvMultiSelect'] tr").each(function () { //尋找頁面所有Table 符合 ID有gvMultiSelect之tr
  87. var thisClass = $(this).attr('class'); //找到該tr的class
  88. var strOnclick = $(this).attr("onclick");
  89. strOnclick = (strOnclick == null) ? "" : strOnclick;
  90. if (thisClass != "table-title" && strOnclick.indexOf("SelectGridView") == -1) { //如果Class不等於table-title
  91. $(this).attr("onclick", strOnclick + "; SelectGridView(this, 'M')")
  92. }
  93. });
  94. }
  95. }
  96. /********************************************
  97. * 函數名稱OpenOrClose(objID)
  98. * 目的縮放Div
  99. * 作者Gary
  100. * 時間2014/05/13
  101. * 參數說明obj物件
  102. *********************************************/
  103. function OpenOrClose(objID) {
  104. var ThisDiv = $(objID).parent().parent(); //找到該物件所屬的Title-Div
  105. var NextDiv = $(ThisDiv).next(); //找到內容的Div
  106. if ($(ThisDiv).attr('class').indexOf('all') == -1) { //判斷是否已經隱藏,如果為非切換Class
  107. $(NextDiv).slideUp(); //Div滑入
  108. checkfloatthead();
  109. $(ThisDiv).attr('class', $(ThisDiv).attr('class').replace('top-rl', 'all')) //替換Title之底部樣式,平底有資料時:radius-top-rl,圓弧底:radius-all
  110. $(objID).attr('class', $(objID).attr('class').replace('shut', 'unfold')) //替換伸縮符號樣式,+:icon-unfold,-:icon-shut
  111. }
  112. else {
  113. $(NextDiv).slideDown(); //Div滑出
  114. checkfloatthead();
  115. $(ThisDiv).attr('class', $(ThisDiv).attr('class').replace('all', 'top-rl')) //替換Title之底部樣式,平底有資料時:radius-top-rl,圓弧底:radius-all
  116. $(objID).attr('class', $(objID).attr('class').replace('unfold', 'shut')) //替換伸縮符號樣式,+:icon-unfold,-:icon-shut
  117. }
  118. }
  119. /********************************************
  120. * 函數名稱AddTextBoxIcon()
  121. * 目的添加Text圖示
  122. * 作者Gary
  123. * 時間2014/09/10
  124. * 用法<input type="text" id="txtSearch" class="w150 " icon="search">
  125. *********************************************/
  126. function AddTextBoxIcon() {
  127. $("<i class=\"icon-search top-title-icon\" onclick=\"SearchArea(txtSearch.value)\" style=\"margin-left:-25px;cursor: pointer; \"></i>").insertAfter("input[type=text][icon=search]");
  128. }
  129. /********************************************
  130. * 函數名稱TextToUpper(obj)
  131. * 目的文字變大寫
  132. * 作者Gary
  133. * 時間2014/06/03
  134. * 用法<input id="txtText" type="text" onchange="TextToUpper(this)" />
  135. *********************************************/
  136. function TextToUpper(obj) {
  137. $(obj).val($(obj).val().toUpperCase());
  138. }
  139. /********************************************
  140. * 函數名稱CheckCanSave()
  141. * 目的判斷是否可以修改
  142. * 作者Gary
  143. * 時間2014/07/14
  144. * 用法return CheckCanSave()
  145. *********************************************/
  146. function CheckCanSave(strToolbarID) {
  147. strToolbarID = (strToolbarID = null) ? "Toolbar1_Save" : strToolbarID;
  148. if ($("#" + strToolbarID).prop("disabled")) {
  149. return false;
  150. }
  151. else {
  152. return true;
  153. }
  154. }
  155. /********************************************
  156. * 函數名稱UpdEnabled()
  157. * 目的判斷是否能新增
  158. * 作者Gary
  159. * 時間2014/07/24
  160. *********************************************/
  161. function UpdEnabled() {
  162. var IsUpd = !$('#Toolbar1_Save').prop('disabled'); //尋找頁面上的儲存按鈕是否"不是"disabled
  163. if (IsUpd) {
  164. return true;
  165. }
  166. else { //回傳false
  167. return false;
  168. }
  169. }
  170. /********************************************
  171. * 函數名稱setFloatHeader(txtgridviewID,txtheadID)
  172. * 目的浮動資料表頭
  173. * 作者Ted
  174. * 時間2014/08/04
  175. *********************************************/
  176. function FloatHeader(txtgridviewID, txtheadID) {
  177. var tempHead;
  178. if ($.type($('#' + txtgridviewID).html()) != "undefined") {
  179. if ($.type($('#' + txtgridviewID).find('.' + txtheadID).html()) != 'undefined') {
  180. tempHead = $("#" + txtgridviewID + " thead tr." + txtheadID).html(); ///有thead就不儲存值
  181. if ($.type(tempHead) === 'undefined') {
  182. tempHead = $("#" + txtgridviewID + " ." + txtheadID).html(); //紀錄原本table-title裡的表頭資料
  183. $("#" + txtgridviewID + " ." + txtheadID).remove(); //移除原本table-title裡的表頭資料
  184. $('#' + txtgridviewID).prepend("<thead><tr class='table-title'>" + tempHead + "</tr></thead>"); //創建一個thead標籤加入原本table-title值
  185. }
  186. //綁定固定窗格效果
  187. $('#' + txtgridviewID).floatThead('destroy');
  188. $('#' + txtgridviewID).floatThead({
  189. useAbsolutePositioning: false,
  190. floatContainerClass: '',
  191. zIndex: 5
  192. });
  193. }
  194. }
  195. }
  196. function setfloatheader() {
  197. $('table[id^=gv]').each(function () {
  198. if ($.type($(this).attr('nofloathead')) == 'undefined') {
  199. var $gvId = $(this).attr('id');
  200. FloatHeader($gvId, $('#' + $gvId).find('th').parent().attr('class'));
  201. }
  202. });
  203. }
  204. function checkfloatthead() {
  205. //var checkThead = DivName.find('table').find('thead').html();
  206. $('.table-box-contenter table[id^="gv"]').each(function () {
  207. var checkThead = $(this).find('thead').html();
  208. if (checkThead != 'undefined' || checkThead != '') {
  209. $txtTableId = $('#' + $(this).attr('id'));
  210. $txtTableId.floatThead('reflow');
  211. }
  212. });
  213. }