Commit 1c3868ef by AlasdairSwan

Update program listing page's sidebar implementation to move to more self-contained subviews

s/our/your
parent 2429a7c2
;(function (define) {
'use strict';
define(['backbone',
'jquery',
'underscore',
'gettext',
'text!../../../templates/learner_dashboard/explore_new_programs.underscore'
],
function(
Backbone,
$,
_,
gettext,
exploreTpl
) {
return Backbone.View.extend({
el: '.program-advertise',
tpl: _.template(exploreTpl),
initialize: function(data) {
this.context = data.context;
this.$parentEl = $(this.parentEl);
if (this.context.xseriesUrl){
// Only render if there is an XSeries link
this.render();
} else {
/**
* If not rendering remove el because
* styles are applied to it
*/
this.remove();
}
},
render: function() {
this.$el.html(this.tpl(this.context));
}
});
}
);
}).call(this, define || RequireJS.define);
...@@ -17,16 +17,21 @@ ...@@ -17,16 +17,21 @@
picturefill picturefill
) { ) {
return Backbone.View.extend({ return Backbone.View.extend({
className: 'program-card', className: 'program-card',
tpl: _.template(programCardTpl), tpl: _.template(programCardTpl),
initialize: function() { initialize: function() {
this.render(); this.render();
}, },
render: function() { render: function() {
var templated = this.tpl(this.model.toJSON()); var templated = this.tpl(this.model.toJSON());
this.$el.html(templated); this.$el.html(templated);
this.postRender(); this.postRender();
}, },
postRender: function() { postRender: function() {
if(navigator.userAgent.indexOf('MSIE') !== -1 || if(navigator.userAgent.indexOf('MSIE') !== -1 ||
navigator.appVersion.indexOf('Trident/') > 0){ navigator.appVersion.indexOf('Trident/') > 0){
...@@ -36,6 +41,7 @@ ...@@ -36,6 +41,7 @@
}.bind(this), 100); }.bind(this), 100);
} }
}, },
// Defer loading the rest of the page to limit FOUC // Defer loading the rest of the page to limit FOUC
reLoadBannerImage: function() { reLoadBannerImage: function() {
var $img = this.$('.program_card .banner-image'), var $img = this.$('.program_card .banner-image'),
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
'jquery', 'jquery',
'underscore', 'underscore',
'gettext', 'gettext',
'js/learner_dashboard/views/explore_new_programs_view',
'text!../../../templates/learner_dashboard/sidebar.underscore' 'text!../../../templates/learner_dashboard/sidebar.underscore'
], ],
function( function(
...@@ -12,19 +13,27 @@ ...@@ -12,19 +13,27 @@
$, $,
_, _,
gettext, gettext,
NewProgramsView,
sidebarTpl sidebarTpl
) { ) {
return Backbone.View.extend({ return Backbone.View.extend({
el: '.sidebar', el: '.sidebar',
tpl: _.template(sidebarTpl), tpl: _.template(sidebarTpl),
initialize: function(data) { initialize: function(data) {
this.context = data.context; this.context = data.context;
}, },
render: function() { render: function() {
if (this.context.xseriesUrl){
//Only show the xseries advertising panel if the link is passed in
this.$el.html(this.tpl(this.context)); this.$el.html(this.tpl(this.context));
} this.postRender();
},
postRender: function() {
this.newProgramsView = new NewProgramsView({
context: this.context
});
} }
}); });
} }
......
...@@ -34,7 +34,7 @@ define([ ...@@ -34,7 +34,7 @@ define([
it('should load the xseries advertising based on passed in xseries URL', function() { it('should load the xseries advertising based on passed in xseries URL', function() {
var $sidebar = view.$el; var $sidebar = view.$el;
expect($sidebar.find('.program-advertise .advertise-message').html().trim()) expect($sidebar.find('.program-advertise .advertise-message').html().trim())
.toEqual('Browse recently launched courses and see what\'s new in our favorite subjects'); .toEqual('Browse recently launched courses and see what\'s new in your favorite subjects');
expect($sidebar.find('.program-advertise .ad-link a').attr('href')).toEqual(context.xseriesUrl); expect($sidebar.find('.program-advertise .ad-link a').attr('href')).toEqual(context.xseriesUrl);
}); });
......
<div class="advertise-message">
<%- gettext('Browse recently launched courses and see what\'s new in your favorite subjects') %>
</div>
<div class="ad-link">
<a href="<%- xseriesUrl %>" class="btn">
<i class="icon fa fa-search" aria-hidden="true"></i>
<span><%- gettext('Explore New XSeries') %></span>
</a>
</div>
<div class="program-advertise"> <div class="program-advertise"></div>
<div class="advertise-message"> <div class="certificate-container"></div>
<%- gettext('Browse recently launched courses and see what\'s new in our favorite subjects') %>
</div>
<div class="ad-link">
<a href="<%- xseriesUrl %>" class="btn">
<i class="icon fa fa-search" aria-hidden="true"></i>
<span><%- gettext('Explore New XSeries') %></span>
</a>
</div
</div>
<div class="certificate-container">
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment