Skip to content

Commit

Permalink
ACR pitch for nightly users (bug 679179)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Van committed Sep 1, 2011
1 parent 6ce4685 commit 1e24109
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 46 deletions.
3 changes: 2 additions & 1 deletion media/css/impala/header.less
Expand Up @@ -460,6 +460,7 @@ button.search-button {
display: none !important;
}
}
.developer-hub .site-balloon {
.developer-hub .site-balloon,
.developer-hub .site-tip {
display: none !important;
}
50 changes: 27 additions & 23 deletions media/js/impala/global.js
Expand Up @@ -86,23 +86,7 @@ function listing_grid() {
$(function() {
"use strict";

// Show the first visit banner.
if (!z.visitor.get('seen_impala_first_visit')) {
$('body').addClass('firstvisit');
z.visitor.set('seen_impala_first_visit', 1);
}

$("#site-nonfx .close").click(function() {
z.visitor.set('seen_badbrowser_warning', 1);
});

// Show the ACR pitch if it has not been dismissed.
if (!z.visitor.get('seen_acr_pitch') && $('body').hasClass('acr-pitch')) {
$('#acr-pitch').show();
$('#acr-pitch .close').click(function() {
z.visitor.set('seen_acr_pitch', 1);
});
}
initBanners();

// Bind to the mobile site if a mobile link is clicked.
$(".mobile-link").attr("href", window.location).click(function() {
Expand Down Expand Up @@ -131,12 +115,6 @@ $(function() {
$this.prev('a').attr('href', 'mailto:' + em);
});

//allow dismissal of site-balloons.
$('.site-balloon .close, .site-tip .close').click(function(e) {
e.preventDefault();
$(this).closest('.site-balloon, .site-tip').fadeOut();
});

$('#page').delegate('.expando .toggle', 'click', _pd(function() {
$(this).closest('.expando').toggleClass('expanded');
}));
Expand All @@ -156,3 +134,29 @@ $(function() {

$("select[name='rating']").ratingwidget();
});


function initBanners() {
// Show the first visit banner.
if (!z.visitor.get('seen_impala_first_visit')) {
$('body').addClass('firstvisit');
z.visitor.set('seen_impala_first_visit', 1);
}

$('#site-nonfx .close').click(function() {
z.visitor.set('seen_badbrowser_warning', 1);
});

// Show the ACR pitch if it has not been dismissed.
if (!z.visitor.get('seen_acr_pitch') && $('body').hasClass('acr-pitch')) {
$('#acr-pitch').show();
$('#acr-pitch .close').click(function() {
z.visitor.set('seen_acr_pitch', 1);
});
}

// Allow dismissal of site-balloons.
$('.site-balloon .close, .site-tip .close').click(_pd(function() {
$(this).closest('.site-balloon, .site-tip').fadeOut();
}));
}
18 changes: 8 additions & 10 deletions media/js/zamboni/buttons.js
Expand Up @@ -75,28 +75,26 @@ var installButton = function() {
params = {addon: addon,
msg: z.appMatchesUserAgent ? addto : gettext('Download Now')},
appSupported = z.appMatchesUserAgent && min && max,
olderBrowser = null,
newerBrowser = null;
$body = $(document.body),
olderBrowser,
newerBrowser;

// If we have os-specific buttons, check that one of them matches the
// current platform.
var badPlatform = ($button.find('.os').length &&
!$button.hasClass(z.platform));

try {
var storage = z.Storage();
z.hasACR = storage.get('ShowIncompatibleAddons');
} catch (TypeError) {
z.hasACR = false;
}

// min and max only exist if the add-on is compatible with request[APP].
if (appSupported && !z.hasACR) {
if (appSupported) {
// The user *has* an older/newer browser.
olderBrowser = VersionCompare.compareVersions(z.browserVersion, min) < 0;
newerBrowser = VersionCompare.compareVersions(z.browserVersion, max) > 0;
}

if (!$body.hasClass('acr-pitch') && newerBrowser && z.hasNightly && !z.hasACR) {
$body.addClass('acr-pitch');
}

// Helper for dealing with lazy-loaded z.button.messages.
var message = function(msg) {
return function(){
Expand Down
2 changes: 1 addition & 1 deletion media/js/zamboni/devhub.js
Expand Up @@ -879,7 +879,7 @@ function initCatFields() {
var $parent = $(this).closest("[data-max-categories]"),
$main = $(this).find(".addon-categories"),
$misc = $(this).find(".addon-misc-category"),
maxCats = parseInt($parent.attr("data-max-categories"));
maxCats = parseInt($parent.attr("data-max-categories"), 10);
var checkMainDefault = function() {
var checkedLength = $("input:checked", $main).length,
disabled = checkedLength >= maxCats;
Expand Down
12 changes: 9 additions & 3 deletions media/js/zamboni/init.js
Expand Up @@ -189,12 +189,18 @@ z.media_url = document.body.getAttribute('data-media-url');

z.readonly = JSON.parse(document.body.getAttribute('data-readonly'));

try {
var storage = z.Storage();
z.hasACR = storage.get('ShowIncompatibleAddons');
} catch (TypeError) {
z.hasACR = false;
}

z.hasNightly = false;
if (z.browser.firefox) {
var nightlyVer = document.body.getAttribute('data-nightly-version');
if (nightlyVer) {
z.hasNightly = (VersionCompare.compareVersions(z.browserVersion, nightlyVer) > -1);
} else {
z.hasNightly = false;
}
var betaVer = document.body.getAttribute('data-min-beta-version');
z.fxBeta = (VersionCompare.compareVersions(z.browserVersion, betaVer) > -1);
Expand All @@ -207,4 +213,4 @@ if (z.browser.firefox) {

if (z.badBrowser) {
$(".get-fx-message").show();
}
}
79 changes: 79 additions & 0 deletions media/js/zamboni/tests/acr_tests.js
@@ -0,0 +1,79 @@
$(document).ready(function() {

var acrFixture = {
setup: function(browserVersion, hasNightly, maxVer) {
this.sandbox = tests.createSandbox('#acr');
this._browser = z.browserVersion;
this._hasNightly = z.hasNightly;
this._hasACR = z.hasACR;
z.browserVersion = browserVersion;
z.hasNightly = hasNightly;
z.hasACR = false;
if (maxVer) {
$('.install', this.sandbox).attr('data-max', maxVer);
}
$('.install', this.sandbox).installButton();
initBanners();
},
teardown: function() {
$(document.body).removeClass('acr-pitch');
z.browserVersion = this._browser;
z.hasNightly = this._hasNightly;
z.hasACR = this._hasACR;
this.sandbox.remove();
},
check: function(showPitch) {
var $body = $(document.body);
if ($body.hasClass('badbrowser')) {
return;
}
var max = $('.install', this.sandbox).attr('data-max'),
newerBrowser = VersionCompare.compareVersions(z.browserVersion, max) > 0;
if (showPitch) {
equals(newerBrowser, true);
tests.hasClass($body, 'acr-pitch');
equals($('#acr-pitch:visible', this.sandbox).length, 1);
} else {
equals(newerBrowser, false);
tests.lacksClass($body, 'acr-pitch');
equals($('#acr-pitch:hidden', this.sandbox).length, 1);
}
}
};


module('ACR nightly incompatible', $.extend({}, acrFixture, {
setup: function() {
acrFixture.setup.call(this,
$(document.body).attr('data-nightly-version'), true, '3.0');
}
}));

test('Show pitch', function() {
this.check(true);
});


module('ACR nightly compatible', $.extend({}, acrFixture, {
setup: function() {
var nightlyVer = $(document.body).attr('data-nightly-version');
acrFixture.setup.call(this, nightlyVer, true, nightlyVer);
}
}));

test('No pitch', function() {
this.check(false);
});


module('ACR non-nightly compatible', $.extend({}, acrFixture, {
setup: function() {
acrFixture.setup.call(this, '4.0', false);
}
}));

test('No pitch', function() {
this.check(false);
});

});
8 changes: 4 additions & 4 deletions media/js/zamboni/tests/devhub_tests.js
Expand Up @@ -13,22 +13,22 @@ var catFixture = {
module('initCatFields', catFixture);

test('Default with initial categories', function() {
var scope = $("#addon-cats-fx", self.sandbox);
var scope = $("#addon-cats-fx", this.sandbox);
var checkedChoices = $("input:checked", scope);
equals(checkedChoices.length, 2);
equals(checkedChoices[0].id, "id_form-0-categories_1");
equals(checkedChoices[1].id, "id_form-0-categories_2");

// 2 categories are selected, the other category should be disabled.
var max = scope.parent("div").attr("data-max-categories");
equals(parseInt(max), 2);
var disabledChoices = $("input:disabled", scope);
equals(parseInt(max, 10), 2);
var disabledChoices = $("input:disabled", this.sandbox);
equals(disabledChoices.length, 1);
equals(disabledChoices[0].id, "id_form-0-categories_0");
});

test('Default without initial categories', function() {
equals($("#addon-cats-tb input:checked", self.sandbox).length, 0);
equals($("#addon-cats-tb input:checked", this.sandbox).length, 0);
});


Expand Down
2 changes: 1 addition & 1 deletion media/js/zamboni/tests/impala/suite.json
Expand Up @@ -3,7 +3,7 @@
"extra_media_urls": [
"js/lib/jstestnet.js",
"js/zamboni/tests.js",
"js/zamboni/global.js",
"js/impala/global.js",
"js/zamboni/devhub.js",
"js/zamboni/validator.js",
"js/zamboni/l10n.js",
Expand Down
3 changes: 2 additions & 1 deletion media/js/zamboni/tests/suite.json
Expand Up @@ -3,7 +3,8 @@
"extra_media_urls": [
"js/lib/jstestnet.js",
"js/zamboni/tests.js",
"js/zamboni/global.js",
"js/zamboni/buttons.js",
"js/impala/global.js",
"js/zamboni/devhub.js",
"js/zamboni/validator.js",
"js/zamboni/l10n.js",
Expand Down
3 changes: 3 additions & 0 deletions settings.py
Expand Up @@ -1074,6 +1074,9 @@ def read_only_mode(env):
previous='2.2'),
)

# Latest nightly version of Firefox.
NIGHTLY_VERSION = COMPAT[0]['main']

# URL for reporting arecibo errors too. If not set, won't be sent.
ARECIBO_SERVER_URL = ""
# Make AMO group posts and wait for 60 seconds when we get lots of errors.
Expand Down
1 change: 0 additions & 1 deletion templates/base.html
Expand Up @@ -43,7 +43,6 @@
data-appname="{{ request.APP.pretty }}"
data-appid="{{ request.APP.id }}"
data-min-beta-version="{{ settings.MIN_BETA_VERSION }}"
data-nightly-version="{{ settings.COMPAT[0]['main'] }}"
data-anonymous="{{ (not request.user.is_authenticated())|json }}"
data-readonly="{{ settings.READ_ONLY|json }}"
data-media-url="{{ MEDIA_URL }}"
Expand Down
2 changes: 1 addition & 1 deletion templates/impala/base.html
Expand Up @@ -48,7 +48,7 @@
data-appname="{{ request.APP.pretty }}"
data-appid="{{ request.APP.id }}"
data-min-beta-version="{{ settings.MIN_BETA_VERSION }}"
data-nightly-version="{{ settings.COMPAT[0]['main'] }}"
data-nightly-version="{{ settings.NIGHTLY_VERSION }}"
data-anonymous="{{ (not request.user.is_authenticated())|json }}"
data-readonly="{{ settings.READ_ONLY|json }}"
data-media-url="{{ MEDIA_URL }}"
Expand Down
13 changes: 13 additions & 0 deletions templates/qunit.html
Expand Up @@ -9,6 +9,7 @@
data-appname="{{ request.APP.pretty }}"
data-appid="{{ request.APP.id }}"
data-min-beta-version="{{ settings.MIN_BETA_VERSION }}"
data-nightly-version="{{ settings.NIGHTLY_VERSION }}"
data-anonymous="true"
data-readonly="false"
data-media-url="{{ MEDIA_URL }}"
Expand Down Expand Up @@ -346,6 +347,18 @@ <h3>Select a license for your Persona.</h3>
</div>
</div>

<div id="acr">
<div class="site-tip hidden" id="acr-pitch">Some ACR propaganda goes here.</div>
<div class="install-shell">
<div class="install featuredaddon" data-addon="1865"
data-name="Adblock Plus" data-min="3.0" data-max="4.0">
<p class="install-button">
<a data-hash="sha256:2bb766a6b096e9724df3a584bbe4f2e0ca687f1cd199e1a2c0ce58d4d8487284"
class="button download">Download Now</a>
</p>
</div>
</div>
</div>

<script type="text/javascript">
waffle = {
Expand Down

0 comments on commit 1e24109

Please sign in to comment.