H-ui.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /* -----------H-ui前端框架-------------
  2. * H-ui.js v2.3.5
  3. * http://www.h-ui.net/
  4. * Created & Modified by guojunhui
  5. * Date modified 2016-01.08
  6. *
  7. * Copyright 2013-2016 北京颖杰联创科技有限公司 All rights reserved.
  8. * Licensed under MIT license.
  9. * http://opensource.org/licenses/MIT
  10. *
  11. */
  12. /*responsive-nav.min.js*/
  13. !function(a,b,c){"use strict";var d=function(d,e){var f=!!b.getComputedStyle;f||(b.getComputedStyle=function(a){return this.el=a,this.getPropertyValue=function(b){var c=/(\-([a-z]){1})/g;return"float"===b&&(b="styleFloat"),c.test(b)&&(b=b.replace(c,function(){return arguments[2].toUpperCase()})),a.currentStyle[b]?a.currentStyle[b]:null},this});var g,h,i,j,k,l,m=function(a,b,c,d){if("addEventListener"in a)try{a.addEventListener(b,c,d)}catch(e){if("object"!=typeof c||!c.handleEvent)throw e;a.addEventListener(b,function(a){c.handleEvent.call(c,a)},d)}else"attachEvent"in a&&("object"==typeof c&&c.handleEvent?a.attachEvent("on"+b,function(){c.handleEvent.call(c)}):a.attachEvent("on"+b,c))},n=function(a,b,c,d){if("removeEventListener"in a)try{a.removeEventListener(b,c,d)}catch(e){if("object"!=typeof c||!c.handleEvent)throw e;a.removeEventListener(b,function(a){c.handleEvent.call(c,a)},d)}else"detachEvent"in a&&("object"==typeof c&&c.handleEvent?a.detachEvent("on"+b,function(){c.handleEvent.call(c)}):a.detachEvent("on"+b,c))},o=function(a){if(a.children.length<1)throw new Error("The Nav container has no containing elements");for(var b=[],c=0;c<a.children.length;c++)1===a.children[c].nodeType&&b.push(a.children[c]);return b},p=function(a,b){for(var c in b)a.setAttribute(c,b[c])},q=function(a,b){0!==a.className.indexOf(b)&&(a.className+=" "+b,a.className=a.className.replace(/(^\s*)|(\s*$)/g,""))},r=function(a,b){var c=new RegExp("(\\s|^)"+b+"(\\s|$)");a.className=a.className.replace(c," ").replace(/(^\s*)|(\s*$)/g,"")},s=function(a,b,c){for(var d=0;d<a.length;d++)b.call(c,d,a[d])},t=a.createElement("style"),u=a.documentElement,v=function(b,c){var d;this.options={animate:!0,transition:284,label:"Menu",insert:"before",customToggle:"",closeOnNavClick:!1,openPos:"relative",navClass:"nav-collapse",navActiveClass:"js-nav-active",jsClass:"js",init:function(){},open:function(){},close:function(){}};for(d in c)this.options[d]=c[d];if(q(u,this.options.jsClass),this.wrapperEl=b.replace("#",""),a.getElementById(this.wrapperEl))this.wrapper=a.getElementById(this.wrapperEl);else{if(!a.querySelector(this.wrapperEl))throw new Error("The nav element you are trying to select doesn't exist");this.wrapper=a.querySelector(this.wrapperEl)}this.wrapper.inner=o(this.wrapper),h=this.options,g=this.wrapper,this._init(this)};return v.prototype={destroy:function(){this._removeStyles(),r(g,"closed"),r(g,"opened"),r(g,h.navClass),r(g,h.navClass+"-"+this.index),r(u,h.navActiveClass),g.removeAttribute("style"),g.removeAttribute("aria-hidden"),n(b,"resize",this,!1),n(b,"focus",this,!1),n(a.body,"touchmove",this,!1),n(i,"touchstart",this,!1),n(i,"touchend",this,!1),n(i,"mouseup",this,!1),n(i,"keyup",this,!1),n(i,"click",this,!1),h.customToggle?i.removeAttribute("aria-hidden"):i.parentNode.removeChild(i)},toggle:function(){j===!0&&(l?this.close():this.open())},open:function(){l||(r(g,"closed"),q(g,"opened"),q(u,h.navActiveClass),q(i,"active"),g.style.position=h.openPos,p(g,{"aria-hidden":"false"}),l=!0,h.open())},close:function(){l&&(q(g,"closed"),r(g,"opened"),r(u,h.navActiveClass),r(i,"active"),p(g,{"aria-hidden":"true"}),h.animate?(j=!1,setTimeout(function(){g.style.position="absolute",j=!0},h.transition+10)):g.style.position="absolute",l=!1,h.close())},resize:function(){"none"!==b.getComputedStyle(i,null).getPropertyValue("display")?(k=!0,p(i,{"aria-hidden":"false"}),g.className.match(/(^|\s)closed(\s|$)/)&&(p(g,{"aria-hidden":"true"}),g.style.position="absolute"),this._createStyles(),this._calcHeight()):(k=!1,p(i,{"aria-hidden":"true"}),p(g,{"aria-hidden":"false"}),g.style.position=h.openPos,this._removeStyles())},handleEvent:function(a){var c=a||b.event;switch(c.type){case"touchstart":this._onTouchStart(c);break;case"touchmove":this._onTouchMove(c);break;case"touchend":case"mouseup":this._onTouchEnd(c);break;case"click":this._preventDefault(c);break;case"keyup":this._onKeyUp(c);break;case"focus":case"resize":this.resize(c)}},_init:function(){this.index=c++,q(g,h.navClass),q(g,h.navClass+"-"+this.index),q(g,"closed"),j=!0,l=!1,this._closeOnNavClick(),this._createToggle(),this._transitions(),this.resize();var d=this;setTimeout(function(){d.resize()},20),m(b,"resize",this,!1),m(b,"focus",this,!1),m(a.body,"touchmove",this,!1),m(i,"touchstart",this,!1),m(i,"touchend",this,!1),m(i,"mouseup",this,!1),m(i,"keyup",this,!1),m(i,"click",this,!1),h.init()},_createStyles:function(){t.parentNode||(t.type="text/css",a.getElementsByTagName("head")[0].appendChild(t))},_removeStyles:function(){t.parentNode&&t.parentNode.removeChild(t)},_createToggle:function(){if(h.customToggle){var b=h.customToggle.replace("#","");if(a.getElementById(b))i=a.getElementById(b);else{if(!a.querySelector(b))throw new Error("The custom nav toggle you are trying to select doesn't exist");i=a.querySelector(b)}}else{var c=a.createElement("a");c.innerHTML=h.label,p(c,{href:"#","class":"nav-toggle"}),"after"===h.insert?g.parentNode.insertBefore(c,g.nextSibling):g.parentNode.insertBefore(c,g),i=c}},_closeOnNavClick:function(){if(h.closeOnNavClick){var a=g.getElementsByTagName("a"),b=this;s(a,function(c){m(a[c],"click",function(){k&&b.toggle()},!1)})}},_preventDefault:function(a){return a.preventDefault?(a.stopImmediatePropagation&&a.stopImmediatePropagation(),a.preventDefault(),a.stopPropagation(),!1):void(a.returnValue=!1)},_onTouchStart:function(a){Event.prototype.stopImmediatePropagation||this._preventDefault(a),this.startX=a.touches[0].clientX,this.startY=a.touches[0].clientY,this.touchHasMoved=!1,n(i,"mouseup",this,!1)},_onTouchMove:function(a){(Math.abs(a.touches[0].clientX-this.startX)>10||Math.abs(a.touches[0].clientY-this.startY)>10)&&(this.touchHasMoved=!0)},_onTouchEnd:function(a){if(this._preventDefault(a),k&&!this.touchHasMoved){if("touchend"===a.type)return void this.toggle();var c=a||b.event;3!==c.which&&2!==c.button&&this.toggle()}},_onKeyUp:function(a){var c=a||b.event;13===c.keyCode&&this.toggle()},_transitions:function(){if(h.animate){var a=g.style,b="max-height "+h.transition+"ms";a.WebkitTransition=a.MozTransition=a.OTransition=a.transition=b}},_calcHeight:function(){for(var a=0,b=0;b<g.inner.length;b++)a+=g.inner[b].offsetHeight;var c="."+h.jsClass+" ."+h.navClass+"-"+this.index+".opened{max-height:"+a+"px !important} ."+h.jsClass+" ."+h.navClass+"-"+this.index+".opened.dropdown-active {max-height:9999px !important}";t.styleSheet?t.styleSheet.cssText=c:t.innerHTML=c,c=""}},new v(d,e)};"undefined"!=typeof module&&module.exports?module.exports=d:b.responsiveNav=d}(document,window,0);
  14. if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
  15. var msViewportStyle = document.createElement("style")
  16. msViewportStyle.appendChild(
  17. document.createTextNode(
  18. "@-ms-viewport{width:auto!important}"
  19. )
  20. )
  21. document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
  22. }
  23. /*placeholder兼容性处理*/
  24. (function(window, document, $) {
  25. var isInputSupported = 'placeholder' in document.createElement('input');
  26. var isTextareaSupported = 'placeholder' in document.createElement('textarea');
  27. var prototype = $.fn;
  28. var valHooks = $.valHooks;
  29. var propHooks = $.propHooks;
  30. var hooks;
  31. var placeholder;
  32. if (isInputSupported && isTextareaSupported) {
  33. placeholder = prototype.placeholder = function() {
  34. return this;
  35. };
  36. placeholder.input = placeholder.textarea = true;
  37. } else {
  38. placeholder = prototype.placeholder = function() {
  39. var $this = this;
  40. $this
  41. .filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
  42. .not('.placeholder')
  43. .bind({
  44. 'focus.placeholder': clearPlaceholder,
  45. 'blur.placeholder': setPlaceholder
  46. })
  47. .data('placeholder-enabled', true)
  48. .trigger('blur.placeholder');
  49. return $this;
  50. };
  51. placeholder.input = isInputSupported;
  52. placeholder.textarea = isTextareaSupported;
  53. hooks = {
  54. 'get': function(element) {
  55. var $element = $(element);
  56. var $passwordInput = $element.data('placeholder-password');
  57. if ($passwordInput) {
  58. return $passwordInput[0].value;
  59. }
  60. return $element.data('placeholder-enabled') && $element.hasClass('placeholder') ? '' : element.value;
  61. },
  62. 'set': function(element, value) {
  63. var $element = $(element);
  64. var $passwordInput = $element.data('placeholder-password');
  65. if ($passwordInput) {
  66. return $passwordInput[0].value = value;
  67. }
  68. if (!$element.data('placeholder-enabled')) {
  69. return element.value = value;
  70. }
  71. if (value == '') {
  72. element.value = value;
  73. if (element != safeActiveElement()) {
  74. setPlaceholder.call(element);
  75. }
  76. } else if ($element.hasClass('placeholder')) {
  77. clearPlaceholder.call(element, true, value) || (element.value = value);
  78. } else {
  79. element.value = value;
  80. }
  81. return $element;
  82. }
  83. };
  84. if (!isInputSupported) {
  85. valHooks.input = hooks;
  86. propHooks.value = hooks;
  87. }
  88. if (!isTextareaSupported) {
  89. valHooks.textarea = hooks;
  90. propHooks.value = hooks;
  91. }
  92. $(function() {
  93. $(document).delegate('form', 'submit.placeholder', function() {
  94. var $inputs = $('.placeholder', this).each(clearPlaceholder);
  95. setTimeout(function() {
  96. $inputs.each(setPlaceholder);
  97. }, 10);
  98. });
  99. });
  100. $(window).bind('beforeunload.placeholder', function() {
  101. $('.placeholder').each(function() {
  102. this.value = '';
  103. });
  104. });
  105. }
  106. function args(elem) {
  107. var newAttrs = {};
  108. var rinlinejQuery = /^jQuery\d+$/;
  109. $.each(elem.attributes, function(i, attr) {
  110. if (attr.specified && !rinlinejQuery.test(attr.name)) {
  111. newAttrs[attr.name] = attr.value;
  112. }
  113. });
  114. return newAttrs;
  115. }
  116. function clearPlaceholder(event, value) {
  117. var input = this;
  118. var $input = $(input);
  119. if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) {
  120. if ($input.data('placeholder-password')) {
  121. $input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id'));
  122. if (event === true) {
  123. return $input[0].value = value;
  124. }
  125. $input.focus();
  126. } else {
  127. input.value = '';
  128. $input.removeClass('placeholder');
  129. input == safeActiveElement() && input.select();
  130. }
  131. }
  132. }
  133. function setPlaceholder() {
  134. var $replacement;
  135. var input = this;
  136. var $input = $(input);
  137. var id = this.id;
  138. if (input.value == '') {
  139. if (input.type == 'password') {
  140. if (!$input.data('placeholder-textinput')) {
  141. try {
  142. $replacement = $input.clone().prop('type','text');
  143. } catch(e) {
  144. $replacement = $('<input>').prop($.extend(args(this), { 'type': 'text' }));
  145. }
  146. $replacement
  147. .removeAttr('name')
  148. .data({
  149. 'placeholder-password': $input,
  150. 'placeholder-id': id
  151. })
  152. .bind('focus.placeholder', clearPlaceholder);
  153. $input
  154. .data({
  155. 'placeholder-textinput': $replacement,
  156. 'placeholder-id': id
  157. })
  158. .before($replacement);
  159. }
  160. $input = $input.removeAttr('id').hide().prev().attr('id', id).show();
  161. }
  162. $input.addClass('placeholder');
  163. $input[0].value = $input.attr('placeholder');
  164. } else {
  165. $input.removeClass('placeholder');
  166. }
  167. }
  168. function safeActiveElement() {
  169. try {
  170. return document.activeElement;
  171. } catch (exception) {}
  172. }
  173. }(this, document, jQuery));
  174. /**/
  175. ;(function($) {
  176. $.extend({
  177. format : function(str, step, splitor) {
  178. str = str.toString();
  179. var len = str.length;
  180. if(len > step) {
  181. var l1 = len%step,
  182. l2 = parseInt(len/step),
  183. arr = [],
  184. first = str.substr(0, l1);
  185. if(first != '') {
  186. arr.push(first);
  187. };
  188. for(var i=0; i<l2 ; i++) {
  189. arr.push(str.substr(l1 + i*step, step));
  190. };
  191. str = arr.join(splitor);
  192. };
  193. return str;
  194. }
  195. });
  196. })(jQuery);
  197. /*Dropdown*/
  198. +function ($) {
  199. 'use strict';
  200. var backdrop = '.dropdown-backdrop';
  201. var toggle = '[data-toggle="dropdown"]';
  202. var Dropdown = function (element) {
  203. $(element).on('click.bs.dropdown', this.toggle)
  204. }
  205. Dropdown.VERSION = '3.3.5';
  206. function getParent($this) {
  207. var selector = $this.attr('data-target');
  208. if (!selector) {
  209. selector = $this.attr('href');
  210. selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, ''); // strip for ie7
  211. }
  212. var $parent = selector && $(selector);
  213. return $parent && $parent.length ? $parent : $this.parent();
  214. }
  215. function clearMenus(e) {
  216. if (e && e.which === 3) return
  217. $(backdrop).remove();
  218. $(toggle).each(function () {
  219. var $this = $(this)
  220. var $parent = getParent($this)
  221. var relatedTarget = { relatedTarget: this }
  222. if (!$parent.hasClass('open')) return
  223. if (e && e.type == 'click' && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return
  224. $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget));
  225. if (e.isDefaultPrevented()) return
  226. $this.attr('aria-expanded', 'false');
  227. $parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget);
  228. });
  229. }
  230. Dropdown.prototype.toggle = function (e) {
  231. var $this = $(this)
  232. if ($this.is('.disabled, :disabled')) return
  233. var $parent = getParent($this);
  234. var isActive = $parent.hasClass('open');
  235. clearMenus();
  236. if (!isActive) {
  237. if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) {
  238. // if mobile we use a backdrop because click events don't delegate
  239. $(document.createElement('div')).addClass('dropdown-backdrop').insertAfter($(this)).on('click', clearMenus);
  240. }
  241. var relatedTarget = { relatedTarget: this }
  242. $parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget));
  243. if (e.isDefaultPrevented()) return
  244. $this.trigger('focus').attr('aria-expanded', 'true');
  245. $parent.toggleClass('open').trigger('shown.bs.dropdown', relatedTarget);
  246. }
  247. return false
  248. }
  249. Dropdown.prototype.keydown = function (e) {
  250. if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return
  251. var $this = $(this)
  252. e.preventDefault()
  253. e.stopPropagation()
  254. if ($this.is('.disabled, :disabled')) return
  255. var $parent = getParent($this);
  256. var isActive = $parent.hasClass('open');
  257. if (!isActive && e.which != 27 || isActive && e.which == 27) {
  258. if (e.which == 27) $parent.find(toggle).trigger('focus')
  259. return $this.trigger('click')
  260. }
  261. var desc = ' li:not(.disabled):visible a'
  262. var $items = $parent.find('.dropdown-menu' + desc)
  263. if (!$items.length) return
  264. var index = $items.index(e.target);
  265. if (e.which == 38 && index > 0) index-- // up
  266. if (e.which == 40 && index < $items.length - 1) index++ // down
  267. if (!~index) index = 0
  268. $items.eq(index).trigger('focus');
  269. }
  270. function Plugin(option) {
  271. return this.each(function () {
  272. var $this = $(this);
  273. var data = $this.data('bs.dropdown');
  274. if (!data){
  275. $this.data('bs.dropdown', (data = new Dropdown(this)));
  276. }
  277. if (typeof option == 'string'){
  278. data[option].call($this);
  279. }
  280. });
  281. }
  282. var old = $.fn.dropdown;
  283. $.fn.dropdown = Plugin;
  284. $.fn.dropdown.Constructor = Dropdown;
  285. $.fn.dropdown.noConflict = function () {
  286. $.fn.dropdown = old;
  287. return this;
  288. }
  289. $(document).on('click.bs.dropdown.data-api', clearMenus).on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }).on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle).on('keydown.bs.dropdown.data-api', toggle, Dropdown.prototype.keydown).on('keydown.bs.dropdown.data-api', '.dropdown-menu', Dropdown.prototype.keydown);
  290. }(jQuery);
  291. /*隐藏显示密码*/
  292. !(function ( $ ) {
  293. $.fn.togglePassword = function( options ) {
  294. var s = $.extend( $.fn.togglePassword.defaults, options ),
  295. input = $( this );
  296. $( s.el ).on( s.ev, function() {
  297. "password" == $( input ).attr( "type" ) ?
  298. $( input ).attr( "type", "text" ) :
  299. $( input ).attr( "type", "password" );
  300. });
  301. };
  302. $.fn.togglePassword.defaults = {
  303. ev: "click"
  304. };
  305. }( jQuery ));
  306. /*transition*/
  307. !function ($) {
  308. "use strict";
  309. $(function () {
  310. $.support.transition = (function () {
  311. var transitionEnd = (function () {
  312. var el = document.createElement('bootstrap'),
  313. transEndEventNames = {
  314. 'WebkitTransition' : 'webkitTransitionEnd',
  315. 'MozTransition' : 'transitionend',
  316. 'OTransition' : 'oTransitionEnd otransitionend',
  317. 'transition' : 'transitionend'
  318. },
  319. name
  320. for (name in transEndEventNames){
  321. if (el.style[name] !== undefined) {
  322. return transEndEventNames[name]
  323. }
  324. }
  325. }())
  326. return transitionEnd && {
  327. end: transitionEnd
  328. }
  329. })()
  330. });
  331. }(window.jQuery);
  332. /*添加收藏
  333. <a title="收藏本站" href="javascript:;" onClick="addFavoritepage('H-ui前端框架','http://www.h-ui.net/');">收藏本站</a>
  334. */
  335. /*收藏主站*/
  336. function addFavorite(name,site){
  337. try{window.external.addFavorite(site,name);}
  338. catch(e){
  339. try{window.sidebar.addPanel(name,site,"");}
  340. catch(e){alert("加入收藏失败,请使用Ctrl+D进行添加");}
  341. }
  342. }
  343. /*收藏页面
  344. <a title="收藏本页" href="javascript:addFavoritepage(0);">收藏本页</a>
  345. */
  346. function addFavoritepage(){var sURL=window.location.href;var sTitle=document.title;try{window.external.addFavorite(sURL,sTitle);}catch(e){try{window.sidebar.addPanel(sTitle,sURL,"");}catch(e){alert("加入收藏失败,请使用Ctrl+D进行添加");}}}
  347. /*设为首页*/
  348. function setHome(obj){
  349. try{obj.style.behavior="url(#default#homepage)";obj.setHomePage(webSite);}
  350. catch(e){if(window.netscape){
  351. try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}
  352. catch(e){alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入\"about:config\"并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");}
  353. var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
  354. prefs.setCharPref('browser.startup.homepage',url);}}
  355. }
  356. /*滚动*/
  357. function marquee(height,speed,delay){
  358. var scrollT;
  359. var pause = false;
  360. var ScrollBox = document.getElementById("marquee");
  361. if(document.getElementById("holder").offsetHeight <= height) return;
  362. var _tmp = ScrollBox.innerHTML.replace('holder', 'holder2')
  363. ScrollBox.innerHTML += _tmp;
  364. ScrollBox.onmouseover = function(){pause = true}
  365. ScrollBox.onmouseout = function(){pause = false}
  366. ScrollBox.scrollTop = 0;
  367. function start(){
  368. scrollT = setInterval(scrolling,speed);
  369. if(!pause) ScrollBox.scrollTop += 2;
  370. }
  371. function scrolling(){
  372. if(ScrollBox.scrollTop % height != 0){
  373. ScrollBox.scrollTop += 2;
  374. if(ScrollBox.scrollTop >= ScrollBox.scrollHeight/2) ScrollBox.scrollTop = 0;
  375. }
  376. else{
  377. clearInterval(scrollT);
  378. setTimeout(start,delay);
  379. }
  380. }
  381. setTimeout(start,delay);
  382. }
  383. /*左侧菜单-隐藏显示*/
  384. function displaynavbar(obj){
  385. if($(obj).hasClass("open")){
  386. $(obj).removeClass("open");
  387. $("body").removeClass("big-page");
  388. }else{
  389. $(obj).addClass("open");
  390. $("body").addClass("big-page");
  391. }
  392. }
  393. /*模拟下拉菜单*/
  394. jQuery.Huiselect = function(divselectid,inputselectid) {
  395. var inputselect = $(inputselectid);
  396. $(divselectid+" cite").click(function(){
  397. var ul = $(divselectid+" ul");
  398. ul.slideToggle();
  399. });
  400. $(divselectid+" ul li a").click(function(){
  401. var txt = $(this).text();
  402. $(divselectid+" cite").html(txt);
  403. var value = $(this).attr("selectid");
  404. inputselect.val(value);
  405. $(divselectid+" ul").hide();
  406. });
  407. $(document).click(function(){$(divselectid+" ul").hide();});
  408. };
  409. /*hover*/
  410. jQuery.Huihover =function(obj) {
  411. $(obj).hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});
  412. };
  413. /*得到失去焦点*/
  414. jQuery.Huifocusblur = function(obj) {
  415. $(obj).focus(function() {$(this).addClass("focus").removeClass("inputError");});
  416. $(obj).blur(function() {$(this).removeClass("focus");});
  417. };
  418. /*tab选项卡*/
  419. jQuery.Huitab =function(tabBar,tabCon,class_name,tabEvent,i){
  420. var $tab_menu=$(tabBar);
  421. // 初始化操作
  422. $tab_menu.removeClass(class_name);
  423. $(tabBar).eq(i).addClass(class_name);
  424. $(tabCon).hide();
  425. $(tabCon).eq(i).show();
  426. $tab_menu.on(tabEvent,function(){
  427. $tab_menu.removeClass(class_name);
  428. $(this).addClass(class_name);
  429. var index=$tab_menu.index(this);
  430. $(tabCon).hide();
  431. $(tabCon).eq(index).show();
  432. });
  433. }
  434. /*折叠*/
  435. jQuery.Huifold = function(obj,obj_c,speed,obj_type,Event){
  436. if(obj_type == 2){
  437. $(obj+":first").find("b").html("-");
  438. $(obj_c+":first").show();
  439. }
  440. $(obj).on(Event,function(){
  441. if($(this).next().is(":visible")){
  442. if(obj_type == 2){
  443. return false;
  444. }else{
  445. $(this).next().slideUp(speed).end().removeClass("selected");
  446. if($(this).find("b")){
  447. $(this).find("b").html("+");
  448. }
  449. }
  450. }
  451. else{
  452. if(obj_type == 3){
  453. $(this).next().slideDown(speed).end().addClass("selected");
  454. if($(this).find("b")){
  455. $(this).find("b").html("-");
  456. }
  457. }else{
  458. $(obj_c).slideUp(speed);
  459. $(obj).removeClass("selected");
  460. if($(this).find("b")){
  461. $(obj).find("b").html("+");
  462. }
  463. $(this).next().slideDown(speed).end().addClass("selected");
  464. if($(this).find("b")){
  465. $(this).find("b").html("-");
  466. }
  467. }
  468. }
  469. });
  470. }
  471. /*返回顶部*/
  472. var $backToTopEle=$('<a href="javascript:void(0)" class="Hui-iconfont toTop" title="返回顶部" alt="返回顶部" style="display:none">&#xe684;</a>').appendTo($("body")).click(function(){
  473. $("html, body").animate({ scrollTop: 0 }, 120);
  474. });
  475. var $backToTopFun = function() {
  476. var st = $(document).scrollTop(), winh = $(window).height();
  477. (st > 0)? $backToTopEle.show(): $backToTopEle.hide();
  478. /*IE6下的定位*/
  479. if(!window.XMLHttpRequest){
  480. $backToTopEle.css("top", st + winh - 166);
  481. }
  482. };
  483. /*textarea 字数限制*/
  484. function textarealength(obj,maxlength){
  485. var v = $(obj).val();
  486. var l = v.length;
  487. if( l > maxlength){
  488. v = v.substring(0,maxlength);
  489. $(obj).val(v);
  490. }
  491. $(obj).parent().find(".textarea-length").text(v.length);
  492. }
  493. /*Huimodalalert*/
  494. function Huimodal_alert(info,speed){
  495. if(speed==0||typeof(speed) == "undefined"){
  496. $(document.body).append(
  497. '<div id="modal-alert" class="modal hide modal-alert">'+
  498. '<div class="modal-alert-info">'+info+'</div>'+
  499. '<div class="modal-footer"> <button class="btn btn-primary radius" onClick="modal_alert_hide()">确定</button></div>'+
  500. '</div>'
  501. );
  502. $("#modal-alert").fadeIn();
  503. }else{
  504. $(document.body).append(
  505. '<div id="modal-alert" class="modal hide modal-alert">'+
  506. '<div class="modal-alert-info">'+info+'</div>'+
  507. '</div>'
  508. );
  509. $("#modal-alert").fadeIn();
  510. setTimeout("Huimodal_alert_hide()",speed);
  511. }
  512. }
  513. function Huimodal_alert_hide() {
  514. $("#modal-alert").fadeOut("normal",function(){
  515. $("#modal-alert").remove();
  516. });
  517. }
  518. /*设置cookie*/
  519. function setCookie(name, value, Days){
  520. if(Days == null || Days == ''){
  521. Days = 300;
  522. }
  523. var exp = new Date();
  524. exp.setTime(exp.getTime() + Days*24*60*60*1000);
  525. document.cookie = name + "="+ escape (value) + "; path=/;expires=" + exp.toGMTString();
  526. }
  527. /*获取cookie*/
  528. function getCookie(name) {
  529. var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
  530. if(arr=document.cookie.match(reg))
  531. return unescape(arr[2]);
  532. else
  533. return null;
  534. }
  535. $(function(){
  536. /*****表单*****/
  537. $.Huifocusblur(".input-text,.textarea");
  538. /*按钮loading*/
  539. $('.btn-loading').click(function () {
  540. var $btn = $(this);
  541. var btnval = $btn.val();
  542. $btn.addClass("disabled").val("loading").attr("disabled","disabled");
  543. setTimeout(function(){
  544. $btn.removeClass("disabled").val(btnval).removeAttr("disabled");
  545. }, 3000);
  546. });
  547. /**/
  548. $.Huiselect("#divselect","#inputselect");
  549. /*全选*/
  550. $("table thead th input:checkbox").on("click" , function(){
  551. $(this).closest("table").find("tr > td:first-child input:checkbox").prop("checked",$("table thead th input:checkbox").prop("checked"));
  552. });
  553. /*上传*/
  554. $(document).on("change",".input-file",function(){
  555. var uploadVal=$(this).val();
  556. $(this).parent().find(".upload-url").val(uploadVal).focus().blur();
  557. });
  558. /*下拉菜单*/
  559. $(document).on("mouseenter",".dropDown",function(){
  560. $(this).addClass("hover");
  561. });
  562. $(document).on("mouseleave",".dropDown",function(){
  563. $(this).removeClass("hover");
  564. });
  565. $(document).on("mouseenter",".dropDown_hover",function(){
  566. $(this).addClass("open");
  567. });
  568. $(document).on("mouseleave",".dropDown_hover",function(){
  569. $(this).removeClass("open");
  570. });
  571. $(document).on("click",".dropDown-menu li a",function(){
  572. $(".dropDown").removeClass('open');
  573. });
  574. $(document).on("mouseenter",".menu > li",function(){
  575. $(this).addClass("open");
  576. });
  577. $(document).on("mouseleave",".menu > li",function(){
  578. $(this).removeClass("open");
  579. });
  580. /*tag标签*/
  581. var tags_a = $(".tags a");
  582. tags_a.each(function(){
  583. var x = 9;
  584. var y = 0;
  585. var rand = parseInt(Math.random() * (x - y + 1) + y);
  586. $(this).addClass("tags"+rand);
  587. });
  588. /*对联广告*/
  589. var dual = $(".dual");
  590. var dual_close = $("a.dual_close");
  591. var screen_w = screen.width;
  592. if(screen_w>1024){dual.show();}
  593. $(window).scroll(function(){
  594. var scrollTop = $(window).scrollTop();
  595. dual.stop().animate({top:scrollTop+260});
  596. });
  597. dual_close.click(function(){
  598. $(this).parent().hide();
  599. return false;
  600. });
  601. /*顶部展开定时自动关闭广告*/
  602. $("#banner").slideDown("slow");
  603. /*图片预览*/
  604. $("a.preview").hover(
  605. function(){
  606. $(this).addClass("active");
  607. $("#tooltip-preview").remove();
  608. var winW=$(window).width();
  609. var winW5=winW/2;
  610. this.myTitle = this.title;
  611. this.title = "";
  612. var midimg = $(this).attr('data-preview');
  613. if(midimg ==''){return false;}
  614. else{
  615. var imgT=$(this).parents(".imgItem").offset().top;
  616. var imgL=$(this).parents(".imgItem").offset().left;
  617. var imgW=$(this).parents(".imgItem").width();
  618. var imgH=$(this).parents(".imgItem").height();
  619. var ww=(imgL+imgW/2);
  620. if(ww < winW5){
  621. var tooltipLeft=(imgW+imgL)+"px";
  622. }
  623. else{
  624. var tooltipRight=(winW-imgL)+"px";
  625. }
  626. var tooltip_keleyi_com = "<div id='tooltip-preview' style='top:"+ imgT +"px;right:"+ tooltipRight +";left:"+ tooltipLeft +"'><span id='tooltip-keleyi-div' class='loading' style='width:50px; height:50px'></span></div>";
  627. $("body").append(tooltip_keleyi_com);
  628. var midimgW = $(this).attr('data-width');
  629. var midimgH = $(this).attr('data-height');
  630. var imgTitle = this.myTitle ? "<br />" + this.myTitle + " 产品预览图" : "";
  631. /*图片预加载*/
  632. var image = new Image();/*创建一个Image对象*/
  633. image.onload = function () {
  634. if($('a.preview.active').attr('data-preview') == midimg){
  635. var midingW2 = this.width;
  636. var midingH2 = this.height;
  637. $("#tooltip-keleyi-div").css({"width":midingW2+"px","height":midingH2+"px"});
  638. $('#tooltip-keleyi-div').append(this);
  639. }
  640. };
  641. image.src = midimg;
  642. }
  643. },
  644. function(){
  645. $(this).removeClass("active");
  646. this.title = this.myTitle;
  647. $("#tooltip-preview").remove();
  648. }
  649. );
  650. /*Huialert*/
  651. $.Huihover('.Huialert i');
  652. $(".Huialert i").on("click",function(){
  653. var Huialert = $(this).parents(".Huialert");
  654. Huialert.fadeOut("normal",function(){
  655. Huialert.remove();
  656. });
  657. });
  658. /*tag标签*/
  659. var time1;
  660. $(".Hui-tags-lable").show();
  661. $(".Hui-tags-input").val("");
  662. $(document).on("blur",".Hui-tags-input",function(){
  663. time1 = setTimeout(function(){
  664. $(this).parents(".Hui-tags").find(".Hui-tags-list").slideUp();
  665. }, 400);
  666. });
  667. $(document).on("focus",".Hui-tags-input",function(){
  668. clearTimeout(time1);
  669. });
  670. $(document).on("click",".Hui-tags-input",function(){
  671. $(this).find(".Hui-tags-input").focus();
  672. $(this).find(".Hui-tags-list").slideDown();
  673. });
  674. function gettagval(obj){
  675. var str ="";
  676. var token =$(obj).parents(".Hui-tags").find(".Hui-tags-token");
  677. //alert(token.length)
  678. if(token.length<1){
  679. $(obj).parents(".Hui-tags").find(".Hui-tags-val").val("");
  680. return false;
  681. }
  682. for(var i = 0;i< token.length;i++){
  683. str += token.eq(i).text() + ",";
  684. $(obj).parents(".Hui-tags").find(".Hui-tags-val").val(str);
  685. }
  686. }
  687. $(document).on("keydown",".Hui-tags-input",function(event){
  688. $(this).next().hide();
  689. var v = $(this).val().replace(/\s+/g, "");
  690. var reg=/^,|,$/gi;
  691. v=v.replace(reg,"");
  692. v=$.trim(v);
  693. var token =$(this).parents(".Hui-tags").find(".Hui-tags-token");
  694. if(v!=''){
  695. if(event.keyCode==13||event.keyCode==108||event.keyCode==32){
  696. $('<span class="Hui-tags-token">'+v+'</span>').insertBefore($(this).parents(".Hui-tags").find(".Hui-tags-iptwrap"));
  697. $(this).val("");
  698. gettagval(this);
  699. }
  700. }else{
  701. if(event.keyCode==8){
  702. if(token.length>=1){
  703. $(this).parents(".Hui-tags").find(".Hui-tags-token:last").remove();
  704. gettagval(this);
  705. }
  706. else{
  707. $(this).parents(".Hui-tags").find(".Hui-tags-lable").show();
  708. return false;
  709. }
  710. }
  711. }
  712. });
  713. $(document).on("click",".Hui-tags-has span",function(){
  714. var taghasV = $(this).text();
  715. taghasV=taghasV.replace(/(^\s*)|(\s*$)/g,"");
  716. $('<span class="Hui-tags-token">'+taghasV+'</span>').insertBefore($(this).parents(".Hui-tags").find(".Hui-tags-iptwrap"));
  717. gettagval(this);
  718. $(this).parents(".Hui-tags").find(".Hui-tags-input").focus();
  719. });
  720. $(document).on("click",".Hui-tags-token",function(){
  721. var token =$(this).parents(".Hui-tags").find(".Hui-tags-token");
  722. var it = $(this).parents(".Hui-tags");
  723. $(this).remove();
  724. switch(token.length){
  725. case 1 : it.find(".Hui-tags-lable").show();
  726. break;
  727. }
  728. var str ="";
  729. var token =it.find(".Hui-tags-token");
  730. //alert(token.length)
  731. if(token.length<1){
  732. it.find(".Hui-tags-val").val("");
  733. return false;
  734. }
  735. for(var i = 0;i< token.length;i++){
  736. str += token.eq(i).text() + ",";
  737. it.find(".Hui-tags-val").val(str);
  738. }
  739. });
  740. });
  741. function displayimg(){
  742. $("#banner").slideUp(1000,function(){
  743. $("#top").slideDown(1000);
  744. });
  745. }
  746. setTimeout("displayimg()",4000);