Changeset 1354091
- Timestamp:
- 02/19/2016 12:34:46 PM (10 years ago)
- Location:
- offline-content/trunk
- Files:
-
- 5 edited
-
lib/js/sw.js (modified) (5 diffs)
-
readme.txt (modified) (2 diffs)
-
vendor/mozilla/wp-sw-manager/README.md (modified) (4 diffs)
-
vendor/mozilla/wp-sw-manager/class-wp-sw-manager.php (modified) (2 diffs)
-
wp-offline-content.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
offline-content/trunk/lib/js/sw.js
r1347574 r1354091 1 1 2 2 (function (self) { 3 self.addEventListener('install', event => { 4 event.waitUntil(Promise.all([ 5 self.skipWaiting(), 6 wpOfflineContent.precache() 7 ])); 8 }); 9 10 self.addEventListener('activate', event => { 11 event.waitUntil(self.clients.claim()); 12 }); 13 14 self.addEventListener('fetch', event => { 15 event.respondWith(wpOfflineContent.get(event.request)); 16 }); 3 var CACHE_PREFIX = '__wp-offline-content::'; 17 4 18 5 var wpOfflineContent = self.wpOfflineContent = { … … 24 11 debug: $debug, 25 12 26 cacheName: $cacheName,13 cacheName: CACHE_PREFIX + $cacheName, 27 14 28 15 networkTimeout: $networkTimeout, … … 36 23 origin: self.location.origin, 37 24 25 onInstall: function (event) { 26 event.waitUntil(Promise.all([ 27 self.skipWaiting(), 28 wpOfflineContent.precache() 29 ])); 30 }, 31 32 onActivate: function (event) { 33 event.waitUntil(Promise.all([self.clients.claim(), this.deleteOutdatedCaches(CACHE_PREFIX)])); 34 }, 35 36 onFetch: function (event) { 37 var request = event.request; 38 if (this.shouldBeHandled(request)) { 39 event.respondWith(wpOfflineContent.get(request)); 40 } 41 }, 42 43 shouldBeHandled: function (request) { 44 return request.method === 'GET' && !this.isExcluded(request.url); 45 }, 46 38 47 precache: function () { 39 48 return this.openCache().then(cache => cache.addAll(this.resources.map(entry => entry[0]))); 49 }, 50 51 deleteOutdatedCaches: function (prefix) { 52 return self.caches.keys().then(names => { 53 return Promise.all(names.map(cacheName => { 54 if (cacheName.startsWith(prefix) && cacheName !== this.cacheName) { 55 return self.caches.delete(cacheName); 56 } 57 return Promise.resolve(); 58 })); 59 }); 40 60 }, 41 61 … … 49 69 throw error; 50 70 }); 51 52 if (request.method !== 'GET' || this.isExcluded(url)) {53 return fetchFromNetwork;54 }55 71 56 72 var fetchAndCache = fetchFromNetwork.then(responseFromNetwork => { … … 124 140 } 125 141 }; 142 143 self.addEventListener('install', wpOfflineContent.onInstall.bind(wpOfflineContent)); 144 self.addEventListener('activate', wpOfflineContent.onActivate.bind(wpOfflineContent)); 145 self.addEventListener('fetch', wpOfflineContent.onFetch.bind(wpOfflineContent)); 146 126 147 })(self); -
offline-content/trunk/readme.txt
r1351108 r1354091 4 4 Requires at least: 3.7 5 5 Tested up to: 4.4.1 6 Stable tag: 0. 2.06 Stable tag: 0.3.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 44 44 == Change Log == 45 45 46 = 0.3.0 = 47 Cleaning old caches when changing the name of the cache where offline content is stored. 48 46 49 = 0.2.0 = 47 50 Now can be combined with other WP plugins using the [WordPress Service Worker Manager library](https://github.com/mozilla/wp-sw-manager/blob/master/README.md) such as [Web Push](https://wordpress.org/plugins/web-push/). -
offline-content/trunk/vendor/mozilla/wp-sw-manager/README.md
r1351108 r1354091 9 9 10 10 ```php 11 WP_SW_Manager::get_manager()->sw()->add_contents(write_sw); 11 include_once(plugins_url(__FILE__) . /vendor/mozilla/wp-sw-manager); 12 13 WP_SW_Manager::get_manager()->sw()->add_content(write_sw); 12 14 13 15 function write_sw() { … … 54 56 55 57 ```php 56 $swmgr->sw()->add_content s(write_sw);58 $swmgr->sw()->add_content(write_sw); 57 59 58 60 function write_sw() { … … 64 66 65 67 ```php 66 $swmgr->sw()->add_content s(array($this, 'write_sw'));68 $swmgr->sw()->add_content(array($this, 'write_sw')); 67 69 68 70 public function write_sw() { … … 74 76 75 77 ```php 76 $swmgr->sw()->add_content s(array($this, 'write_sw'));78 $swmgr->sw()->add_content(array($this, 'write_sw')); 77 79 78 80 public function write_sw() { -
offline-content/trunk/vendor/mozilla/wp-sw-manager/class-wp-sw-manager.php
r1351108 r1354091 25 25 * ``` 26 26 * 27 * @version 0. 1.027 * @version 0.2.0 28 28 * @license GPL 29 29 * @author Salvador de la Puente González <salva@unoyunodiez.com> … … 134 134 $real_absolute_url = $this->router->route_url(self::SW_REGISTRAR_SCRIPT_URL); 135 135 $relative_to_root_url = ltrim($real_absolute_url, site_url('', 'relative')); 136 wp_ register_script(self::SW_REGISTRAR_SCRIPT, $relative_to_root_url);136 wp_enqueue_script(self::SW_REGISTRAR_SCRIPT, $relative_to_root_url); 137 137 } 138 138 -
offline-content/trunk/wp-offline-content.php
r1351108 r1354091 4 4 Description: Allow your users to read your content even while offline. 5 5 Plugin URI: https://github.com/delapuente/wp-offline-content 6 Version: 0. 2.06 Version: 0.3.0 7 7 Author: Mozilla 8 8 Author URI: https://www.mozilla.org/
Note: See TracChangeset
for help on using the changeset viewer.