Plugin Directory

Changeset 1543099


Ignore:
Timestamp:
11/30/2016 07:16:35 AM (9 years ago)
Author:
emrysforge
Message:

HTTPS widget fix - sub/ubsub button

File:
1 edited

Legend:

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

    r1430511 r1543099  
    11'use strict';
    22
     3
     4
    35var scripts = document.getElementsByTagName( "script" ) ;
     6
    47var currentScriptUrl = ( document.currentScript || scripts[scripts.length] ).src ;
     8
    59var scriptName = currentScriptUrl.length > 0 ? currentScriptUrl : scripts[scripts.length].baseURI.split( "/" ).pop() ;
     10
    611var arr = scriptName.split('?');
     12
    713var params = arr[1];
    814
     15
     16
    917//document.getElementById('pushem-notification-https-sub').style.display = 'none';
    1018
     19
     20
    1121if ('serviceWorker' in navigator) {
    1222
    13 navigator.serviceWorker.register('/wp-content/plugins/em_desktop_notifications/js/sdk/sw.js').then(function(reg) {
     23
     24
     25navigator.serviceWorker.register('/wp-content/plugins/web-push-notifications-lite/js/sdk/sw.js').then(function(reg) {
     26
    1427        //console.log(':^)', reg);
     28
    1529//console.log('some');
    1630
    17     navigator.serviceWorker.getRegistration('/wp-content/plugins/em_desktop_notifications/js/sdk/sw.js').then(function(reg) {
     31
     32
     33    navigator.serviceWorker.getRegistration('/wp-content/plugins/web-push-notifications-lite/js/sdk/sw.js').then(function(reg) {
     34
    1835        reg.pushManager.getSubscription(reg).then(function(sub) {
    1936
     37
     38
    2039            //SET COOKIE, USE FOR ANONYMOUS
     40
    2141            if (sub != null) {
     42
    2243                var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     44
    2345                document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d;
     46
    2447                //document.getElementById('pushem-notification-https-sub').style.display = 'block';
     48
    2549            }
     50
    2651            //END OF COOKIE
    2752
     53
     54
    2855            var get_settings_line = 'https://pushem.org/api/sources/get_settings/?'+params;
    2956
     57
     58
    3059            fetch(get_settings_line).then(function(response) {
     60
    3161                response.json().then(function(data) {
    3262
     63
     64
    3365                    //console.log(data.source.mode);
     66
    3467                if (sub == null) {                   
     68
    3569                    //console.log("Unsubed1");
     70
    3671               
     72
    3773                if (data.source.mode == 'auto') {
     74
    3875                    reg.pushManager.subscribe({
     76
    3977                        userVisibleOnly: true
     78
    4079                    }).then(function(sub) {
    4180
     81
     82
    4283                        //SET COOKIE, USE FOR ANONYMOUS
     84
    4385                            var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     86
    4487                            document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d;
     88
    4589                        //END OF COOKIE
    4690
     91
     92
    4793                        //console.log(sub);
     94
    4895                        //console.log('endpoint:', sub.endpoint);
     96
    4997                                   
     98
    5099                                    document.getElementById('pushem-notification-https-unsub').innerHTML = data.source.unsubbtn;
     100
    51101                                    document.getElementById('pushem-notification-https-unsub').style.display = 'block';
    52102
     103
     104
    53105                                    document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg;
     106
    54107                                    document.getElementById('pushem-notification-https-msg').style.display = 'block';
     108
    55109                                    setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000);
     110
    56111           
     112
    57113                    var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint;
     114
    58115           
     116
    59117                    fetch(endpoint_line).then(function(response) {
    60118
     119
     120
    61121                    });
    62122
     123
     124
    63125                    var httpunsubbtn = document.getElementById('pushem-notification-https-unsub');
     126
    64127                        httpunsubbtn.style.cursor = 'pointer';
     128
    65129                            httpunsubbtn.onclick = function() {
     130
    66131                                reg.pushManager.getSubscription(reg).then(function(sub) {
     132
    67133                                    sub.unsubscribe().then(function(event) {
    68134
     135
     136
    69137                                        //SET COOKIE, USE FOR ANONYMOUS
     138
    70139                                            var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     140
    71141                                            var s = "";
     142
    72143                                            document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d;
     144
    73145                                        //END OF COOKIE
     146
    74147                                    //console.log('Unsubed2');
     148
    75149                                    document.getElementById('pushem-notification-https-unsub').style.display = 'none';
     150
    76151                                    document.getElementById('pushem-notification-https-sub').style.display = 'block';
    77152
     153
     154
    78155                                    document.getElementById('pushem-widget-https').style.display = 'none';
     156
    79157                                    document.getElementById('pushem-widget-https-bg').style.display = 'none';
    80158
     159
     160
    81161                                    document.getElementById('pushem-notification-https-msg').innerHTML = data.source.unsubmsg;
     162
    82163                                    document.getElementById('pushem-notification-https-msg').style.display = 'block';
     164
    83165                                    setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000);
    84166
     167
     168
    85169                                    var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint;
     170
    86171                                   
     172
    87173                                    //console.log(idget_line);
    88174
     175
     176
    89177                                    fetch(idget_line).then(function(response) {
     178
    90179                                        response.json().then(function(data) {               
    91180
     181
     182
    92183                                        var idremove_line = "https://pushem.org/api/subscribers/remove/?"+params+"&id="+data.subscriber.id;
     184
    93185                                        fetch(idremove_line).then(function(response) {
    94186
     187
     188
    95189                                        });
    96190
    97                                     });
    98                                     });
     191
     192
     193                                    });
     194
     195                                    });
     196
     197
     198
     199
    99200
    100201
    101202
    102203                    var httpsubbtn = document.getElementById('pushem-notification-https-sub');
     204
    103205                        httpsubbtn.style.cursor = 'pointer';
     206
    104207                            httpsubbtn.onclick = function() {
     208
    105209                                reg.pushManager.subscribe({
     210
    106211                                    userVisibleOnly: true
     212
    107213                                }).then(function(sub) {
    108214
     215
     216
    109217                                    //SET COOKIE, USE FOR ANONYMOUS
     218
    110219                                        var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     220
    111221                                        document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d;
     222
    112223                                    //END OF COOKIE
    113224
     225
     226
    114227                                    //console.log(sub);
     228
    115229                                    //console.log('endpoint:', sub.endpoint);
    116230
     231
     232
    117233                                    document.getElementById('pushem-notification-https-sub').style.display = 'none';
     234
    118235                                    document.getElementById('pushem-notification-https-unsub').style.display = 'block';
    119236
     237
     238
    120239                                    document.getElementById('pushem-widget-https').style.display = 'none';
     240
    121241                                    document.getElementById('pushem-widget-https-bg').style.display = 'none';
    122242
     243
     244
    123245                                    document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg;
     246
    124247                                    document.getElementById('pushem-notification-https-msg').style.display = 'block';
     248
    125249                                    setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000);
    126250
     251
     252
    127253                                    var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint;
    128254
     255
     256
    129257                                    fetch(endpoint_line).then(function(response) {
    130258
    131                                     });
     259
     260
     261                                    });
     262
     263
    132264
    133265                                });     
     266
    134267                            };
    135268
    136269
    137                                     });
     270
     271
     272
     273                                    });
     274
    138275                                });
     276
    139277                            };
    140278
     279
     280
    141281                    });
     282
    142283                } else {
     284
    143285                    document.getElementById('pushem-notification-https-sub').innerHTML = data.source.subbtn;
     286
    144287                    document.getElementById('pushem-notification-https-sub').style.display = 'block';
    145288
     289
     290
    146291                    var httpsubbtn = document.getElementById('pushem-notification-https-sub');
     292
    147293                        httpsubbtn.style.cursor = 'pointer';
     294
    148295                            httpsubbtn.onclick = function() {
     296
    149297                                reg.pushManager.subscribe({
     298
    150299                                    userVisibleOnly: true
     300
    151301                                }).then(function(sub) {
    152302
     303
     304
    153305                                    //SET COOKIE, USE FOR ANONYMOUS
     306
    154307                                        var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     308
    155309                                        document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d;
     310
    156311                                    //END OF COOKIE
    157312
     313
     314
    158315                                    //console.log(sub);
     316
    159317                                    //console.log('endpoint:', sub.endpoint);
    160318
     319
     320
    161321                                    document.getElementById('pushem-notification-https-sub').style.display = 'none';
     322
    162323                                    document.getElementById('pushem-notification-https-unsub').style.display = 'block';
    163324
     325
     326
    164327                                    document.getElementById('pushem-widget-https').style.display = 'none';
     328
    165329                                    document.getElementById('pushem-widget-https-bg').style.display = 'none';
    166330
     331
     332
    167333                                    document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg;
     334
    168335                                    document.getElementById('pushem-notification-https-msg').style.display = 'block';
     336
    169337                                    setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000);
    170338
     339
     340
    171341                                    var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint;
    172342
     343
     344
    173345                                    fetch(endpoint_line).then(function(response) {
    174346
    175                                     });
     347
     348
     349                                    });
     350
     351
     352
     353
     354
     355
     356
    176357
    177358
     
    181362
    182363                    var httpunsubbtn = document.getElementById('pushem-notification-https-unsub');
     364
    183365                        httpunsubbtn.style.cursor = 'pointer';
     366
    184367                            httpunsubbtn.onclick = function() {
     368
    185369                                reg.pushManager.getSubscription(reg).then(function(sub) {
     370
    186371                                    sub.unsubscribe().then(function(event) {
    187372
     373
     374
    188375                                        //SET COOKIE, USE FOR ANONYMOUS
     376
    189377                                            var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     378
    190379                                            var s = "";
     380
    191381                                            document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d;
     382
    192383                                        //END OF COOKIE
     384
    193385                                    //console.log('Unsubed2');
     386
    194387                                    document.getElementById('pushem-notification-https-unsub').style.display = 'none';
     388
    195389                                    document.getElementById('pushem-notification-https-sub').style.display = 'block';
    196390
     391
     392
    197393                                    document.getElementById('pushem-widget-https').style.display = 'none';
     394
    198395                                    document.getElementById('pushem-widget-https-bg').style.display = 'none';
    199396
     397
     398
    200399                                    document.getElementById('pushem-notification-https-msg').innerHTML = data.source.unsubmsg;
     400
    201401                                    document.getElementById('pushem-notification-https-msg').style.display = 'block';
     402
    202403                                    setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000);
    203404
     405
     406
    204407                                    var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint;
     408
    205409                                   
     410
    206411                                    //console.log(idget_line);
    207412
     413
     414
    208415                                    fetch(idget_line).then(function(response) {
     416
    209417                                        response.json().then(function(data) {               
    210418
     419
     420
    211421                                        var idremove_line = "https://pushem.org/api/subscribers/remove/?"+params+"&id="+data.subscriber.id;
     422
    212423                                        fetch(idremove_line).then(function(response) {
    213424
     425
     426
    214427                                        });
    215428
    216                                     });
    217                                     });
     429
     430
     431                                    });
     432
     433                                    });
     434
     435
     436
     437
    218438
    219439
    220440
    221441                    var httpsubbtn = document.getElementById('pushem-notification-https-sub');
     442
    222443                        httpsubbtn.style.cursor = 'pointer';
     444
    223445                            httpsubbtn.onclick = function() {
     446
    224447                                reg.pushManager.subscribe({
     448
    225449                                    userVisibleOnly: true
     450
    226451                                }).then(function(sub) {
    227452
     453
     454
    228455                                    //SET COOKIE, USE FOR ANONYMOUS
     456
    229457                                        var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     458
    230459                                        document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d;
     460
    231461                                    //END OF COOKIE
    232462
     463
     464
    233465                                    //console.log(sub);
     466
    234467                                    //console.log('endpoint:', sub.endpoint);
    235468
     469
     470
    236471                                    document.getElementById('pushem-notification-https-sub').style.display = 'none';
     472
    237473                                    document.getElementById('pushem-notification-https-unsub').style.display = 'block';
    238474
     475
     476
    239477                                    document.getElementById('pushem-widget-https').style.display = 'none';
     478
    240479                                    document.getElementById('pushem-widget-https-bg').style.display = 'none';
    241480
     481
     482
    242483                                    document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg;
     484
    243485                                    document.getElementById('pushem-notification-https-msg').style.display = 'block';
     486
    244487                                    setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000);
    245488
     489
     490
    246491                                    var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint;
    247492
     493
     494
    248495                                    fetch(endpoint_line).then(function(response) {
    249496
    250                                     });
     497
     498
     499                                    });
     500
     501
    251502
    252503                                });     
     504
    253505                            };
    254506
    255507
    256                                     });
     508
     509
     510
     511                                    });
     512
    257513                                });
     514
    258515                            };
    259516
     
    267524
    268525
     526
     527
     528
     529
     530
     531
     532
     533
     534
     535
     536
    269537                                });     
     538
    270539                            };
     540
    271541                }
    272542
     543
     544
    273545                } else {
     546
    274547                    //console.log("Subed", sub.endpoint);
     548
    275549                    //console.log(data.source.unsubbtn);
     550
    276551                    document.getElementById('pushem-notification-https-unsub').innerHTML = data.source.unsubbtn;
     552
    277553                    document.getElementById('pushem-notification-https-unsub').style.display = 'block';
    278554
     555
     556
    279557                    var httpunsubbtn = document.getElementById('pushem-notification-https-unsub');
     558
    280559                        httpunsubbtn.style.cursor = 'pointer';
     560
    281561                            httpunsubbtn.onclick = function() {
     562
    282563                                reg.pushManager.getSubscription(reg).then(function(sub) {
     564
    283565                                    sub.unsubscribe().then(function(event) {
    284566
     567
     568
    285569                                    //SET COOKIE, USE FOR ANONYMOUS
     570
    286571                                        var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     572
    287573                                        var s = "";
     574
    288575                                        document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d;
     576
    289577                                    //END OF COOKIE
    290578
     579
     580
    291581                                    //console.log('Unsubed3');
     582
    292583                                    document.getElementById('pushem-notification-https-unsub').style.display = 'none';
     584
    293585                                    document.getElementById('pushem-notification-https-sub').style.display = 'block';
    294586
     587
     588
    295589                                    document.getElementById('pushem-widget-https').style.display = 'none';
     590
    296591                                    document.getElementById('pushem-widget-https-bg').style.display = 'none';
    297592
     593
     594
    298595                                    document.getElementById('pushem-notification-https-msg').innerHTML = data.source.unsubmsg;
     596
    299597                                    document.getElementById('pushem-notification-https-msg').style.display = 'block';
     598
    300599                                    setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000);
    301600
     601
     602
    302603                                    var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint;
     604
    303605                                   
     606
    304607                                    //console.log(idget_line);
    305608
     609
     610
    306611                                    fetch(idget_line).then(function(response) {
     612
    307613                                        response.json().then(function(data) {               
    308614
     615
     616
    309617                                        var idremove_line = "https://pushem.org/api/subscribers/remove/?"+params+"&id="+data.subscriber.id;
     618
    310619                                        fetch(idremove_line).then(function(response) {
    311620
     621
     622
    312623                                        });
    313624
    314                                     });
    315                                     });
     625
     626
     627                                    });
     628
     629                                    });
     630
     631
     632
     633
    316634
    317635
    318636
    319637                    var httpsubbtn = document.getElementById('pushem-notification-https-sub');
     638
    320639                        httpsubbtn.style.cursor = 'pointer';
     640
    321641                            httpsubbtn.onclick = function() {
     642
    322643                                reg.pushManager.subscribe({
     644
    323645                                    userVisibleOnly: true
     646
    324647                                }).then(function(sub) {
    325648
     649
     650
    326651                                    //SET COOKIE, USE FOR ANONYMOUS
     652
    327653                                        var d = new Date(new Date().getTime() + 3600 * 1000 * 365);
     654
    328655                                        document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d;
     656
    329657                                    //END OF COOKIE
    330658
     659
     660
    331661                                    //console.log(sub);
     662
    332663                                    //console.log('endpoint:', sub.endpoint);
    333664
     665
     666
    334667                                    document.getElementById('pushem-notification-https-sub').style.display = 'none';
     668
    335669                                    document.getElementById('pushem-notification-https-unsub').style.display = 'block';
    336670
     671
     672
    337673                                    document.getElementById('pushem-widget-https').style.display = 'none';
     674
    338675                                    document.getElementById('pushem-widget-https-bg').style.display = 'none';
    339676
     677
     678
    340679                                    document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg;
     680
    341681                                    document.getElementById('pushem-notification-https-msg').style.display = 'block';
     682
    342683                                    setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000);
    343684
     685
     686
    344687                                    var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint;
    345688
     689
     690
    346691                                    fetch(endpoint_line).then(function(response) {
    347692
    348                                     });
     693
     694
     695                                    });
     696
     697
    349698
    350699                                });     
     700
    351701                            };
    352702
    353703
    354                                     });
     704
     705
     706
     707                                    });
     708
    355709                                });
     710
    356711                            };
    357712
     713
     714
    358715                }
     716
    359717            });
     718
    360719            });
     720
    361721        });
     722
    362723    });
    363724
     725
     726
    364727}).catch(function(error) {
     728
    365729    //console.log(':^(', error);
     730
    366731});
    367732
     733
     734
    368735}
    369736
     737
     738
Note: See TracChangeset for help on using the changeset viewer.