-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue/2808 convert to es6 classes modules
- Loading branch information
Showing
8 changed files
with
187 additions
and
251 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import MenuItemView from 'core/js/views/menuItemView'; | ||
import BoxMenuItemView from './BoxMenuItemView'; | ||
|
||
class BoxMenuGroupView extends MenuItemView { | ||
|
||
className() { | ||
return 'boxMenuGroup'; | ||
} | ||
|
||
postRender() { | ||
_.defer(this.addChildren.bind(this)); | ||
this.$el.imageready(this.setReadyStatus.bind(this)); | ||
this.$el.parents('.boxmenu__item-container').addClass('has-groups'); | ||
} | ||
} | ||
|
||
BoxMenuGroupView.template = 'boxmenu-group'; | ||
BoxMenuGroupView.childContainer = '.js-group-children'; | ||
BoxMenuGroupView.childView = BoxMenuItemView; | ||
|
||
export default BoxMenuGroupView; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import MenuItemView from 'core/js/views/menuItemView'; | ||
import router from 'core/js/router'; | ||
|
||
class BoxMenuItemView extends MenuItemView { | ||
|
||
className() { | ||
return 'boxmenu-item'; | ||
} | ||
|
||
events() { | ||
return { | ||
'click .js-btn-click': 'onClickMenuItemButton' | ||
}; | ||
} | ||
|
||
onClickMenuItemButton(event) { | ||
if (event && event.preventDefault) event.preventDefault(); | ||
if (this.model.get('_isLocked')) return; | ||
router.navigateToElement(this.model.get('_id')); | ||
} | ||
} | ||
|
||
BoxMenuItemView.template = 'boxMenuItem'; | ||
|
||
export default BoxMenuItemView; |
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import Adapt from 'core/js/adapt'; | ||
import MenuView from 'core/js/views/menuView'; | ||
import BoxMenuItemView from './BoxMenuItemView'; | ||
import BoxMenuGroupView from './BoxMenuGroupView'; | ||
|
||
class BoxMenuView extends MenuView { | ||
|
||
className() { | ||
return 'boxmenu'; | ||
} | ||
|
||
initialize() { | ||
super.initialize(); | ||
this.setStyles(); | ||
|
||
this.listenTo(Adapt, 'device:changed', this.onDeviceResize); | ||
} | ||
|
||
onDeviceResize() { | ||
this.setStyles(); | ||
} | ||
|
||
addChildren() { | ||
let nthChild = 0; | ||
const models = this.model.getChildren().models; | ||
const childViews = []; | ||
models.forEach(model => { | ||
if (!model.get('_isAvailable')) return; | ||
|
||
nthChild++; | ||
model.set('_nthChild', nthChild); | ||
|
||
const ChildView = (model.get('_type') === 'menu' && model.get('_boxMenu') && model.get('_boxMenu')._renderAsGroup) ? | ||
BoxMenuGroupView : | ||
BoxMenuItemView; | ||
|
||
const $parentContainer = this.$(this.constructor.childContainer); | ||
const childView = new ChildView({ model }); | ||
|
||
childViews.push(childView); | ||
|
||
$parentContainer.append(childView.$el); | ||
}); | ||
|
||
this.setChildViews(childViews); | ||
} | ||
|
||
setStyles() { | ||
this.setBackgroundImage(); | ||
this.setBackgroundStyles(); | ||
this.processHeader(); | ||
} | ||
|
||
setBackgroundImage() { | ||
const config = this.model.get('_boxMenu'); | ||
const backgroundImages = config?._backgroundImage; | ||
if (!backgroundImages) return; | ||
const backgroundImage = backgroundImages[`_${Adapt.device.screenSize}`] ?? backgroundImages._small; | ||
this.$el | ||
.toggleClass('has-bg-image', Boolean(backgroundImage)) | ||
.css('background-image', backgroundImage ? 'url(' + backgroundImage + ')' : ''); | ||
} | ||
|
||
setBackgroundStyles() { | ||
const config = this.model.get('_boxMenu'); | ||
const styles = config?._backgroundStyles; | ||
if (!styles) return; | ||
this.$el.css({ | ||
'background-repeat': styles._backgroundRepeat, | ||
'background-size': styles._backgroundSize, | ||
'background-position': styles._backgroundPosition | ||
}); | ||
} | ||
|
||
processHeader() { | ||
const config = this.model.get('_boxMenu'); | ||
const header = config?._menuHeader; | ||
|
||
if (!header) return; | ||
|
||
const $header = this.$('.menu__header'); | ||
|
||
this.setHeaderBackgroundImage(header, $header); | ||
this.setHeaderBackgroundStyles(header, $header); | ||
this.setHeaderMinimumHeight(header, $header); | ||
} | ||
|
||
setHeaderBackgroundImage(config, $header) { | ||
const backgroundImages = config._backgroundImage; | ||
if (!backgroundImages) return; | ||
const backgroundImage = backgroundImages[`_${Adapt.device.screenSize}`] ?? backgroundImages._small; | ||
$header | ||
.toggleClass('has-bg-image', Boolean(backgroundImage)) | ||
.css('background-image', backgroundImage ? 'url(' + backgroundImage + ')' : ''); | ||
} | ||
|
||
setHeaderBackgroundStyles(config, $header) { | ||
const styles = config._backgroundStyles; | ||
|
||
if (!styles) return; | ||
|
||
$header.css({ | ||
'background-repeat': styles._backgroundRepeat, | ||
'background-size': styles._backgroundSize, | ||
'background-position': styles._backgroundPosition | ||
}); | ||
} | ||
|
||
setHeaderMinimumHeight(config, $header) { | ||
const minimumHeights = config._minimumHeights; | ||
if (!minimumHeights) return; | ||
const minimumHeight = minimumHeights[`_${Adapt.device.screenSize}`] ?? minimumHeights._small; | ||
$header | ||
.toggleClass('has-min-height', Boolean(minimumHeight)) | ||
.css('min-height', minimumHeight ? minimumHeight + 'px' : ''); | ||
} | ||
|
||
} | ||
|
||
BoxMenuView.template = 'boxMenu'; | ||
|
||
export default BoxMenuView; |
Oops, something went wrong.