diff options
Diffstat (limited to 'addons/web_unsplash/static/src/js/unsplash_beacon.js')
| -rw-r--r-- | addons/web_unsplash/static/src/js/unsplash_beacon.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/web_unsplash/static/src/js/unsplash_beacon.js b/addons/web_unsplash/static/src/js/unsplash_beacon.js new file mode 100644 index 00000000..c15ff027 --- /dev/null +++ b/addons/web_unsplash/static/src/js/unsplash_beacon.js @@ -0,0 +1,34 @@ +odoo.define('web_unsplash.beacon', function (require) { +'use strict'; + +var publicWidget = require('web.public.widget'); + +publicWidget.registry.UnsplashBeacon = publicWidget.Widget.extend({ + // /!\ To adapt the day the beacon makes sense for backend customizations + selector: '#wrapwrap', + + /** + * @override + */ + start: function () { + var unsplashImages = _.map(this.$('img[src*="/unsplash/"]'), function (img) { + // get image id from URL (`http://www.domain.com:1234/unsplash/xYdf5feoI/lion.jpg` -> `xYdf5feoI`) + return img.src.split('/unsplash/')[1].split('/')[0]; + }); + if (unsplashImages.length) { + this._rpc({ + route: '/web_unsplash/get_app_id', + }).then(function (appID) { + if (!appID) { + return; + } + $.get('https://views.unsplash.com/v', { + 'photo_id': unsplashImages.join(','), + 'app_id': appID, + }); + }); + } + return this._super.apply(this, arguments); + }, +}); +}); |
