PageRenderTime 59ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/MvcHoaKhoi/MvcThienThaoNguyen/Static/frontend/hoakhoi/jscript/theme-scripts.js

https://gitlab.com/thanhtv.its/hoakhoi-source
JavaScript | 375 lines | 296 code | 72 blank | 7 comment | 36 complexity | 2f5a4c7c8b7df48a2ea343df0689754a MD5 | raw file
  1. var breakingStart = true; // autostart breaking news
  2. var breakingSpeed = 40; // breaking msg speed
  3. var breakingScroll = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  4. var breakingOffset = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  5. var elementsToClone = [true, true, true, true, true, true, true, true, true, true];
  6. var elementsActive = [];
  7. var theCount = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  8. (function ($) {
  9. "use strict";
  10. var supports = (function() {
  11. var div = document.createElement('div'),
  12. vendors = 'Khtml Ms O Moz Webkit'.split(' '),
  13. len = vendors.length;
  14. return function(prop) {
  15. if ( prop in div.style ) return true;
  16. prop = prop.replace(/^[a-z]/, function(val) {
  17. return val.toUpperCase();
  18. });
  19. while(len--) {
  20. if ( vendors[len] + prop in div.style ) {
  21. return true;
  22. }
  23. }
  24. return false;
  25. };
  26. })();
  27. jQuery(window).scroll(function() {
  28. if(jQuery(".sidebar-fixed").length){
  29. if(parseInt(jQuery("#sidebar").height()) >= parseInt(jQuery(".left-content").height())){
  30. jQuery(".sidebar-fixed.is-now-fixed").removeClass("is-now-fixed").css("paddingTop", "0px");
  31. return false;
  32. }
  33. var fixedSidebar = jQuery(".sidebar-fixed"),
  34. additionalPx = (jQuery("#wpadminbar").length > 0)?32:0;
  35. if (jQuery(window).scrollTop() + 100 + additionalPx >= fixedSidebar.offset().top) {
  36. var newtop = parseInt(jQuery(window).scrollTop())-parseInt(fixedSidebar.offset().top) +111+additionalPx,
  37. v1 = parseInt(fixedSidebar.height()),
  38. v2 = parseInt(newtop)+parseInt(fixedSidebar.offset().top);
  39. if (parseInt(jQuery(".footer").offset().top) <= (v1 + v2)) {
  40. // reached end
  41. } else {
  42. if ($(window).width() > 992) {
  43. fixedSidebar.addClass("is-now-fixed").css("paddingTop", newtop + "px");
  44. }
  45. }
  46. }else{
  47. jQuery(".sidebar-fixed.is-now-fixed").removeClass("is-now-fixed").css("paddingTop", "0px");
  48. }
  49. console.log(parseInt(jQuery(window).scrollTop()) + " - " + parseInt(fixedSidebar.offset().top));
  50. }
  51. });
  52. jQuery(window).ready(function() {
  53. jQuery("body").addClass("ot-menu-ipad-enable").addClass("ot-menu-iphone-enable");
  54. function init() {
  55. var speed = 250,
  56. easing = mina.easeinout;
  57. [].slice.call ( document.querySelectorAll( 'a.image-hover[data-path-hover]' ) ).forEach( function( el ) {
  58. var s = Snap( el.querySelector( 'svg' ) ), path = s.select( 'path' ),
  59. pathConfig = {
  60. from : path.attr( 'd' ),
  61. to : el.getAttribute( 'data-path-hover' )
  62. };
  63. el.addEventListener( 'mouseenter', function() {
  64. path.animate( { 'path' : pathConfig.to }, speed, easing );
  65. } );
  66. el.addEventListener( 'mouseleave', function() {
  67. path.animate( { 'path' : pathConfig.from }, speed, easing );
  68. } );
  69. } );
  70. }
  71. function makeFixedHeader(){
  72. var element = jQuery(".header.willfix");
  73. if(element.hasClass("makefixed"))return false;
  74. element.css("height", element.children(".wrapper").height());
  75. element.addClass("makefixed");
  76. element.children("div").addClass("animated bounceInDown");
  77. }
  78. function removeFixedHeader(){
  79. var element = jQuery(".header.willfix");
  80. if(!element.hasClass("makefixed"))return false;
  81. element.css("height", "auto");
  82. element.removeClass("makefixed");
  83. element.children("div").removeClass("animated bounceInDown");
  84. }
  85. jQuery(window).resize(function() {
  86. var htop = (parseInt(jQuery(".header").offset().top+100)+parseInt(jQuery(".header").css("padding-top")));
  87. if(jQuery(window).scrollTop() >= htop){
  88. makeFixedHeader();
  89. }else{
  90. removeFixedHeader();
  91. }
  92. jQuery(".header.makefixed > .wrapper").css("left", "50%").css("margin-left", -(parseInt(jQuery(".header.makefixed > .wrapper").css("width"))/2));
  93. });
  94. jQuery(window).scroll(function() {
  95. var htop = (parseInt(jQuery(".header").offset().top+100)+parseInt(jQuery(".header").css("padding-top")));
  96. if(jQuery(window).scrollTop() >= htop){
  97. makeFixedHeader();
  98. }else{
  99. removeFixedHeader();
  100. }
  101. jQuery(".header.makefixed > .wrapper").css("left", "50%").css("margin-left", -(parseInt(jQuery(".header.makefixed > .wrapper").css("width"))/2));
  102. });
  103. jQuery("a[href='#close-alert']").click(function(){
  104. jQuery(this).parent().hide();
  105. return false;
  106. });
  107. init();
  108. if ( supports('perspective') ) {
  109. jQuery(".main-menu").addClass("transition-active");
  110. }else{
  111. jQuery(".main-menu").removeClass("transition-active");
  112. }
  113. function otdoanim(element, theway){
  114. var animel = (!element.data("anim-object"))?element:jQuery(element.data("anim-object")),
  115. animationin = (!element.data("anim-in"))?"":element.data("anim-in"),
  116. animationout = (!element.data("anim-out"))?"":element.data("anim-out");
  117. // element.css("width", element.width()).css("height", element.height());
  118. if(theway == "in"){
  119. if(element.data("anim-object") == ".header-logo a.otanimation img, .header-logo a.otanimation h1"){
  120. otdoanim(jQuery(".header-logo > strong"), "out");
  121. }
  122. animel.removeClass("animated "+animationout);
  123. animel.addClass("animated "+animationin);
  124. }else
  125. if(theway == "out"){
  126. if(element.data("anim-object") == ".header-logo a.otanimation img, .header-logo a.otanimation h1"){
  127. otdoanim(jQuery(".header-logo > strong"), "in");
  128. }
  129. animel.removeClass("animated "+animationin);
  130. animel.addClass("animated "+animationout);
  131. }
  132. }
  133. jQuery(".otanimation").mouseenter(function (){
  134. otdoanim(jQuery(this), "in");
  135. }).mouseleave(function (){
  136. otdoanim(jQuery(this), "out");
  137. });
  138. jQuery(".search-header input[type=text], .search-header input[type=search]").on("focus", function(){
  139. var elemet = jQuery(".search-header");
  140. elemet.addClass("active").siblings("ul").addClass("hidelis");
  141. }).on("blur", function(){
  142. jQuery(".search-header").removeClass("active").siblings("ul").removeClass("hidelis");
  143. });
  144. var mega_widget_height = new Array(),
  145. mega_widget_counter = 0;
  146. jQuery(".has-ot-mega-menu").mouseenter(function (){
  147. var getThisel = jQuery(this).find(".widget");
  148. mega_widget_height[mega_widget_counter] = 0;
  149. getThisel.css("height", "auto");
  150. for (var i = 0; i <= getThisel.length - 1; i++) {
  151. if(parseInt(getThisel.eq(i).height())+(parseInt(getThisel.eq(i).css("padding-top"))*2) > mega_widget_height[mega_widget_counter]){
  152. mega_widget_height[mega_widget_counter] = parseInt(getThisel.eq(i).height())+(parseInt(getThisel.eq(i).css("padding-top"))*2);
  153. }
  154. }
  155. getThisel.css("height", mega_widget_height[mega_widget_counter]+"px");
  156. mega_widget_counter += 1;
  157. });
  158. jQuery(".ot-tabbed h3").click(function(){
  159. var element = jQuery(this);
  160. element.addClass("active").siblings(".active").removeClass("active");
  161. element.parent().siblings("div").eq(element.index()).addClass("active").siblings(".active").removeClass("active");
  162. return false;
  163. });
  164. // Breaking News Scroller
  165. jQuery(".breaking-news").mouseenter(function () {
  166. var thisindex = jQuery(this).attr("rel");
  167. clearTimeout(elementsActive[thisindex]);
  168. }).mouseleave(function () {
  169. var thisindex = jQuery(this).attr("rel");
  170. elementsActive[thisindex] = false;
  171. });
  172. start();
  173. // Accordion blocks
  174. jQuery(".accordion > div > a").click(function () {
  175. var thisel = jQuery(this).parent();
  176. if (thisel.hasClass("active")) {
  177. thisel.removeClass("active").children("div").animate({
  178. "height": "toggle",
  179. "opacity": "toggle",
  180. "padding-top": "toggle"
  181. }, 300);
  182. return false;
  183. }
  184. // thisel.siblings("div").removeClass("active");
  185. thisel.siblings("div").each(function () {
  186. var tz = jQuery(this);
  187. if (tz.hasClass("active")) {
  188. tz.removeClass("active").children("div").animate({
  189. "height": "toggle",
  190. "opacity": "toggle",
  191. "padding-top": "toggle"
  192. }, 300);
  193. }
  194. });
  195. // thisel.addClass("active");
  196. thisel.addClass("active").children("div").animate({
  197. "height": "toggle",
  198. "opacity": "toggle",
  199. "padding-top": "toggle"
  200. }, 300);
  201. return false;
  202. });
  203. // Tabbed blocks
  204. jQuery(".short-tabs").each(function () {
  205. var thisel = jQuery(this);
  206. thisel.children("div").eq(0).addClass("active");
  207. thisel.children("ul").children("li").eq(0).addClass("active");
  208. });
  209. jQuery(".short-tabs > ul > li a").click(function () {
  210. var thisel = jQuery(this).parent();
  211. thisel.siblings(".active").removeClass("active");
  212. thisel.addClass("active");
  213. thisel.parent().siblings("div.active").removeClass("active");
  214. thisel.parent().siblings("div").eq(thisel.index()).addClass("active");
  215. return false;
  216. });
  217. jQuery(".lightbox").click(function () {
  218. jQuery(".lightbox").css('overflow', 'hidden');
  219. jQuery("body").css('overflow', 'auto');
  220. jQuery(".lightbox .lightcontent").fadeOut('fast');
  221. jQuery(".lightbox").fadeOut('slow');
  222. }).children().click(function (e) {
  223. return false;
  224. });
  225. jQuery(".widget .photo-gallery-widget .gallery-navi a").click(function(){
  226. var thisel = jQuery(this),
  227. imageel = thisel.parent().siblings(".gallery-change").children("a.active");
  228. if(thisel.attr("href") == "#gal-left") {
  229. imageel.parent().find("img").removeClass("bounceInLeft").removeClass("bounceOutRight").removeClass("bounceInRight").removeClass("bounceOutLeft");
  230. imageel.prev().addClass("active").children("img").addClass("animated bounceInLeft").parent().siblings("a.active").removeClass("active").children("img").addClass("animated bounceOutRight");
  231. }else
  232. if(thisel.attr("href") == "#gal-right") {
  233. imageel.parent().find("img").removeClass("bounceInLeft").removeClass("bounceOutRight").removeClass("bounceInRight").removeClass("bounceOutLeft");
  234. imageel.next().addClass("active").children("img").addClass("animated bounceInRight").parent().siblings("a.active").removeClass("active").children("img").addClass("animated bounceOutLeft");
  235. }
  236. return false;
  237. });
  238. jQuery(".home-featured-article .home-featured-menu a").click(function(){
  239. var thisel = jQuery(this);
  240. thisel.addClass("active").siblings("a").removeClass("active").parent().parent().children(".home-featured-item").eq(thisel.index()).addClass("active").siblings(".home-featured-item").removeClass("active");
  241. return false;
  242. });
  243. });
  244. })(jQuery);
  245. function refreshMegamenu() {
  246. var getThisel = jQuery(".has-ot-mega-menu").find(".widget");
  247. mega_widget_height = 0;
  248. getThisel.css("height", "auto");
  249. for (var i = 0; i <= getThisel.length - 1; i++) {
  250. if(parseInt(getThisel.eq(i).height())+(parseInt(getThisel.eq(i).css("padding-top"))*2) > mega_widget_height){
  251. mega_widget_height = parseInt(getThisel.eq(i).height())+(parseInt(getThisel.eq(i).css("padding-top"))*2);
  252. }
  253. }
  254. getThisel.css("height", mega_widget_height+"px");
  255. }
  256. function start() {
  257. var z = 0;
  258. jQuery('.breaking-block ul').each(function () {
  259. var thisitem = jQuery(this), thisindex = z;
  260. z = z + 1;
  261. if (thisitem.find("li").size() > 0) {
  262. if (!breakingStart) { return false; }
  263. var theBreakingMargin = parseInt(thisitem.find("li").css("margin-right")),
  264. theBreakingWidth = parseInt(thisitem.parent().css("width")),
  265. itemul = thisitem,
  266. itemtemp = 0,
  267. items = itemul.find("li").each(function(){
  268. itemtemp = itemtemp+parseInt(jQuery(this).width()) + parseInt(jQuery(this).css("padding-right")) + parseInt(jQuery(this).css("margin-right"));
  269. });
  270. theCount[thisindex] = (itemtemp / 2);
  271. if (elementsToClone[thisindex]) {
  272. jQuery(this).parent().parent().addClass("isscrolling");
  273. jQuery('.breaking-block').eq(thisindex).parent().attr("rel", thisindex);
  274. thisitem.find("li").clone().appendTo(this);
  275. elementsToClone[thisindex] = false;
  276. }
  277. var theNumber = theCount[thisindex] + breakingOffset[thisindex];
  278. if (Math.abs(theNumber) <= (Math.abs(breakingScroll[thisindex]))) {
  279. cloneBreakingLine(thisindex);
  280. }
  281. if (!elementsActive[thisindex]) {
  282. elementsActive[thisindex] = setInterval(function () {
  283. beginScrolling(thisitem, thisindex);
  284. }, breakingSpeed);
  285. }
  286. }
  287. });
  288. setTimeout("start()", breakingSpeed);
  289. }
  290. function beginScrolling(thisitem, thisindex) {
  291. breakingScroll[thisindex] = breakingScroll[thisindex] - 1;
  292. thisitem.css("left", breakingScroll[thisindex] + 'px');
  293. }
  294. function cloneBreakingLine(thisindex) {
  295. breakingScroll[thisindex] = 0;
  296. jQuery('.breaking-block').eq(thisindex).find('ul').css("left", "0px");
  297. }
  298. function lightboxclose() {
  299. jQuery(".lightbox").css('overflow', 'hidden');
  300. jQuery(".lightbox .lightcontent").fadeOut('fast');
  301. jQuery(".lightbox").fadeOut('slow');
  302. jQuery("body").css('overflow', 'auto');
  303. }