Plugin Directory

Changeset 1430511


Ignore:
Timestamp:
06/04/2016 05:07:22 PM (10 years ago)
Author:
emrysforge
Message:

small js hotfix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • web-push-notifications-lite/trunk/js/sdk/init.js

    r1429330 r1430511  
    1 'use strict';
     1'use strict'; 
    22
    33var scripts = document.getElementsByTagName( "script" ) ;
     
    77var params = arr[1];
    88
     9//document.getElementById('pushem-notification-https-sub').style.display = 'none';
     10
    911if ('serviceWorker' in navigator) {
    1012
    1113navigator.serviceWorker.register('/wp-content/plugins/em_desktop_notifications/js/sdk/sw.js').then(function(reg) {
    12         console.log(':^)', reg);
     14        //console.log(':^)', reg);
     15//console.log('some');
    1316
    1417    navigator.serviceWorker.getRegistration('/wp-content/plugins/em_desktop_notifications/js/sdk/sw.js').then(function(reg) {
     
    1619
    1720            //SET COOKIE, USE FOR ANONYMOUS
     21            if (sub != null) {
    1822                var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
    1923                document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d;
     24                //document.getElementById('pushem-notification-https-sub').style.display = 'block';
     25            }
    2026            //END OF COOKIE
    2127
     
    2430            fetch(get_settings_line).then(function(response) {
    2531                response.json().then(function(data) {
    26                
    27                     console.log(data.source.mode);
    28 
    29                 if (sub == null) {
    30                     console.log("Unsubed");
     32
     33                    //console.log(data.source.mode);
     34                if (sub == null) {                   
     35                    //console.log("Unsubed1");
    3136               
    3237                if (data.source.mode == 'auto') {
     
    4045                        //END OF COOKIE
    4146
    42                         console.log(sub);
    43                         console.log('endpoint:', sub.endpoint);
     47                        //console.log(sub);
     48                        //console.log('endpoint:', sub.endpoint);
    4449                                   
    4550                                    document.getElementById('pushem-notification-https-unsub').innerHTML = data.source.unsubbtn;
     
    6772                                            document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d;
    6873                                        //END OF COOKIE
    69                                     console.log('Unsubed');
     74                                    //console.log('Unsubed2');
    7075                                    document.getElementById('pushem-notification-https-unsub').style.display = 'none';
    7176                                    document.getElementById('pushem-notification-https-sub').style.display = 'block';
     
    8085                                    var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint;
    8186                                   
    82                                     console.log(idget_line);
     87                                    //console.log(idget_line);
    8388
    8489                                    fetch(idget_line).then(function(response) {
     
    107112                                    //END OF COOKIE
    108113
    109                                     console.log(sub);
    110                                     console.log('endpoint:', sub.endpoint);
     114                                    //console.log(sub);
     115                                    //console.log('endpoint:', sub.endpoint);
    111116
    112117                                    document.getElementById('pushem-notification-https-sub').style.display = 'none';
     
    151156                                    //END OF COOKIE
    152157
    153                                     console.log(sub);
    154                                     console.log('endpoint:', sub.endpoint);
     158                                    //console.log(sub);
     159                                    //console.log('endpoint:', sub.endpoint);
    155160
    156161                                    document.getElementById('pushem-notification-https-sub').style.display = 'none';
     
    170175                                    });
    171176
    172                                 });     
    173                             };
    174                 }
    175 
    176                 } else {
    177                     console.log("Subed", sub.endpoint);
    178                     console.log(data.source.unsubbtn);
    179                     document.getElementById('pushem-notification-https-unsub').innerHTML = data.source.unsubbtn;
    180                     document.getElementById('pushem-notification-https-unsub').style.display = 'block';
     177
     178
     179
     180
    181181
    182182                    var httpunsubbtn = document.getElementById('pushem-notification-https-unsub');
     
    186186                                    sub.unsubscribe().then(function(event) {
    187187
    188                                     //SET COOKIE, USE FOR ANONYMOUS
    189                                         var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
    190                                         var s = "";
    191                                         document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d;
    192                                     //END OF COOKIE
    193 
    194                                     console.log('Unsubed');
     188                                        //SET COOKIE, USE FOR ANONYMOUS
     189                                            var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     190                                            var s = "";
     191                                            document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d;
     192                                        //END OF COOKIE
     193                                    //console.log('Unsubed2');
    195194                                    document.getElementById('pushem-notification-https-unsub').style.display = 'none';
    196195                                    document.getElementById('pushem-notification-https-sub').style.display = 'block';
     
    205204                                    var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint;
    206205                                   
    207                                     console.log(idget_line);
     206                                    //console.log(idget_line);
    208207
    209208                                    fetch(idget_line).then(function(response) {
     
    232231                                    //END OF COOKIE
    233232
    234                                     console.log(sub);
    235                                     console.log('endpoint:', sub.endpoint);
     233                                    //console.log(sub);
     234                                    //console.log('endpoint:', sub.endpoint);
     235
     236                                    document.getElementById('pushem-notification-https-sub').style.display = 'none';
     237                                    document.getElementById('pushem-notification-https-unsub').style.display = 'block';
     238
     239                                    document.getElementById('pushem-widget-https').style.display = 'none';
     240                                    document.getElementById('pushem-widget-https-bg').style.display = 'none';
     241
     242                                    document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg;
     243                                    document.getElementById('pushem-notification-https-msg').style.display = 'block';
     244                                    setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000);
     245
     246                                    var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint;
     247
     248                                    fetch(endpoint_line).then(function(response) {
     249
     250                                    });
     251
     252                                });     
     253                            };
     254
     255
     256                                    });
     257                                });
     258                            };
     259
     260
     261
     262
     263
     264
     265
     266
     267
     268
     269                                });     
     270                            };
     271                }
     272
     273                } else {
     274                    //console.log("Subed", sub.endpoint);
     275                    //console.log(data.source.unsubbtn);
     276                    document.getElementById('pushem-notification-https-unsub').innerHTML = data.source.unsubbtn;
     277                    document.getElementById('pushem-notification-https-unsub').style.display = 'block';
     278
     279                    var httpunsubbtn = document.getElementById('pushem-notification-https-unsub');
     280                        httpunsubbtn.style.cursor = 'pointer';
     281                            httpunsubbtn.onclick = function() {
     282                                reg.pushManager.getSubscription(reg).then(function(sub) {
     283                                    sub.unsubscribe().then(function(event) {
     284
     285                                    //SET COOKIE, USE FOR ANONYMOUS
     286                                        var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     287                                        var s = "";
     288                                        document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d;
     289                                    //END OF COOKIE
     290
     291                                    //console.log('Unsubed3');
     292                                    document.getElementById('pushem-notification-https-unsub').style.display = 'none';
     293                                    document.getElementById('pushem-notification-https-sub').style.display = 'block';
     294
     295                                    document.getElementById('pushem-widget-https').style.display = 'none';
     296                                    document.getElementById('pushem-widget-https-bg').style.display = 'none';
     297
     298                                    document.getElementById('pushem-notification-https-msg').innerHTML = data.source.unsubmsg;
     299                                    document.getElementById('pushem-notification-https-msg').style.display = 'block';
     300                                    setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000);
     301
     302                                    var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint;
     303                                   
     304                                    //console.log(idget_line);
     305
     306                                    fetch(idget_line).then(function(response) {
     307                                        response.json().then(function(data) {               
     308
     309                                        var idremove_line = "https://pushem.org/api/subscribers/remove/?"+params+"&id="+data.subscriber.id;
     310                                        fetch(idremove_line).then(function(response) {
     311
     312                                        });
     313
     314                                    });
     315                                    });
     316
     317
     318
     319                    var httpsubbtn = document.getElementById('pushem-notification-https-sub');
     320                        httpsubbtn.style.cursor = 'pointer';
     321                            httpsubbtn.onclick = function() {
     322                                reg.pushManager.subscribe({
     323                                    userVisibleOnly: true
     324                                }).then(function(sub) {
     325
     326                                    //SET COOKIE, USE FOR ANONYMOUS
     327                                        var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     328                                        document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d;
     329                                    //END OF COOKIE
     330
     331                                    //console.log(sub);
     332                                    //console.log('endpoint:', sub.endpoint);
    236333
    237334                                    document.getElementById('pushem-notification-https-sub').style.display = 'none';
     
    266363
    267364}).catch(function(error) {
    268     console.log(':^(', error);
     365    //console.log(':^(', error);
    269366});
    270367
Note: See TracChangeset for help on using the changeset viewer.