Skip to content

Commit

Permalink
amend articleView.js, blockView.js, componentView.js, menuView.js & p…
Browse files Browse the repository at this point in the history
…ageView.js so that they all set a data-adapt-id attribute in their HTML (resolves #1380)

switch to AMD style module definitions, stop using shortcut paths
move concatenation operators from beginning of lines to end of lines as JSHint's recommendation
  • Loading branch information
moloko committed Jan 17, 2017
1 parent b533cb6 commit 171e04d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 50 deletions.
28 changes: 17 additions & 11 deletions src/core/js/views/articleView.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
define(function(require) {

var AdaptView = require('coreViews/adaptView');
var BlockView = require('coreViews/blockView');
define([
'core/js/views/adaptView',
'core/js/views/blockView'
], function(AdaptView, BlockView) {

var ArticleView = AdaptView.extend({

attributes: function() {
return {
"data-adapt-id": this.model.get('_id')
};
},

className: function() {
return "article "
+ this.model.get('_id')
+ " " + this.model.get('_classes')
+ " " + this.setVisibility()
+ " nth-child-"
+ this.model.get("_nthChild");
return "article " +
this.model.get('_id') +
" " + this.model.get('_classes') +
" " + this.setVisibility() +
" nth-child-" +
this.model.get("_nthChild");
}

}, {
Expand All @@ -23,4 +29,4 @@ define(function(require) {

return ArticleView;

});
});
22 changes: 14 additions & 8 deletions src/core/js/views/blockView.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
define([
'core/js/views/adaptView'
], function(AdaptView) {
], function(AdaptView) {

var BlockView = AdaptView.extend({

attributes: function() {
return {
"data-adapt-id": this.model.get('_id')
};
},

className: function() {
return "block "
+ this.model.get('_id')
+ " " + this.model.get('_classes')
+ " " + this.setVisibility()
+ " nth-child-"
+ this.model.get("_nthChild");
return "block " +
this.model.get('_id') +
" " + this.model.get('_classes') +
" " + this.setVisibility() +
" nth-child-" +
this.model.get("_nthChild");
}

}, {
Expand All @@ -21,4 +27,4 @@ define([

return BlockView;

});
});
30 changes: 18 additions & 12 deletions src/core/js/views/componentView.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
define(function(require) {

var Adapt = require("coreJS/adapt");
var AdaptView = require('coreViews/adaptView');
define([
'core/js/adapt',
'core/js/views/adaptView'
], function(Adapt, AdaptView) {

var ComponentView = AdaptView.extend({

attributes: function() {
return {
"data-adapt-id": this.model.get('_id')
};
},

className: function() {
return "component "
+ this.model.get('_component')
+ "-component " + this.model.get('_id')
+ " " + this.model.get('_classes')
+ " " + this.setVisibility()
+ " component-" + this.model.get('_layout')
+ " nth-child-" + this.model.get("_nthChild");
return "component " +
this.model.get('_component') +
"-component " + this.model.get('_id') +
" " + this.model.get('_classes') +
" " + this.setVisibility() +
" component-" + this.model.get('_layout') +
" nth-child-" + this.model.get("_nthChild");
},

initialize: function(){
Expand Down Expand Up @@ -54,4 +60,4 @@ define(function(require) {

return ComponentView;

});
});
24 changes: 15 additions & 9 deletions src/core/js/views/menuView.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
define(function(require) {

var AdaptView = require('coreViews/adaptView');
var Adapt = require('coreJS/adapt');
define([
'core/js/adapt',
'core/js/views/adaptView'
], function(Adapt, AdaptView) {

var MenuView = AdaptView.extend({

attributes: function() {
return {
"data-adapt-id": this.model.get('_id')
};
},

className: function() {
var visible = "visibility-hidden";
if (this.model.get('_isVisible')) {
visible = "";
}
return 'menu '
+ 'menu-'
+ this.model.get('_id')
+ " " + this.model.get('_classes')
+ " " + this.setVisibility();
return 'menu ' +
'menu-' +
this.model.get('_id') +
" " + this.model.get('_classes') +
" " + this.setVisibility();
},

preRender: function() {
Expand Down
26 changes: 16 additions & 10 deletions src/core/js/views/pageView.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
define(function(require) {

var AdaptView = require('coreViews/adaptView');
var ArticleView = require('coreViews/articleView');
var Adapt = require('coreJS/adapt');
define([
'core/js/adapt',
'core/js/views/adaptView',
'core/js/views/articleView'
], function(Adapt, AdaptView, ArticleView) {

var PageView = AdaptView.extend({

attributes: function() {
return {
"data-adapt-id": this.model.get('_id')
};
},

className: function() {
return "page "
+ this.model.get('_id')
+ " " + this.model.get('_classes')
+ " " + this.setVisibility();
return "page " +
this.model.get('_id') +
" " + this.model.get('_classes') +
" " + this.setVisibility();
},

preRender: function() {
Expand Down Expand Up @@ -51,4 +57,4 @@ define(function(require) {

return PageView;

});
});

0 comments on commit 171e04d

Please sign in to comment.