Download core/resources/views/partials/push_script.blade.php from pnacorp/codeplus: direct link, hf CLI and curl.
- Browser
- Download file 3.14 kB
-
https://huggingface.co/pnacorp/codeplus/resolve/main/core/resources/views/partials/push_script.blade.php
- Command line
-
hf download hf://pnacorp/codeplus/core/resources/views/partials/push_script.blade.php
-
curl -L -o push_script.blade.php https://huggingface.co/pnacorp/codeplus/resolve/main/core/resources/views/partials/push_script.blade.php
3.14 kB
| <script src="{{asset('assets/global/js/firebase/firebase-8.3.2.js')}}"></script> | |
| <script> | |
| "use strict"; | |
| var permission = null; | |
| var authenticated = '{{ auth()->user() ? true : false }}'; | |
| var pushNotify = @json(gs('pn')); | |
| var firebaseConfig = @json(gs('firebase_config')); | |
| function pushNotifyAction(){ | |
| permission = Notification.permission; | |
| if(!('Notification' in window)){ | |
| notify('info', 'Push notifications not available in your browser. Try Chromium.') | |
| } | |
| else if(permission === 'denied' || permission == 'default'){ //Notice for users dashboard | |
| $('.notice').append(` | |
| <div class="col-12"> | |
| <div class="alert alert--danger" role="alert"> | |
| <h4 class="alert-heading text--danger mb-2 fs-18">@lang('Please Allow / Reset Browser Notification') <i class='las la-bell'></i></h4> | |
| <p class="fs-16">@lang('If you want to get push notification then you have to allow notification from your browser')</p> | |
| </div> | |
| </div> | |
| `); | |
| } | |
| } | |
| //If enable push notification from admin panel | |
| if(pushNotify == 1){ | |
| pushNotifyAction(); | |
| } | |
| //When users allow browser notification | |
| if(permission != 'denied' && firebaseConfig){ | |
| //Firebase | |
| firebase.initializeApp(firebaseConfig); | |
| const messaging = firebase.messaging(); | |
| navigator.serviceWorker.register("{{ asset('assets/global/js/firebase/firebase-messaging-sw.js') }}") | |
| .then((registration) => { | |
| messaging.useServiceWorker(registration); | |
| function initFirebaseMessagingRegistration() { | |
| messaging | |
| .requestPermission() | |
| .then(function () { | |
| return messaging.getToken() | |
| }) | |
| .then(function (token){ | |
| $.ajax({ | |
| url: '{{ route("user.add.device.token") }}', | |
| type: 'POST', | |
| data: { | |
| token: token, | |
| '_token': "{{ csrf_token() }}" | |
| }, | |
| success: function(response){ | |
| }, | |
| error: function (err) { | |
| }, | |
| }); | |
| }).catch(function (error){ | |
| }); | |
| } | |
| messaging.onMessage(function (payload){ | |
| const title = payload.notification.title; | |
| const options = { | |
| body: payload.notification.body, | |
| icon: payload.data.icon, | |
| image: payload.notification.image, | |
| click_action:payload.data.click_action, | |
| vibrate: [200, 100, 200] | |
| }; | |
| new Notification(title, options); | |
| }); | |
| //For authenticated users | |
| if(authenticated){ | |
| initFirebaseMessagingRegistration(); | |
| } | |
| }); | |
| } | |
| </script> | |