H-ui.admin.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* -----------H-ui前端框架-------------
  2. * H-ui.admin.js v2.4
  3. * http://www.h-ui.net/
  4. * Created & Modified by guojunhui
  5. * Date modified 15:42 2016.03.14
  6. *
  7. * Copyright 2013-2016 北京颖杰联创科技有限公司 All rights reserved.
  8. * Licensed under MIT license.
  9. * http://opensource.org/licenses/MIT
  10. *
  11. */
  12. var num=0,oUl=$("#min_title_list"),hide_nav=$("#Hui-tabNav");
  13. /*获取顶部选项卡总长度*/
  14. function tabNavallwidth(){
  15. var taballwidth=0,
  16. $tabNav = hide_nav.find(".acrossTab"),
  17. $tabNavWp = hide_nav.find(".Hui-tabNav-wp"),
  18. $tabNavitem = hide_nav.find(".acrossTab li"),
  19. $tabNavmore =hide_nav.find(".Hui-tabNav-more");
  20. if (!$tabNav[0]){return}
  21. $tabNavitem.each(function(index, element) {
  22. taballwidth+=Number(parseFloat($(this).width()+60))
  23. });
  24. $tabNav.width(taballwidth+25);
  25. var w = $tabNavWp.width();
  26. if(taballwidth+25>w){
  27. $tabNavmore.show()}
  28. else{
  29. $tabNavmore.hide();
  30. $tabNav.css({left:0})
  31. }
  32. }
  33. /*左侧菜单响应式*/
  34. function Huiasidedisplay(){
  35. if($(window).width()>=768){
  36. $(".Hui-aside").show()
  37. }
  38. }
  39. function getskincookie(){
  40. var v = getCookie("Huiskin");
  41. var hrefStr=$("#skin").attr("href");
  42. if(v==null||v==""){
  43. v="default";
  44. }
  45. if(hrefStr!=undefined){
  46. var hrefRes=hrefStr.substring(0,hrefStr.lastIndexOf('skin/'))+'skin/'+v+'/skin.css';
  47. $("#skin").attr("href",hrefRes);
  48. }
  49. }
  50. function Hui_admin_tab(obj){
  51. if($(obj).attr('_href')){
  52. var bStop=false;
  53. var bStopIndex=0;
  54. var _href=$(obj).attr('_href');
  55. var _titleName=$(obj).attr("data-title");
  56. var topWindow=$(window.parent.document);
  57. var show_navLi=topWindow.find("#min_title_list li");
  58. show_navLi.each(function() {
  59. if($(this).find('span').attr("data-href")==_href){
  60. bStop=true;
  61. bStopIndex=show_navLi.index($(this));
  62. return false;
  63. }
  64. });
  65. if(!bStop){
  66. creatIframe(_href,_titleName);
  67. min_titleList();
  68. }
  69. else{
  70. show_navLi.removeClass("active").eq(bStopIndex).addClass("active");
  71. var iframe_box=topWindow.find("#iframe_box");
  72. iframe_box.find(".show_iframe").hide().eq(bStopIndex).show().find("iframe").attr("src",_href);
  73. }
  74. }
  75. }
  76. function min_titleList(){
  77. var topWindow=$(window.parent.document);
  78. var show_nav=topWindow.find("#min_title_list");
  79. var aLi=show_nav.find("li");
  80. };
  81. function creatIframe(href,titleName){
  82. var topWindow=$(window.parent.document);
  83. var show_nav=topWindow.find('#min_title_list');
  84. show_nav.find('li').removeClass("active");
  85. var iframe_box=topWindow.find('#iframe_box');
  86. show_nav.append('<li class="active"><span data-href="'+href+'">'+titleName+'</span><i></i><em></em></li>');
  87. var taballwidth=0,
  88. $tabNav = topWindow.find(".acrossTab"),
  89. $tabNavWp = topWindow.find(".Hui-tabNav-wp"),
  90. $tabNavitem = topWindow.find(".acrossTab li"),
  91. $tabNavmore =topWindow.find(".Hui-tabNav-more");
  92. if (!$tabNav[0]){return}
  93. $tabNavitem.each(function(index, element) {
  94. taballwidth+=Number(parseFloat($(this).width()+60))
  95. });
  96. $tabNav.width(taballwidth+25);
  97. var w = $tabNavWp.width();
  98. if(taballwidth+25>w){
  99. $tabNavmore.show()}
  100. else{
  101. $tabNavmore.hide();
  102. $tabNav.css({left:0})
  103. }
  104. var iframeBox=iframe_box.find('.show_iframe');
  105. iframeBox.hide();
  106. iframe_box.append('<div class="show_iframe"><div class="loading"></div><iframe frameborder="0" src='+href+'></iframe></div>');
  107. var showBox=iframe_box.find('.show_iframe:visible');
  108. showBox.find('iframe').load(function(){
  109. showBox.find('.loading').hide();
  110. });
  111. }
  112. function removeIframe(){
  113. var topWindow = $(window.parent.document);
  114. var iframe = topWindow.find('#iframe_box .show_iframe');
  115. var tab = topWindow.find(".acrossTab li");
  116. var showTab = topWindow.find(".acrossTab li.active");
  117. var showBox=topWindow.find('.show_iframe:visible');
  118. var i = showTab.index();
  119. tab.eq(i-1).addClass("active");
  120. iframe.eq(i-1).show();
  121. tab.eq(i).remove();
  122. iframe.eq(i).remove();
  123. }
  124. /*弹出层*/
  125. /*
  126. 参数解释:
  127. title 标题
  128. url 请求的url
  129. id 需要操作的数据id
  130. w 弹出层宽度(缺省调默认值)
  131. h 弹出层高度(缺省调默认值)
  132. */
  133. function layer_show(title,url,w,h){
  134. if (title == null || title == '') {
  135. title=false;
  136. };
  137. if (url == null || url == '') {
  138. url="404.html";
  139. };
  140. if (w == null || w == '') {
  141. w=800;
  142. };
  143. if (h == null || h == '') {
  144. h=($(window).height() - 50);
  145. };
  146. layer.open({
  147. type: 2,
  148. area: [w+'px', h +'px'],
  149. fix: false, //不固定
  150. maxmin: true,
  151. shade:0.6,
  152. title: title,
  153. moveType: 1, //拖拽风格,0是默认,1是传统拖动
  154. content: url,
  155. });
  156. }
  157. /*关闭弹出框口*/
  158. function layer_close(){
  159. var index = parent.layer.getFrameIndex(window.name);
  160. parent.layer.close(index);
  161. }
  162. $(function(){
  163. getskincookie();
  164. //layer.config({extend: 'extend/layer.ext.js'});
  165. Huiasidedisplay();
  166. var resizeID;
  167. $(window).resize(function(){
  168. clearTimeout(resizeID);
  169. resizeID = setTimeout(function(){
  170. Huiasidedisplay();
  171. },500);
  172. });
  173. $(".nav-toggle").click(function(){
  174. $(".Hui-aside").slideToggle();
  175. });
  176. $(".Hui-aside").on("click",".menu_dropdown dd li a",function(){
  177. if($(window).width()<768){
  178. $(".Hui-aside").slideToggle();
  179. }
  180. });
  181. /*左侧菜单*/
  182. $.Huifold(".menu_dropdown dl dt",".menu_dropdown dl dd","fast",1,"click");
  183. /*选项卡导航*/
  184. $(".Hui-aside").on("click",".menu_dropdown a",function(){
  185. // console.log(3)
  186. Hui_admin_tab(this);
  187. $(this).closest('aside').find('[data-title]').removeClass('hover');
  188. $(this).addClass('hover');
  189. });
  190. $(document).on("click","#min_title_list li",function(){
  191. var bStopIndex=$(this).index();
  192. var iframe_box=$("#iframe_box");
  193. $("#min_title_list li").removeClass("active").eq(bStopIndex).addClass("active");
  194. iframe_box.find(".show_iframe").hide().eq(bStopIndex).show();
  195. });
  196. $(document).on("click","#min_title_list li i",function(){
  197. var aCloseIndex=$(this).parents("li").index();
  198. $(this).parent().remove();
  199. $('#iframe_box').find('.show_iframe').eq(aCloseIndex).remove();
  200. num==0?num=0:num--;
  201. tabNavallwidth();
  202. });
  203. $(document).on("dblclick","#min_title_list li",function(){
  204. var aCloseIndex=$(this).index();
  205. var iframe_box=$("#iframe_box");
  206. if(aCloseIndex>0){
  207. $(this).remove();
  208. $('#iframe_box').find('.show_iframe').eq(aCloseIndex).remove();
  209. num==0?num=0:num--;
  210. $("#min_title_list li").removeClass("active").eq(aCloseIndex-1).addClass("active");
  211. iframe_box.find(".show_iframe").hide().eq(aCloseIndex-1).show();
  212. tabNavallwidth();
  213. }else{
  214. return false;
  215. }
  216. });
  217. tabNavallwidth();
  218. $('#js-tabNav-next').click(function(){
  219. num==oUl.find('li').length-1?num=oUl.find('li').length-1:num++;
  220. toNavPos();
  221. });
  222. $('#js-tabNav-prev').click(function(){
  223. num==0?num=0:num--;
  224. toNavPos();
  225. });
  226. function toNavPos(){
  227. oUl.stop().animate({'left':-num*100},100);
  228. }
  229. /*换肤*/
  230. $("#Hui-skin .dropDown-menu a").click(function(){
  231. var v = $(this).attr("data-val");
  232. setCookie("Huiskin", v);
  233. var hrefStr=$("#skin").attr("href");
  234. var hrefRes=hrefStr.substring(0,hrefStr.lastIndexOf('skin/'))+'skin/'+v+'/skin.css';
  235. $(window.frames.document).contents().find("#skin").attr("href",hrefRes);
  236. //$("#skin").attr("href",hrefResd);
  237. });
  238. });