H-ui.admin.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /* -----------H-ui前端框架-------------
  2. * H-ui.admin.js v3.1
  3. * http://www.h-ui.net/
  4. * Created & Modified by guojunhui
  5. * Date modified 2017.02.03
  6. * Copyright 2013-2017 北京颖杰联创科技有限公司 All rights reserved.
  7. * Licensed under MIT license.
  8. * http://opensource.org/licenses/MIT
  9. */
  10. var num=0,oUl=$("#min_title_list"),hide_nav=$("#Hui-tabNav");
  11. /*获取顶部选项卡总长度*/
  12. function tabNavallwidth(){
  13. var taballwidth=0,
  14. $tabNav = hide_nav.find(".acrossTab"),
  15. $tabNavWp = hide_nav.find(".Hui-tabNav-wp"),
  16. $tabNavitem = hide_nav.find(".acrossTab li"),
  17. $tabNavmore =hide_nav.find(".Hui-tabNav-more");
  18. if (!$tabNav[0]){return}
  19. $tabNavitem.each(function(index, element) {
  20. taballwidth += Number(parseFloat($(this).width()+60))
  21. });
  22. $tabNav.width(taballwidth+25);
  23. var w = $tabNavWp.width();
  24. if(taballwidth+25>w){
  25. $tabNavmore.show()}
  26. else{
  27. $tabNavmore.hide();
  28. $tabNav.css({left:0});
  29. }
  30. }
  31. /*左侧菜单响应式*/
  32. function Huiasidedisplay(){
  33. if($(window).width()>=768){
  34. $(".Hui-aside").show();
  35. }
  36. }
  37. $(".Hui-aside").on("click",".menu_dropdown dd li a",function(){
  38. if($(window).width()<768){
  39. $(".Hui-aside").slideToggle();
  40. }
  41. });
  42. /*选项卡导航*/
  43. $(".Hui-aside").on("click",".menu_dropdown a",function(){
  44. Hui_admin_tab(this);
  45. });
  46. /*获取皮肤cookie*/
  47. function getskincookie(){
  48. var v = $.cookie("Huiskin");
  49. var hrefStr=$("#skin").attr("href");
  50. if(v==null||v==""){
  51. v="default";
  52. }
  53. if(hrefStr!=undefined){
  54. var hrefRes=hrefStr.substring(0,hrefStr.lastIndexOf('skin/'))+'skin/'+v+'/skin.css';
  55. $("#skin").attr("href",hrefRes);
  56. }
  57. }
  58. /*菜单导航*/
  59. function Hui_admin_tab(obj){
  60. var bStop = false,
  61. bStopIndex = 0,
  62. href = $(obj).attr('data-href'),
  63. title = $(obj).attr("data-title"),
  64. topWindow = $(window.parent.document),
  65. show_navLi = topWindow.find("#min_title_list li"),
  66. iframe_box = topWindow.find("#iframe_box");
  67. //console.log(topWindow);
  68. if(!href||href==""){
  69. alert("data-href不存在,v2.5版本之前用_href属性,升级后请改为data-href属性");
  70. return false;
  71. }if(!title){
  72. alert("v2.5版本之后使用data-title属性");
  73. return false;
  74. }
  75. if(title==""){
  76. alert("data-title属性不能为空");
  77. return false;
  78. }
  79. show_navLi.each(function() {
  80. if($(this).find('span').attr("data-href")==href){
  81. bStop=true;
  82. bStopIndex=show_navLi.index($(this));
  83. return false;
  84. }
  85. });
  86. if(!bStop){
  87. creatIframe(href,title);
  88. min_titleList();
  89. }
  90. else{
  91. show_navLi.removeClass("active").eq(bStopIndex).addClass("active");
  92. iframe_box.find(".show_iframe").hide().eq(bStopIndex).show().find("iframe").attr("src",href);
  93. }
  94. }
  95. /*最新tab标题栏列表*/
  96. function min_titleList(){
  97. var topWindow = $(window.parent.document),
  98. show_nav = topWindow.find("#min_title_list"),
  99. aLi = show_nav.find("li");
  100. }
  101. /*创建iframe*/
  102. function creatIframe(href,titleName){
  103. var topWindow=$(window.parent.document),
  104. show_nav=topWindow.find('#min_title_list'),
  105. iframe_box=topWindow.find('#iframe_box'),
  106. iframeBox=iframe_box.find('.show_iframe'),
  107. $tabNav = topWindow.find(".acrossTab"),
  108. $tabNavWp = topWindow.find(".Hui-tabNav-wp"),
  109. $tabNavmore =topWindow.find(".Hui-tabNav-more");
  110. var taballwidth=0;
  111. show_nav.find('li').removeClass("active");
  112. show_nav.append('<li class="active"><span data-href="'+href+'">'+titleName+'</span><i></i><em></em></li>');
  113. if('function'==typeof $('#min_title_list li').contextMenu){
  114. $("#min_title_list li").contextMenu('Huiadminmenu', {
  115. bindings: {
  116. 'closethis': function(t) {
  117. var $t = $(t);
  118. if($t.find("i")){
  119. $t.find("i").trigger("click");
  120. }
  121. },
  122. 'closeall': function(t) {
  123. $("#min_title_list li i").trigger("click");
  124. },
  125. }
  126. });
  127. }else {
  128. }
  129. var $tabNavitem = topWindow.find(".acrossTab li");
  130. if (!$tabNav[0]){return}
  131. $tabNavitem.each(function(index, element) {
  132. taballwidth+=Number(parseFloat($(this).width()+60))
  133. });
  134. $tabNav.width(taballwidth+25);
  135. var w = $tabNavWp.width();
  136. if(taballwidth+25>w){
  137. $tabNavmore.show()}
  138. else{
  139. $tabNavmore.hide();
  140. $tabNav.css({left:0})
  141. }
  142. iframeBox.hide();
  143. iframe_box.append('<div class="show_iframe"><div class="loading"></div><iframe frameborder="0" src='+href+'></iframe></div>');
  144. var showBox=iframe_box.find('.show_iframe:visible');
  145. showBox.find('iframe').load(function(){
  146. showBox.find('.loading').hide();
  147. });
  148. }
  149. /*关闭iframe*/
  150. function removeIframe(){
  151. var topWindow = $(window.parent.document),
  152. iframe = topWindow.find('#iframe_box .show_iframe'),
  153. tab = topWindow.find(".acrossTab li"),
  154. showTab = topWindow.find(".acrossTab li.active"),
  155. showBox=topWindow.find('.show_iframe:visible'),
  156. i = showTab.index();
  157. tab.eq(i-1).addClass("active");
  158. tab.eq(i).remove();
  159. iframe.eq(i-1).show();
  160. iframe.eq(i).remove();
  161. }
  162. /*关闭所有iframe*/
  163. function removeIframeAll(){
  164. var topWindow = $(window.parent.document),
  165. iframe = topWindow.find('#iframe_box .show_iframe'),
  166. tab = topWindow.find(".acrossTab li");
  167. for(var i=0;i<tab.length;i++){
  168. if(tab.eq(i).find("i").length>0){
  169. tab.eq(i).remove();
  170. iframe.eq(i).remove();
  171. }
  172. }
  173. }
  174. /*弹出层*/
  175. /*
  176. 参数解释:
  177. title 标题
  178. url 请求的url
  179. id 需要操作的数据id
  180. w 弹出层宽度(缺省调默认值)
  181. h 弹出层高度(缺省调默认值)
  182. */
  183. function layer_show(title,url,w,h){
  184. if (title == null || title == '') {
  185. title=false;
  186. };
  187. if (url == null || url == '') {
  188. url="404.html";
  189. };
  190. if (w == null || w == '') {
  191. w=800;
  192. };
  193. if (h == null || h == '') {
  194. h=($(window).height() - 50);
  195. };
  196. layer.open({
  197. type: 2,
  198. area: [w+'px', h +'px'],
  199. fix: false, //不固定
  200. maxmin: true,
  201. shade:0.4,
  202. title: title,
  203. content: url
  204. });
  205. }
  206. /*关闭弹出框口*/
  207. function layer_close(){
  208. var index = parent.layer.getFrameIndex(window.name);
  209. parent.layer.close(index);
  210. }
  211. /*时间*/
  212. function getHTMLDate(obj) {
  213. var d = new Date();
  214. var weekday = new Array(7);
  215. var _mm = "";
  216. var _dd = "";
  217. var _ww = "";
  218. weekday[0] = "星期日";
  219. weekday[1] = "星期一";
  220. weekday[2] = "星期二";
  221. weekday[3] = "星期三";
  222. weekday[4] = "星期四";
  223. weekday[5] = "星期五";
  224. weekday[6] = "星期六";
  225. _yy = d.getFullYear();
  226. _mm = d.getMonth() + 1;
  227. _dd = d.getDate();
  228. _ww = weekday[d.getDay()];
  229. obj.html(_yy + "年" + _mm + "月" + _dd + "日 " + _ww);
  230. };
  231. $(function(){
  232. getHTMLDate($("#top_time"));
  233. getskincookie();
  234. //layer.config({extend: 'extend/layer.ext.js'});
  235. Huiasidedisplay();
  236. var resizeID;
  237. $(window).resize(function(){
  238. clearTimeout(resizeID);
  239. resizeID = setTimeout(function(){
  240. Huiasidedisplay();
  241. },500);
  242. });
  243. $(".nav-toggle").click(function(){
  244. $(".Hui-aside").slideToggle();
  245. });
  246. $(document).on("click","#min_title_list li",function(){
  247. var bStopIndex=$(this).index();
  248. var iframe_box=$("#iframe_box");
  249. $("#min_title_list li").removeClass("active").eq(bStopIndex).addClass("active");
  250. iframe_box.find(".show_iframe").hide().eq(bStopIndex).show();
  251. });
  252. $(document).on("click","#min_title_list li i",function(){
  253. var aCloseIndex=$(this).parents("li").index();
  254. $(this).parent().remove();
  255. $('#iframe_box').find('.show_iframe').eq(aCloseIndex).remove();
  256. num==0?num=0:num--;
  257. tabNavallwidth();
  258. });
  259. $(document).on("dblclick","#min_title_list li",function(){
  260. var aCloseIndex=$(this).index();
  261. var iframe_box=$("#iframe_box");
  262. if(aCloseIndex>0){
  263. $(this).remove();
  264. $('#iframe_box').find('.show_iframe').eq(aCloseIndex).remove();
  265. num==0?num=0:num--;
  266. $("#min_title_list li").removeClass("active").eq(aCloseIndex-1).addClass("active");
  267. iframe_box.find(".show_iframe").hide().eq(aCloseIndex-1).show();
  268. tabNavallwidth();
  269. }else{
  270. return false;
  271. }
  272. });
  273. tabNavallwidth();
  274. $('#js-tabNav-next').click(function(){
  275. num==oUl.find('li').length-1?num=oUl.find('li').length-1:num++;
  276. toNavPos();
  277. });
  278. $('#js-tabNav-prev').click(function(){
  279. num==0?num=0:num--;
  280. toNavPos();
  281. });
  282. function toNavPos(){
  283. oUl.stop().animate({'left':-num*100},100);
  284. }
  285. /*换肤*/
  286. $("#Hui-skin .dropDown-menu a").click(function(){
  287. var v = $(this).attr("data-val");
  288. $.cookie("Huiskin", v);
  289. var hrefStr=$("#skin").attr("href");
  290. var hrefRes=hrefStr.substring(0,hrefStr.lastIndexOf('skin/'))+'skin/'+v+'/skin.css';
  291. $(window.frames.document).contents().find("#skin").attr("href",hrefRes);
  292. });
  293. });