Showing the changes to assets/javascripts (18 of 43 files). Show all
Unified · Split
| @@ -13,10 +13,12 @@ · 12 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | @el = $('._app') |
| 15 | 15 | @localStorage = new LocalStorageStore |
| 16 | − @appCache = new app.AppCache if app.AppCache.isEnabled() | |
| 16 | + @serviceWorker = new app.ServiceWorker if app.ServiceWorker.isEnabled() | |
| 17 | 17 | @settings = new app.Settings |
| 18 | 18 | @db = new app.DB() |
| 19 | 19 | |
| 20 | + @settings.initLayout() | |
| 21 | + | |
| 20 | 22 | @docs = new app.collections.Docs |
| 21 | 23 | @disabledDocs = new app.collections.Docs |
| 22 | 24 | @entries = new app.collections.Entries |
| @@ -147,7 +149,7 @@ · 124 unmodified lines | ||
| 147 | 149 | saveDocs: -> |
| 148 | 150 | @settings.setDocs(doc.slug for doc in @docs.all()) |
| 149 | 151 | @db.migrate() |
| 150 | − @appCache?.updateInBackground() | |
| 152 | + @serviceWorker?.updateInBackground() | |
| 151 | 153 | |
| 152 | 154 | welcomeBack: -> |
| 153 | 155 | visitCount = @settings.get('count') |
| @@ -167,14 +169,14 @@ · 13 unmodified lines | ||
| 167 | 169 | reload: -> |
| 168 | 170 | @docs.clearCache() |
| 169 | 171 | @disabledDocs.clearCache() |
| 170 | − if @appCache then @appCache.reload() else @reboot() | |
| 172 | + if @serviceWorker then @serviceWorker.reload() else @reboot() | |
| 171 | 173 | return |
| 172 | 174 | |
| 173 | 175 | reset: -> |
| 174 | 176 | @localStorage.reset() |
| 175 | 177 | @settings.reset() |
| 176 | 178 | @db?.reset() |
| 177 | − @appCache?.update() | |
| 179 | + @serviceWorker?.update() | |
| 178 | 180 | window.location = '/' |
| 179 | 181 | return |
| 180 | 182 | |
| @@ -193,9 +195,9 @@ · 12 unmodified lines | ||
| 193 | 195 | return |
| 194 | 196 | |
| 195 | 197 | indexHost: -> |
| 196 | − # Can't load the index files from the host/CDN when applicationCache is | |
| 198 | + # Can't load the index files from the host/CDN when service worker is | |
| 197 | 199 | # enabled because it doesn't support caching URLs that use CORS. |
| 198 | − @config[if @appCache and @settings.hasDocs() then 'index_path' else 'docs_origin'] | |
| 200 | + @config[if @serviceWorker and @settings.hasDocs() then 'index_path' else 'docs_origin'] | |
| 199 | 201 | |
| 200 | 202 | onBootError: (args...) -> |
| 201 | 203 | @trigger 'bootError' |
| @@ -252,7 +254,7 @@ · 50 unmodified lines | ||
| 252 | 254 | matchMedia: !!window.matchMedia |
| 253 | 255 | insertAdjacentHTML: !!document.body.insertAdjacentHTML |
| 254 | 256 | defaultPrevented: document.createEvent('CustomEvent').defaultPrevented is false |
| 255 | − cssVariables: CSS.supports and CSS.supports('(--t: 0)') | |
| 257 | + cssVariables: !!CSS?.supports?('(--t: 0)') | |
| 256 | 258 | |
| 257 | 259 | for key, value of features when not value |
| 258 | 260 | Raven.captureMessage "unsupported/#{key}", level: 'info' |
| @@ -1,42 +0,0 @@ | ||
| 1 | −class app.AppCache | |
| 2 | − $.extend @prototype, Events | |
| 3 | − | |
| 4 | − @isEnabled: -> | |
| 5 | − try | |
| 6 | − applicationCache and applicationCache.status isnt applicationCache.UNCACHED | |
| 7 | − catch | |
| 8 | − | |
| 9 | − constructor: -> | |
| 10 | − @cache = applicationCache | |
| 11 | − @notifyUpdate = true | |
| 12 | − @onUpdateReady() if @cache.status is @cache.UPDATEREADY | |
| 13 | − | |
| 14 | − $.on @cache, 'progress', @onProgress | |
| 15 | − $.on @cache, 'updateready', @onUpdateReady | |
| 16 | − | |
| 17 | − update: -> | |
| 18 | − @notifyUpdate = true | |
| 19 | − @notifyProgress = true | |
| 20 | − try @cache.update() catch | |
| 21 | − return | |
| 22 | − | |
| 23 | − updateInBackground: -> | |
| 24 | − @notifyUpdate = false | |
| 25 | − @notifyProgress = false | |
| 26 | − try @cache.update() catch | |
| 27 | − return | |
| 28 | − | |
| 29 | − reload: -> | |
| 30 | − $.on @cache, 'updateready noupdate error', -> app.reboot() | |
| 31 | − @notifyUpdate = false | |
| 32 | − @notifyProgress = true | |
| 33 | − try @cache.update() catch | |
| 34 | − return | |
| 35 | − | |
| 36 | − onProgress: (event) => | |
| 37 | − @trigger 'progress', event if @notifyProgress | |
| 38 | − return | |
| 39 | − | |
| 40 | − onUpdateReady: => | |
| 41 | − @trigger 'updateready' if @notifyUpdate | |
| 42 | − return | |
| @@ -13,3 +13,5 @@ app.config = · 12 unmodified lines | ||
| 13 | 13 | version: <%= Time.now.to_i %> |
| 14 | 14 | release: <%= Time.now.utc.httpdate.to_json %> |
| 15 | 15 | mathml_stylesheet: '<%= App.cdn_origin %>/mathml.css' |
| 16 | + service_worker_path: '/service-worker.js' | |
| 17 | + service_worker_enabled: <%= App.environment == :production || ENV['ENABLE_SERVICE_WORKER'] == 'true' %> | |
| @@ -0,0 +1,49 @@ | ||
| 1 | +class app.ServiceWorker | |
| 2 | + $.extend @prototype, Events | |
| 3 | + | |
| 4 | + @isEnabled: -> | |
| 5 | + !!navigator.serviceWorker and app.config.service_worker_enabled | |
| 6 | + | |
| 7 | + constructor: -> | |
| 8 | + @registration = null | |
| 9 | + @notifyUpdate = true | |
| 10 | + | |
| 11 | + navigator.serviceWorker.register(app.config.service_worker_path, {scope: '/'}) | |
| 12 | + .then( | |
| 13 | + (registration) => @updateRegistration(registration), | |
| 14 | + (error) -> console.error('Could not register service worker:', error) | |
| 15 | + ) | |
| 16 | + | |
| 17 | + update: -> | |
| 18 | + return unless @registration | |
| 19 | + @notifyUpdate = true | |
| 20 | + return @registration.update().catch(->) | |
| 21 | + | |
| 22 | + updateInBackground: -> | |
| 23 | + return unless @registration | |
| 24 | + @notifyUpdate = false | |
| 25 | + return @registration.update().catch(->) | |
| 26 | + | |
| 27 | + reload: -> | |
| 28 | + return @updateInBackground().then(() -> app.reboot()) | |
| 29 | + | |
| 30 | + updateRegistration: (registration) -> | |
| 31 | + @registration = registration | |
| 32 | + $.on @registration, 'updatefound', @onUpdateFound | |
| 33 | + return | |
| 34 | + | |
| 35 | + onUpdateFound: => | |
| 36 | + $.off @installingRegistration, 'statechange', @onStateChange() if @installingRegistration | |
| 37 | + @installingRegistration = @registration.installing | |
| 38 | + $.on @installingRegistration, 'statechange', @onStateChange | |
| 39 | + return | |
| 40 | + | |
| 41 | + onStateChange: => | |
| 42 | + if @installingRegistration and @installingRegistration.state == 'installed' and navigator.serviceWorker.controller | |
| 43 | + @installingRegistration = null | |
| 44 | + @onUpdateReady() | |
| 45 | + return | |
| 46 | + | |
| 47 | + onUpdateReady: -> | |
| 48 | + @trigger 'updateready' if @notifyUpdate | |
| 49 | + return | |
| @@ -20,6 +20,8 @@ class app.Settings · 19 unmodified lines | ||
| 20 | 20 | 'news' |
| 21 | 21 | ] |
| 22 | 22 | |
| 23 | + LAYOUTS: ['_max-width', '_sidebar-hidden', '_native-scrollbars'] | |
| 24 | + | |
| 23 | 25 | @defaults: |
| 24 | 26 | count: 0 |
| 25 | 27 | hideDisabled: false |
| @@ -40,6 +42,7 @@ class app.Settings · 14 unmodified lines | ||
| 40 | 42 | set: (key, value) -> |
| 41 | 43 | @store.set(key, value) |
| 42 | 44 | delete @cache[key] |
| 45 | + @toggleDark(value) if key == 'dark' | |
| 43 | 46 | return |
| 44 | 47 | |
| 45 | 48 | del: (key) -> |
| @@ -65,6 +68,8 @@ class app.Settings · 19 unmodified lines | ||
| 65 | 68 | return |
| 66 | 69 | |
| 67 | 70 | setLayout: (name, enable) -> |
| 71 | + @toggleLayout(name, enable) | |
| 72 | + | |
| 68 | 73 | layout = (@store.get('layout') || '').split(' ') |
| 69 | 74 | $.arrayDelete(layout, '') |
| 70 | 75 | |
| @@ -106,3 +111,28 @@ class app.Settings · 35 unmodified lines | ||
| 106 | 111 | @store.reset() |
| 107 | 112 | @cache = {} |
| 108 | 113 | return |
| 114 | + | |
| 115 | + initLayout: -> | |
| 116 | + @toggleDark(@get('dark') is 1) | |
| 117 | + @toggleLayout(layout, @hasLayout(layout)) for layout in @LAYOUTS | |
| 118 | + @initSidebarWidth() | |
| 119 | + return | |
| 120 | + | |
| 121 | + toggleDark: (enable) -> | |
| 122 | + classList = document.documentElement.classList | |
| 123 | + classList.toggle('_theme-default', !enable) | |
| 124 | + classList.toggle('_theme-dark', enable) | |
| 125 | + color = getComputedStyle(document.documentElement).getPropertyValue('--headerBackground').trim() | |
| 126 | + $('meta[name=theme-color]').setAttribute('content', color) | |
| 127 | + return | |
| 128 | + | |
| 129 | + toggleLayout: (layout, enable) -> | |
| 130 | + classList = document.body.classList | |
| 131 | + classList.toggle(layout, enable) unless layout is '_sidebar-hidden' | |
| 132 | + classList.toggle('_overlay-scrollbars', $.overlayScrollbarsEnabled()) | |
| 133 | + return | |
| 134 | + | |
| 135 | + initSidebarWidth: -> | |
| 136 | + size = @get('size') | |
| 137 | + document.documentElement.style.setProperty('--sidebarWidth', size + 'px') if size | |
| 138 | + return | |
| @@ -3,13 +3,13 @@ class app.UpdateChecker · 2 unmodified lines | ||
| 3 | 3 | @lastCheck = Date.now() |
| 4 | 4 | |
| 5 | 5 | $.on window, 'focus', @onFocus |
| 6 | − app.appCache.on 'updateready', @onUpdateReady if app.appCache | |
| 6 | + app.serviceWorker?.on 'updateready', @onUpdateReady | |
| 7 | 7 | |
| 8 | 8 | setTimeout @checkDocs, 0 |
| 9 | 9 | |
| 10 | 10 | check: -> |
| 11 | − if app.appCache | |
| 12 | − app.appCache.update() | |
| 11 | + if app.serviceWorker | |
| 12 | + app.serviceWorker.update() | |
| 13 | 13 | else |
| 14 | 14 | ajax |
| 15 | 15 | url: $('script[src*="application"]').getAttribute('src') |
| @@ -352,6 +352,10 @@ isIE = null · 351 unmodified lines | ||
| 352 | 352 | $.isIE = -> |
| 353 | 353 | isIE ?= navigator.userAgent?.indexOf('MSIE') >= 0 || navigator.userAgent?.indexOf('rv:11.0') >= 0 |
| 354 | 354 | |
| 355 | +isChromeForAndroid = null | |
| 356 | +$.isChromeForAndroid = -> | |
| 357 | + isChromeForAndroid ?= navigator.userAgent?.indexOf('Android') >= 0 && /Chrome\/([.0-9])+ Mobile/.test(navigator.userAgent) | |
| 358 | + | |
| 355 | 359 | isAndroid = null |
| 356 | 360 | $.isAndroid = -> |
| 357 | 361 | isAndroid ?= navigator.userAgent?.indexOf('Android') >= 0 |
| @@ -1,4 +1,8 @@ | ||
| 1 | 1 | [ |
| 2 | + [ | |
| 3 | + "2019-07-19", | |
| 4 | + "Replaced the AppCache with a Service Worker (which makes DevDocs an installable PWA) and fixed layout preferences on Firefox." | |
| 5 | + ], | |
| 2 | 6 | [ |
| 3 | 7 | "2018-09-23", |
| 4 | 8 | "New documentations: <a href=\"/puppeteer/\">Puppeteer</a> and <a href=\"/handlebars/\">Handlebars.js</a>" |
| @@ -12,8 +12,8 @@ app.templates.notFoundPage = -> · 11 unmodified lines | ||
| 12 | 12 | |
| 13 | 13 | app.templates.pageLoadError = -> |
| 14 | 14 | error """ The page failed to load. """, |
| 15 | − """ It may be missing from the server (try reloading the app) or you could be offline.<br> | |
| 16 | − If you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. """, | |
| 15 | + """ It may be missing from the server (try reloading the app) or you could be offline (try <a href="/offline">installing the documentation for offline usage</a> when online again).<br> | |
| 16 | + If you're online and you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. """, | |
| 17 | 17 | """ #{back} · <a href="/##{location.pathname}" target="_top" class="_error-link">Reload</a> |
| 18 | 18 | · <a href="#" class="_error-link" data-retry>Retry</a> """ |
| 19 | 19 | |
| @@ -57,9 +57,9 @@ app.templates.unsupportedBrowser = """ · 37 unmodified lines | ||
| 57 | 57 | <p class="_fail-text">DevDocs is an API documentation browser which supports the following browsers: |
| 58 | 58 | <ul class="_fail-list"> |
| 59 | 59 | <li>Recent versions of Firefox, Chrome, or Opera |
| 60 | − <li>Safari 9.1+ | |
| 61 | − <li>Edge 16+ | |
| 62 | − <li>iOS 10+ | |
| 60 | + <li>Safari 11.1+ | |
| 61 | + <li>Edge 17+ | |
| 62 | + <li>iOS 11.3+ | |
| 63 | 63 | </ul> |
| 64 | 64 | <p class="_fail-text"> |
| 65 | 65 | If you're unable to upgrade, we apologize. |
| @@ -25,8 +25,8 @@ app.templates.offlinePage = (docs) -> """ · 24 unmodified lines | ||
| 25 | 25 | <h2 class="_block-heading">Questions & Answers</h2> |
| 26 | 26 | <dl> |
| 27 | 27 | <dt>How does this work? |
| 28 | − <dd>Each page is cached as a key-value pair in <a href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API">IndexedDB</a> (downloaded from a single file).<br> | |
| 29 | − The app also uses <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache">AppCache</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API">localStorage</a> to cache the assets and index files. | |
| 28 | + <dd>Each page is cached as a key-value pair in <a href="https://devdocs.io/dom/indexeddb_api">IndexedDB</a> (downloaded from a single file).<br> | |
| 29 | + The app also uses <a href="https://devdocs.io/dom/service_worker_api/using_service_workers">Service Workers</a> and <a href="https://devdocs.io/dom/web_storage_api">localStorage</a> to cache the assets and index files. | |
| 30 | 30 | <dt>Can I close the tab/browser? |
| 31 | 31 | <dd>#{canICloseTheTab()} |
| 32 | 32 | <dt>What if I don't update a documentation? |
| @@ -41,10 +41,15 @@ app.templates.offlinePage = (docs) -> """ · 8 unmodified lines | ||
| 41 | 41 | """ |
| 42 | 42 | |
| 43 | 43 | canICloseTheTab = -> |
| 44 | − if app.AppCache.isEnabled() | |
| 44 | + if app.ServiceWorker.isEnabled() | |
| 45 | 45 | """ Yes! Even offline, you can open a new tab, go to <a href="//devdocs.io">devdocs.io</a>, and everything will work as if you were online (provided you installed all the documentations you want to use beforehand). """ |
| 46 | 46 | else |
| 47 | − """ No. AppCache isn't available in your browser (or is disabled), so loading <a href="//devdocs.io">devdocs.io</a> offline won't work.<br> | |
| 47 | + reason = "aren't available in your browser (or are disabled)" | |
| 48 | + | |
| 49 | + if app.config.env != 'production' | |
| 50 | + reason = "are disabled in your development instance of DevDocs (enable them by setting the <code>ENABLE_SERVICE_WORKER</code> environment variable to <code>true</code>)" | |
| 51 | + | |
| 52 | + """ No. Service Workers #{reason}, so loading <a href="//devdocs.io">devdocs.io</a> offline won't work.<br> | |
| 48 | 53 | The current tab will continue to function even when you go offline (provided you installed all the documentations beforehand). """ |
| 49 | 54 | |
| 50 | 55 | app.templates.offlineDoc = (doc, status) -> |
| @@ -8,7 +8,7 @@ app.templates.intro = """ · 7 unmodified lines | ||
| 8 | 8 | <p>Thanks for downloading DevDocs. Here are a few things you should know: |
| 9 | 9 | <ol class="_intro-list"> |
| 10 | 10 | <li>Your local version of DevDocs won't self-update. Unless you're modifying the code, |
| 11 | − I recommend using the hosted version at <a href="https://devdocs.io">devdocs.io</a>. | |
| 11 | + we recommend using the hosted version at <a href="https://devdocs.io">devdocs.io</a>. | |
| 12 | 12 | <li>Run <code>thor docs:list</code> to see all available documentations. |
| 13 | 13 | <li>Run <code>thor docs:download <name></code> to download documentations. |
| 14 | 14 | <li>Run <code>thor docs:download --installed</code> to update all downloaded documentations. |
| @@ -39,7 +39,7 @@ app.templates.intro = """ · 24 unmodified lines | ||
| 39 | 39 | <li>DevDocs works <a href="/offline">offline</a>, on mobile, and can be installed on <a href="https://chrome.google.com/webstore/detail/devdocs/mnfehgbmkapmjnhcnbodoamcioleeooe">Chrome</a>. |
| 40 | 40 | <li>For the latest news, follow <a href="https://twitter.com/DevDocs">@DevDocs</a>. |
| 41 | 41 | <li>DevDocs is free and <a href="https://github.com/freeCodeCamp/devdocs">open source</a>. |
| 42 | − <iframe class="_github-btn" src="//ghbtns.com/github-btn.html?user=freeCodeCamp&repo=devdocs&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="100" height="20"></iframe> | |
| 42 | + <object data="https://img.shields.io/github/stars/freeCodeCamp/devdocs.svg?style=social" type="image/svg+xml" aria-hidden="true"></object> | |
| 43 | 43 | <li>And if you're new to coding, check out <a href="https://www.freecodecamp.org/">freeCodeCamp's open source curriculum</a>. |
| 44 | 44 | </ol> |
| 45 | 45 | <p>Happy coding! |
| @@ -123,7 +123,7 @@ class app.views.EntryPage extends app.View · 122 unmodified lines | ||
| 123 | 123 | @render @tmpl('pageLoadError') |
| 124 | 124 | @resetClass() |
| 125 | 125 | @addClass @constructor.errorClass |
| 126 | − app.appCache?.update() | |
| 126 | + app.serviceWorker?.update() | |
| 127 | 127 | return |
| 128 | 128 | |
| 129 | 129 | cache: -> |
| @@ -1,7 +1,4 @@ | ||
| 1 | 1 | class app.views.SettingsPage extends app.View |
| 2 | − LAYOUTS = ['_max-width', '_sidebar-hidden', '_native-scrollbars'] | |
| 3 | − SIDEBAR_HIDDEN_LAYOUT = '_sidebar-hidden' | |
| 4 | − | |
| 5 | 2 | @className: '_static' |
| 6 | 3 | |
| 7 | 4 | @events: |
| @@ -18,25 +15,18 @@ class app.views.SettingsPage extends app.View · 10 unmodified lines | ||
| 18 | 15 | settings.smoothScroll = !app.settings.get('fastScroll') |
| 19 | 16 | settings.arrowScroll = app.settings.get('arrowScroll') |
| 20 | 17 | settings.analyticsConsent = app.settings.get('analyticsConsent') |
| 21 | − settings[layout] = app.settings.hasLayout(layout) for layout in LAYOUTS | |
| 18 | + settings[layout] = app.settings.hasLayout(layout) for layout in app.settings.LAYOUTS | |
| 22 | 19 | settings |
| 23 | 20 | |
| 24 | 21 | getTitle: -> |
| 25 | 22 | 'Preferences' |
| 26 | 23 | |
| 27 | 24 | toggleDark: (enable) -> |
| 28 | − html = document.documentElement | |
| 29 | − html.classList.toggle('_theme-default') | |
| 30 | − html.classList.toggle('_theme-dark') | |
| 31 | 25 | app.settings.set('dark', !!enable) |
| 32 | − app.appCache?.updateInBackground() | |
| 33 | 26 | return |
| 34 | 27 | |
| 35 | 28 | toggleLayout: (layout, enable) -> |
| 36 | − document.body.classList[if enable then 'add' else 'remove'](layout) unless layout is SIDEBAR_HIDDEN_LAYOUT | |
| 37 | − document.body.classList[if $.overlayScrollbarsEnabled() then 'add' else 'remove']('_overlay-scrollbars') | |
| 38 | 29 | app.settings.setLayout(layout, enable) |
| 39 | − app.appCache?.updateInBackground() | |
| 40 | 30 | return |
| 41 | 31 | |
| 42 | 32 | toggleSmoothScroll: (enable) -> |
| @@ -11,9 +11,6 @@ class app.views.Resizer extends app.View · 10 unmodified lines | ||
| 11 | 11 | init: -> |
| 12 | 12 | @el.setAttribute('draggable', 'true') |
| 13 | 13 | @appendTo $('._app') |
| 14 | − | |
| 15 | − @style = $('style[data-resizer]') | |
| 16 | − @size = @style.getAttribute('data-size') | |
| 17 | 14 | return |
| 18 | 15 | |
| 19 | 16 | MIN = 260 |
| @@ -24,15 +21,11 @@ class app.views.Resizer extends app.View · 4 unmodified lines | ||
| 24 | 21 | return unless value > 0 |
| 25 | 22 | value = Math.min(Math.max(Math.round(value), MIN), MAX) |
| 26 | 23 | newSize = "#{value}px" |
| 27 | − @style.innerHTML = @style.innerHTML.replace(new RegExp(@size, 'g'), newSize) | |
| 28 | − @size = newSize | |
| 29 | − if save | |
| 30 | − app.settings.setSize(value) | |
| 31 | − app.appCache?.updateInBackground() | |
| 24 | + document.documentElement.style.setProperty('--sidebarWidth', newSize) | |
| 25 | + app.settings.setSize(value) if save | |
| 32 | 26 | return |
| 33 | 27 | |
| 34 | 28 | onDragStart: (event) => |
| 35 | − @style.removeAttribute('disabled') | |
| 36 | 29 | event.dataTransfer.effectAllowed = 'link' |
| 37 | 30 | event.dataTransfer.setData('Text', '') |
| 38 | 31 | $.on(window, 'dragover', @onDrag) |
| @@ -25,7 +25,6 @@ class app.views.Settings extends app.View · 24 unmodified lines | ||
| 25 | 25 | if super |
| 26 | 26 | @render() |
| 27 | 27 | document.body.classList.remove(SIDEBAR_HIDDEN_LAYOUT) |
| 28 | − app.appCache?.on 'progress', @onAppCacheProgress | |
| 29 | 28 | return |
| 30 | 29 | |
| 31 | 30 | deactivate: -> |
| @@ -33,7 +32,6 @@ class app.views.Settings extends app.View · 1 unmodified line | ||
| 33 | 32 | @resetClass() |
| 34 | 33 | @docPicker.detach() |
| 35 | 34 | document.body.classList.add(SIDEBAR_HIDDEN_LAYOUT) if app.settings.hasLayout(SIDEBAR_HIDDEN_LAYOUT) |
| 36 | − app.appCache?.off 'progress', @onAppCacheProgress | |
| 37 | 35 | return |
| 38 | 36 | |
| 39 | 37 | render: -> |
| @@ -52,7 +50,7 @@ class app.views.Settings extends app.View · 12 unmodified lines | ||
| 52 | 50 | docs = @docPicker.getSelectedDocs() |
| 53 | 51 | app.settings.setDocs(docs) |
| 54 | 52 | |
| 55 | − @saveBtn.textContent = if app.appCache then 'Downloading\u2026' else 'Saving\u2026' | |
| 53 | + @saveBtn.textContent = 'Saving\u2026' | |
| 56 | 54 | disabledDocs = new app.collections.Docs(doc for doc in app.docs.all() when docs.indexOf(doc.slug) is -1) |
| 57 | 55 | disabledDocs.uninstall -> |
| 58 | 56 | app.db.migrate() |
| @@ -83,9 +81,3 @@ class app.views.Settings extends app.View · 24 unmodified lines | ||
| 83 | 81 | $.stopEvent(event) |
| 84 | 82 | app.router.show '/' |
| 85 | 83 | return |
| 86 | − | |
| 87 | − onAppCacheProgress: (event) => | |
| 88 | − if event.lengthComputable | |
| 89 | − percentage = Math.round event.loaded * 100 / event.total | |
| 90 | − @saveBtn.textContent = "Downloading\u2026 (#{percentage}%)" | |
| 91 | − return | |
| @@ -30,6 +30,9 @@ class app.views.Search extends app.View · 29 unmodified lines | ||
| 30 | 30 | .on 'results', @onResults |
| 31 | 31 | .on 'end', @onEnd |
| 32 | 32 | |
| 33 | + @scope | |
| 34 | + .on 'change', @onScopeChange | |
| 35 | + | |
| 33 | 36 | app.on 'ready', @onReady |
| 34 | 37 | $.on window, 'hashchange', @searchUrl |
| 35 | 38 | $.on window, 'focus', @onWindowFocus |
| @@ -138,6 +141,11 @@ class app.views.Search extends app.View · 102 unmodified lines | ||
| 138 | 141 | $.stopEvent(event) |
| 139 | 142 | return |
| 140 | 143 | |
| 144 | + onScopeChange: => | |
| 145 | + @value = '' | |
| 146 | + @onInput() | |
| 147 | + return | |
| 148 | + | |
| 141 | 149 | afterRoute: (name, context) => |
| 142 | 150 | return if app.shortcuts.eventInProgress?.name is 'escape' |
| 143 | 151 | @reset(true) if not context.init and app.router.isIndex() |
| @@ -6,7 +6,9 @@ class app.views.SearchScope extends app.View · 5 unmodified lines | ||
| 6 | 6 | tag: '._search-tag' |
| 7 | 7 | |
| 8 | 8 | @events: |
| 9 | + click: 'onClick' | |
| 9 | 10 | keydown: 'onKeydown' |
| 11 | + textInput: 'onTextInput' | |
| 10 | 12 | |
| 11 | 13 | @routes: |
| 12 | 14 | after: 'afterRoute' |
| @@ -87,17 +89,33 @@ class app.views.SearchScope extends app.View · 74 unmodified lines | ||
| 87 | 89 | @trigger 'change', null, previousDoc |
| 88 | 90 | return |
| 89 | 91 | |
| 92 | + doScopeSearch: (event) => | |
| 93 | + @search @input.value[0...@input.selectionStart] | |
| 94 | + $.stopEvent(event) if @doc | |
| 95 | + return | |
| 96 | + | |
| 97 | + onClick: (event) => | |
| 98 | + if event.target is @tag | |
| 99 | + @reset() | |
| 100 | + $.stopEvent(event) | |
| 101 | + return | |
| 102 | + | |
| 90 | 103 | onKeydown: (event) => |
| 91 | 104 | if event.which is 8 # backspace |
| 92 | − if @doc and not @input.value | |
| 93 | − $.stopEvent(event) | |
| 105 | + if @doc and @input.selectionEnd is 0 | |
| 94 | 106 | @reset() |
| 95 | − else if not @doc and @input.value | |
| 107 | + $.stopEvent(event) | |
| 108 | + else if not @doc and @input.value and not $.isChromeForAndroid() | |
| 96 | 109 | return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey |
| 97 | 110 | if event.which is 9 or # tab |
| 98 | 111 | (event.which is 32 and app.isMobile()) # space |
| 99 | − @search @input.value[0...@input.selectionStart] | |
| 100 | − $.stopEvent(event) if @doc | |
| 112 | + @doScopeSearch(event) | |
| 113 | + return | |
| 114 | + | |
| 115 | + onTextInput: (event) => | |
| 116 | + return unless $.isChromeForAndroid() | |
| 117 | + if not @doc and @input.value and event.data == ' ' | |
| 118 | + @doScopeSearch(event) | |
| 101 | 119 | return |
| 102 | 120 | |
| 103 | 121 | extractHashValue: -> |
| @@ -28,7 +28,7 @@ class app.views.Sidebar extends app.View · 27 unmodified lines | ||
| 28 | 28 | |
| 29 | 29 | app.on 'ready', @onReady |
| 30 | 30 | |
| 31 | − $.on document.documentElement, 'mouseleave', (event) => @display() if event.clientX < 10 | |
| 31 | + $.on document.documentElement, 'mouseleave', (event) => @display() unless event.clientX <= 0 | |
| 32 | 32 | $.on document.documentElement, 'mouseenter', => @resetDisplay(forceNoHover: false) |
| 33 | 33 | return |
| 34 | 34 | |