.pubsub.subscribe({ topic : 'tmg.cmp.onConsentReady', func : function(){ function truncate(string, maxLength) { if (string.length <= maxLength) return string; return string.slice(0, maxLength - 2).replace(/[^\w\s]?\s[^\s]*$/, '') + '...'; } // ------------------------------------------------------------------------ // // RecommendedList widget function RecommendedList(element) { this.element = element; } RecommendedList.selector = { ROOT: '#li-recommendation-widget', WIDGETNAME: 'li-recommendation-widget' }; RecommendedList.prototype.init = function () { if (this.element) { liftigniter('register', { max: 5, widget: RecommendedList.selector.WIDGETNAME, callback: this.onRequestSuccess.bind(this) }); } }; RecommendedList.prototype.onRequestSuccess = function (response) { var data = response; data.widgetTitle = this.element.dataset.title || ''; data.items.forEach(function (item) { item.truncatedTitle = truncate(item.title, 100); }); this.render(data); liftigniter('track', { elements: this.element.querySelectorAll('.recommended-articles__item'), name: RecommendedList.selector.WIDGETNAME, source: 'LI', opts: {}, _debug : false }); }; RecommendedList.prototype.render = function (data) { var template = ''; this.element.innerHTML = liftigniter('render', template, data); }; try{ // Initialise RecommendedList widget var rlElements = document.querySelectorAll(RecommendedList.selector.ROOT); var rlArray = Array.prototype.slice.call(rlElements); rlArray.forEach(function (element) { var widget = new RecommendedList(element); widget.init(); }); // Fetch has been moved to the botton because it needs to be called once // all widget are registered (multiple widgets case) otherwise // only the first one will be rendered. liftigniter('fetch'); } catch(err) { console.log('ANALYTICS:LAUNCH: LiftIgniter - try/catch error - error message = ',err); } }, runIfAlreadyPublished: true }); }, runIfAlreadyPublished: true }); })();