hide First Time promo after five visits (bug 698078)

This commit is contained in:
Chris Van 2011-11-01 14:16:08 -07:00
Родитель 9593c84bf7
Коммит 569b7ab5e7
7 изменённых файлов: 95 добавлений и 48 удалений

Просмотреть файл

@ -26,8 +26,7 @@
<a href="{{ services_url('discovery.addons.detail', addon.slug,
src='discovery-promo') }}" target="_self">
{% else %}
<a href="{{ url('addons.detail', addon.slug,
src='hp-dl-promo') }}" target="_self">
<a href="{{ addon.get_url_path()|urlparams(src='hp-dl-promo') }}" target="_self">
{% endif %}
{% if addon.type == amo.ADDON_PERSONA %}
<h3 class="htruncate">{{ addon.name }}</h3>

Просмотреть файл

@ -1,28 +0,0 @@
$(document).ready(function() {
var homepageSlider = AmoSlideshow();
if ($(document.body).hasClass('user-login')) {
// If the user login detected, switch to the second item to skip intro.
homepageSlider.moveToItem(2);
} else {
// Show the intro to anon users for 5 visits, then switch to second item.
var SEEN_COOKIE = 'amo_home_promo_seen',
MAX_SEEN = 5,
times_seen = parseInt($.cookie(SEEN_COOKIE));
if (!times_seen) times_seen = 0;
if (times_seen >= MAX_SEEN) {
// If the intro has been seen enough times, skip it.
// disabling this for Firefox Cup. TODO potch re-enable this.
// homepageSlider.moveToItem(2);
} else {
// Otherwise, count another appearance and stash in a cookie.
$.cookie(SEEN_COOKIE, times_seen + 1, {
path: '/',
expires: (new Date()).getTime() + ( 1000 * 60 * 60 * 24 * 365 )
});
}
}
$(".mobile-link").attr("href", window.location).click(function() {
$.cookie("mamo", "on", {expires:30});
});
});

Просмотреть файл

@ -1,23 +1,59 @@
(function () {
if (!$("#promos").length) return;
$("#promos").show();
var promos_base = $('#promos').attr('data-promo-url'),
promos_url = format('{0}?version={1}&platform={2}', promos_base, z.browserVersion, z.platform);
initPromos();
})();
function initPromos($context) {
if (typeof $context === 'undefined') {
$context = $(document.body);
}
var $promos = $('#promos[data-promo-url]', $context);
if (!$promos.length) {
return;
}
$promos.show();
var promos_base = $promos.attr('data-promo-url'),
promos_url = format('{0}?version={1}&platform={2}',
promos_base, z.browserVersion, z.platform);
if (z.badBrowser) {
promos_url = format('{0}?version={1}&platform={2}', promos_base, '5.0', 'mac');
promos_url = format('{0}?version={1}&platform={2}',
promos_base, '5.0', 'mac');
}
$.get(promos_url, function(resp) {
$('#promos ul').append($(resp));
$('#promos').append('<a href="#" class="control prev">&laquo;</a>\
<a href="#" class="control next">&raquo;</a>');
var $q = $('#promos div').zCarousel({
$('ul', $promos).append($(resp));
hideHomePromo();
$promos.append('<a href="#" class="control prev">&laquo;</a>\
<a href="#" class="control next">&raquo;</a>');
var $q = $('div', $promos).zCarousel({
circular: true,
btnPrev: $('#promos .prev'),
btnNext: $('#promos .next')
btnPrev: $('.prev', $promos),
btnNext: $('.next', $promos)
});
$('#promos .addons h3').truncate({dir: 'h'});
$('#promos .addons .desc').truncate({dir: 'v'});
$('#promos .install').installButton();
$('.addons h3', $promos).truncate({dir: 'h'});
$('.addons .desc', $promos).truncate({dir: 'v'});
$('.install', $promos).installButton();
});
$('.toplist .name').truncate({showTitle: true});
})();
}
function hideHomePromo($context) {
if (typeof $context === 'undefined') {
$context = $(document.body);
}
if (!$('#promos', $context).length) {
return;
}
// Show the intro to anon users for 5 visits, then switch to second item.
var KEY = 'amo_home_promo_seen',
MAX_SEEN = 5,
visitor = z.Storage('visitor'),
times_seen = parseInt(visitor.get(KEY) || 0, 10);
if (times_seen >= MAX_SEEN) {
// If the intro has been seen enough times, skip it.
$('#starter', $context).closest('.panel').remove();
} else {
// Otherwise, count another appearance and stash in localStorage.
visitor.set(KEY, times_seen + 1);
}
}

Просмотреть файл

@ -31,7 +31,7 @@ $(function() {
initReviewActions();
}
if($('#monthly').exists()) {
if($('#monthly.highcharts-container').exists()) {
initPerformanceStats();
}

Просмотреть файл

@ -0,0 +1,31 @@
module('Homepage promos', {
setup: function(hasAppsSupport, hasSeenAppsSupportWarning) {
this.sandbox = tests.createSandbox('#amo-promos');
this.visitor = z.Storage('visitor');
this.KEY = 'amo_home_promo_seen';
this.MAX_SEEN = 5;
this._promo_seen = this.visitor.get(this.KEY);
this.visitor.remove(this.KEY);
hideHomePromo(this.sandbox);
},
teardown: function() {
this.visitor.set(this.KEY, this._promo_seen);
this.sandbox.remove();
},
check: function(showPromo, cnt) {
var $panel = $('#starter', this.sandbox).closest('.panel');
equal($panel.length, showPromo ? 1 : 0);
equal(parseInt(this.visitor.get(this.KEY), 10), cnt || 0);
}
});
test('Home promo visible', function() {
this.check(true, 1);
});
test('Home promo not visible on 6th visit', function() {
for (var i = 0; i < 5; i++) {
hideHomePromo(this.sandbox);
}
this.check(false, 5);
});

Просмотреть файл

@ -559,7 +559,6 @@ MINIFY_BUNDLES = {
'js/amo2009/global.js',
'js/impala/ratingwidget.js',
'js/lib/jquery-ui/jqModal.js',
'js/amo2009/home.js',
'js/zamboni/l10n.js',
'js/zamboni/debouncer.js',

Просмотреть файл

@ -211,7 +211,7 @@
<div id="balloons">
<div class="site-balloon" id="site-noinstall-apps">
<p>
It seems your browser does not support Open Web Apps. Consider
It seems your browser does not support Open Web Apps. Consider
downloading <a href="#">Mozilla Firefox</a>,
a fast, free way to surf the Web!
</p>
@ -219,4 +219,14 @@
</div>
</div>
<div id="amo-promos">
<section id="promos" class="island">
<div>
<ul class="slider">
<li class="panel"><section id="starter"></section></li>
<li class="panel"><section id="ryff"></section></li>
</ul>
</div>
</section>
</div>
{% endblock %}