H-ui.admin.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* -----------H-ui前端框架-------------
  2. * H-ui.admin.js v2.5
  3. * http://www.h-ui.net/
  4. * Created & Modified by guojunhui
  5. * Date modified 2016.10.09
  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. /*获取皮肤cookie*/
  40. function getskincookie(){
  41. var v = getCookie("Huiskin");
  42. var hrefStr=$("#skin").attr("href");
  43. if(v==null||v==""){
  44. v="default";
  45. }
  46. if(hrefStr!=undefined){
  47. var hrefRes=hrefStr.substring(0,hrefStr.lastIndexOf('skin/'))+'skin/'+v+'/skin.css';
  48. $("#skin").attr("href",hrefRes);
  49. }
  50. }
  51. /*菜单导航*/
  52. function Hui_admin_tab(obj){
  53. if($(obj).attr('data-href')){
  54. var bStop = false,
  55. bStopIndex = 0,
  56. href = $(obj).attr('data-href'),
  57. title = $(obj).attr("data-title"),
  58. topWindow = $(window.parent.document),
  59. show_navLi = topWindow.find("#min_title_list li"),
  60. iframe_box = topWindow.find("#iframe_box");
  61. show_navLi.each(function() {
  62. if($(this).find('span').attr("data-href")==href){
  63. bStop=true;
  64. bStopIndex=show_navLi.index($(this));
  65. return false;
  66. }
  67. });
  68. if(!bStop){
  69. creatIframe(href,title);
  70. min_titleList();
  71. }
  72. else{
  73. show_navLi.removeClass("active").eq(bStopIndex).addClass("active");
  74. iframe_box.find(".show_iframe").hide().eq(bStopIndex).show().find("iframe").attr("src",href);
  75. }
  76. }
  77. }
  78. function min_titleList(){
  79. var topWindow = $(window.parent.document),
  80. show_nav = topWindow.find("#min_title_list"),
  81. aLi = show_nav.find("li");
  82. };
  83. function creatIframe(href,titleName){
  84. var topWindow=$(window.parent.document),
  85. show_nav=topWindow.find('#min_title_list'),
  86. iframe_box=topWindow.find('#iframe_box'),
  87. iframeBox=iframe_box.find('.show_iframe'),
  88. $tabNav = topWindow.find(".acrossTab"),
  89. $tabNavWp = topWindow.find(".Hui-tabNav-wp"),
  90. $tabNavmore =topWindow.find(".Hui-tabNav-more");
  91. var taballwidth=0;
  92. show_nav.find('li').removeClass("active");
  93. show_nav.append('<li class="active"><span data-href="'+href+'">'+titleName+'</span><i></i><em></em></li>');
  94. var $tabNavitem = topWindow.find(".acrossTab li");
  95. if (!$tabNav[0]){return}
  96. $tabNavitem.each(function(index, element) {
  97. taballwidth+=Number(parseFloat($(this).width()+60))
  98. });
  99. $tabNav.width(taballwidth+25);
  100. var w = $tabNavWp.width();
  101. if(taballwidth+25>w){
  102. $tabNavmore.show()}
  103. else{
  104. $tabNavmore.hide();
  105. $tabNav.css({left:0})
  106. }
  107. iframeBox.hide();
  108. iframe_box.append('<div class="show_iframe"><div class="loading"></div><iframe frameborder="0" src='+href+'></iframe></div>');
  109. var showBox=iframe_box.find('.show_iframe:visible');
  110. showBox.find('iframe').load(function(){
  111. showBox.find('.loading').hide();
  112. });
  113. }
  114. function removeIframe(){
  115. var topWindow = $(window.parent.document),
  116. iframe = topWindow.find('#iframe_box .show_iframe'),
  117. tab = topWindow.find(".acrossTab li"),
  118. showTab = topWindow.find(".acrossTab li.active"),
  119. showBox=topWindow.find('.show_iframe:visible'),
  120. i = showTab.index();
  121. tab.eq(i-1).addClass("active");
  122. tab.eq(i).remove();
  123. iframe.eq(i-1).show();
  124. iframe.eq(i).remove();
  125. }
  126. /*弹出层*/
  127. /*
  128. 参数解释:
  129. title 标题
  130. url 请求的url
  131. id 需要操作的数据id
  132. w 弹出层宽度(缺省调默认值)
  133. h 弹出层高度(缺省调默认值)
  134. */
  135. function layer_show(title,url,w,h){
  136. if (title == null || title == '') {
  137. title=false;
  138. };
  139. if (url == null || url == '') {
  140. url="404.html";
  141. };
  142. if (w == null || w == '') {
  143. w=800;
  144. };
  145. if (h == null || h == '') {
  146. h=($(window).height() - 50);
  147. };
  148. layer.open({
  149. type: 2,
  150. area: [w+'px', h +'px'],
  151. fix: false, //不固定
  152. maxmin: true,
  153. shade:0.4,
  154. title: title,
  155. content: url
  156. });
  157. }
  158. /*关闭弹出框口*/
  159. function layer_close(){
  160. var index = parent.layer.getFrameIndex(window.name);
  161. parent.layer.close(index);
  162. }
  163. /*时间*/
  164. function getHTMLDate(obj) {
  165. var d = new Date();
  166. var weekday = new Array(7);
  167. var _mm = "";
  168. var _dd = "";
  169. var _ww = "";
  170. weekday[0] = "星期日";
  171. weekday[1] = "星期一";
  172. weekday[2] = "星期二";
  173. weekday[3] = "星期三";
  174. weekday[4] = "星期四";
  175. weekday[5] = "星期五";
  176. weekday[6] = "星期六";
  177. _yy = d.getFullYear();
  178. _mm = d.getMonth() + 1;
  179. _dd = d.getDate();
  180. _ww = weekday[d.getDay()];
  181. obj.html(_yy + "年" + _mm + "月" + _dd + "日 " + _ww);
  182. };
  183. $(function(){
  184. getHTMLDate($("#top_time"));
  185. getskincookie();
  186. //layer.config({extend: 'extend/layer.ext.js'});
  187. Huiasidedisplay();
  188. var resizeID;
  189. $(window).resize(function(){
  190. clearTimeout(resizeID);
  191. resizeID = setTimeout(function(){
  192. Huiasidedisplay();
  193. },500);
  194. });
  195. $(".nav-toggle").click(function(){
  196. $(".Hui-aside").slideToggle();
  197. });
  198. $(".Hui-aside").on("click",".menu_dropdown dd li a",function(){
  199. if($(window).width()<768){
  200. $(".Hui-aside").slideToggle();
  201. }
  202. });
  203. /*左侧菜单*/
  204. $.Huifold(".menu_dropdown dl dt",".menu_dropdown dl dd","fast",1,"click");
  205. /*选项卡导航*/
  206. $(".Hui-aside").on("click",".menu_dropdown a",function(){
  207. Hui_admin_tab(this);
  208. });
  209. $(document).on("click","#min_title_list li",function(){
  210. var bStopIndex=$(this).index();
  211. var iframe_box=$("#iframe_box");
  212. $("#min_title_list li").removeClass("active").eq(bStopIndex).addClass("active");
  213. iframe_box.find(".show_iframe").hide().eq(bStopIndex).show();
  214. });
  215. $(document).on("click","#min_title_list li i",function(){
  216. var aCloseIndex=$(this).parents("li").index();
  217. $(this).parent().remove();
  218. $('#iframe_box').find('.show_iframe').eq(aCloseIndex).remove();
  219. num==0?num=0:num--;
  220. tabNavallwidth();
  221. });
  222. $(document).on("dblclick","#min_title_list li",function(){
  223. var aCloseIndex=$(this).index();
  224. var iframe_box=$("#iframe_box");
  225. if(aCloseIndex>0){
  226. $(this).remove();
  227. $('#iframe_box').find('.show_iframe').eq(aCloseIndex).remove();
  228. num==0?num=0:num--;
  229. $("#min_title_list li").removeClass("active").eq(aCloseIndex-1).addClass("active");
  230. iframe_box.find(".show_iframe").hide().eq(aCloseIndex-1).show();
  231. tabNavallwidth();
  232. }else{
  233. return false;
  234. }
  235. });
  236. tabNavallwidth();
  237. $('#js-tabNav-next').click(function(){
  238. num==oUl.find('li').length-1?num=oUl.find('li').length-1:num++;
  239. toNavPos();
  240. });
  241. $('#js-tabNav-prev').click(function(){
  242. num==0?num=0:num--;
  243. toNavPos();
  244. });
  245. function toNavPos(){
  246. oUl.stop().animate({'left':-num*100},100);
  247. }
  248. /*换肤*/
  249. $("#Hui-skin .dropDown-menu a").click(function(){
  250. var v = $(this).attr("data-val");
  251. setCookie("Huiskin", v);
  252. var hrefStr=$("#skin").attr("href");
  253. var hrefRes=hrefStr.substring(0,hrefStr.lastIndexOf('skin/'))+'skin/'+v+'/skin.css';
  254. $(window.frames.document).contents().find("#skin").attr("href",hrefRes);
  255. //$("#skin").attr("href",hrefResd);
  256. });
  257. });