-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc9061a
commit 664b205
Showing
6 changed files
with
169 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
define([ | ||
'core/js/adapt', | ||
'./logoView' | ||
], function(Adapt, LogoView) { | ||
'core/js/adapt', | ||
'./logoView' | ||
], function (Adapt, LogoView) { | ||
|
||
var Logo = _.extend({ | ||
var Logo = _.extend({ | ||
|
||
initialize: function() { | ||
this.listenToOnce(Adapt, 'app:dataReady', this.onAppDataReady); | ||
}, | ||
initialize: function () { | ||
this.listenToOnce(Adapt, 'app:dataReady', this.onAppDataReady); | ||
}, | ||
|
||
onAppDataReady: function() { | ||
this.listenTo(Adapt.config, 'change:_activeLanguage', this.onLangChange); | ||
onAppDataReady: function () { | ||
this.listenTo(Adapt.config, 'change:_activeLanguage', this.onLangChange); | ||
|
||
if (!Adapt.course.get('_logo')) return; | ||
if (!Adapt.course.get('_logo')) return; | ||
|
||
if (Adapt.course.get('_logo')._isEnabled) { | ||
this.setupLogo(); | ||
this.setupListeners(); | ||
} | ||
}, | ||
if (Adapt.course.get('_logo')._isEnabled) { | ||
this.setupLogo(); | ||
this.setupListeners(); | ||
} | ||
}, | ||
|
||
onLangChange: function() { | ||
this.removeListeners(); | ||
this.listenToOnce(Adapt, 'app:dataReady', this.onAppDataReady); | ||
}, | ||
onLangChange: function () { | ||
this.removeListeners(); | ||
this.listenToOnce(Adapt, 'app:dataReady', this.onAppDataReady); | ||
}, | ||
|
||
setupLogo: function() { | ||
this.config = Adapt.course.get('_logo'); | ||
this.model = new Backbone.Model(this.config); | ||
}, | ||
setupLogo: function () { | ||
this.config = Adapt.course.get('_logo'); | ||
this.model = new Backbone.Model(this.config); | ||
}, | ||
|
||
setupListeners: function() { | ||
this.listenTo(Adapt, 'navigationView:postRender', this.renderLogoView); | ||
}, | ||
setupListeners: function () { | ||
this.listenTo(Adapt, 'navigationView:postRender', this.renderLogoView); | ||
}, | ||
|
||
removeListeners: function() { | ||
this.stopListening(Adapt, 'navigationView:postRender', this.renderLogoView); | ||
this.stopListening(Adapt.config, 'change:_activeLanguage', this.onLangChange); | ||
}, | ||
removeListeners: function () { | ||
this.stopListening(Adapt, 'navigationView:postRender', this.renderLogoView); | ||
this.stopListening(Adapt.config, 'change:_activeLanguage', this.onLangChange); | ||
}, | ||
|
||
renderLogoView: function() { | ||
new LogoView({model: this.model}); | ||
} | ||
renderLogoView: function () { | ||
new LogoView({model: this.model}); | ||
} | ||
|
||
}, Backbone.Events); | ||
}, Backbone.Events); | ||
|
||
Logo.initialize(); | ||
Logo.initialize(); | ||
|
||
return Logo; | ||
return Logo; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,111 @@ | ||
define([ | ||
'core/js/adapt' | ||
], function(Adapt) { | ||
|
||
var LogoView = Backbone.View.extend({ | ||
|
||
className: 'logo', | ||
|
||
events: { | ||
'click .logo-button': 'onClick' | ||
}, | ||
|
||
initialize: function() { | ||
this.listenTo(Adapt.config, 'change:_activeLanguage', this.remove); | ||
this.listenTo(Adapt, 'device:changed', this.setupLogo); | ||
this.render(); | ||
}, | ||
|
||
render: function() { | ||
var data = this.model.toJSON(); | ||
var template = Handlebars.templates['logo']; | ||
|
||
// Check position | ||
if (this.model.get('_position') == "left" || this.model.get('_position') == "right") { | ||
this.$el.html(template(data)).prependTo('.navigation'+'>.navigation-inner'); | ||
} else { | ||
this.$el.html(template(data)).appendTo('.navigation'+'>.navigation-inner'); | ||
} | ||
|
||
this.image = ""; | ||
this.title = ""; | ||
|
||
this.setupLogo(); | ||
}, | ||
|
||
setupLogo: function () { | ||
this.deviceSize = Adapt.device.screenSize; | ||
this.image = ""; | ||
this.title = ""; | ||
|
||
// Add image if enabled | ||
if (this.model.get('_graphic')._isEnabled) { | ||
// Check device size | ||
switch (this.deviceSize) { | ||
case "large": | ||
this.image = this.model.get('_graphic')._large; | ||
break; | ||
case "medium": | ||
this.image = this.model.get('_graphic')._medium; | ||
break; | ||
default: | ||
// If "small" | ||
this.image = this.model.get('_graphic')._small; | ||
} | ||
// Add image | ||
this.$('img').attr('src', this.image); | ||
} | ||
// add title if enabled | ||
if (this.model.get('_title')._isEnabled) { | ||
// Check device size | ||
switch (this.deviceSize) { | ||
case "large": | ||
this.title = this.model.get('_title').large; | ||
break; | ||
case "medium": | ||
this.title = this.model.get('_title').medium; | ||
break; | ||
default: | ||
// If "small" | ||
this.title = this.model.get('_title').small; | ||
} | ||
// Add title | ||
this.$('.course-title').html(this.title); | ||
} | ||
|
||
// Add class to logo | ||
this.$el.addClass(this.model.get('_position')); | ||
|
||
// Hide elements if they are empty | ||
if (this.image == "") { | ||
this.$('.course-logo').hide(); | ||
} else { | ||
this.$('.course-logo').show(); | ||
} | ||
|
||
if (this.title == "") { | ||
this.$('.course-title').hide(); | ||
} else { | ||
this.$('.course-title').show(); | ||
} | ||
}, | ||
|
||
onClick: function(event) { | ||
if (event && event.preventDefault) event.preventDefault(); | ||
|
||
var currentId = Adapt.location._currentId; | ||
var parentId = Adapt.contentObjects.findWhere({ _id: currentId }).get('_parentId'); | ||
|
||
// Don't continue if the page is in the root of the course | ||
if (parentId === "course") return; | ||
|
||
if (this.model.get('_link')._parentPage) { | ||
Adapt.trigger('navigation:parentButton'); | ||
} | ||
'core/js/adapt' | ||
], function (Adapt) { | ||
|
||
var LogoView = Backbone.View.extend({ | ||
|
||
className: 'logo', | ||
|
||
events: { | ||
'click .js-nav-logo-btn': 'onClick' | ||
}, | ||
|
||
initialize: function () { | ||
this.listenTo(Adapt.config, 'change:_activeLanguage', this.remove); | ||
this.listenTo(Adapt, 'device:changed', this.setupLogo); | ||
this.render(); | ||
}, | ||
|
||
render: function () { | ||
var data = this.model.toJSON(); | ||
var template = Handlebars.templates['logo']; | ||
|
||
// Check position | ||
if (this.model.get('_position') == "left" || this.model.get('_position') == "right") { | ||
this.$el.html(template(data)).prependTo('.nav'+'>.nav__inner'); | ||
} else { | ||
this.$el.html(template(data)).appendTo('.nav'+'>.nav__inner'); | ||
} | ||
|
||
this.image = ""; | ||
this.title = ""; | ||
|
||
this.setupLogo(); | ||
}, | ||
|
||
setupLogo: function () { | ||
this.deviceSize = Adapt.device.screenSize; | ||
this.image = ""; | ||
this.title = ""; | ||
|
||
// Add image if enabled | ||
if (this.model.get('_graphic')._isEnabled) { | ||
// Check device size | ||
switch (this.deviceSize) { | ||
case "large": | ||
this.image = this.model.get('_graphic')._large; | ||
break; | ||
case "medium": | ||
this.image = this.model.get('_graphic')._medium; | ||
break; | ||
default: | ||
// If "small" | ||
this.image = this.model.get('_graphic')._small; | ||
} | ||
// Add image | ||
this.$('img').attr('src', this.image); | ||
} | ||
// add title if enabled | ||
if (this.model.get('_title')._isEnabled) { | ||
// Check device size | ||
switch (this.deviceSize) { | ||
case "large": | ||
this.title = this.model.get('_title').large; | ||
break; | ||
case "medium": | ||
this.title = this.model.get('_title').medium; | ||
break; | ||
default: | ||
// If "small" | ||
this.title = this.model.get('_title').small; | ||
} | ||
// Add title | ||
this.$('.logo__title').html(this.title); | ||
} | ||
|
||
// Add class to logo | ||
this.$el.addClass(this.model.get('_position')); | ||
|
||
// Hide elements if they are empty | ||
if (this.image == "") { | ||
this.$('.logo__image').hide(); | ||
} else { | ||
this.$('.logo__image').show(); | ||
} | ||
|
||
if (this.title == "") { | ||
this.$('.logo__title').hide(); | ||
} else { | ||
this.$('.logo__title').show(); | ||
} | ||
}, | ||
|
||
onClick: function (event) { | ||
if (event && event.preventDefault) event.preventDefault(); | ||
|
||
var currentId = Adapt.location._currentId; | ||
var parentId = Adapt.contentObjects.findWhere({ _id: currentId }).get('_parentId'); | ||
|
||
// Don't continue if the page is in the root of the course | ||
if (parentId === "course") return; | ||
|
||
if (this.model.get('_link')._parentPage) { | ||
Adapt.router.navigateToParent(); | ||
} | ||
} | ||
|
||
}); | ||
}); | ||
|
||
return LogoView; | ||
return LogoView; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.