'use strict';
function get_browser_info() {
var ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [], d = 'desktop', OSName = 'unknown-os';
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua)) {
d = 'mobile';
}
if (navigator.appVersion.indexOf("Win") != -1)
OSName = "windows";
if (navigator.appVersion.indexOf("Mac") != -1)
OSName = "mac";
if (navigator.appVersion.indexOf("X11") != -1)
OSName = "unix";
if (navigator.appVersion.indexOf("Linux") != -1)
OSName = "linux";
if (/trident/i.test(M[1])) {
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
return {name: 'ie', version: (tem[1] || ''), device: d, os: OSName};
}
if (M[1] === 'Chrome') {
tem = ua.match(/\bOPR\/(\d+)/)
if (tem != null) {
return {name: 'opera', version: tem[1], device: d, os: OSName};
}
}
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
if ((tem = ua.match(/version\/(\d+)/i)) != null) {
M.splice(1, 1, tem[1]);
}
return {name: M[0].toLowerCase(), version: M[1], device: d, os: OSName};
}
var __browser = get_browser_info();
function isSupportedNotification() { if ('serviceWorker' in navigator && 'PushManager' in window && window.safari === undefined) { return true; } return false; /* if (((__browser.name == 'opera' && __browser.version >= 26) || (__browser.name == 'chrome' && __browser.version >= 43) || (__browser.device != 'mobile' && __browser.name == 'firefox' && __browser.version >= 44))) { return true; } return false; */ }
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(base_url + 'sw.js', {scope: base_url})
.catch(function (error) {
//printMsg('Your browser is not supporting this feature, please get chrome (42+) or firefox (44+) ' + error)
});
}
function querySt(e) {
var hu = '', ft = '';
hu = window.location.search.substring(1).split("&");
for (var i = 0; i < hu.length; i++) {
ft = hu[i].split("=");
if (ft[0] == e) {
return ft[1]
}
}
return '';
}
var unsubscribe = '',__elexConst='';
var settings = '';var ___site = 'ndtv';
var sections = '', constID = '';
var __pushSite = (typeof __pushSite === "undefined") ? 'ndtv' : __pushSite;
//__pushSite = 'ndtv';
var blogID = querySt('blogID') || 0;
var parentsite = document.referrer || 'https://www.ndtv.com';
var isSilent = false;
parentsite = parentsite + ((parentsite.indexOf('?') > -1) ? '&' : '?') + 'browserpush=true';
var usermsg = (constID?'Election ':'')+'News alerts are turned off. Click here to turn on.';
var usermsg_un = 'You have subscribed to our '+(constID?'Election ':'')+'news updates. To unsubscribe, click here ';
var usermsg_re = (constID?'Election ':'')+'News alerts are turned off. Click here to turn on.';
var site_text = '';
var sitetitle = 'NDTV';
switch(__pushSite) {
case 'profit':
sitetitle = 'NDTV Profit';
___site = 'profit';
break;
case 'news-tamil':
sitetitle = 'NDTV Tamil';
usermsg = usermsg_re = 'நியூஸ் அலெர்ட் நிறுத்தி வைக்கப்பட்டுள்ளது. ஆன் செய்ய இங்கே க்ளிக் செய்யவும். ';
usermsg_un = 'நியூஸ் அலெர்ட் ஆன் செய்யப்பட்டுள்ளது. நிறுத்தி வைக்க இங்கே க்ளிக் செய்யவும். ';
___site = 'ndtvtamil';
break;
case 'news-bengali':
sitetitle = 'NDTV Bangla';
usermsg = usermsg_re = 'নিউজ অ্যালার্ট বন্ধ আছে। এখানে ক্লিক করে অন করুন ';
usermsg_un = 'নিউজ অ্যালার্ট অন আছে। এখানে ক্লিক করে বন্ধ করুন ';
___site = 'ndtvbengali';
break;
case 'education':
sitetitle = 'NDTV Education';
___site = 'education';
break;
case 'entertainment':
sitetitle = 'NDTV Movies';
___site = 'entertainment';
site_text = '
Get Entertainment News Alerts From '+sitetitle+'. We\'ll send you updates on celebrity news and trending stories through the day. You can manage them any time from your browser settings.
';
usermsg = 'Entertainment alerts are turned off. Click here to turn on.';
usermsg_un = 'You have subscribed to our Entertainment news updates. To unsubscribe, click here ';
usermsg_re = 'Entertainment alerts are turned off. Click here to turn on.';
break;
case 'swirlster':
sitetitle = 'NDTV Swirlster';
___site = 'swirlster';
break;
case 'shopping':
sitetitle = 'NDTV Shopping';
___site = 'shopping';
site_text = 'Get The Best Shopping Alerts From '+sitetitle+'. You will receive the latest updates on the best deals from NDTV Shopping through the day. You can manage them when you need in browser settings.
';
usermsg = sitetitle+ ' alerts are turned off. Click here to turn on.';
usermsg_un = 'You have subscribed to our '+sitetitle+' updates. To unsubscribe, click here ';
usermsg_re = sitetitle + ' alerts are turned off. Click here to turn on.';
break;
default:
sitetitle = 'NDTV';
}
if(site_text==''){
site_text = 'Get Breaking News Alerts From '+sitetitle+'. We\'ll send you latest news updates through the day. You can manage them any time from your browser settings.
';
}
var __cname = ___site + '_isSubscribed_elex_v1';
var ___page = (typeof __page !== 'undefined') ? __page : '';
var dbName = 'ndtvNotify', dbTable = 'settings', dbVersion = 1, db;
var notifyType = 'news';
checkSetup('');
function checkSetup(passconstID) {
if (!isSupportedNotification()) {
return false;
}
//check for live blog
if($("input[data-type='lv']").length){
$('.live__updts').css('display','flex');
var tmp = {'id':$("input[data-type='lv']").attr('data-id'),'type':'liveblog','action':'get'};
initalizeDB(tmp);
}
var check = __getCookieVal(__cname) || '';
ndtvUnsubscribeButton(); //show setting bell
if (check == '') {
setTimeout(__showSubscribePopup, ___page=='hp'?17000:3000);
return false;
}
//disabled auto subscribe
//refresh the notification subscription if you want
var __checkRefresh = parseInt(localStorage.getItem('_ndtvBPush')) || 0;
var currTime = new Date().getTime();
//60*60*24*5 = 2 days
if (Notification.permission == 'granted' && (currTime - __checkRefresh > 1000 * 60 * 60 * 24 * 10)) {
localStorage.setItem('_ndtvBPush', new Date().getTime());
isSilent = true;
initialiseState();
}
}
function initalizeDB(obj) {
if (!indexedDB) {
console.log("Your Browser does not support IndexedDB");
} else {
var requestDB = indexedDB.open(dbName, dbVersion);
requestDB.onerror = function (event) {
console.log("Error opening DB", event);
}
requestDB.onupgradeneeded = function (event) {
console.log("Upgrading");
db = event.target.result;
db.createObjectStore(dbTable, {keyPath: 'val'});
};
requestDB.onsuccess = function (event) {
console.log("Success opening DB");
db = event.target.result;
if (obj.id && obj.type) {
if (obj.action === 'get') {
getDB(obj.id, obj.type);
}else if (obj.action === 'remove') {
removeDB(obj.id, obj.type);
} else {
if(obj.type == 'election'){
removeDB(obj.id, obj.type);
obj.id.split(/\s*,\s*/).forEach(function(ii) {
saveDB(ii, obj.type);
});
}else{
saveDB(obj.id, obj.type);
}
}
}
}
}
}
function getDB(id, type) {
var transaction = db.transaction([dbTable], "readwrite");
var objectStore = transaction.objectStore(dbTable);
var gid = objectStore.get(id + '-' + type);
gid.onsuccess = function(event){
if(gid.result && gid.result.val == id + '-' + type){
$("input[data-id='"+id+"']").attr('checked','checked');
}
}
}
function saveDB(id, type) {
var transaction = db.transaction([dbTable], "readwrite");
var objectStore = transaction.objectStore(dbTable);
objectStore.add({id: id, type: type, lastId: 0, val: id + '-' + type});
}
function removeDB(id, type) {
var transaction = db.transaction([dbTable], "readwrite");
var objectStore = transaction.objectStore(dbTable);
//objectStore.delete(id + '-' + type);
objectStore.clear()
}
function initialiseState() {
if (!('showNotification' in ServiceWorkerRegistration.prototype)) {
printMsg('Notifications aren\'t supported.');
return false;
}
if (Notification.permission == 'granted') {
//already registered or not allowed
//printMsg(usermsg_un);
//return false;
}
if (Notification.permission == 'default' && settings == '') {
overlayAction('block');
}
if (Notification.permission === 'denied') {
overlayAction('none');
printMsg('You have blocked notifications for this site.Click here for detials. ');
}
if (!('PushManager' in window)) {
overlayAction('none');
printMsg('Push messaging isn\'t supported.');
redirectToParent(2000);
return;
}
navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) {
// Do we already have a push message subscription?
serviceWorkerRegistration.pushManager.getSubscription()
.then(function (subscription) {
var msg = '';
if (!subscription) {
// We aren't subscribed to push, so set UI
subscribe('');
return true;
}
var ep = getEndPoint(subscription);
subscribeNow(ep, '');
printMsg((constID ? 'Election ' : '') +usermsg_un);
ndtvCloseThis(365, 'yes');
})
.catch(function (err) {
printMsg('Error during getSubscription()', err);
//window.location.reload();
return;
});
}).catch(function (error) {
printMsg('Your browser is not supporting this feature, please get chrome (42+) or firefox (44+) ' + error);
});
}
function unSubscribe() {
navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) {
// To unsubscribe from push messaging, you need get the
// subscription object, which you can call unsubscribe() on.
serviceWorkerRegistration.pushManager.getSubscription().then(
function (subscription) {
// Check we have a subscription to unsubscribe
if (!subscription) {
printMsg((constID ? 'Election ' : '') +usermsg_re);
ndtvCloseThis(1, '');
return;
}
var ep = getEndPoint(subscription);
subscribeNow(ep, 1);
subscription.unsubscribe().then(function (successful) {
printMsg((constID ? 'Election ' : '') +usermsg_re);
ndtvCloseThis(1, '');
}).catch(function (e) {
printMsg('Error during getSubscription()', e);
window.location.reload();
return;
});
}).catch(function (e) {
printMsg('Error thrown while unsubscribing from push messaging.', e);
window.location.reload();
return;
});
});
}
function subscribe(old) {
if (Notification.permission == 'default') {
overlayAction('block');
}
if (Notification.permission == 'granted') {
overlayAction('none');
}
navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe({userVisibleOnly: true})
.then(function (subscription) {
var ep = getEndPoint(subscription);
if ((settings == '' || old == '1') && !isSilent) {
onRegisterNotify(serviceWorkerRegistration);
}
overlayAction('none');
subscribeNow(ep, '');
printMsg((constID ? 'Election ' : '') +usermsg_un);
ndtvCloseThis(365,'yes');
return true;
})
.catch(function (e) {
if (Notification.permission === 'denied') {
overlayAction('none');
printMsg('You have blocked notifications for this site.Click here for detials. ');
} else {
overlayAction('none');
console.log(e);
printMsg('Something went wrong Please refresh page ');
}
});
});
}
function overlayAction(type) {
if (document.getElementById('ndtvnotify') && (type == 'block' || type == 'none')) {
document.getElementById('ndtvnotify').style.display = type;
}
}
function redirectToParent(time) {
return;
if (parentsite != '') {
setTimeout(function () {
location.href = parentsite;
}, time);
}
}
function getEndPoint(pushSubscription) {
//console.log(pushSubscription);
if (pushSubscription.subscriptionId) {
return pushSubscription.subscriptionId;
}
var endpoint = 'https://android.googleapis.com/gcm/send/';
var parts = pushSubscription.endpoint.split(endpoint);
if (parts.length > 1)
{
return {
'browser': 'chrome',
'id': parts[1]
};
}
var endpoint = 'https://fcm.googleapis.com/fcm/send/';
var parts = pushSubscription.endpoint.split(endpoint);
if (parts.length > 1)
{
return {
'browser': 'chrome',
'id': parts[1]
};
}
endpoint = 'https://updates.push.services.mozilla.com/push/';
parts = pushSubscription.endpoint.split(endpoint);
if (parts.length > 1)
{
return {
'browser': 'firefox',
'id': parts[1]
};
}
endpoint = 'https://updates.push.services.mozilla.com/wpush/';
parts = pushSubscription.endpoint.split(endpoint);
if (parts.length > 1)
{
return {
'browser': 'firefox',
'id': parts[1]
};
}
return '';
}
function subscribeNow(registrationDetail, unregister) {
if (!registrationDetail) {
return;
}
/*console.log(registrationDetail);*/
var ep = 'https://ipush.apps.ndtv.com/subscribeBrowser.php';
//var ep = 'http://localhost/ndtvapps/pushnotification/public/subscribeBrowser.php';
$.ajax({
type: 'POST',
dataType: 'json',
url: ep,
data: {
'packageName': ___site+'.' + registrationDetail.browser,
'env': 'PRODUCTION',
'sections': sections,
'unregister': unregister,
'registration_id': registrationDetail.id,
'blogID':blogID
},
complete: function (data) {}
});
var obj = {id: 'news', type: ___site};
if (blogID) {
notifyType = 'liveblog';
obj = {id: blogID, type: 'liveblog'};
//message format change
sitetitle = "Live Updates";
usermsg_un = "Thanks for subscribing. You will receive news alerts as this story develops";
usermsg_re = usermsg = "Thank You, Unsubscribe request completed. Click here to re-subscribe";
}
if (constID) {
notifyType = 'election';
obj = {id: constID, type: 'election'};
storageSet('__elexConst',constID);
}
if(unregister){
obj.action = 'remove';
storageSet('__elexConst','');
}
initalizeDB(obj);
}
function printMsg(msg) {
if(!isSilent){
$('.popover-content').html('' + msg);
$('.popover').show();
}
//alert(msg);
//if (document.getElementById('msg')) {document.getElementById('msg').innerHTML = msg;}
}
function onRegisterNotify(reg) {
var logo = 'https://drop.ndtv.com/ndtv/alerts/logo/'+___site+'.png';
//var m_ = 'You have subscribed to NDTV election alerts. We\'ll send you latest updates as votes are counted on Dec 18. Stay tuned.';
var m_ = 'Thank you for subscribing to ' + sitetitle + (constID ? ' Election' : '') + ' News alerts.';
var ss_ = 'NDTV';
if(blogID){
m_ = 'Thanks for subscribing. You will receive news alerts as this story develops';
ss_ = 'NDTV Updates';
}
try {
var notification = reg.showNotification(ss_, {
body: m_,
icon: logo,
vibrate: [300, 100, 400],
tag: 'ndtvnews-welcome',
data: {
url: 'https://www.ndtv.com?browserpush=true'
}
});
notification.onclick = function (event) {
event.target.close();
window.location.href = event.target.data.url;
return;
};
} catch (err) {console.log(err.message);}
}
function __setCookieVal(c_name, value, exdays)
{
var current = new Date();
var exdate = new Date(current.getTime() + 86400000 * exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString() + ';path=/;');
document.cookie = c_name + "=" + c_value;
}
function __getCookieVal(c_name)
{
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++)
{
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name)
{
return unescape(y);
}
}
return '';
}
function __showSubscribePopup(){
//elexSubs(true);return;
var logo = 'https://drop.ndtv.com/ndtv/alerts/logo/'+___site+'.png';
var id = document.getElementById('___ndtvpushdiv');
if(id){
id.innerHTML = '';
id.innerHTML +='';
if(___page=='mobile' || ___page=='wap'){
id.innerHTML += '';
}
}
}
function ndtvCloseThis(cday, val) {
__setCookieVal(__cname, val, cday);
if (document.getElementById('__cricketsubscribe')) {
document.getElementById('__cricketsubscribe').style.display = 'none';
}
}
function ndtvUnsubscribeButton(){
if(isSupportedNotification()){
var id = document.getElementById('___ndtvspldiv');
var msg = (constID ? 'Election ' : '') +(__getCookieVal(__cname) == 'yes' ? usermsg_un : usermsg);
msg = (Notification.permission === 'denied') ? 'You have blocked notifications for this site.Click here for detials. ' : msg
if(id){
var msgdispl = (window.location.href.indexOf('browserpush=true') > -1)?'block':'none';
if(___page=='mobile'){
id.innerHTML = '';
id.innerHTML += '';
}else if(___page=='wap'){
id.innerHTML = '';
id.innerHTML += '';
}else{
id.innerHTML = '';
id.innerHTML += ' ';
}
}
if(document.getElementById('___ndtvELexBanner')){
elexSubs(true);document.getElementById('___ndtvELexBanner').style.display = 'block';
}
}
}
function __getcheckboxes() {
var chkbox = [];
$("input:checkbox[name^=__s]:checked").each(function(){
chkbox.push($(this).attr('id'));
});
var vals = chkbox.join(',');
return vals;
}
function __alw() {
if(document.getElementById('__emsg')){
document.getElementById('__emsg').innerHTML = '';
}
ndtvCloseThis(180,'yes');
initialiseState();
//setTimeout(function(){location.href = 'https://alerts.ndtv.com/';},2);
return false;
}
function elexSubs(forced){
if(!isSupportedNotification()){return true;}
forced = (typeof forced !== 'undefined') ? forced : false;
var check = __getCookieVal(__cname) || '';
if(forced){check = '';}
if (check!='') {return false;}
var _stts = 'Meghalaya Nagaland Tripura ';
var _consts = '';
var _elecdt = '2nd March';
var html = '\
';
var id = document.getElementById('___ndtvELexBanner');
if (id) {
id.innerHTML = html;
var userClicked = 0;
$(".__drpdown dt a").on('click', function () {
$(".__drpdown dd").slideToggle('fast');
$('.tgle').toggle();
userClicked = 1;
});
$(".__drpdown dd ul li a").on('click', function () {
$(".__drpdown dd").hide();
});
$('.__drpdown .mutliSelect li').on('click', function () {
var checkboxID = $(this).closest('li').find('input[type="checkbox"]').attr('id');
var title = $(this).closest('li').find('input[type="checkbox"]').val();//title = title + ",";
var isChecked = $(this).closest('li').find('input[type="checkbox"]').attr('data-checked');
isChecked = parseInt(isChecked);
if (!isChecked) {
if($('input[name^=__s]:checked').length>=10 && userClicked){alert('You can only select up to 10 constituencies'); return true;}
var html = '' + title + ' x
';
$('.multiSel').append(html);
$(".hida").hide();
$('#' + checkboxID).attr('checked', true);
$('#' + checkboxID).attr('data-checked', 1);
} else {
$('div[title="' + checkboxID + '"]').remove();
var ret = $(".hida");
$('.__drpdown dt a').append(ret);
$('#' + checkboxID).attr('checked', false);
$('#' + checkboxID).attr('data-checked', 0);
}
$("#_elex_sub").attr("data-constid", __getcheckboxes());
});
$(document).bind('click', function (e) {
var $clicked = $(e.target);
if (!$clicked.parents().hasClass("__drpdown"))
$(".__drpdown dd").hide();
//$('.close_a').hide();
if ($('.__drpdown dd').css('display') == 'none') {
$(".close_a").hide();
$(".drop_a").show();
}
});
__elexConst = storageGet('__elexConst') || '';
if(__elexConst){
$.each( __elexConst.split(','), function(index, value) {
if($('#'+value)){
$('#'+value).trigger( "click");
}
});
}
}
}
function uncheckOpt(checkboxID){
$('div[title="' + checkboxID + '"]').remove();
$('#'+checkboxID).trigger( "click");
}
function getSelectedValue(id) {
return $("#" + id).find("dt a span.value").html();
}
function storageSet(name, val) {
try {
localStorage.setItem(name, val);
} catch (e) {
}
}
function storageGet(name) {
var val = null;
try {
val = localStorage.getItem(name);
} catch (e) {
val = null;
}
return val;
}