'use strict'; if (!String.prototype.startsWith) { String.prototype.startsWith = function (searchString, position) { position = position || 0; return this.substr(position, searchString.length) === searchString; }; } var Bookmark = function (id, strategy, pages, excludedPages, resolution) { this.id = id; this.strategy = strategy; this.pages = pages; this.excludedPages = excludedPages; this.resolution = resolution; this.toggle(); this.listenResize(); }; Bookmark.prototype = { toggle: function () { if (this.canApplyStrategy() && !this.isExcluded() && $(window).width() >= this.resolution) { this.show(); } else { this.hide(); } }, show: function () { $('#' + this.id).show(); }, hide: function () { $('#' + this.id).hide(); }, canApplyStrategy: function () { var matchingPage = _.some(this.pages, function (page) { return (page === '/') ? window.location.pathname === page // special case for homepage : window.location.pathname.toLowerCase().startsWith(page); }); return (this.strategy === 'exclusion') ? !matchingPage : matchingPage; }, isExcluded: function () { return _.some(this.excludedPages, function (page) { return window.location.pathname.toLowerCase().startsWith(page); }); }, listenResize: function () { $(window).on('resize', $.proxy(this.toggle, this)); } }; /** Toogle VP Signet on absolute right value **/ function ToggleVPSignet(Id, Direction) { //get dynamic width image var width_encart = $('#' + Id + ' a:last-child > img').width(); // Show or hide on the right or left side of the screen var valueToMove = ($('#' + Id).css(Direction) == '0px') ? - width_encart : '0px'; var currentObject = $('#' + Id); $(currentObject).animate($.parseJSON('{"' + Direction + '": "' + valueToMove + '"}'), 250); return false; } function showAnimatedBookmark(id) { var sleep = $(id).find('.sleep'), awake = $(id).find('.awake'); sleep.hide(); awake.show(); return false; } function hideAnimatedBookmark(id) { var sleep = $(id).find('.sleep'), awake = $(id).find('.awake'); awake.hide(); sleep.show(); return false; }