Advertisement
Guest User

menu.js

a guest
Jan 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.50 KB | None | 0 0
  1.  
  2. /* Stik Up menu script */
  3. (function($) {
  4. $.fn.tmStickUp=function(options) {
  5.  
  6. var getOptions = {
  7. correctionSelector: $('.correctionSelector')
  8. }
  9. $.extend(getOptions, options);
  10.  
  11. var
  12. _this = $(this)
  13. , _window = $(window)
  14. , _document = $(document)
  15. , thisOffsetTop = 0
  16. , thisOuterHeight = 0
  17. , thisMarginTop = 0
  18. , thisPaddingTop = 0
  19. , documentScroll = 0
  20. , pseudoBlock
  21. , lastScrollValue = 0
  22. , scrollDir = ''
  23. , tmpScrolled
  24. ;
  25.  
  26. init();
  27. function init() {
  28. thisOffsetTop = parseInt(_this.offset().top);
  29. thisMarginTop = parseInt(_this.css('margin-top'));
  30. thisOuterHeight = parseInt(_this.outerHeight(true));
  31.  
  32. $('<div class="pseudoStickyBlock"></div>').insertAfter(_this);
  33. pseudoBlock = $('.pseudoStickyBlock');
  34. pseudoBlock.css({'position':'relative', 'display':'block'});
  35. addEventsFunction();
  36. }//end init
  37.  
  38. function addEventsFunction() {
  39. _document.on('scroll', function() {
  40. tmpScrolled = $(this).scrollTop();
  41. if (tmpScrolled > lastScrollValue) {
  42. scrollDir = 'down';
  43. } else {
  44. scrollDir = 'up';
  45. }
  46. lastScrollValue = tmpScrolled;
  47.  
  48. correctionValue = getOptions.correctionSelector.outerHeight(true);
  49. documentScroll = parseInt(_window.scrollTop());
  50.  
  51. if (thisOffsetTop - correctionValue < documentScroll) {
  52. _this.css({top:correctionValue});
  53. _this.addClass('isStuck');
  54. _this.addClass('fadeInDown');
  55. pseudoBlock.css({'height':thisOuterHeight});
  56. } else if(thisOffsetTop - correctionValue > documentScroll) {
  57. _this.removeClass('isStuck');
  58. _this.removeClass('fadeInDown');
  59. _this.css({top:0});
  60. pseudoBlock.css({'height':0});
  61. }
  62. }).trigger('scroll');
  63. }
  64. }//end tmStickUp function
  65. })(jQuery)
  66. jQuery(document).ready(function() {
  67. if (jQuery('#icemegamenu').length > 0) {
  68. var stickMenu = true;
  69. var docWidth= jQuery('body').find('#navigation').width();
  70.  
  71. //alert(windowsize);
  72. if (stickMenu && docWidth > 767) {
  73. jQuery('body').find('#navigation').wrapInner('<div class="stickUpTop"><div class="stickUpHolder">');
  74. jQuery('.stickUpTop').addClass('animated');
  75. jQuery('.stickUpTop').tmStickUp();
  76. var windowsizes = '100%';
  77. jQuery('.stickUpTop').css({'width':windowsizes});
  78. }
  79. }
  80. })
  81.  
  82. //jQuery(window).resize(function() {
  83. //var windowsize = jQuery('body').find('#top').width();
  84. //jQuery('.stickUpTop').css({'width':windowsize});
  85. //alert(windowsize);
  86. //});
  87. jQuery(function($){
  88. ///////////////////
  89. $('.icemegamenu li>a.iceMenuTitle').hover(function(){
  90. $(this).addClass('hover');
  91. },
  92. function(){
  93. $(this).removeClass('hover');
  94. });
  95. var $hide_block = false;
  96. $('.icemega_modulewrap input[type]').focus(function(){
  97. $hide_block = true;
  98. })
  99. $('.icemega_modulewrap input[type]').blur(function(){
  100. $hide_block = false;
  101. })
  102. if($('body').hasClass('desktop_mode') || ($('body').hasClass('mobile') && screen.width>767)){
  103. $('.icemegamenu li').not('.parent').find('>a.iceMenuTitle[href^="#"]').click(function(){
  104. var a=$(this);
  105. animate_body(a);
  106. })
  107. $('.icemegamenu li.parent>a.iceMenuTitle[href^="#"]').click(function(){
  108. var a=$(this);
  109. if(a.closest("li").hasClass("hover")){
  110. hide_submenu(a);
  111. animate_body(a);
  112. }
  113. else{
  114. $('.icemegamenu li.parent[class^="iceMenuLiLevel"]').not(a.closest("li").parents("li")).not(a.closest("li")).removeClass("hover");
  115. a.closest("li").addClass("hover").attr("data-hover","true");
  116. a.closest("li").find(">ul.icesubMenu").addClass("visible");
  117. return false
  118. }
  119. })
  120. $('.icemegamenu li.parent>a').not('[href]').click(function(){
  121. var a=$(this);
  122. if(a.closest("li").hasClass("hover")){
  123. if(!a.attr('href')){
  124. a.removeClass('hover');
  125. a.closest("li").attr('data-hover','false');
  126. hide_submenu(a, 0);
  127. }
  128. }
  129. else{
  130. $('.icemegamenu li.parent[class^="iceMenuLiLevel"]').not(a.closest("li").parents("li")).not(a.closest("li")).removeClass("hover");
  131. a.closest("li").addClass("hover").attr("data-hover","true");
  132. a.closest("li").find(">ul.icesubMenu").addClass("visible");
  133. return false;
  134. }
  135. })
  136. $('.icemegamenu li[class^="iceMenuLiLevel"]').not('.parent').find('>a.iceMenuTitle[href]').not('[href^="#"]').click(function(){
  137. var a=$(this);
  138. if(window.location.href.split("#")[0]==a.attr('href')) {
  139. animate_body(a);
  140. return false;
  141. }
  142. })
  143. $('.icemegamenu li.parent[class^="iceMenuLiLevel"]').find('>a.iceMenuTitle[href]').not('[href^="#"]').click(function(){
  144. var a=$(this);
  145. if(a.closest("li").hasClass("hover")){
  146. if(window.location.href.split("#")[0]==a.attr('href')){
  147. hide_submenu(a);
  148. animate_body(a);
  149. return false;
  150. }
  151. }
  152. else{
  153. $('.icemegamenu li.parent[class^="iceMenuLiLevel"]').not(a.closest("li").parents("li")).not(a.closest("li")).removeClass("hover");
  154. a.closest("li").addClass("hover").attr("data-hover","true");
  155. a.closest("li").find(">ul.icesubMenu").addClass("visible");
  156. return false;
  157. }
  158. })
  159. $('body').click(function(){
  160. $('.icemegamenu li.parent').each(function(){
  161. $(this).attr('data-hover','false');
  162. a = $(this).find('>a');
  163. hide_submenu(a, 0);
  164. })
  165. })
  166. }
  167. else{
  168. $('.icemegamenu li.parent[class^="iceMenuLiLevel"]').hover(function(){
  169. $('#icemegamenu li.parent[class^="iceMenuLiLevel"]').not($(this).parents('li')).not($(this)).removeClass('hover');
  170. $(this).addClass('hover').attr('data-hover','true');
  171. $(this).find('>ul.icesubMenu').addClass('visible');
  172. },
  173. function(){
  174. $(this).attr('data-hover','false');
  175. a = $(this).find('>a');
  176. hide_submenu(a);
  177. })
  178. $('.icemegamenu li.iceMenuLiLevel_1>a.iceMenuTitle[href^="#"]').click(function(){
  179. var a=$(this);
  180. animate_body(a);
  181. })
  182. $('.icemegamenu li[class^="iceMenuLiLevel"]>a.iceMenuTitle[href]').click(function(){
  183. var a=$(this);
  184. if(window.location.href.split("#")[0]==a.attr('href')) {
  185. animate_body(a);
  186. return false;
  187. }
  188.  
  189. })
  190. }
  191. function hide_submenu(a, delay){
  192. delay = typeof delay !== 'undefined' ? delay : 800;
  193. a.delay(delay).queue(function(b){
  194. if(a.closest("li").attr("data-hover")=="false" && $hide_block != true){
  195. a.closest("li").removeClass("hover").delay(250).queue(function(c){
  196. if(a.closest("li").attr("data-hover")=="false"){
  197. a.closest("li").find(">ul.icesubMenu").removeClass("visible")
  198. }
  199. c()
  200. })
  201. }
  202. b()
  203. });
  204. }
  205. function animate_body(a){
  206. if(window.location.href.split("#")[0]!=a.attr('href')){
  207. if($('a[name="'+a.attr("href").substring(1)+'"]').length){
  208. click_scroll=true;
  209. $('.icemegamenu li[class^="iceMenuLiLevel"]').removeClass("hover").find(">a.iceMenuTitle").removeClass("icemega_active").removeClass('hover');
  210. a.addClass("icemega_active");
  211. if(history.pushState){
  212. history.pushState(null,null,a.attr("href"))
  213. }
  214. $scrollEl.animate({
  215. scrollTop: $('a[name="'+a.attr("href").substring(1)+'"]').offset().top-$(".scroll-to-fixed-fixed").outerHeight()
  216. },400,function(){
  217. $(this).delay(200).queue(function(b){
  218. click_scroll=false;
  219. $(this).delay(1200).queue(function(c){
  220. if(typeof $.fn.lazy=="function"){
  221. $("img.lazy").lazy({
  222. bind:"event",effect:"fadeIn",effectTime:500
  223. })
  224. }
  225. c()
  226. });
  227. b()
  228. })
  229. })
  230. }
  231. }
  232. if(window.location.href.split("#")[0]==a.attr('href')){
  233. click_scroll=true;
  234. $('.icemegamenu li[class^="iceMenuLiLevel"]').removeClass("hover").find(">a.iceMenuTitle").removeClass("icemega_active").removeClass('hover');
  235. a.addClass("icemega_active");
  236. if(history.pushState){
  237. history.pushState(null,null,'#')
  238. }
  239. $scrollEl.animate({
  240. scrollTop: 0
  241. },400,function(){
  242. $(this).delay(200).queue(function(b){
  243. click_scroll=false;
  244. $(this).delay(1200).queue(function(c){
  245. if(typeof $.fn.lazy=="function"){
  246. $("img.lazy").lazy({
  247. bind:"event",effect:"fadeIn",effectTime:500
  248. })
  249. }
  250. c()
  251. });
  252. b()
  253. })
  254. })
  255. }
  256. return false;
  257. }
  258. function change_menu_item(){
  259. if(!click_scroll){
  260. var a=$(window).scrollTop(),
  261. d="";
  262. y = $(document).height();
  263. if(!init_hash||init_hash==""){
  264. for(var b=0,c=idArray.length;b<c;b++){
  265. if($('a[name="'+idArray[b].substring(1)+'"]').length){
  266. if(a+($(window).height()-$(".scroll-to-fixed-fixed").outerHeight())/2>=$('a[name="'+idArray[b].substring(1)+'"]').offset().top && y>a+($(window).height()-$(".scroll-to-fixed-fixed").outerHeight())/2-$('a[name="'+idArray[b].substring(1)+'"]').offset().top){
  267. d=idArray[b];
  268. y=a+($(window).height()-$(".scroll-to-fixed-fixed").outerHeight())/2-$('a[name="'+idArray[b].substring(1)+'"]').offset().top
  269. }
  270. }
  271. }
  272. lastScrollTop=a;
  273. if(window.location.hash!=d&&d!=""){
  274. if(history.pushState){
  275. history.pushState(null,null,d)
  276. }
  277. $('.icemegamenu li[class^="iceMenuLiLevel"]').removeClass("hover").find(">a.iceMenuTitle").removeClass("icemega_active").removeClass('hover');
  278. $("a.iceMenuTitle[href="+d+"]").addClass("icemega_active")
  279. }
  280. if(a == 0){
  281. if(history.pushState && window.location.hash){
  282. history.pushState(null,null,'#')
  283. }
  284. $('.icemegamenu li[class^="iceMenuLiLevel"]').removeClass("hover").find(">a.iceMenuTitle").removeClass("icemega_active").removeClass('hover');
  285. if(window.location.hash){
  286. $("a.iceMenuTitle[href=\""+window.location.href+"\"]").addClass("icemega_active")
  287. }
  288. else{
  289. $("a.iceMenuTitle[href=\""+window.location.href.split('#')[0]+"\"]").addClass("icemega_active")
  290. }
  291. }
  292. }
  293. else{
  294. if($("a.iceMenuTitle[href="+init_hash+"]").length){
  295. $('.icemegamenu li[class^="iceMenuLiLevel"]').removeClass("hover").find(">a.iceMenuTitle").removeClass("icemega_active").removeClass('hover');
  296. $("a.iceMenuTitle[href="+init_hash+"]").addClass("icemega_active");
  297. }
  298. if($('a[name="'+init_hash.substring(1)+'"]').length){
  299. click_scroll=true;
  300. $scrollEl.delay(100).queue(function(z){
  301. $scrollEl.animate({
  302. scrollTop: $('a[name="'+init_hash.substring(1)+'"]').offset().top-$(".scroll-to-fixed-fixed").outerHeight()
  303. },400,function(){
  304. $(this).delay(200).queue(function(e){
  305. click_scroll=false;
  306. init_hash=false;
  307. $(this).delay(1200).queue(function(f){
  308. if(typeof $.fn.lazy=="function"){
  309. $(".lazy_container img").lazy({
  310. bind:"event",effect:"fadeIn",effectTime:500
  311. })
  312. }
  313. f()
  314. });
  315. e()
  316. })
  317. })
  318. z()
  319. })
  320. }
  321. }
  322. return false
  323. }
  324. }
  325. if($('.icemegamenu li[class^="iceMenuLiLevel"]>a.iceMenuTitle[href^="#"]').length && $('.icemegamenu li[class^="iceMenuLiLevel"]>a.iceMenuTitle[href^="#"]').attr('href')!='#'){
  326. $(window).scroll($.throttle(500,function(){change_menu_item()}));
  327. $(window).load(function(){
  328. change_menu_item();
  329. if($(this).scrollTop()>24){
  330. $("body:first").addClass("scrolled")
  331. }
  332. else{
  333. $("body:first").removeClass("scrolled")
  334. }
  335. });
  336. var idArray=[],
  337. click_scroll=false,
  338. init_hash=window.location.hash,
  339. lastScrollTop=0;
  340. $('.icemegamenu li[class^="iceMenuLiLevel"]>a.iceMenuTitle[href^="#"]').each(function(a){
  341. idArray[a]=$(this).attr("href");
  342. });
  343. }
  344. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement