1jQuery.noConflict(); 2 3function getCookie(name) { 4 var matches = document.cookie.match(new RegExp( 5 "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" 6 )); 7 return matches ? decodeURIComponent(matches[1]) : undefined; 8} 9 10function setCookie(name, value, options) { 11 options = options || {}; 12 13 var expires = options.expires; 14 15 if (typeof expires == "number" && expires) { 16 var d = new Date(); 17 d.setTime(d.getTime() + expires * 1000); 18 expires = options.expires = d; 19 } 20 if (expires && expires.toUTCString) { 21 options.expires = expires.toUTCString(); 22 } 23 24 value = encodeURIComponent(value); 25 26 var updatedCookie = name + "=" + value; 27 28 for (var propName in options) { 29 updatedCookie += "; " + propName; 30 var propValue = options[propName]; 31 if (propValue !== true) { 32 updatedCookie += "=" + propValue; 33 } 34 } 35 36 document.cookie = updatedCookie; 37} 38 39function deleteCookie(name, options) { 40 options = options || {}; 41 options['expires'] = -1; 42 setCookie(name, "", options); 43} 44 45function logging(id) 46{ 47 var i = new Image(); 48 i.src = document.location.protocol + "//www.giveawayoftheday.com/log.php?id="+id+"&r=" + Math.round(100000 * Math.random()); 49} 50 51function isChrome() 52{ 53 return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); 54} 55 56function isChromePushSupport() 57{ 58 return isChrome() && 'serviceWorker' in navigator; 59} 60 61function detectPrivateMode(cb) { 62 var db, 63 on = cb.bind(null, true), 64 off = cb.bind(null, false); 65 66 function tryls() { 67 try { 68 localStorage.length ? off() : (localStorage.x = 1, localStorage.removeItem("x"), off()); 69 } catch (e) { 70 // Safari only enables cookie in private mode 71 // if cookie is disabled then all client side storage is disabled 72 // if all client side storage is disabled, then there is no point 73 // in using private mode 74 navigator.cookieEnabled ? on() : off(); 75 } 76 } 77 78 // Blink (chrome & opera) 79 window.webkitRequestFileSystem ? webkitRequestFileSystem(0, 0, off, on) 80 // FF 81 : "MozAppearance" in document.documentElement.style ? (db = indexedDB.open("test"), db.onerror = on, db.onsuccess = off) 82 // Safari 83 : /constructor/i.test(window.HTMLElement) || window.safari ? tryls() 84 // IE10+ & edge 85 : !window.indexedDB && (window.PointerEvent || window.MSPointerEvent) ? on() 86 // Rest 87 : off() 88} 89 90function detectNotificationSupported(callback) 91{ 92 if ('safari' in window && 'pushNotification' in window.safari) { 93 callback(true, 'safari'); 94 } else { 95 var is_exist_notif = ( 96 'serviceWorker' in navigator && 97 'PushManager' in window && 98 'Notification' in window && 99 'fetch' in window && 100 ServiceWorkerRegistration.prototype.hasOwnProperty('showNotification') && 101 PushSubscription.prototype.hasOwnProperty('getKey') 102 ); 103 104 if (!is_exist_notif) { 105 callback(false); 106 } else { 107 // not support in private mode 108 detectPrivateMode(function(isPrivate) { 109 callback(!isPrivate, 'firebase'); 110 }); 111 } 112 } 113} 114 115function getScripts(scripts, callback) { 116 var progress = 0; 117 scripts.forEach(function(script) { 118 jQuery.getScript(script, function () { 119 if (++progress == scripts.length) callback(); 120 }); 121 }); 122} 123 124var common_actions = (function($) { 125 return { 126 conf: { 127 search_url: '', 128 is_ie9: false, 129 twitter_acc: 'https://twitter.com/GiveawayotDay', 130 fb_app_id: '', 131 project: '', 132 locale: '', 133 safari_push: { 134 enabled: 0, 135 enabled_subprojects: 0, 136 website_uid: '', 137 url: '', 138 token_url: '' 139 } 140 }, 141 142 init: function(settings) { 143 $.extend(true, this.conf, settings); 144 145 $('input[placeholder], textarea[placeholder]').placeholder(); 146 if(Modernizr.mq('only all')) { 147 $('.header_side').clone().attr('id', 'header_side2').addClass((this.conf.is_ie9 ? 'closed ' : '') + 'st-menu st-effect-1').appendTo('.st-container'); 148 } 149 150 this.bindActions(); 151 }, 152 153 bindActions: function() { 154 var that = this; 155 //that.rowResize(); 156 //$(window).on('resize',function(e) {that.rowResize(e);}); 157 $(window).on('resize',function(e) {that.subResize(e);}); 158 $(function(e) {that.subResize(e);}); 159 $('.header_search .button').on('click', function(e) {that.showSearchInput(e)}); 160 $(document).on('mouseup', function (e) {that.hideSearchInput(e)}); 161 $(document).on('keypress', function(e) {that.runSearch(e)}); 162 $(document).on('click', '.curr_lang', function(e) {that.showLanguageMenu(e)}); 163 $(document).on('mouseup', function (e) {that.hideLanguageMenu(e)}); 164 $('.like_block').on('mousemove', function(e){that.showSocialPlusoneButtons(e)}); 165 $('.header .header_nav_trig').on('click', function(e){that.openSideMenu(e)}); 166 $(document).on('click', '.st-menu .header_nav_trig', function(e){that.closeSideMenu(e)}); 167 $('.language').on('change', function(e){that.selectLanguage(e)}
167); 168 169 $('#topMessageClose').on('click', function(e) { 170 $('#topMessageBanner').hide(); 171 return false; 172 }); 173 // if (that.conf.safari_push.enabled && 'safari' in window && 'pushNotification' in window.safari) { 174 // that.getSafariNotificationPermission(); 175 // } 176 }, 177 178 179 180 181 getSafariNotificationPermission: function () { 182 var permissionData = window.safari.pushNotification.permission(this.conf.safari_push.website_uid); 183 this.checkSafariNotificationPermission(permissionData); 184 }, 185 186 checkSafariNotificationPermission: function(permissionData) { 187 var that = this; 188 if (permissionData.permission === 'default') { 189 var webservice_url = that.conf.safari_push.url.split('?')[0]; 190 window.safari.pushNotification.requestPermission( 191 webservice_url, 192 that.conf.safari_push.website_uid, 193 {locale: that.conf.locale}, 194 that.checkSafariNotificationPermission 195 ); 196 } else if (permissionData.permission === 'denied') { 197 console.log('safari_push: denied'); 198 } else if (permissionData.permission === 'granted') { 199 if (that.conf.safari_push.enabled_subprojects) { 200 $.ajax({
201 type: 'POST', 202 url: that.conf.safari_push.token_url, 203 data: {token: permissionData.deviceToken, locale: that.conf.locale}, 204 dataType: 'json' 205 }).done(function (resp) { 206 if (!resp.status) { 207 console.log('Not registered for this pro.'); 208 } else { 209 console.log('User already subscribed.'); 210 } 211 }); 212 } 213 } 214 }, 215 216 showSearchInput: function(e) { 217 var $target = $(e.target); 218 var par = $target.parents('.header_search'); 219 if (!par.hasClass('active')) { 220 par.addClass('active'); 221 var search_width = ''; 222 if (this.conf.project!='win') { 223 if (Modernizr.mq('(max-width: 1036px)')) { 224 search_width = $(document).width() - 60 - 63; 225 $('.inputbox_wrap').css('width', search_width); 226 $('.header_logo').hide(); 227 } 228 } 229 else 230 if (Modernizr.mq('(min-width: 720px) and (max-width: 1036px)')) { 231 search_width = Math.round($(document).width()/2) - 135 - 80; 232 $('.inputbox_wrap').css('width', search_width); 233 } else if (Modernizr.mq('(max-width: 720px)')) { 234 search_width = $(document).width() - 60 - 63; 235 $('.inputbox_wrap').css('width', search_width); 236 $('.header_logo').hide(); 237 } 238 $('.header_search .inputbox').focus(); 239 } 240 }, 241 242 hideSearchInput: function(e) { 243 var container = $('.header_search .inputbox, .curr_lang, .st-menu'); 244 if (!container.is(e.target) && container.has(e.target).length === 0) { 245 $('.header_search').removeClass('active'); 246 $('.inputbox_wrap').css('width', ''); 247 $('.header_logo:hidden').show(); 248 if (this.conf.is_ie9) 249 { 250 $('#header_side2').removeClass('opened'); 251 $('#header_side2').addClass('closed'); 252 } 253 $('.st-container').removeClass('st-menu-open'); 254 $('html').removeClass('overflow'); 255 } 256 }, 257 258 hideLanguageMenu: function(e) { 259 var container = $('.languages, .curr_lang'); 260 if (!container.is(e.target) && container.has(e.target).length === 0) { 261 $('.curr_lang').removeClass('active'); 262 $('.languages').slideUp(300); 263 } 264 }, 265 266 runSearch: function(e) { 267 var that = this; 268 var $target = $(e.target); 269 var search_str = $.trim($target.val()); 270 if(e.which == 13 && search_str && $target.hasClass('inputbox') && $('.header_search').hasClass('active')) { 271 var s_url = that.conf.search_url; 272 s_url += (s_url.split('?')[1] ? '&' : '?') + 's=' + search_str; 273 window.location.replace(s_url); 274 } 275 }, 276 277 showLanguageMenu: function(e) { 278 $(e.currentTarget).toggleClass('active').next('.languages').slideToggle(300); 279 }, 280 281 showSocialPlusoneButtons: function(e) { 282 var $target = $(e.target); 283 $target.hide(); 284 285 var $parent = $target.parent(); 286 if($parent.find('.like_block_rendered').length) { 287 return; 288 } 289 290 var $buttons = $('<ul></ul>'); 291 $buttons.addClass('like_block_rendered'); 292 $target.after($buttons); 293 294 if ($buttons.children().length == 0) { 295 var $li_fb = $('<li></li>'); 296 $li_fb.html('<div id="fb-root"></div><div class="fb-like" data-href="https://www.facebook.com/giveawayotday/" data-layout="button" data-action="like" data-show-faces="false" data-share="false"></div>'); 297 $buttons.append($li_fb); 298 downloadShareForm.fbInit(this.conf.fb_app_id); 299 300 var $li_tw = $('<li></li>'); 301 $li_tw.html('<a href="https://twitter.com/GiveawayotDay" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow</a>'); 302 $buttons.append($li_tw); 303 if(typeof (twttr) != 'undefined') { 304 twttr.widgets.load(); 305 } else { 306 $.getScript("//platform.twitter.com/widgets.js"); 307 } 308 } 309 }, 310 311 showSocialFbLikeButton: function(e){
312 313 var current_url = 'https://www.facebook.com/giveawayotday/'; 314 e.target.style.display = 'none'; 315 var parent = e.target.parentNode; 316 317 if (!parent || parent.getElementsByClassName('prog_soc').length) 318 return; 319 parent.innerHTML = ''; 320 var span = document.createElement('span'); 321 span.className = 'like_link opened'; 322 parent.appendChild(span); 323 324 var iframe = document.createElement('iframe'); 325 iframe.src = 'https://www.facebook.com/plugins/like.php?locale=en_US&href=' + encodeURIComponent(current_url) + '&send=false&layout=button&width=86&show_faces=false&action=like&colorscheme=light&font&height=20'; 326 iframe.style.border = 'none'; 327 iframe.style.overflow = 'hidden'; 328 iframe.style.width = '49px'; 329 iframe.style.height = '20px'; 330 iframe.setAttribute('allowtransparency', 'true'); 331 span.appendChild(iframe); 332 }, 333 334 showSocialTwLikeButton: function(e){ 335 336 var current_url = 'https://www.facebook.com/giveawayotday/'; 337 e.target.style.display = 'none'; 338 var parent = e.target.parentNode; 339 340 if (!parent || parent.getElementsByClassName('twitter-follow-button').length) 341 return; 342 343 parent.innerHTML = '<a href="' + this.conf.twitter_acc + '" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false"></a>';; 344 if(typeof (twttr) != 'undefined') { 345 twttr.widgets.load(); 346 } else { 347 $.getScript("//platform.twitter.com/widgets.js"); 348 } 349 }, 350 351 rowResize: function() { 352 var $prev = $('.col1.prev'); 353 var $offers = $('.col2.offers'); 354 if($prev.length && $offers.length) { 355 var height = ''; 356 //$prev.css('height', height); 357 //$offers.css('height', height); 358 if(Modernizr.mq('(min-width: 1037px)')) { 359 height = Math.max($prev.outerHeight(), $offers.outerHeight()); 360 } 361 //$prev.css('height', height); 362 //$offers.css('height', height); 363 } 364 //var $max_height = Math.max($('.right_clmn').outerHeight(), $('.right_col').outerHeight(), $('.left_col').outerHeight()); 365 //$('.right_clmn').css('height', $max_height); 366 ////$('.right_col').css('height', $max_height); 367 //$('.left_col').css('height', $max_height); 368 369 /*var $h1_1 = $('.banner'), 370 $h1_2 = $('.top'), 371 $h2 = $('.soft'); 372 373 $('.soft, .top').css('min-height', 0); 374 if ($(window).width() > 1420){ 375 if ($h1_1.outerHeight() + $h1_2.outerHeight() > $h2.outerHeight()) { 376 $h2.css('min-height', $h1_1.outerHeight() + $h1_2.outerHeight()); 377 } else { 378 $h1_2.css('min-height', $h2.outerHeight() - $h1_1.outerHeight()); 379 } 380 } else if ($(window).width() < 1421 && $(window).width() > 1020){ 381 if ($h1_2.outerHeight() > $h2.outerHeight()) { 382 $h2.css('min-height', $h1_2.outerHeight()); 383 } else { 384 $h1_2.css('min-height', $h2.outerHeight()); 385 } 386 } else{ 387 $('.soft, .top').css('min-height',0); 388 }*/ 389 }, 390 391 subResize: function(e) { 392 if(Modernizr.mq('(max-width: 720px)')) 393 $('#new-sub').removeClass('subs-col col2-2'); 394 else 395 $('#new-sub').addClass('subs-col col2-2'); 396 }, 397 398 openSideMenu: function(e) { 399 if (this.conf.is_ie9) 400 { 401 $('#header_side2').removeClass('closed'); 402 $('#header_side2').addClass('opened'); 403 } 404 $('.st-container').addClass('st-effect-1 st-menu-open'); 405 $('html').addClass('overflow'); 406 }, 407 408 closeSideMenu: function(e) { 409 if (this.conf.is_ie9) 410 { 411 $('#header_side2').removeClass('opened'); 412 $('#header_side2').addClass('closed'); 413 } 414 $('.st-container').removeClass('st-menu-open'); 415 $('html').removeClass('overflow'); 416 }, 417 418 selectLanguage: function (e) { 419 location.href = $(e.target).val(); 420 }, 421 422 defineFooterGiveawaysColumnsHeight: function () { 423 var max_height = ''; 424 var $right = $('.right_clmn'); 425 var $left = $('.left_col'); 426 var $middle = $('.right_col'); 427 if (Modernizr.mq('(min-width: 1436px)')) { 428 max_height = Math.max($right.outerHeight(), $middle.outerHeight(), $left.outerHeight()); 429 $right.css('height', max_height); 430 } else if (Modernizr.mq('(min-width: 720px)')) { 431 max_height = Math.max($middle.outerHeight(), $left.outerHeight()); 432 $right.css('height', ''); 433 } 434 $middle.css('height', max_height); 435 $left.css('height', max_height); 436 } 437 }; 438})(jQuery); 439 440var post_actions = (function($){ 441 return { 442 conf: { 443 post_id: 0, 444 is_active: 0, 445 is_competition: 0, 446 read_more: 'Read more', 447 448 desc_more: { 449 cont: '.prog_descr', 450 btn: '.show_more a', 451 class: 'content_hidden' 452 }, 453 vote: { 454 cont: '.wrap_votes', 455 positive: 'positive', 456 negative: 'negative', 457 send_url: '', 458 negative_form_cont: '[data-remodal-id=modal]', 459 negative_form: false 460 }, 461 negative_form: { 462 holder: '[data-remodal-id=modal]', 463 content: '#remodal-content', 464 url: '' 465 }, 466 last_comments: { 467 cont: '.wrap_last_comments', 468 send_url: '' 469 }, 470 firebase_push: { 471 enabled: 0, 472 hash: '', 473 url: '' 474 } 475 }, 476 477 init: function(settings) { 478 $.extend(true, this.conf, settings); 479 480 this.resizePostBlock(); 481 this.updateRequirements(); 482 this.bindActions(); 483 }, 484 485 bindActions: function() { 486 var that = this; 487 488 if(!$(that.conf.vote.cont).hasClass('disabled')) { 489 $(that.conf.vote.cont).on('click', 'span', function (e) { 490 e.preventDefault(); 491 that.addVote(e) 492 }); 493 } 494 495 if(!$(that.conf.last_comments.cont).hasClass('disabled')) { 496 $(that.conf.last_comments.cont).on('click', '.last_comments', function (e) { 497 that.showOtherComments(e); 498 }); 499 if (location.hash.indexOf('comment-') !== -1) { 500 $(that.conf.last_comments.cont).find('.last_comments').click(); 501 } 502 } 503 504 $(document).on('confirmation', '.remodal', function (e) {that.validateNegativeVoteForm(e)}); 505 $(window).on('resize', function(e) {that.resizePostBlock(e); that.updateRequirements()}); 506 507 508 509 var $desc = $('.competition-content .prog_descr:first'); 510 var descr_height = $desc.prop('scrollHeight'); 511 if (this.conf.is_active && descr_height >= 445) { 512 $desc.addClass(this.conf.desc_more.class).append('<div class="show_more"><hr><a href="#">
512' + this.conf.read_more + '<i></i></a></div>'); 513 } 514 515 $(that.conf.desc_more.btn).on('click', function(e){that.showFullDescription(e)}); 516 517 $(".join-competition_btn").click(function(){ 518 $.scrollTo('#gleam-widget', {duration: 300}); 519 return false; 520 }); 521 522 $.localScroll({duration:300}); 523 524 detectNotificationSupported(function (status, type) { 525 if (status && type == 'firebase') { 526 that.initFirebasePush(); 527 } 528 }); 529 }, 530 531 initFirebasePush: function() { 532 if (!this.conf.firebase_push.enabled) { 533 return false; 534 } 535 var that = this; 536 537 $.getScript('https://www.gstatic.com/firebasejs/6.6.2/firebase-app.js', function () { 538 $.getScript('https://www.gstatic.com/firebasejs/6.6.2/firebase-messaging.js', function () { 539 firebase.initializeApp({ 540 messagingSenderId: '691824957021' 541 }); 542 543 var messaging = firebase.messaging(); 544 that.conf.firebase_push.messaging = messaging; 545 546 messaging.onMessage(function (payload) { 547 console.log('Message received. ', payload); 548 549 navigator.serviceWorker.getRegistration('/firebase-cloud-messaging-push-scope').then(function (registration) { 550 payload.notification.data = payload.notification; 551 return registration.showNotification(payload.notification.title, payload.notification); 552 }); 553 }); 554 555 messaging.onTokenRefresh(function () { 556 messaging.getToken() 557 .then(function (refreshedToken) { 558 that.setTokenSentToServer(false); 559 that.sendTokenToServer(refreshedToken, 'firebase'); 560 }) 561 .catch(function (error) { 562 console.warn('Unable to retrieve refreshed token.', error); 563 }); 564 }); 565 }); 566 }); 567 }, 568 569 subscribeSafari: function() { 570 var permissionData = window.safari.pushNotification.permission(common_actions.conf.safari_push.website_uid); 571 this.subscribeSafariCheck(permissionData); 572 }, 573 574 subscribeSafariCheck: function (permissionData) { 575 var that = this; 576 if (permissionData.permission === 'default') { 577 console.log('safari_push: default'); 578 var webservice_url = common_actions.conf.safari_push.url.split('?')[0]; 579 window.safari.pushNotification.requestPermission( 580 webservice_url, 581 common_actions.conf.safari_push.website_uid, 582 {locale: common_actions.conf.locale}, 583 that.subscribeSafariCheck 584 ); 585 } else if (permissionData.permission === 'denied') { 586 console.log('safari_push: denied'); 587 } else if (permissionData.permission === 'granted') { 588 console.log('safari_push: ok'); 589 if (permissionData.deviceToken) { 590 $('.notification-dwn').html('The link has been sent to you. You\'ll get it just in a few seconds.'); 591 that.sendTokenToServer(permissionData.deviceToken, 'safari'); 592 } 593 } 594 }, 595 596 subscribe: function() { 597 var that = this; 598 var messaging = that.conf.firebase_push.messaging; 599 console.log('subs...'); 600 logging(7127); 601 messaging.requestPermission() 602 .then(function () { 603 messaging.getToken() 604 .then(function (currentToken) { 605 console.log(currentToken); 606 607 if (currentToken) { 608 $('.notification-dwn').html('The link has been sent to you. You\'ll get it just in a few seconds.'); 609 logging(7128); 610 that.sendTokenToServer(currentToken, 'firebase'); 611 } else { 612 console.warn('Unable to get token.'); 613 that.setTokenSentToServer(false, that.conf.post_id); 614 } 615 }) 616 .catch(function (err) { 617 console.warn('An error occurred while retrieving token. ', err); 618 that.setTokenSentToServer(false, that.conf.post_id); 619 }); 620 }) 621 .catch(function (err) { 622 console.warn('Unable to get permission to notify.', err); 623 }); 624 }, 625 626 sendTokenToServer: function(currentToken, type) { 627 var that = this; 628 if (!that.isTokenSentToServer(currentToken, that.conf.post_id)) {
629 console.log('Send token to server...'); 630 631 jQuery.post(that.conf.firebase_push.url, { 632 token: currentToken, 633 browser: type, 634 hash: that.conf.firebase_push.hash, 635 pid: that.conf.post_id 636 }); 637 638 that.setTokenSentToServer(currentToken, that.conf.post_id); 639 } else { 640 console.log('Token already sended.'); 641 } 642 }, 643 644 isTokenSentToServer: function(currentToken, post_id) { 645 if (window.localStorage.getItem('sentFirebaseMessagingToken2') != currentToken) { 646 return false; 647 } 648 649 var ids = window.localStorage.getItem('sentFirebaseMessagingIds2'); 650 if (ids) { 651 ids = JSON.parse(ids); 652 if (ids.indexOf(post_id) !== -1) { 653 return true; 654 } 655 } 656 657 return false; 658 }, 659 660 setTokenSentToServer: function(currentToken, post_id) { 661 window.localStorage.setItem( 662 'sentFirebaseMessagingToken2', 663 currentToken ? currentToken : '' 664 ); 665 666 var ids = window.localStorage.getItem('sentFirebaseMessagingIds2'); 667 if (ids) { 668 ids = JSON.parse(ids); 669 if (ids.indexOf(post_id) === -1) { 670 ids.push(post_id); 671 } 672 } else { 673 ids = [post_id]; 674 } 675 ids = JSON.stringify(ids); 676 window.localStorage.setItem('sentFirebaseMessagingIds2', ids); 677 }, 678 679 addVote: function(e) { 680 var that = this; 681 var $target = $(e.target); 682 if ($target.hasClass(that.conf.vote.positive)) { 683 that.addPositiveVote(); 684 } else if($target.hasClass(that.conf.vote.negative)) { 685 that.addNegativeVote(); 686 } 687 }, 688 689 addPositiveVote: function() { 690 var that = this; 691 var data = { 692 post_id:that.conf.post_id, 693 type:'positive' 694 }; 695 that.sendVote(data).done(function (resp) { 696 if (!resp.status) { 697 alert(resp.msg); 698 } else { 699 $(that.conf.vote.cont + ' .'+that.conf.vote.positive).html(resp.thumber_positive); 700 comments_actions.showThanksText(); 701 } 702 $(that.conf.vote.cont).off('click', 'span'); 703 $(that.conf.vote.cont).addClass('disabled'); 704 }); 705 }, 706 707 addNegativeVote: function(e) { 708 var that = this; 709 that.getNegativeForm(); 710 }, 711 712 getNegativeForm: function() { 713 var that = this; 714 if($(that.conf.negative_form.content).is(':empty')) { 715 $.get(that.conf.negative_form.url, function(data) { 716 $(that.conf.negative_form.content).html(data); 717 718 // Remove question v5 for competition 719 if (that.conf.is_competition) { 720 $('#v5').parent().remove(); 721 } 722 }); 723 } 724 this.conf.negative_form.obj = $(that.conf.negative_form.holder).remodal({hashTracking: false, closeOnConfirm: false}); 725 this.conf.negative_form.obj.open(); 726 }, 727 728 sendVote: function(data) { 729 return $.ajax({ 730 type: 'POST', 731 url: this.conf.vote.send_url, 732 data: data, 733 dataType: 'json' 734 }); 735 }, 736 737 validateNegativeVoteForm: function(e) { 738 var checkedElement = $('input[name=reasons]:checked'); 739 var error_text = ''; 740 if (!$("#other_reason").val()) { 741 error_text = this.conf.error_no_description_text; 742 $('#other_reason').addClass('error'); 743 $('#other_reason').on('keydown', function(e){$(this).removeClass('error');}); 744 } 745 if (!checkedElement.length) { 746 error_text = this.conf.error_no_reason_text; 747 } 748 if (error_text) { 749 $('#votedown_err').html(error_text); 750 $('#votedown_err').show(); 751 return false; 752 } 753 754 this.confirmNegativeVoteForm(); 755 756 return false; 757 }, 758 759 confirmNegativeVoteForm: function() { 760 var that = this; 761 $('#mess').html(''); 762 var checked_reason = $("input[name='reasons']:checked").val(); 763 764 var data = { 765 post_id: that.conf.post_id, 766 type: 'negative', 767 reason: checked_reason, 768 comment: $("#other_reason").val() 769 }; 770 that.sendVote(data).done(function (resp) { 771 if (!resp.status) { 772 alert(resp.msg); 773 } else { 774 $(that.conf.vote.cont + ' .'+that.conf.vote.positive).html(resp.thumber_positive); 775 } 776 that.conf.negative_form.obj.close(); 777 $(that.conf.vote.cont).off('click', 'span'); 778 $(that.conf.vote.cont).addClass('disabled'); 779 }); 780 }, 781 782 showOtherComments: function(e) { 783 e.preventDefault(); 784 var that = this; 785 $('#comments_loading').show(); 786 787 var data = { 788 post_id: that.conf.post_id 789 }; 790 791 return $.ajax({
792 type: 'GET', 793 url: that.conf.last_comments.send_url, 794 data: data, 795 dataType: 'json' 796 }).done(function (resp) { 797 if (!resp.status) { 798 alert(resp.msg); 799 } else { 800 $('#comments_loading').hide(); 801 $(that.conf.last_comments.cont).html(resp.comments); 802 that.resizePostBlock(); 803 804 if (location.hash.indexOf('comment-') !== -1) { 805 setTimeout(function () { 806 $.scrollTo(location.hash); 807 }, 50); 808 } 809 } 810 }); 811 }, 812 813 recalculateTimerParams: function() { 814 if(!this.conf.is_active) 815 return; 816 817 var $timer = $('.timer'); 818 var timer_height = $timer.outerHeight(); 819 if (timer_height > 150) { 820 var style = '<style>.timer .left:before {border-top-width: '+Math.round(timer_height/2)+'px; border-bottom-width: '+Math.round(timer_height/2)+'px;}</style>' 821 $('html > head').append(style); 822 } 823 }, 824 825 updateRequirements: function() { 826 if (this.conf.is_active) 827 return; 828 829 if (Modernizr.mq('(min-width: 1036px) and (max-width: 1436px)')) { 830 var cgb_top = 0; 831 if ($('.cgb_wrapper').length) { 832 cgb_top = $('.cgb_wrapper').outerHeight()+20; 833 } 834 $(".requirements").css({top: $('.download').outerHeight() + cgb_top + 20}); 835 } 836 else 837 $(".requirements").removeAttr('style'); 838 }, 839 840 resizePostBlock: function(e) { 841 if(this.conf.is_active) { 842 var padding_top = $('.requirements').outerHeight(); 843 844 if ($('.cgb_wrapper').length) { 845 padding_top = padding_top + $('.cgb_wrapper').outerHeight(); 846 } 847 848 if(padding_top) { 849 if(!Modernizr.mq('(min-width: 1036px)')) { 850 padding_top = ''; 851 } 852 $('.right_col').css('padding-top', padding_top); 853 } 854 //this.recalculateTimerParams(); 855 } else { 856 var margin_top = $('.requirements').outerHeight() + $('.download').outerHeight() + 20; 857 if ($('.cgb_wrapper').length) { 858 margin_top = margin_top + $('.cgb_wrapper').outerHeight()+20; 859 } 860 if(!Modernizr.mq('(min-width: 1036px)')) { 861 margin_top = ''; 862 } 863 $('.offers').css('margin-top', margin_top); 864 } 865 /*var $comments_cont = $('#comment_conteiner'); 866 var $comments = $('#comments'); 867 var $softupdates_cont = $('#updates_conteiner'); 868 var cont_height = Math.max($comments.outerHeight(), $softupdates_cont.outerHeight()); 869 $comments_cont.height(cont_height); 870 $softupdates_cont.height(cont_height); 871 872 var doc_width = $(document).width();*/ 873 //Featured titles 874 //if (doc_width > 720) { 875 // var $featured_blocks = $('.wrap_items .prog_item'); 876 // var featured_blocks_h = $featured_blocks.map(function() { return $(this).outerHeight(); }).get(); 877 // $featured_blocks.css('height', Math.max.apply(null, featured_blocks_h)); 878 //} 879 //Show/hide fake featured. 880 //if (doc_width > 1418) 881 // $('.prog_item_empty').show(); 882 //else 883 // $('.prog_item_empty').hide(); 884 885 //Description 886 //if (doc_width > 1036 && doc_width < 1436) { 887 // var instruction_h = $('.instruction').length > 0 ? $('.instruction').outerHeight() : $('.download').outerHeight(); 888 // var desc_height = $('.timer').outerHeight() + instruction_h + $('.requirements').outerHeight() - $('.ads_wrap').outerHeight(); 889 // /* console.log('timer - ' + jQuery('.timer').outerHeight() ); 890 // console.log('instruction - ' + jQuery('.instruction').outerHeight() ); 891 // console.log('download - ' + jQuery('.download').outerHeight() ); 892 // console.log('requirements - ' + jQuery('.requirements').outerHeight() );
893 // console.log('ads_wrap - ' + jQuery('.ads_wrap').outerHeight() ); 894 // console.log('desc_height - ' + desc_height); 895 // console.log('---------------------------------------------');*/ 896 // $('.prog_descr').outerHeight(desc_height); 897 //} 898 }, 899 900 showFullDescription: function(e) { 901 e.preventDefault(); 902 var $target = $(e.target); 903 $target.parents(this.conf.desc_more.cont).removeClass(this.conf.desc_more.class); 904 } 905 }; 906})(jQuery); 907 908var comments_actions = (function($) { 909 return { 910 conf: { 911 post_id: 0, 912 comment_id: 0, 913 lang_id: 0, 914 vote_url: '', 915 add_comment_url: '', 916 translate_comment_url: '', 917 //rating_actions: '.cmnt_options .rght a', 918 rating_actions: '.votelinks a', 919 up_class: 'comment-up', 920 down_class: 'comment-down', 921 rating: '.comment-rating', 922 positive_rating: 'green', 923 reply_class: 'link_reply', 924 cancel_class: 'link_cancel', 925 wrap_comment_form: '.wrap_form', 926 comment_form: '#comment_form', 927 comments_holder: '.wrap_comments', 928 reply_text: 'Reply', 929 cancel_text: 'Cancel', 930 wrap_comment_reply: 'form_reply', 931 replies_notice: 'replies_notice', 932 // translate_button: 'link_translate' 933 translate_button: 'translate_button', 934 935 fb_app_id: '', 936 show_fb_comments: false, 937 comment_form_hidden: false, 938 fb_comm_url: '' 939 }, 940 941 init: function(settings) { 942 $.extend(true, this.conf, settings); 943 this.bindActions(); 944 $(this.conf.comment_form).find('[name="content"]').val(""); 945 }, 946 947 onLoadActions: function (e) { 948 this.checkIsNeedFBinit(e); 949 }, 950 951 bindActions: function() { 952 var that = this; 953 $(that.conf.comments_holder).on('click', that.conf.rating_actions, function (e) {that.voteToComment(e)}); 954 $(that.conf.comments_holder).on('click', '.'+that.conf.reply_class, function(e) {that.showReplyForm(e)}); 955 $(that.conf.comments_holder).on('click', '.'+that.conf.cancel_class, function(e) {that.cancelReplyForm(e)}); 956 $(that.conf.comment_form).on('submit', function(e) {that.validateCommentForm(e)}); 957 $(that.conf.comment_form).on('change', '#'+that.conf.replies_notice, function(e) {that.setDenialRepliesNotice(e)}); 958 $(that.conf.comment_form).on('click', '[name="content"]', function(e) {that.showCommentFormFields()}); 959 $(that.conf.comments_holder).on('click', '.'+that.conf.translate_button, function(e) {that.commentTranslate(e)}); 960 961 $(function(e) {that.onLoadActions(e)}); 962 963 $(document).on('scroll.fbInit', function(e) {that.checkIsNeedFBinit(e)}); 964 $('.fb_link').on('click', function(e) {that.showFBCommentsForm(e)}); 965 $(document).on('fb.loaded', function (e, resp) {that.scrollToCommentIfHash()}); 966 $(document).on('fb.comment_create', function (e, resp) {that.onFbCommentCreate(resp)}); 967 $(document).on('fb.comment_remove', function (e, resp) {that.onFbCommentRemove(resp)}); 968 969 }, 970 971 fbInit: function (app_id) { 972 var that = this; 973 var fb_params = { status: true, cookie: true, xfbml: true, version: 'v14.0', appId: app_id }; 974 if (typeof (FB) != 'undefined') { 975 that.fbInitEvents(fb_params); 976 } else { 977 $.getScript("//connect.facebook.net/"+this.langToFbLang(that.conf.lang)+"/sdk.js", function () { 978 // $.getScript("//connect.facebook.net/"+this.langToFbLang(that.conf.lang)+"/sdk/debug.js", function () { 979 that.fbInitEvents(fb_params); 980 }); 981 } 982 }, 983 fbInitEvents: function (fb_params) { 984 FB.init(fb_params); 985 FB.Event.subscribe('xfbml.render', function(resp){$(document).trigger('fb.loaded', resp)});
986 FB.Event.subscribe('comment.create', function(resp){$(document).trigger('fb.comment_create', resp)}); 987 FB.Event.subscribe('comment.remove', function(resp){$(document).trigger('fb.comment_remove', resp)}); 988 }, 989 990 checkIsNeedFBinit: function (e) { 991 if (!$('.fb_wrap').is(":visible")) { 992 return; 993 } 994 var comments_wrap = $('#comment_conteiner').offset().top; 995 var cur_scroll = $(e.target).scrollTop() + $(window).height(); 996 if (cur_scroll >= comments_wrap) { 997 this.fbInit(this.conf.fb_app_id); 998 $(document).off('scroll.fbInit'); 999 } 1000 }, 1001 1002 showFBCommentsForm: function (e) { 1003 if (this.conf.show_fb_comments) { 1004 $.scrollTo('.fb_wrap', {duration: 100}); 1005 return; 1006 } 1007 var $com_cont = $('#comment_conteiner'); 1008 var h = $com_cont.height(); 1009 $com_cont.height(h); 1010 var $fb = $('.fb_wrap'); 1011 var $fb_loader = $fb.find('.fb-loading'); 1012 $fb.show(); 1013 $fb_loader.show(); 1014 this.fbInit(this.conf.fb_app_id); 1015 $(document).on('fb.loaded', function () { 1016 $com_cont.height(''); 1017 $fb_loader.hide(); 1018 }); 1019 $(document).off('scroll.fbInit'); 1020 this.conf.comment_form_hidden = true; 1021 $(this.conf.wrap_comment_form).hide(); 1022 $('.link_fb').hide(); 1023 }, 1024 onFbCommentCreate: function (resp) { 1025 var data = { 1026 post_id: this.conf.post_id, 1027 lang_id: this.conf.lang_id, 1028 type: 'create' 1029 1030 }; 1031 this.sendPostRequest(this.conf.fb_comm_url, data); 1032 }, 1033 1034 onFbCommentRemove: function (resp) { 1035 var data = { 1036 post_id: this.conf.post_id, 1037 lang_id: this.conf.lang_id, 1038 type: 'remove' 1039 }; 1040 this.sendPostRequest(this.conf.fb_comm_url, data); 1041 }, 1042 sendPostRequest: function (url, data) { 1043 $.ajax({
1044 type: 'POST', 1045 url: url, 1046 data: data, 1047 dataType: 'json' 1048 }); 1049 }, 1050 1051 scrollToCommentIfHash: function () { 1052 if (location.hash.indexOf('comment-') !== -1) { 1053 setTimeout(function () { 1054 $.scrollTo(location.hash); 1055 }, 1000); 1056 } 1057 }, 1058 langToFbLang: function(lang) { 1059 var fb_lang = { 1060 'ar': 'ar_AR', 1061 'de': 'de_DE', 1062 'el': 'el_GR', 1063 'en': 'en_US', 1064 'es': 'es_ES', 1065 'fr': 'fr_FR', 1066 'it': 'it_IT', 1067 'ja': 'ja_JP', 1068 'nl': 'nl_NL', 1069 'pt': 'pt_BR', 1070 'ro': 'ro_RO', 1071 'ru': 'ru_RU', 1072 'tr': 'tr_TR' 1073 }; 1074 1075 return lang in fb_lang ? fb_lang[lang] : 'en_US'; 1076 }, 1077 1078 showCommentFormFields: function () { 1079 var $form = $(this.conf.comment_form); 1080 var $content = $form.find('[name=content]'); 1081 $content.addClass('height80'); 1082 if (!this.conf.user_id) { 1083 $form.find('.top_wrap.first').fadeIn(600); 1084 $form.find('.top_wrap.second').fadeIn(600); 1085 } 1086 $form.find('.c-input-submit').fadeIn(600); 1087 $form.find('.gray').fadeIn(600); 1088 1089 $('#googlerecaptcha').show(); 1090 /* 1091 if (this.conf.recaptcha.enabled) { 1092 var $grecaptcha = $("#googlerecaptcha"); 1093 if (!$grecaptcha.length || $grecaptcha.is(":empty")) { 1094 $form.find('.submit-block').addClass('height80'); 1095 $form.find('.c-voting').addClass('flright'); 1096 this.recaptchaInit(); 1097 } 1098 } 1099 */ 1100 }, 1101 1102 voteToComment: function(e) { 1103 e.preventDefault(); 1104 var that = this; 1105 var $link = $(e.target); 1106 if($link.parent().hasClass('no_vote')) { 1107 return false; 1108 } 1109 var comment_id = $link.parents('.cmnt').data('cid'); 1110 var type = $link.attr('class') == that.conf.up_class ? 'up' : 'down'; 1111 1112 var data = { 1113 comment_id: comment_id, 1114 type: type 1115 }; 1116 1117 $.ajax({
1118 type: 'POST', 1119 url: this.conf.vote_url, 1120 data: data, 1121 dataType: 'json' 1122 }).done(function(resp) { 1123 if (!resp.status) { 1124 alert(resp.msg); 1125 } else { 1126 var $rating_cont = $link.nextAll(that.conf.rating); 1127 var rating_val = ''; 1128 if(resp.rating > 0) { 1129 rating_val += '(+' + resp.rating + ')'; 1130 $rating_cont.addClass(that.conf.positive_rating); 1131 } else { 1132 rating_val += '(' + resp.rating + ')'; 1133 $rating_cont.removeClass(that.conf.positive_rating); 1134 } 1135 $rating_cont.html(rating_val); 1136 } 1137 $link.parent().addClass('no_vote'); 1138// $(that.conf.actions_holder).off('click', 'a'); 1139 }); 1140 }, 1141 1142 showThanksText: function () { 1143 var that = this; 1144 $('html,body').animate({ 1145 scrollTop: $(that.conf.comments_holder).offset().top 1146 }, 500); 1147 $('.rate_thx').fadeIn(1200); 1148 }, 1149 1150 showReplyForm: function(e) { 1151 e.preventDefault(); 1152 1153 var that = this; 1154 var $link = $(e.target); 1155 var $comment_form = $(that.conf.wrap_comment_form); 1156 var parent_id = $link.closest('.cmnt[data-parent="0"]').data('cid') || 0; 1157 var reply_id = $link.closest('.cmnt').data('cid') || 0; 1158 var parent_author = $link.closest('.cmnt').data("author"); 1159 1160 $.scrollTo($(window).scrollTop() - $comment_form.height() + "px"); 1161 1162 $('.' + that.conf.cancel_class).addClass(that.conf.reply_class).removeClass(that.conf.cancel_class).html(that.conf.reply_text); 1163 1164 $link.parents('.cmnt_options').after($comment_form); 1165 1166 //$comment_form.find('h2').hide(); 1167 $comment_form.find('#comment_parent').val(parent_id); 1168 $comment_form.find('#comment_reply').val(reply_id); 1169 $link.removeClass(that.conf.reply_class).addClass(that.conf.cancel_class).html(that.conf.cancel_text); 1170 $comment_form.addClass(that.conf.wrap_comment_reply); 1171 $comment_form.find('textarea').focus().val(parent_author ? parent_author + ", " : ""); 1172 $('.link_fb').hide(); 1173 if (that.conf.comment_form_hidden) { 1174 $comment_form.show(); 1175 } 1176 }, 1177 1178 cancelReplyForm: function(e) { 1179 e.preventDefault(); 1180 1181 var that = this; 1182 var $link = $(e.target); 1183 var $comment_form = $(that.conf.wrap_comment_form); 1184 1185 $('.wrap_fb_and_link').before($comment_form); 1186 1187 //$comment_form.find('h2').show(); 1188 $comment_form.find('#comment_parent').val(0); 1189 $comment_form.find('#comment_reply').val(0); 1190 $comment_form.removeClass(that.conf.wrap_comment_reply); 1191 $link.addClass(that.conf.reply_class).removeClass(that.conf.cancel_class).html(that.conf.reply_text); 1192 $comment_form.find('textarea').val(''); 1193 1194 $.scrollTo($(window).scrollTop() + $comment_form.height() + "px"); 1195 if (this.conf.comment_form_hidden) { 1196 $comment_form.hide(); 1197 } else { 1198 $('.link_fb').show(); 1199 } 1200 }, 1201 1202 validateCommentForm: function(e) { 1203 e.preventDefault(); 1204 var that = this; 1205 var $form = $(e.currentTarget); 1206 var $content = $form.find('[name=content]'); 1207 if (!$content.hasClass('height80')) { 1208 this.showCommentFormFields(); 1209 return; 1210 } 1211 var $form = $(e.target); 1212 var name = $form.find('[name=name]').val(); 1213 var email = $form.find('[name=email]').val(); 1214 var content = $form.find('[name=content]').val(); 1215 var parent = $form.find('#comment_parent').val(); 1216 var reply = $form.find('#comment_reply').val(); 1217 var replies_notice = $form.find('#replies_notice').prop('checked') ? '1' : '0'; 1218 1219 1220 var error = false; 1221 if(!name || !email || !content) { 1222 if (!name) { 1223 this.addErrorToField($form.find('[name=name]')); 1224 } 1225 if (!email) { 1226 this.addErrorToField($form.find('[name=email]')); 1227 } 1228 if (!content) { 1229 this.addErrorToField($form.find('[name=content]')); 1230 } 1231 $('.comments_error').html(this.conf.no_fields_text).show(); 1232 1233 error = true; 1234 } 1235 1236 var re = /.+@.+\..+/i; 1237 if (!re.test(email)) { 1238 this.addErrorToField($form.find('[name=email]')); 1239 $('.comments_error').html(this.conf.no_fields_text).show(); 1240 1241 error = true; 1242 } 1243 1244 //if($(".g-recaptcha").is(":visible")) { 1245 if(!$("#googlerecaptcha").is(":empty")) { 1246 if(!$('#g-recaptcha-response').val()){ 1247 alert('Wrong recaptcha!'); 1248 error = true; 1249 } 1250 } 1251 1252 if (error) { 1253 return false; 1254 } 1255 1256 $('.comments_error').html(""); 1257 1258 1259 var data = { 1260 name: name, 1261 email: email, 1262 content: content, 1263 parent: parent, 1264 reply: reply, 1265 replies_notice: replies_notice, 1266 post_id: this.conf.post_id, 1267 lang_id: this.conf.lang_id, 1268 g_recaptcha_response: $('#g-recaptcha-response').val() 1269 }; 1270 1271 this.submitCommentForm(data); 1272 }, 1273 1274 addErrorToField: function ($field) { 1275 $field.addClass('error').keyup(function () { 1276 $field.removeClass('error').unbind('keyup'); 1277 }); 1278 }, 1279 1280 submitCommentForm: function(data) { 1281 var that = this; 1282 var $button = $('#comment_form [type="submit"]'); 1283 var $loading = $('.comment_form_loading'); 1284 1285 $button.prop('disabled', true); 1286 $loading.css("display", "inline-block"); 1287 1288 $.ajax({
1289 type: 'POST', 1290 url: this.conf.add_comment_url, 1291 data: data, 1292 dataType: 'json' 1293 }).done(function(resp) { 1294 $button.prop('disabled', false); 1295 $loading.css("display", "none"); 1296 $(that.conf.wrap_comment_form).find('textarea').val(""); 1297 if (!resp.status) { 1298 $('.comments_error').html(resp.msg).show(); 1299 } else { 1300 $('.link_cancel').click(); 1301 if (data.parent > 0) { 1302 $('#comment-' + data.parent).append(resp.comment); 1303 } else { 1304 var $parent = $('#comments_container'); 1305 var $sibling_is_top = $parent.children('.cmnt.is_top:last'); 1306 if ($sibling_is_top.length) { 1307 $sibling_is_top.after(resp.comment); 1308 } else { 1309 $parent.prepend(resp.comment); 1310 } 1311 //$('#comments_container').prepend(resp.comment); 1312 } 1313 $.scrollTo('#comment-' + resp.comment_id, {duration: 100}); 1314 1315 if (resp.show_captcha) { 1316 //$('#googlerecaptcha').empty(); 1317 if($("#googlerecaptcha").is(":empty")) { 1318 renderRecaptcha(); 1319 } else { 1320 grecaptcha.reset(); 1321 } 1322 } 1323 } 1324 }); 1325 }, 1326 1327 setDenialRepliesNotice: function (e) { 1328 var $checkbox = $(e.target); 1329 var options = { 1330 path: '/', 1331 domain: '.' + check_user_lang.conf.domain 1332 }; 1333 if ($checkbox.prop("checked")) { 1334 options.expires = 0; 1335 setCookie('denial_replies_notice', '', options); 1336 } else { 1337 options.expires = 365 * 24 * 3600; 1338 setCookie('denial_replies_notice', 1, options); 1339 } 1340 }, 1341 1342 commentTranslate: function (e) { 1343 e.preventDefault(); 1344 1345 var $button = $(e.target); 1346 1347 if ($button.hasClass("original")) { 1348 this.setCommentOriginal($button); 1349 } else { 1350 this.setCommentTranslate($button); 1351 } 1352 }, 1353 setCommentTranslate: function ($button) { 1354 var $comment = $button.closest('.cmnt'); 1355 1356 if ($comment.find('.translate_loading').length === 0) { 1357 // $button.after('<div class="comment_form_loading"></div>'); 1358 1359 //$comment.find('img.load').attr("style", ""); 1360 $('img#load-'+$button.data('id')).attr("style", ""); 1361 } 1362 1363 var data = { 1364 comment_id: $button.data('id') 1365 }; 1366 1367 $.ajax({
1368 type: 'GET', 1369 url: this.conf.translate_comment_url, 1370 data: data, 1371 dataType: 'json' 1372 }).done(function(resp) { 1373 if (resp.status) { 1374 $('#comment-' + $button.data('id') + ' > .comment_content').hide(); 1375 $('#comment-' + $button.data('id') + ' > .comment_translate').html(resp.content).show(); 1376 $button.addClass("original").html($button.data("original")); 1377 } else { 1378 alert(resp.error); 1379 } 1380 //$button.next('.comment_form_loading').remove(); 1381 1382 //$comment.find('img.load').attr("style", "display: none;"); 1383 $('img#load-'+$button.data('id')).attr("style", "display: none;") 1384 1385// $comment.find('.translate_loading').remove(); 1386// if (resp.status) { 1387// $button.addClass("disabled gray"); 1388// $comment.children('.cmnt_options').after('<div class="comment_translate">' + resp.content + '</div>'); 1389// } else { 1390// $comment.children('.cmnt_options').after('<div class="comment_translate error">' + resp.error + '</div>'); 1391// } 1392 }); 1393 }, 1394 setCommentOriginal: function ($button) { 1395 $('#comment-' + $button.data('id') + ' > .comment_content').show(); 1396 $('#comment-' + $button.data('id') + ' > .comment_translate').hide(); 1397 $button.removeClass("original").html($button.data("translate")); 1398 } 1399 }; 1400})(jQuery); 1401 1402var language_support = (function($) { 1403 return { 1404 conf: { 1405 wrap: 'lang_wrap', 1406 selected_wrap: 'selected_lang_wrap', 1407 lang_holder: 'one_lang_holder', 1408 add_btn: 'lang_add', 1409 del_btn: 'lang_del', 1410 val_holder: 'lang_val', 1411 hidden: '#lang_support' 1412 }, 1413 1414 init: function(settings) { 1415 $.extend(true, this.conf, settings); 1416 this.bindActions(); 1417 }, 1418 1419 bindActions: function() { 1420 var that = this; 1421 $('.'+that.conf.wrap).on('click', '.'+that.conf.lang_holder, function (e) {that.highlightLang(e)}); 1422 $('.'+that.conf.wrap).on('click', '.'+that.conf.add_btn, function (e) {that.addLang(e)}); 1423 $('.'+that.conf.selected_wrap).on('click', '.'+that.conf.del_btn, function (e) {that.delLang(e)}); 1424 $('.program_form').on('submit', function(e) {that.getSelectedLangs(e)}); 1425 }, 1426 1427 highlightLang: function(e) { 1428 var $target = $(e.currentTarget); 1429 $('.'+this.conf.lang_holder).removeClass('active'); 1430 $target.addClass('active'); 1431 }, 1432 1433 addLang: function(e) { 1434 var $target = $(e.target); 1435 var lang = this.getLangFromTarget($target); 1436 $('.'+this.conf.selected_wrap).append(this.renderSelected(lang)); 1437 $target.parents('.'+this.conf.lang_holder).remove(); 1438 }, 1439 1440 getLangFromTarget: function($target) { 1441 return $target.parents('.'+this.conf.lang_holder).find('.'+this.conf.val_holder).text(); 1442 }, 1443 1444 delLang: function(e) { 1445 var $target = $(e.target); 1446 var lang = this.getLangFromTarget($target); 1447 $('.'+this.conf.wrap).append(this.renderSupported(lang)); 1448 $target.parents('.'+this.conf.lang_holder).remove(); 1449 }, 1450 1451 renderSelected: function(lang) { 1452 return '<div class="'+this.conf.lang_holder+'">' + 1453 '<span class="'+this.conf.del_btn+'"></span>' + 1454 '<span class="'+this.conf.val_holder+'">' +lang + '</span>' + 1455 '</div>'; 1456 }, 1457 1458 renderSupported: function(lang) { 1459 return '<div class="'+this.conf.lang_holder+'">' + 1460 '<span class="'+this.conf.val_holder+'">' +lang + '</span>' + 1461 '<span class="'+this.conf.add_btn+'"></span>' + 1462 '</div>'; 1463 }, 1464 1465 getSelectedLangs: function(e) { 1466 var selected_lang = []; 1467 $('.'+this.conf.selected_wrap+' .'+this.conf.val_holder).each(function() { 1468 selected_lang.push($(this).text()); 1469 }); 1470 $(this.conf.hidden).val(selected_lang.join(',')); 1471 } 1472 }; 1473})(jQuery); 1474 1475var downloadShareForm = (function($) { 1476 return { 1477 conf: { 1478 form_url: '', 1479 social_url: '', 1480 email_url: '', 1481 form_id: '#soc_download', 1482 post_id: 1, 1483 post_title: '', 1484 post_url: '', 1485 fb_app_id: '', 1486 landing_url: '', 1487 is_auth: 0, 1488 start: 0, 1489 test_mode: 0, 1490 notification_instruction_url: '' 1491 }, 1492 1493 init: function(settings) { 1494 $.extend(true, this.conf, settings); 1495 this.fbInit(this.conf.fb_app_id); 1496 this.bindActions(); 1497 }, 1498 1499 fbInit: function (app_id) { 1500 var that = this;
1501 var fb_params = { status: true, cookie: true, xfbml: true, version: 'v14.0', appId: app_id }; 1502 if(typeof (FB) != 'undefined') { 1503 FB.init(fb_params); 1504 } else { 1505 $.getScript("//connect.facebook.net/en_US/sdk.js", function () { 1506 // $.getScript("//connect.facebook.net/en_US/sdk/debug.js", function () { 1507 FB.init(fb_params); 1508 }); 1509 } 1510 var initializedInterval = setInterval(function () { 1511 if (typeof (FB) !== 'undefined'/* && FB.__globalCallbacks*/) { 1512 for (var i in FB.__globalCallbacks) { // check empty 1513 clearInterval(initializedInterval); 1514 1515 if (location.hash.indexOf('comment-') !== -1) { 1516 setTimeout(function () { 1517 $.scrollTo(location.hash); 1518 }, 1000); 1519 } 1520 1521 return; 1522 } 1523 } 1524 }, 100); 1525 }, 1526 1527 bindActions: function() { 1528 var that = this; 1529 $('.download_btn, .second_btn, .label_link').on('click', function(e) {that.showShareForm(e); _gaq.push(['_trackPageview', '/downloads']); }); 1530 $(document).on('click', '.close_btn', function(e) {that.closeShareForm(e)}); 1531 $(document).on('click', 'block .btn_download', function(e) {that.closeShareForm(e)}); 1532 $(document).on('click', '.return_a', function(e) {that.returnToShareForm(e)}); 1533 $(document).on('click', '#fb_dshare', function(e) {that.fbShare(e)}); 1534 $(document).on('click', '#tw_dshare', function(e) {that.twShare(e)}); 1535 //$(window).on('message', function(e) {that.checkTwShare(e)}); 1536 $(document).on('click', "#ask_link", function(e) {that.sendLinkToEmail(e)}); 1537 $(document).on('keypress', function(e) {that.checkSendLinkToEmail(e)}); 1538 1539 if(that.conf.start) { 1540 $(window).on('load', function(e) {that.showShareForm(e);}); 1541 } 1542 }, 1543 1544 showShareForm: function(e) { 1545 e.preventDefault(); 1546 var that = this; 1547 1548 if(!that.conf.start && that.openLanding()) { 1549 return false; 1550 } 1551 1552 var $form = $(that.conf.form_id); 1553 if(!$form.length) { 1554 $.get(that.conf.form_url, {pid: that.conf.post_id}, function (data) { 1555 if(data.auth) { 1556 window.location.href = data.content; 1557 } else { 1558 $('body').append(data.content); 1559 $(that.conf.form_id).show(); 1560 $(document.body).addClass('overflow'); 1561 1562 //Check if user logged in with Facebook 1563 FB.getLoginStatus(function(response) { 1564 that.statusChangeCallback(response); 1565 }); 1566 1567 detectNotificationSupported(function (status, type) { 1568 if (status) { 1569 if (type == 'safari' && !that.conf.test_mode) { 1570 return; 1571 } 1572 that.showNotificationStr(type); 1573 } 1574 }); 1575 } 1576 }, 1577 'json'); 1578 } else { 1579 $form.show(); 1580 $(document.body).addClass('overflow'); 1581 } 1582 that.log(4304); 1583 }, 1584 1585 showNotificationStr: function (type) { 1586 var notif = false; 1587 if (type == 'safari') { 1588 notif = window.safari.pushNotification.permission(common_actions.conf.safari_push.website_uid); 1589 } else { 1590 notif = window.Notification; 1591 } 1592 var texts = { 1593 granted: 'You can get a download link via push notifications. To receive it, please click <a href="#" class="notification-dwn-btn">here</a>.', 1594 denied: 'You can get a download link through push notifications. Please <a target="_blank" href="'+this.conf.notification_instruction_url+'">enable</a> notifications for our website and the link will come in a few seconds.', 1595 default: 'You can get a download link via push notifications. To receive it, please <a href="#" class="notification-dwn-btn">enable</a> notifications for our website.' 1596 }; 1597 var text = ''; 1598 if (notif.permission === 'granted') { 1599 logging(7124); 1600 text = texts['granted']; 1601 } else if (notif.permission !== 'denied') { 1602 logging(7125);
1603 text = texts['default']; 1604 } else { 1605 logging(7126); 1606 text = texts['denied']; 1607 1608 var timerId = setTimeout(function tick() { 1609 console.log('check perms...'); 1610 var new_perm = notif.permission; 1611 if (new_perm == 'denied') { 1612 timerId = setTimeout(tick, 2000); 1613 } else { 1614 $('.notification-dwn').html(texts[new_perm]); 1615 } 1616 }, 2000); 1617 } 1618 1619 jQuery(document).on('click', '.notification-dwn-btn', function () { 1620 if (type == 'safari') { 1621 post_actions.subscribeSafari(); 1622 } else { 1623 post_actions.subscribe(); 1624 } 1625 }); 1626 1627 $('.notification-dwn').html(text).show(); 1628 }, 1629 1630 openLanding: function() { 1631 if(!this.conf.landing_url) return false; 1632 if (getCookie('cgb_lan')) return false; 1633 1634 setCookie('cgb_lan', 1, {expires: 14*24*60*60, path: '/', domain: '.giveawayoftheday.com'}); 1635 window.open(this.conf.post_url + '?start'); 1636 location.href = this.conf.landing_url; 1637 1638 return true; 1639 }, 1640 1641 closeShareForm: function(e) { 1642 //e.preventDefault(); 1643 $(this.conf.form_id).hide(); 1644 $(document.body).removeClass('overflow'); 1645 }, 1646 1647 returnToShareForm: function(e) { 1648 e.preventDefault(); 1649 var $target = $(e.target); 1650 $target.parents('.block').hide(); 1651 $('#soc_download_inner').show(); 1652 }, 1653 1654 checkSendLinkToEmail: function(e) { 1655 var $target = $(e.target); 1656 if (e.which == 13 && $target.attr('id') == 'download_email') { 1657 $('#ask_link').click(); 1658 } 1659 }, 1660 1661 sendLinkToEmail: function(e) { 1662 e.preventDefault(); 1663 var that = this; 1664 var email = $("#download_email").val(); 1665 if (!that.validateEmail(email)) { 1666 alert('Wrong email!'); 1667 return; 1668 } 1669 1670 if($("div").is(".email_steam_keys")) { 1671 if(!$('#g-recaptcha-response').val()){ 1672 alert('Wrong recaptcha!'); 1673 return; 1674 } 1675 } 1676 1677 var params = { 1678 pid: that.conf.post_id, 1679 email: email, 1680 subscribe: $("#subs").attr('checked'), 1681 g_recaptcha_response: $('#g-recaptcha-response').val() 1682 }; 1683 $.ajax({
1684 url: that.conf.email_url, 1685 type: 'POST', 1686 data: params, 1687 success: function (response) { 1688 if (response.status) { 1689 $("#soc_download_inner").hide(); 1690 $("#soc_download_inner").after(response.content); 1691 that.log(4322); 1692 } 1693 } 1694 }); 1695 }, 1696 1697 log: function(id) { 1698 var i = new Image(); 1699 i.src = document.location.protocol + "//www.giveawayoftheday.com/log.php?id="+id+"&r=" + Math.round(100000 * Math.random()); 1700 }, 1701 1702 fbShare: function(e) { 1703 e.preventDefault(); 1704 var that = this; 1705 $.ajax({ 1706 type: 'POST', 1707 url: '/ajax/posts/fbclklog', 1708 data: {pid: that.conf.post_id}, 1709 dataType: 'json' 1710 }); 1711 window.open('https://www.facebook.com/sharer.php?u=' + encodeURIComponent(that.conf.post_url),'sharer'); 1712 that.showLink('facebook', 0); 1713 _gaq.push(['_trackPageview', '/facebookshare']); 1714 }, 1715 1716 twShare: function(e) { 1717 e.preventDefault(); 1718 var that = this; 1719 window.open(that.tweetUrlBuilder({url: that.conf.post_url, text: that.conf.post_title}), 'Tweet', 'height=500,width=700'); 1720 }, 1721 1722 tweetUrlBuilder: function(o) { 1723 return [ 1724 'https://twitter.com/intent/tweet?tw_p=tweetbutton', 1725 '&url=', encodeURI(o.url), 1726 '&text=', o.text 1727 ].join(''); 1728 }, 1729 1730 checkTwShare: function(e) { 1731 var that = this; 1732 if(e && e.originalEvent.data){ 1733 var data; 1734 try{ 1735 data = JSON.parse(e.originalEvent.data); 1736 }catch(e){ 1737 // Don't care. 1738 } 1739 if(data && data.params && data.params.indexOf('tweet') > -1){ 1740 that.showLink('twitter'); 1741 } 1742 } 1743 }, 1744 1745 showLink: function(soc_type, soc_post) { 1746 var that = this; 1747 var params = { 1748 pid: that.conf.post_id, 1749 soc_post: soc_post 1750 }; 1751 1752 $.ajax({
1753 url: that.conf.social_url+'/'+soc_type, 1754 type: 'POST', 1755 data: params, 1756 success: function (response) { 1757 if (response.status) { 1758 sd_form = $("#sd_table_cell").html(); 1759 $("#soc_download_inner").hide(); 1760 $("#soc_download_inner").after(response.content); 1761 that.log(4322); 1762 } 1763 } 1764 }); 1765 }, 1766 1767 validateEmail: function (email) { 1768 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 1769 1770 return re.test(email); 1771 }, 1772 1773 statusChangeCallback: function (response) { 1774 //console.log('statusChangeCallback'); 1775 //console.log(response); 1776 // 1777 // The response object is returned with a status field that lets the 1778 // app know the current login status of the person. 1779 // Full docs on the response object can be found in the documentation 1780 // for FB.getLoginStatus(). 1781 if (response.status === 'connected') { 1782 // Logged into your app and Facebook. 1783 this.afterFbLogin(); 1784 } else { 1785 // The person is not logged into your app or we are unable to tell. 1786 // document.getElementById('status').innerHTML = 'Please log ' + 1787 // 'into this app.'; 1788 1789 } 1790 }, 1791 1792 afterFbLogin: function () { 1793 var that = this; 1794 FB.api('/me', {fields: 'id,name'}, function(response) { 1795 //console.log('Successful login for: ' + response.name); 1796 // document.getElementById('status').innerHTML = 1797 // 'Thanks for logging in, ' + response.name + '!'; 1798 1799 //console.log('user_id: ' + response.id); 1800 1801 //Set gaotd_auth_fb cookie 1802 $.get(that.conf.set_auth_fb_cookie_url, {fb_user_id: response.id, post_id: that.conf.post_id}, 1803 function (data) {}, 'json'); 1804 1805 }); 1806 }, 1807 1808 loginViaFacebook: function() { 1809 var that = this; 1810 FB.login(function(response) { 1811 that.checkLoginState(); 1812 }, {scope: 'public_profile,email'}); 1813 }, 1814 1815 checkLoginState: function() { 1816 var that = this; 1817 FB.getLoginStatus(function(response) { 1818 that.statusChangeCallback(response); 1819 }); 1820 } 1821 1822 }; 1823})(jQuery); 1824 1825 1826 1827var gaotd_countdown = (function($){ 1828 return { 1829 render_sec: function(holder, until, texts) { 1830 var hours = texts['hours'] || 'hours'; 1831 var mins = texts['mins'] || 'mins'; 1832 var secs = texts['secs'] || 'secs'; 1833 $(holder).countdown({ 1834 until: until, 1835 timezone: 0, 1836 format: 'HMS', 1837 layout: '<span class="countdown-row countdown-show3">' + 1838 '<span class="countdown-section">' + 1839 '<span class="countdown-amount">{h<}<span class="diggit">{h10}</span><span class="diggit">{h1}</span>{h>}</span>' + 1840 '<span class="countdown-period">' + hours + '</span>' + 1841 '</span>' + 1842 '<span class="countdown-section">' + 1843 '<span class="countdown-amount">{m<}<span class="diggit">{m10}</span><span class="diggit">{m1}</span>{m>}</span>' + 1844 '<span class="countdown-period">' + mins + '</span>' + 1845 '</span>' + 1846 '<span class="countdown-section">' + 1847 '<span class="countdown-amount">{s<}<span class="diggit">{s10}</span><span class="diggit">{s1}</span>{s>}</span>' + 1848 '<span class="countdown-period">' + secs + '</span></span>' + 1849 '</span>' 1850 }); 1851 }, 1852 render_days: function(holder, until, texts) { 1853 var days = texts['days'] || 'days'; 1854 var hours = texts['hours'] || 'hours'; 1855 var mins = texts['mins'] || 'mins'; 1856 $(holder).countdown({ 1857 until: until, 1858 timezone: 0, 1859 format: 'DHM', 1860 layout: '<span class="countdown-row countdown-show3">' + 1861 '<span class="countdown-section">' + 1862 '<span class="countdown-amount">{d<}<span class="diggit">{d10}</span><span class="diggit">{d1}</span>{d>}</span>' + 1863 '<span class="countdown-period">' + days + '</span>' + 1864 '</span>' + 1865 '<span class="countdown-section">' + 1866 '<span class="countdown-amount">{h<}<span class="diggit">{h10}</span><span class="diggit">{h1}</span>{h>}</span>' + 1867 '<span class="countdown-period">' + hours + '</span>' + 1868 '</span>' + 1869 '<span class="countdown-section">' + 1870 '<span class="countdown-amount">{m<}<span class="diggit">{m10}</span><span class="diggit">{m1}</span>{m>}</span>' + 1871 '<span class="countdown-period">' + mins + '</span></span>' + 1872 '</span>' 1873 }); 1874 }, 1875 render: function(holder, until, texts) { 1876 if ($(holder).length>0) { 1877 var today = new Date(); 1878 var diff = Math.abs( until.getTime() - today.getTime()); 1879 var diffDays = Math.floor( diff / (1000 * 3600 * 24)); 1880 if (diffDays >= 1) 1881 this.render_days(holder, until, texts); 1882 else 1883 this.render_sec(holder, until, texts); 1884 } 1885 } 1886 } 1887})(jQuery); 1888 1889var subscribe_action = (function($) { 1890 return { 1891 conf: { 1892 post_id: 0, 1893 subscribe: { 1894 btn: '#featured_subscribe', 1895 field: '#featured_email', 1896 url: '', 1897 error: 'subscribe_error' 1898 } 1899 }, 1900 init: function(settings) { 1901 $.extend(true, this.conf, settings); 1902 this.bindActions(); 1903 }, 1904 bindActions: function() { 1905 var that = this; 1906 $(that.conf.subscribe.btn).on('click', function(e){that.featuredSubscribe(e)}); 1907 $(document).on('keypress', function(e) {that.checkSubscribeIsSubmit(e)}); 1908 }, 1909 1910 featuredSubscribe: function (e) { 1911 var that = this; 1912 var email = $(that.conf.subscribe.field).val();
1913 $('.subscribe_error').html('').css(''); 1914 if (!email || !downloadShareForm.validateEmail(email)) { 1915 $(that.conf.subscribe.field).addClass('error'); 1916 return; 1917 } 1918 1919 $.ajax({ 1920 type: 'POST', 1921 url: that.conf.subscribe.url, 1922 data: {email: email, pid: that.conf.post_id}, 1923 dataType: 'json' 1924 }).done(function (resp) { 1925 if (!resp.status) { 1926 $(that.conf.subscribe.field).addClass('error'); 1927 } else { 1928 respinmarkup = '<label class="thnks green">'+resp.content+'</label>'; 1929 if ($('.subscribe_block').length) { //еÑли Ñакой ÑÐ»ÐµÐ¼ÐµÐ½Ñ ÑÑÑеÑÑвÑÐµÑ 1930 $('.subscribe_block').html(respinmarkup); 1931 } else if ($('#subscribe_with_game_block').length) { 1932 $('#subscribe_with_game_block').html(respinmarkup); 1933 } 1934 } 1935 }); 1936 }, 1937 1938 checkSubscribeIsSubmit: function(e) { 1939 var $target = $(e.target); 1940 if(e.which == 13 && '#' + $target.attr('id') == this.conf.subscribe.field) { 1941 $(this.conf.subscribe.btn).click(); 1942 } 1943 } 1944 } 1945})(jQuery); 1946 1947var subscribe_popup_form = (function($) { 1948 return { 1949 conf: { 1950 form_id: '#subscribe_popup_form', 1951 popup_button: '.call_subscribe_form', 1952 subscribe: { 1953 btn: '#featured_subscribe_popup', 1954 field: '#featured_email_popup', 1955 url: '', 1956 error: 'subscribe_error' 1957 } 1958 }, 1959 init: function(settings) { 1960 $.extend(true, this.conf, settings); 1961 this.bindActions(); 1962 }, 1963 bindActions: function () { 1964 var that = this; 1965 $(that.conf.popup_button).on('click', function(e) {that.showSubscribeForm(e)}); 1966 $(document).on('keypress', function(e) {that.checkSubscribeIsSubmit(e)}); 1967 }, 1968 showSubscribeForm: function(e) { 1969 e.preventDefault(); 1970 1971 var that = this; 1972 var $form = $(that.conf.form_id); 1973 if(!$form.length) { 1974 var that = this; 1975 $.get(that.conf.form_url, {}, function (data) { 1976 $('body').append(data.content); 1977 $(that.conf.form_id).show(); 1978 that.bindFromActions(e, $(that.conf.form_id)); 1979 $(document.body).addClass('overflow'); 1980 }, 1981 'json'); 1982 } else { 1983 $form.show(); 1984 $(document.body).addClass('overflow'); 1985 } 1986 }, 1987 1988 closeSubscribeForm: function() { 1989 $(this.conf.form_id).hide(); 1990 $(document.body).removeClass('overflow'); 1991 }, 1992 1993 bindFromActions: function (e, $form) { 1994 var that = this; 1995 $form.find('.close_btn').click(function () { that.closeSubscribeForm(e); }); 1996 $(that.conf.subscribe.btn).click(function () { that.featuredSubscribe(e); }) 1997 }, 1998 1999 featuredSubscribe: function (e) { 2000 var that = this; 2001 var email = $(that.conf.subscribe.field).val(); 2002 $('.subscribe_error').html('').css(''); 2003 if (!email || !downloadShareForm.validateEmail(email)) { 2004 $(that.conf.subscribe.field).addClass('error'); 2005 return; 2006 } 2007 2008 $.ajax({
2009 type: 'POST', 2010 url: that.conf.subscribe.url, 2011 data: {email: email, pid: that.conf.post_id}, 2012 dataType: 'json' 2013 }).done(function (resp) { 2014 if (!resp.status) { 2015 $(that.conf.subscribe.field).addClass('error'); 2016 } else { 2017 $('#subscribe_popup_form .subscribe_block').html('<label class="thnks green">'+resp.content+'</label>'); 2018 setTimeout(function () { 2019 that.closeSubscribeForm(); 2020 }, 2000); 2021 } 2022 }); 2023 }, 2024 2025 checkSubscribeIsSubmit: function(e) { 2026 var $target = $(e.target); 2027 if(e.which == 13 && '#' + $target.attr('id') == this.conf.subscribe.field) { 2028 $(this.conf.subscribe.btn).click(); 2029 } 2030 } 2031 }; 2032})(jQuery); 2033 2034var help_translate_popup_form = (function($) { 2035 return { 2036 conf: { 2037 form_id: '#help_translate_popup_form', 2038 popup_button: '#help_translate', 2039 formform_id: '#translateform', 2040 send: { 2041 btn: '#send_btn', 2042 field_name: '#h-name', 2043 field_email: '#h-email', 2044 field_descr: '#h-descr', 2045 field_sdescr: '#h-short_descr', 2046 url: '' 2047 } 2048 }, 2049 init: function(settings) { 2050 $.extend(true, this.conf, settings); 2051 this.bindActions(); 2052 }, 2053 bindActions: function () { 2054 var that = this; 2055 $(that.conf.popup_button).on('click', function(e) {that.showForm(e); return false;}); 2056 $(document).on('keypress', function(e) {that.checkIsSubmit(e)}); 2057 $(window).resize(function(e) {that.resize(e)}) 2058 }, 2059 showForm: function(e) { 2060 e.preventDefault(); 2061 2062 var that = this; 2063 var $form = $(that.conf.form_id); 2064 if(!$form.length) { 2065 var that = this; 2066 $.get(that.conf.form_url, {}, function (data) { 2067 $('body').append(data.content); 2068 $(that.conf.form_id).show(); 2069 that.resize(e); 2070 that.bindFromActions(e, $(that.conf.form_id)); 2071 $(document.body).addClass('overflow'); 2072 }, 2073 'json'); 2074 } else { 2075 $form.show(); 2076 $(document.body).addClass('overflow'); 2077 } 2078 }, 2079 2080 closeForm: function() { 2081 $(this.conf.form_id).hide(); 2082 $(document.body).removeClass('overflow'); 2083 }, 2084 2085 bindFromActions: function (e, $form) { 2086 var that = this; 2087 $form.find('.close_btn').click(function () { that.closeForm(e); }); 2088 $(that.conf.send.btn).click(function () { that.sendTranslate(e); return false; }) 2089 }, 2090 2091 sendTranslate: function (e) { 2092 var that = this; 2093 var name = $(that.conf.send.field_name); 2094 var error = $(that.conf.form_id + ' .error'); 2095 $(that.conf.form_id + ' #captchaerror').hide(); 2096 error.css(''); 2097 var allok = true; 2098 if (name.val() == '') { 2099 name.addClass('error-input'); 2100 allok = false; 2101 } 2102 else name.removeClass('error-input'); 2103 var email = $(that.conf.send.field_email); 2104 if (email.val()=='' || !downloadShareForm.validateEmail(email.val())) { 2105 email.addClass('error-input'); 2106 allok = false; 2107 } 2108 else email.removeClass('error-input'); 2109 2110 var short_d = $('#h-descr'); 2111 if (short_d.val() == '') { 2112 short_d.addClass('error-input'); 2113 allok = false; 2114 } 2115 else short_d.removeClass('error-input'); 2116 2117 var h_content = $('#h-short_descr'); 2118 if (h_content.val() == '') { 2119 h_content.addClass('error-input'); 2120 allok = false; 2121 } 2122 else h_content.removeClass('error-input'); 2123 2124 if (!allok) { 2125 error.css('visibility','visible'); 2126 $(that.conf.form_id+ ' .block').animate({scrollTop:0},100); 2127 return; 2128 } 2129 2130 $.ajax({
2131 type: 'POST', 2132 url: that.conf.send.url, 2133 data: $(that.conf.formform_id).serialize(), 2134 dataType: 'json' 2135 }).done(function (resp) { 2136 if (!resp.status) { 2137 $(that.conf.send.field).addClass('error'); 2138 if (resp.wrongcaptcha) { 2139 error.css('visibility','visible'); 2140 $(that.conf.form_id + ' #captchaerror').show(); 2141 $(that.conf.form_id+ ' .block').animate({scrollTop:0},100); 2142 } 2143 } else { 2144 $(that.conf.form_id + ' ' + that.conf.formform_id+', '+ that.conf.form_id + ' .modal_title').hide(); 2145 $(that.conf.form_id + ' .thankyoublock').show(); 2146 setTimeout(function () { 2147 that.closeForm(); 2148 }, 2000); 2149 } 2150 }); 2151 }, 2152 2153 checkIsSubmit: function(e) { 2154 var $target = $(e.target); 2155 if(e.which == 13 && '#' + $target.attr('id') == this.conf.send.field) { 2156 $(this.conf.send.btn).click(); 2157 } 2158 }, 2159 2160 resize: function(e) { 2161 var that = this; 2162 $(that.conf.form_id + ' .h-descr2').height($(that.conf.form_id + ' .h-descr1').height()); 2163 $(that.conf.form_id + ' .h-short_descr2').height($(that.conf.form_id + ' .h-short_descr1').height()); 2164 if (Modernizr.mq('(max-width: 1036px)')) { 2165 $(that.conf.send.field_name).attr('placeholder','Enter your name*'); 2166 $(that.conf.send.field_email).attr('placeholder','Enter your email*'); 2167 } 2168 else { 2169 $(that.conf.send.field_name).attr('placeholder',''); 2170 $(that.conf.send.field_email).attr('placeholder',''); 2171 } 2172 2173 } 2174 }; 2175})(jQuery); 2176 2177 2178var share_iphone_popup= (function($) { 2179 return { 2180 conf: { 2181 form_id: '#share_iphone_popup', 2182 popup_button: '.download_logging', 2183 form_url: '', 2184 post_url: '', 2185 post_title: '', 2186 fb_app_id: '', 2187 post_id: '', 2188 is_test_mode: false 2189 }, 2190 init: function(settings) { 2191 $.extend(true, this.conf, settings); 2192 var cookie_name = 'p_sh_'+this.conf.post_id; 2193 if (!getCookie(cookie_name) && !getCookie('p_x_'+this.conf.post_id)) 2194 this.bindActions(); 2195 setCookie(cookie_name, '1', {expires: 24*60*60*30, path: '/', domain: '.giveawayoftheday.com'}); 2196 2197 }, 2198 bindActions: function () { 2199 var that = this; 2200 $(that.conf.popup_button).on('click', function(e) { setTimeout(function() { that.showShareForm(e); logging(5103) },2000); 2201 return that.conf.is_test_mode ? false : true; 2202 }); 2203 }, 2204 showShareForm: function(e) { 2205 if (getCookie('p_x_'+this.conf.post_id)) 2206 return true; 2207 2208 e.preventDefault(); 2209 2210 var that = this; 2211 var $form = $(that.conf.form_id); 2212 if(!$form.length) { 2213 var that = this; 2214 $.get(that.conf.form_url, {}, function (data) { 2215 $('body').append(data.content); 2216 $(that.conf.form_id).show(); 2217 that.bindFromActions(e, $(that.conf.form_id)); 2218 $(document.body).addClass('overflow'); 2219 }, 2220 'json'); 2221 } else { 2222 $form.show(); 2223 $(document.body).addClass('overflow'); 2224 } 2225 }, 2226 2227 closeShareForm: function() { 2228 setCookie('p_x_'+this.conf.post_id, '1', {expires: 24*60*60*30, path: '/', domain: '.giveawayoftheday.com'}); 2229 $(this.conf.form_id).hide(); 2230 $(document.body).removeClass('overflow'); 2231 }, 2232 2233 bindFromActions: function (e, $form) { 2234 var that = this; 2235 $form.find('.close_div').click(function () { that.closeShareForm(e);return false; }); 2236 $form.find('.fb').on('click',function(e) { 2237 logging(5104); 2238 location.href="https://www.facebook.com/dialog/share?app_id="+that.conf.fb_app_id+"&display=popup&href="+that.conf.post_url+"&redirect_uri="+that.conf.post_url; 2239 return false; 2240 }); 2241 $form.find('.tweeter').on('click',function(e) { 2242 logging(5105); 2243 location.href="http://twitter.com/share?url="+that.conf.tweet_url+"&text=%23giveaway%20%23iPhone%20The%20%22"+that.conf.post_title+"%22%20app%20for%20iPhone"; 2244 return false; 2245 }); 2246 } 2247 }; 2248})(jQuery); 2249 2250 2251 2252 2253var check_user_lang = (function($) { 2254 return { 2255 conf: { 2256 is_lang_redirect: false, 2257 subdomains_json: '', 2258 domain: '', 2259 path: '' 2260 }, 2261 init: function(settings) { 2262 $.extend(true, this.conf, settings); 2263 this.bindActions(); 2264 }, 2265 bindActions: function() { 2266 var that = this; 2267 if (this.conf.is_lang_redirect) { 2268 that.lang_redirect(); 2269 } 2270 }, 2271 2272 lang_redirect: function() { 2273 if (getCookie('lang') == 1) { 2274 return; 2275 } 2276
2277 setCookie('lang', 1, {path: '/', expires: 15*24*60*60, domain: '.' + this.conf.domain}); 2278 var subdomain = document.location.hostname.split('.'); 2279 subdomain = subdomain[0]; 2280 if (subdomain != 'www') { 2281 return; 2282 } 2283 2284 var lang_domain = 'www'; 2285 var subdomains = JSON.parse(this.conf.subdomains_json); 2286 $.each(subdomains, function(url, lang) { 2287 if (navigator.language == lang['code'] || navigator.language.indexOf(lang['code']+'-') >= 0) { 2288 lang_domain = url; 2289 } 2290 }); 2291 2292 if (lang_domain == subdomain) { 2293 return; 2294 } 2295 2296 location.href = 'https://' + lang_domain + '.'+this.conf.domain + '/' + this.conf.path; 2297 } 2298 } 2299})(jQuery); 2300 2301 2302var chrome_push_notifications_banner = (function($) { 2303 return { 2304 conf: { 2305 subscribe_id: '#chromePushYes', 2306 close_id: '#chromePushNo', 2307 chromePushBanner_id: "#chromePushBanner", 2308 bannerSocBtns_id: "#bannerSocBtns", 2309 chromeSubscribeAfterDeny_id: "#chromeSubscribeAfterDeny", 2310 is_test_mode: 0 2311 }, 2312 isValidBrowser: function() { 2313 return isChrome() && 'serviceWorker' in navigator; 2314 }, 2315 init: function(settings) { 2316 var that = this; 2317 if (!that.isValidBrowser()) return false; 2318 2319 $.extend(true, this.conf, settings); 2320 2321 this.bindActions(); 2322 2323 2324 //Ðоказ баннеÑа Ñо ÑÑÑлкой на инÑÑÑÑкÑии подпиÑки Ð´Ð»Ñ Ð¾ÑказавÑÐ¸Ñ ÑÑ 2325 if (/* that.is_test_mode && */ Notification.permission == 'denied') { 2326 console.log('Notification.permission: denied - show instructions'); 2327 setCookie('push_chrome_denied', '1', 2328 {expires: 24*60*60*30, path: '/', domain: '.giveawayoftheday.com'}); 2329 $(that.conf.bannerSocBtns_id).hide(); 2330 $(that.conf.chromeSubscribeAfterDeny_id).show(); 2331 logging(5122); 2332 return false; 2333 } 2334 2335 2336 if (!getCookie('push_google_chrome_banner_closed') && 2337 !getCookie('push_chrome_allow') && 2338 ('serviceWorker' in navigator) && 2339 Notification.permission != 'granted') { 2340 $(that.conf.chromePushBanner_id).show(); 2341 logging(5116); 2342 $(that.conf.bannerSocBtns_id).hide(); 2343 } 2344 2345 //ÐодпиÑка оÑказавÑÐ¸Ñ ÑÑ Ñанее, а поÑом ÑазÑеÑивÑÐ¸Ñ 2346 if(getCookie('push_chrome_denied') && Notification.permission === 'granted') { 2347 this.clickSubscribe(true); 2348 //deleteCookie('push_chrome_denied'); 2349 setCookie('push_chrome_denied', '', 2350 {expires: -1, path: '/', domain: '.giveawayoftheday.com'}); 2351 console.log('re-subscribe'); 2352 logging(5128); 2353 } 2354 }, 2355 bindActions: function () { 2356 var that = this; 2357 $(that.conf.subscribe_id).on('click', function(e) { 2358 that.clickSubscribe(e); 2359 }); 2360 $(that.conf.close_id).on('click', function(e) { 2361 that.clickClose(e); 2362 }); 2363 }, 2364 clickClose: function (e) { 2365 var that = this; 2366 $(that.conf.chromePushBanner_id).hide(); 2367 setCookie('push_google_chrome_banner_closed', '1', 2368 {expires: 24*60*60*7, path: '/', domain: '.giveawayoftheday.com'}); 2369 2370 logging(5118); 2371 return false; 2372 }, 2373/* 2374 clickSubscribe: function (e) { 2375 var that = this; 2376 //if (!getCookie('push_google_chrome')) { 2377 if ('serviceWorker' in navigator) { 2378 //setCookie('push_google_chrome', '1', 2379 // {expires: 24*60*60*7, path: '/', domain: '.giveawayoftheday.com'}); 2380 if (subscribeDevice(chrome_push_user_id)) { 2381 navigator.serviceWorker.register('/service-worker.js?loc='+locale+'&hash='+chrome_push_user_id, { 2382 //scope: './' 2383 scope: '/' 2384 }).then(function(registration) {registration.update() }).catch(function(error) { 2385 // registration failed 2386 console.log('Registration failed with ' + error); 2387 }); 2388 } 2389 //$(that.conf.chromePushBanner_id).hide(); 2390 } 2391 //} 2392 logging(5117); 2393 return false; 2394 } 2395*/ 2396 clickSubscribe: function (e) { 2397 var that = this; 2398 //if (!getCookie('push_google_chrome')) { 2399 if ('serviceWorker' in navigator) { 2400 //setCookie('push_google_chrome', '1', 2401 // {expires: 24*60*60*7, path: '/', domain: '.giveawayoftheday.com'}); 2402 subscribeDevice(chrome_push_user_id); 2403 navigator.serviceWorker.register('/service-worker.js?loc='+locale+'&hash='+chrome_push_user_id, { 2404 //scope: './' 2405 scope: '/' 2406 }).then(function(registration) {registration.update() }).catch(function(error) { 2407 // registration failed 2408 console.log('Registration failed with ' + error); 2409 }); 2410 2411 //$(that.conf.chromePushBanner_id).hide(); 2412 } 2413 //} 2414 logging(5117); 2415 return false; 2416 } 2417 2418 } 2419})(jQuery); 2420 2421// ÐÐ»Ñ Ð¿Ð¾Ð´Ð¿Ð¸Ñки на ÑÐ²ÐµÐ´Ð¾Ð¼Ð»ÐµÐ½Ð¸Ñ Ð² Firefox иÑполÑзÑем ÑÐ¾Ñ Ð¶Ðµ баннеÑ, 2422// коÑоÑÑй иÑполÑзÑеÑÑÑ Ð´Ð»Ñ Ð¿Ð¾Ð´Ð¿Ð¸Ñки в Chrome. 2423var firefox_push_notifications_banner = (function($) { 2424 return { 2425 conf: { 2426 subscribe_id: '#chromePushYes', 2427 close_id: '#chromePushNo', 2428 chromePushBanner_id: "#chromePushBanner", 2429 bannerSocBtns_id: "#bannerSocBtns", 2430 chromeSubscribeAfterDeny_id: "#chromeSubscribeAfterDeny", 2431 is_test_mode: 0 2432 }, 2433 isValidBrowser: function() { 2434 isFirefox = typeof InstallTrigger !== 'undefined'; 2435 return isFirefox && 'serviceWorker' in navigator; 2436 }, 2437 init: function(settings) { 2438 var that = this; 2439 if (!that.isValidBrowser()) return false; 2440 2441 $.extend(true, this.conf, settings); 2442 2443// Only for test mode 2444/* 2445if (this.conf.is_test_mode) { 2446 console.log('this is test mode'); 2447} else { 2448 console.log('this in NOT test mode'); 2449 return false; 2450} 2451*/ 2452 this.bindActions(); 2453 2454 2455 //Ðоказ баннеÑа Ñо ÑÑÑлкой на инÑÑÑÑкÑии подпиÑки Ð´Ð»Ñ Ð¾ÑказавÑÐ¸Ñ ÑÑ 2456 /* 2457 if (// that.is_test_mode && 2458 Notification.permission == 'denied') { 2459 console.log('Notification.permission: denied - show instructions');
2460 setCookie('push_chrome_denied', '1', 2461 {expires: 24*60*60*30, path: '/', domain: '.giveawayoftheday.com'}); 2462 $(that.conf.bannerSocBtns_id).hide(); 2463 $(that.conf.chromeSubscribeAfterDeny_id).show(); 2464 logging(5122); 2465 return false; 2466 } 2467 */ 2468 2469 if (!getCookie('push_firefox_banner_closed') && 2470 !getCookie('push_firefox_allow') && 2471 ('serviceWorker' in navigator) && 2472 Notification.permission != 'granted') { 2473 $(that.conf.chromePushBanner_id).show(); 2474 logging(6960); 2475 $(that.conf.bannerSocBtns_id).hide(); 2476 } 2477 2478 //ÐодпиÑка оÑказавÑÐ¸Ñ ÑÑ Ñанее, а поÑом ÑазÑеÑивÑÐ¸Ñ 2479 if(getCookie('push_firefox_denied') && Notification.permission === 'granted') { 2480 this.clickSubscribe(true); 2481 //deleteCookie('push_chrome_denied'); 2482 setCookie('push_firefox_denied', '', 2483 {expires: -1, path: '/', domain: '.giveawayoftheday.com'}); 2484 console.log('re-subscribe'); 2485 //logging(5128); 2486 } 2487 }, 2488 bindActions: function () { 2489 var that = this; 2490 $(that.conf.subscribe_id).on('click', function(e) { 2491 that.clickSubscribe(e); 2492 }); 2493 $(that.conf.close_id).on('click', function(e) { 2494 that.clickClose(e); 2495 }); 2496 }, 2497 clickClose: function (e) { 2498 var that = this; 2499 $(that.conf.chromePushBanner_id).hide(); 2500 setCookie('push_firefox_banner_closed', '1', 2501 {expires: 24*60*60*7, path: '/', domain: '.giveawayoftheday.com'}); 2502 2503 //logging(5118); 2504 return false; 2505 }, 2506 clickSubscribe: function (e) { 2507 var that = this; 2508 //if (!getCookie('push_google_chrome')) { 2509 if ('serviceWorker' in navigator) { 2510 //setCookie('push_google_chrome', '1', 2511 // {expires: 24*60*60*7, path: '/', domain: '.giveawayoftheday.com'}); 2512 subscribeDeviceFirefox(chrome_push_user_id); 2513 navigator.serviceWorker.register('/service-worker.js?loc='+locale+'&hash='+chrome_push_user_id, { 2514 //scope: './' 2515 scope: '/' 2516 }).then(function(registration) {registration.update() }).catch(function(error) { 2517 // registration failed 2518 console.log('Registration failed with ' + error); 2519 }); 2520 2521 //$(that.conf.chromePushBanner_id).hide(); 2522 } 2523 //} 2524 //logging(5117); 2525 return false; 2526 } 2527 } 2528})(jQuery); 2529/* 2530var chrome_push_notifications_banner_test2 = (function($) { 2531 return { 2532 conf: { 2533 is_bind: false, 2534 is_test_mode: 0, 2535 modal_chrome_notif_id: '#modal_chrome_notif', 2536 no_btn_modal_chrome_id: '#no_btn_modal_chrome', 2537 yes_btn_modal_chrome_id: '#yes_btn_modal_chrome', 2538 close_btn_modal_chrome_id: '#close_btn_modal_chrome' 2539 }, 2540 isValidBrowser: function() { 2541 return isChrome() && 'serviceWorker' in navigator; 2542 }, 2543 init: function(settings) { 2544 var that = this; 2545 if (!that.isValidBrowser()) return false; 2546 2547 $.extend(true, this.conf, settings); 2548 2549 }, 2550 // ÐнаÑÐµÐ½Ð¸Ñ source: 2551 // download_page_from_email 2552 // download_page_direct_link 2553 // popup_after_sharing 2554 // download_page_ajax_link 2555 showModal: function(source) { 2556 //ТеÑÑовÑй Ñежим 2557 //if (this.conf.is_test_mode != 1) return false; 2558 2559 var that = this; 2560 if (!that.isValidBrowser()) return false; 2561 2562 this.bindActions(); 2563 2564 if (!getCookie('push_google_chrome_no_test2') && 2565 Notification.permission != 'granted' &&
2566 Notification.permission != 'denied'&& 2567 !getCookie('push_chrome_allow_test2')) { 2568 switch (source) { 2569 case 'download_page_from_email': 2570 $(this.conf.modal_chrome_notif_id).show(); 2571 logging(5165); 2572 break; 2573 case 'download_page_direct_link': 2574 $(this.conf.modal_chrome_notif_id).show(); 2575 logging(5165); 2576 break; 2577 case 'popup_after_sharing': 2578 downloadShareForm.closeShareForm(); 2579 $(this.conf.modal_chrome_notif_id).show(); 2580 logging(5165); 2581 break; 2582 case 'download_page_ajax_link': 2583 $(this.conf.modal_chrome_notif_id).show(); 2584 logging(5165); 2585 break; 2586 } 2587 } 2588 }, 2589 bindActions: function () { 2590 var that = this; 2591 if (that.is_bind) return false; 2592 2593 $(that.conf.yes_btn_modal_chrome_id).on('click', function(e) { 2594 that.clickYes(e); 2595 }); 2596 2597 $(that.conf.no_btn_modal_chrome_id).on('click', function(e) { 2598 that.clickNo(e); 2599 }); 2600 2601 $(that.conf.close_btn_modal_chrome_id).on('click', function(e) { 2602 that.clickClose(e); 2603 }); 2604 2605 that.is_bind = true; 2606 }, 2607 clickYes: function (e) { 2608 var that = this; 2609 if ('serviceWorker' in navigator) { 2610 subscribeDevice(chrome_push_user_id); 2611 navigator.serviceWorker.register('/service-worker.js?loc='+locale+'&hash='+chrome_push_user_id, { 2612 scope: '/' 2613 }).then(function(registration) {registration.update() }).catch(function(error) { 2614 // registration failed 2615 console.log('Registration failed with ' + error); 2616 }); 2617 } 2618 $(this.conf.modal_chrome_notif_id).hide(); 2619 2620 logging(5166); 2621 return false; 2622 }, 2623 clickNo: function (e) { 2624 var that = this; 2625 $(that.conf.modal_chrome_notif_id).hide(); 2626 setCookie('push_google_chrome_no_test2', '1', 2627 {expires: 24*60*60*7, path: '/', domain: '.giveawayoftheday.com'}); 2628 2629 logging(5167); 2630 return false; 2631 }, 2632 clickClose: function (e) { 2633 var that = this; 2634 $(that.conf.modal_chrome_notif_id).hide(); 2635 //setCookie('push_google_chrome_banner_closed', '1', 2636 // {expires: 24*60*60*7, path: '/', domain: '.giveawayoftheday.com'}); 2637 2638 logging(5168); 2639 return false; 2640 } 2641 } 2642})(jQuery); 2643*/ 2644 2645var achecker = (function($) { 2646 return { 2647 conf: { 2648 blocks_num: { 2649 300: { 2650 'rest': 'ab', //&f=300 2651 'fdm': 'fdm300', 2652 'si': 'si', 2653 'photo': 'photo300' 2654 }, 2655 728: { 2656 'rest': 'ab', //&f=728 2657 'fdm': 'fdm728', 2658 'si': 'si728', 2659 'photo': 'photo' 2660 } 2661 }, 2662 link: 'https://android.giveawayoftheday.com/web/bannerinf.js?body=1', 2663 class: 'aa-', 2664 is_mobile: false, 2665 show_rest: false, 2666 enabled: false, 2667 from: '' 2668 }, 2669 ba: false, 2670 banner_num: 1, 2671 2672 init: function(settings) { 2673 $.extend(true, this.conf, settings); 2674 if (!this.conf.enabled) { 2675 return; 2676 } 2677 this.ba = new BlockAdBlock({ 2678 checkOnLoad: true, 2679 resetOnEnd: true 2680 }); 2681 this.bindActions(); 2682 }, 2683 2684 bindActions: function() { 2685 var that = this; 2686 that.ba.on(true, function (e) {that.replaceAdv(e)}); 2687 }, 2688 2689 createBanner: function(block, type) { 2690 var id = 'inf_bnr_' + this.banner_num; 2691 var script = document.createElement('script'); 2692 script.src = this.conf.link + '&num='+ type + '&from=' + this.conf.from + '&dnm='+id; 2693 var d = document.createElement('div'); 2694 d.id = id; 2695 d.style.overflow = 'hidden'; 2696 block.insertBefore(d, block.firstChild); 2697 if (script) { 2698 block.insertBefore(script, block.firstChild); 2699 } 2700 this.banner_num++; 2701 }, 2702 2703 getSize: function(classname) { 2704 var expr = new RegExp(this.conf.class + "\\d+"); 2705 var size_class = classname.match(expr); 2706 if (!size_class) { 2707 return false; 2708 } 2709 var size = size_class[0].replace(this.conf.class, ''); 2710 if (size == 336 || this.conf.is_mobile) { 2711 size = 300; 2712 } 2713 2714 return size; 2715 }, 2716 2717 replaceAdv: function(e) { 2718 var adv_blocks = document.querySelectorAll("div[class*='"+this.conf.class+"'], span[class*='"+this.conf.class+"']"); 2719 var used_blocks = {300:{}, 728:{}}; 2720 var size = 0; 2721 for (var i = 0; i < adv_blocks.length; i++) {
2722 size = this.getSize(adv_blocks[i].className); 2723 if (i == 0 && this.conf.show_rest) { 2724 this.createBanner(adv_blocks[i], this.conf.blocks_num[size]['rest']); 2725 $('.col1.giveaway_day').addClass('need_pad'); 2726 } else { 2727 if (this.conf.is_mobile) { 2728 this.createBanner(adv_blocks[i], 'static_inf'); 2729 } else { 2730 var cur_block = this.conf.blocks_num[size]; 2731 var block_showed = false; 2732 for (var type in cur_block) { 2733 if (!cur_block.hasOwnProperty(type) || type == 'rest') { 2734 continue; 2735 } 2736 if (used_blocks[type] == "undefined" || !used_blocks[type]) { 2737 this.createBanner(adv_blocks[i], cur_block[type]); 2738 used_blocks[type] = true; 2739 block_showed = true; 2740 break; 2741 } 2742 } 2743 if (!block_showed) { 2744 this.createBanner(adv_blocks[i], cur_block['fdm']); 2745 } 2746 } 2747 } 2748 } 2749 } 2750 } 2751})(jQuery); 2752 2753function preventDefault(e) { 2754 e = e || window.event; 2755 if (e.preventDefault) 2756 e.preventDefault(); 2757 e.returnValue = false; 2758} 2759 2760function preventDefaultForScrollKeys(e) { 2761 if (keys[e.keyCode]) { 2762 preventDefault(e); 2763 return false; 2764 } 2765} 2766 2767function disableScroll() { 2768 if (window.addEventListener) // older FF 2769 window.addEventListener('DOMMouseScroll', preventDefault, false); 2770 window.onwheel = preventDefault; // modern standard 2771 window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE 2772 window.ontouchmove = preventDefault; // mobile 2773 document.onkeydown = preventDefaultForScrollKeys; 2774} 2775 2776function enableScroll() { 2777 if (window.removeEventListener) 2778 window.removeEventListener('DOMMouseScroll', preventDefault, false); 2779 window.onmousewheel = document.onmousewheel = null; 2780 window.onwheel = null; 2781 window.ontouchmove = null; 2782 document.onkeydown = null; 2783} 2784 2785var away_bnr = (function($) { 2786 return { 2787 conf: { 2788 enabled: false, 2789 is_showed_on_no_active: false, 2790 idle_interval: 5000, 2791 is_open: false 2792 }, 2793 2794 init: function(settings) { 2795 $.extend(true, this.conf, settings); 2796 if (this.conf.enabled) { 2797 this.bindActions(); 2798 } 2799 }, 2800 2801 bindActions: function() { 2802 var that = this; 2803 $(document).on('mousedown.away_bnr keydown.away_bnr mousemove.away_bnr scroll.away_bnr', function (e) { 2804 that.isActive(e); 2805 }); 2806 $('.close_onload_btn').on('click', function (e) { 2807 e.preventDefault(); 2808 that.showBanner(); 2809 }); 2810 $(document).on('click', function (e) { 2811 that.checkCloseBanner(e); 2812 }); 2813 this.timer = setTimeout(function () { 2814 that.isNotActive(); 2815 }, that.conf.idle_interval); 2816 }, 2817 2818 showBanner: function () { 2819 var that = this; 2820 if (that.conf.is_open) { 2821 return; 2822 } 2823 2824 var left_start = $('.close_onload_btn').offset()['left']; 2825 var top_start = $('.close_onload_btn').offset()['top']; 2826 var left_end = $(window).width()/2 - $(".bil_onnoactive").outerWidth()/2; 2827 var top_end = $(window).height()/2 - $(".bil_onnoactive").outerHeight()/2 + $(window).scrollTop(); 2828 2829 $(".bil_onnoactive") 2830 .clone() 2831 .css({ 2832 'position': 'absolute', 2833 'z-index': '11100', 2834 left: left_start, 2835 top: top_start, 2836 width: 50, 2837 height: 50, 2838 }) 2839 .appendTo("body") 2840 .animate({ 2841 opacity: 1, 2842 left: left_end, 2843 top: top_end, 2844 width: $(".bil_onnoactive").outerWidth(), 2845 height: $(".bil_onnoactive").outerHeight() 2846 }, { 2847 duration: 1000, 2848 start: function () { 2849 $(".bil_onnoactive").hide(); 2850 $(this).show(); 2851 $('#billion_onnoactive').show(); 2852 }, 2853 complete: function () { 2854 $(this).remove(); 2855 disableScroll(); 2856 $(".bil_onnoactive").show(); 2857 that.conf.is_open = true; 2858 } 2859 } 2860 ); 2861 }, 2862 2863 checkCloseBanner: function (e) { 2864 if (!this.conf.is_open) { 2865 return; 2866 } 2867 e.preventDefault(); 2868 var $container = $('.bil_onnoactive, .close_onload_btn'); 2869 if (!$container.is(e.target) && $container.has(e.target).length === 0) { 2870 this.closeBanner(); 2871 } 2872 }, 2873 2874 closeBanner: function () { 2875 this.conf.is_open = false; 2876 $('#billion_onnoactive').fadeOut(200); 2877 enableScroll(); 2878 $(".bil_onnoactive") 2879 .clone() 2880 .css({ 2881 'position': 'absolute', 2882 'z-index': '11100', 2883 top: $(".bil_onnoactive").offset().top, 2884 left: $(".bil_onnoactive").offset().left 2885 }) 2886 .appendTo("body") 2887 .animate({ 2888 opacity: 0.05, 2889 left: $('.close_onload_btn').offset().left, 2890 top: $('.close_onload_btn').offset().top, 2891 width: 20, 2892 height: 20 2893 }, 1000, 2894 function() { 2895 $(this).remove(); 2896 } 2897 ); 2898 }, 2899 2900 isActive: function (e) { 2901 var that = this; 2902 if (that.conf.is_open && that.conf.is_showed_on_no_active) { 2903 $(document).off('.away_bnr'); 2904 that.closeBanner(); 2905 //that.conf.is_showed_on_no_active = false; 2906 2907 return; 2908 } 2909 clearTimeout(that.timer); 2910 that.timer = setTimeout(function () { 2911 that.isNotActive(); 2912 }, that.conf.idle_interval); 2913 }, 2914 2915 isNotActive: function (e) { 2916 if (this.conf.is_open) { 2917 return; 2918 } 2919 this.conf.is_showed_on_no_active = true; 2920 this.showBanner(); 2921 } 2922 }; 2923})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.