add-to-homescreen-rails 3.1.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67fb181bb27e8cb1c7973d144313746d5493f24f
4
- data.tar.gz: 225a4d7c2c6827c352407eadd818c3e26f8ea10c
3
+ metadata.gz: 492c97c8e3ab203c83384e7f9385c70a7db64b69
4
+ data.tar.gz: 3b853d638ff657162ca69e772bdfdbd0ab35b199
5
5
  SHA512:
6
- metadata.gz: bd7397abb431e8a970df84e4a2c5eada9f2ce3032143fc7217bdaa75da7b246f210d2f86bbbcb79b0aaba99b15e0b9f932c6898e28c7cbeac14b2903aa884a34
7
- data.tar.gz: ca02fcb1df83163c7aba10d96ab2da884a5eec03c2db21953e1831fd1fdac230dff4549eda62aae8f5477ba955fc708472963e38f082a324bc29accde6629a65
6
+ metadata.gz: 6694dcb34f0176ec459c4af3fd1b26467863d8f41cdfc773df8361564752ca2066a04ebf218634de0eca37980fdde2537d090cca859ba028456c63731d0df4d6
7
+ data.tar.gz: b60f305e413eb3e5c8c2bb49b4b86cd744f4f649449c43701fc7b773b9162f8c235bdd20a6c0f0a61a59c146ee524b94e760d42f23d5773ec3574cd4122601dd
@@ -1,4 +1,4 @@
1
- /* Add to Homescreen v3.1.2 ~ (c) 2015 Matteo Spinelli ~ @license: http://cubiq.org/license */
1
+ /* Add to Homescreen v3.2.0 ~ (c) 2015 Matteo Spinelli ~ @license: http://cubiq.org/license */
2
2
  (function (window, document) {
3
3
  /*
4
4
  _ _ _____ _____
@@ -63,6 +63,11 @@ ath.intl = {
63
63
  android: 'Para añadir esta aplicación web a la pantalla de inicio, abre las opciones y pulsa <strong>Añadir a pantalla inicio</strong>. <small>El menú se puede acceder pulsando el botón táctil en caso de tenerlo, o bien el icono de la parte superior derecha de la pantalla <span class="ath-action-icon">icon</span>.</small>',
64
64
  },
65
65
 
66
+ fi_fi: {
67
+ ios: 'Liitä tämä sovellus kotivalikkoon: klikkaa %icon ja tämän jälkeen <strong>Lisää kotivalikkoon</strong>.',
68
+ android: 'Lisätäksesi tämän sovelluksen aloitusnäytölle, avaa selaimen valikko ja klikkaa tähti -ikonia tai <strong>Lisää aloitusnäytölle tekstiä</strong>. <small>Valikkoon pääsee myös painamalla menuvalikkoa, jos laitteessasi on sellainen tai koskettamalla oikealla yläkulmassa menu ikonia <span class="ath-action-icon">icon</span>.</small>',
69
+ },
70
+
66
71
  fr_fr: {
67
72
  ios: 'Pour ajouter cette application web sur l\'écran d\'accueil : Appuyez %icon et sélectionnez <strong>Ajouter sur l\'écran d\'accueil</strong>.',
68
73
  android: 'Pour ajouter cette application web sur l\'écran d\'accueil : Appuyez sur le bouton "menu", puis sur <strong>Ajouter sur l\'écran d\'accueil</strong>. <small>Le menu peut-être accessible en appyant sur le bouton "menu" du téléphone s\'il en possède un <i class="fa fa-bars"></i>. Sinon, il se trouve probablement dans la coin supérieur droit du navigateur %icon.</small>',
@@ -78,6 +83,16 @@ ath.intl = {
78
83
  android: 'Per aggiungere questa web app alla schermata iniziale, apri il menu opzioni del browser e premi su <strong>Aggiungi alla homescreen</strong>. <small>Puoi accedere al menu premendo il pulsante hardware delle opzioni se la tua device ne ha uno, oppure premendo l\'icona <span class="ath-action-icon">icon</span> in alto a destra.</small>',
79
84
  },
80
85
 
86
+ ja_jp: {
87
+ ios: 'このウェプアプリをホーム画面に追加するために%iconを押して<strong>ホーム画面に追加</strong>。',
88
+ android: 'To add this web app to the home screen open the browser option menu and tap on <strong>Add to homescreen</strong>. <small>The menu can be accessed by pressing the menu hardware button if your device has one, or by tapping the top right menu icon <span class="ath-action-icon">icon</span>.</small>',
89
+ },
90
+
91
+ ko_kr: {
92
+ ios: '홈 화면에 바로가기 생성: %icon 을 클릭한 후 <strong>홈 화면에 추가</strong>.',
93
+ android: '브라우저 옵션 메뉴의 <string>홈 화면에 추가</string>를 클릭하여 홈화면에 바로가기를 생성할 수 있습니다. <small>옵션 메뉴는 장치의 메뉴 버튼을 누르거나 오른쪽 상단의 메뉴 아이콘 <span class="ath-action-icon">icon</span>을 클릭하여 접근할 수 있습니다.</small>'
94
+ },
95
+
81
96
  nb_no: {
82
97
  ios: 'For å installere denne appen på hjem-skjermen: trykk på %icon og deretter <strong>Legg til på Hjem-skjerm</strong>.',
83
98
  android: 'For å legge til denne webappen på startsiden åpner en nettlesermenyen og velger <strong>Legg til på startsiden</strong>. <small>Menyen åpnes ved å trykke på den fysiske menyknappen hvis enheten har det, eller ved å trykke på menyikonet øverst til høyre <span class="ath-action-icon">icon</span>.</small>',
@@ -98,6 +113,11 @@ ath.intl = {
98
113
  android: 'To add this web app to the home screen open the browser option menu and tap on <strong>Add to homescreen</strong>. <small>The menu can be accessed by pressing the menu hardware button if your device has one, or by tapping the top right menu icon <span class="ath-action-icon">icon</span>.</small>',
99
114
  },
100
115
 
116
+ ru_ru: {
117
+ ios: 'Чтобы добавить этот сайт на свой домашний экран, нажмите на иконку %icon и затем <strong>На экран "Домой"</strong>.',
118
+ android: 'Чтобы добавить сайт на свой домашний экран, откройте меню браузера и нажмите на <strong>Добавить на главный экран</strong>. <small>Меню можно вызвать, нажав на кнопку меню вашего телефона, если она есть. Или найдите иконку сверху справа <span class="ath-action-icon">иконка</span>.</small>',
119
+ },
120
+
101
121
  sv_se: {
102
122
  ios: 'För att lägga till denna webbapplikation på hemskärmen: tryck på %icon och därefter <strong>Lägg till på hemskärmen</strong>.',
103
123
  android: 'För att lägga till den här webbappen på hemskärmen öppnar du webbläsarens alternativ-meny och väljer <strong>Lägg till på startskärmen</strong>. <small>Man hittar menyn genom att trycka på hårdvaruknappen om din enhet har en sådan, eller genom att trycka på menyikonen högst upp till höger <span class="ath-action-icon">icon</span>.</small>',
@@ -113,11 +133,6 @@ ath.intl = {
113
133
  android: 'To add this web app to the home screen open the browser option menu and tap on <strong>Add to homescreen</strong>. <small>The menu can be accessed by pressing the menu hardware button if your device has one, or by tapping the top right menu icon <span class="ath-action-icon">icon</span>.</small>',
114
134
  },
115
135
 
116
- fi_fi: {
117
- ios: 'Liitä tämä sovellus kotivalikkoon: klikkaa %icon ja tämän jälkeen <strong>Lisää kotivalikkoon</strong>.',
118
- android: 'Lisätäksesi tämän sovelluksen aloitusnäytölle, avaa selaimen valikko ja klikkaa tähti -ikonia tai <strong>Lisää aloitusnäytölle tekstiä</strong>. <small>Valikkoon pääsee myös painamalla menuvalikkoa, jos laitteessasi on sellainen tai koskettamalla oikealla yläkulmassa menu ikonia <span class="ath-action-icon">icon</span>.</small>',
119
- }
120
-
121
136
  };
122
137
 
123
138
  // Add 2 characters language support (Android mostly)
@@ -130,6 +145,7 @@ ath.defaults = {
130
145
  appID: 'org.cubiq.addtohome', // local storage name (no need to change)
131
146
  fontSize: 15, // base font size, used to properly resize the popup based on viewport scale factor
132
147
  debug: false, // override browser checks
148
+ logging: false, // log reasons for showing or not showing to js console; defaults to true when debug is true
133
149
  modal: false, // prevent further actions until the message is closed
134
150
  mandatory: false, // you can't proceed if you don't add the app to the homescreen
135
151
  autostart: true, // show the message automatically
@@ -158,7 +174,7 @@ _extend(ath, {
158
174
  hasToken: document.location.hash == '#ath' || _reSmartURL.test(document.location.href) || _reQueryString.test(document.location.search),
159
175
  isRetina: window.devicePixelRatio && window.devicePixelRatio > 1,
160
176
  isIDevice: (/iphone|ipod|ipad/i).test(_ua),
161
- isMobileChrome: _ua.indexOf('Android') > -1 && (/Chrome\/[.0-9]*/).test(_ua),
177
+ isMobileChrome: _ua.indexOf('Android') > -1 && (/Chrome\/[.0-9]*/).test(_ua) && _ua.indexOf("Version") == -1,
162
178
  isMobileIE: _ua.indexOf('Windows Phone') > -1,
163
179
  language: _nav.language && _nav.language.toLowerCase().replace('-', '_') || ''
164
180
  });
@@ -193,10 +209,23 @@ ath.removeSession = function (appID) {
193
209
  }
194
210
  };
195
211
 
212
+ ath.doLog = function (logStr) {
213
+ if ( this.options.logging ) {
214
+ console.log(logStr);
215
+ }
216
+ };
217
+
196
218
  ath.Class = function (options) {
219
+ // class methods
220
+ this.doLog = ath.doLog;
221
+
197
222
  // merge default options with user config
198
223
  this.options = _extend({}, ath.defaults);
199
224
  _extend(this.options, options);
225
+ // override defaults that are dependent on each other
226
+ if ( options.debug && (typeof options.logging === "undefined") ) {
227
+ this.options.logging = true;
228
+ }
200
229
 
201
230
  // IE<9 so exit (I hate you, really)
202
231
  if ( !_eventListener ) {
@@ -222,7 +251,7 @@ ath.Class = function (options) {
222
251
  this.container = document.documentElement;
223
252
 
224
253
  // load session
225
- this.session = localStorage.getItem(this.options.appID);
254
+ this.session = this.getItem(this.options.appID);
226
255
  this.session = this.session ? JSON.parse(this.session) : undefined;
227
256
 
228
257
  // user most likely came from a direct link containing our token, we don't need it and we remove it
@@ -233,6 +262,7 @@ ath.Class = function (options) {
233
262
 
234
263
  // the device is not supported
235
264
  if ( !ath.isCompatible ) {
265
+ this.doLog("Add to homescreen: not displaying callout because device not supported");
236
266
  return;
237
267
  }
238
268
 
@@ -261,13 +291,21 @@ ath.Class = function (options) {
261
291
  }
262
292
 
263
293
  // check compatibility with old versions of add to homescreen. Opt-out if an old session is found
264
- if ( localStorage.getItem('addToHome') ) {
294
+ if ( this.getItem('addToHome') ) {
265
295
  this.optOut();
266
296
  }
267
297
 
268
298
  // critical errors:
269
- // user opted out, already added to the homescreen, not a valid location
270
- if ( this.session.optedout || this.session.added || !isValidLocation ) {
299
+ if ( this.session.optedout ) {
300
+ this.doLog("Add to homescreen: not displaying callout because user opted out");
301
+ return;
302
+ }
303
+ if ( this.session.added ) {
304
+ this.doLog("Add to homescreen: not displaying callout because already added to the homescreen");
305
+ return;
306
+ }
307
+ if ( !isValidLocation ) {
308
+ this.doLog("Add to homescreen: not displaying callout because not a valid location");
271
309
  return;
272
310
  }
273
311
 
@@ -283,6 +321,7 @@ ath.Class = function (options) {
283
321
  }
284
322
  }
285
323
 
324
+ this.doLog("Add to homescreen: not displaying callout because in standalone mode");
286
325
  return;
287
326
  }
288
327
 
@@ -302,6 +341,7 @@ ath.Class = function (options) {
302
341
  }
303
342
  }
304
343
 
344
+ this.doLog("Add to homescreen: not displaying callout because URL has token, so we are likely coming from homescreen");
305
345
  return;
306
346
  }
307
347
 
@@ -322,12 +362,14 @@ ath.Class = function (options) {
322
362
 
323
363
  // we do not show the message if this is your first visit
324
364
  if ( this.options.skipFirstVisit ) {
365
+ this.doLog("Add to homescreen: not displaying callout because skipping first visit");
325
366
  return;
326
367
  }
327
368
  }
328
369
 
329
370
  // we do no show the message in private mode
330
371
  if ( !this.options.privateModeOverride && !ath.hasLocalStorage ) {
372
+ this.doLog("Add to homescreen: not displaying callout because browser is in private mode");
331
373
  return;
332
374
  }
333
375
 
@@ -339,6 +381,7 @@ ath.Class = function (options) {
339
381
  }
340
382
 
341
383
  if ( this.options.autostart ) {
384
+ this.doLog("Add to homescreen: autostart displaying callout");
342
385
  this.show();
343
386
  }
344
387
  };
@@ -369,11 +412,14 @@ ath.Class.prototype = {
369
412
  // in autostart mode wait for the document to be ready
370
413
  if ( this.options.autostart && !_DOMReady ) {
371
414
  setTimeout(this.show.bind(this), 50);
415
+ // we are not displaying callout because DOM not ready, but don't log that because
416
+ // it would log too frequently
372
417
  return;
373
418
  }
374
419
 
375
420
  // message already on screen
376
421
  if ( this.shown ) {
422
+ this.doLog("Add to homescreen: not displaying callout because already shown on screen");
377
423
  return;
378
424
  }
379
425
 
@@ -383,16 +429,19 @@ ath.Class.prototype = {
383
429
  if ( force !== true ) {
384
430
  // this is needed if autostart is disabled and you programmatically call the show() method
385
431
  if ( !this.ready ) {
432
+ this.doLog("Add to homescreen: not displaying callout because not ready");
386
433
  return;
387
434
  }
388
435
 
389
436
  // we obey the display pace (prevent the message to popup too often)
390
437
  if ( now - lastDisplayTime < this.options.displayPace * 60000 ) {
438
+ this.doLog("Add to homescreen: not displaying callout because displayed recently");
391
439
  return;
392
440
  }
393
441
 
394
442
  // obey the maximum number of display count
395
443
  if ( this.options.maxDisplayCount && this.session.displayCount >= this.options.maxDisplayCount ) {
444
+ this.doLog("Add to homescreen: not displaying callout because displayed too many times already");
396
445
  return;
397
446
  }
398
447
  }
@@ -415,9 +464,13 @@ ath.Class.prototype = {
415
464
 
416
465
  var message = '';
417
466
 
418
- if ( this.options.message in ath.intl ) { // you can force the locale
467
+ if ( typeof this.options.message == 'object' && ath.language in this.options.message ) { // use custom language message
468
+ message = this.options.message[ath.language][ath.OS];
469
+ } else if ( typeof this.options.message == 'object' && ath.OS in this.options.message ) { // use custom os message
470
+ message = this.options.message[ath.OS];
471
+ } else if ( this.options.message in ath.intl ) { // you can force the locale
419
472
  message = ath.intl[this.options.message][ath.OS];
420
- } else if ( this.options.message !== '' ) { // or use a custom message
473
+ } else if ( this.options.message !== '' ) { // use a custom message
421
474
  message = this.options.message;
422
475
  } else { // otherwise we use our message
423
476
  message = ath.intl[ath.language][ath.OS];
@@ -456,17 +509,6 @@ ath.Class.prototype = {
456
509
  this.element.appendChild(this.img);
457
510
  }
458
511
 
459
-
460
- // Add the application name
461
- if (this.options.appName) {
462
- var appName = document.createElement("h3");
463
- appName.className = "appName";
464
- appName.innerHTML = this.options.appName;
465
-
466
- this.element.appendChild(appName);
467
- }
468
-
469
-
470
512
  this.element.innerHTML += message;
471
513
 
472
514
  // we are not ready to show, place the message out of sight
@@ -477,7 +519,9 @@ ath.Class.prototype = {
477
519
  this.container.appendChild(this.viewport);
478
520
 
479
521
  // if we don't have to wait for an image to load, show the message right away
480
- if ( !this.img ) {
522
+ if ( this.img ) {
523
+ this.doLog("Add to homescreen: not displaying callout because waiting for img to load");
524
+ } else {
481
525
  this._delayedShow();
482
526
  }
483
527
  },
@@ -607,6 +651,15 @@ ath.Class.prototype = {
607
651
  this.updateSession();
608
652
  },
609
653
 
654
+ getItem: function(item) {
655
+ try {
656
+ return localStorage.getItem(item);
657
+ } catch(e) {
658
+ // Preventing exception for some browsers when fetching localStorage key
659
+ ath.hasLocalStorage = false;
660
+ }
661
+ },
662
+
610
663
  optOut: function () {
611
664
  this.session.optedout = true;
612
665
  this.updateSession();
@@ -2,7 +2,7 @@ module Add
2
2
  module To
3
3
  module Homescreen
4
4
  module Rails
5
- VERSION = "3.1.2"
5
+ VERSION = "3.2.0"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: add-to-homescreen-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RogerE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-18 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides the 'Add to Home screen' assets for your Rails application.
14
14
  email: