Duplicate shop tab code for rewrite

The old code is still used on the user page.
This commit is contained in:
Maikel Linke
2020-03-04 14:47:40 +11:00
parent 2d21341183
commit 8aa892136e
5 changed files with 63 additions and 6 deletions

View File

@@ -0,0 +1,12 @@
Darkswarm.directive "page", ->
restrict: "C"
require: "^^pagesetCtrl"
scope:
name: "@"
link: (scope, element, attrs, ctrl) ->
element.on "click", ->
scope.$apply ->
ctrl.toggle(scope.name)
ctrl.registerSelectionListener (prefix, selection) ->
element.toggleClass('selected', selection == scope.name)

View File

@@ -0,0 +1,15 @@
Darkswarm.directive "pageView", ->
restrict: "C"
require: "^^pagesetCtrl"
template: "<div ng-include='template'></div>"
scope:
templates: "="
link: (scope, element, attrs, ctrl) ->
scope.template = null
ctrl.registerSelectionListener (prefix, selection) ->
if selection?
selection = "#{prefix}/#{selection}" if prefix?
scope.template = "#{selection}.html"
else
scope.template = null

View File

@@ -0,0 +1,30 @@
Darkswarm.directive "pagesetCtrl", (Tabsets, $location) ->
restrict: "C"
scope:
id: "@"
selected: "@"
navigate: "="
prefix: "@?"
alwaysopen: "="
controller: ($scope, $element) ->
if $scope.navigate
path = $location.path()?.match(/^\/\w+$/)?[0]
$scope.selected = path[1..] if path
this.toggle = (name) ->
state = if $scope.alwaysopen then 'open' else null
Tabsets.toggle($scope.id, name, state)
this.select = (selection) ->
$scope.$broadcast("selection:changed", selection)
$element.toggleClass("expanded", selection?)
$location.path(selection) if $scope.navigate
this.registerSelectionListener = (callback) ->
$scope.$on "selection:changed", (event, selection) ->
callback($scope.prefix, selection)
this
link: (scope, element, attrs, ctrl) ->
Tabsets.register(ctrl, scope.id, scope.selected)

View File

@@ -3,7 +3,7 @@
@import "branding";
// Tabs styling
.tabset-ctrl#shop-tabs {
.pageset-ctrl#shop-tabs {
.tab-buttons {
color: $dark-grey;
@@ -23,7 +23,7 @@
}
}
.tab {
.page {
text-align: center;
border-top: 4px solid transparent;
display: inline-block;
@@ -75,7 +75,7 @@
// content revealed in accordion
.tab-view {
.page-view {
margin-bottom: 5em;
background: none;
border: none;

View File

@@ -3,12 +3,12 @@
- shop_tabs.each do |tab|
= render "shopping_shared/tabs/#{tab[:name]}"
.tabset-ctrl#shop-tabs{ navigate: 'true', alwaysopen: 'true', selected: shop_tabs.first[:name], prefix: 'shop', ng: { cloak: true } }
.pageset-ctrl#shop-tabs{ navigate: 'true', alwaysopen: 'true', selected: shop_tabs.first[:name], prefix: 'shop', ng: { cloak: true } }
.tab-buttons
.row
.columns.small-12.large-8
- shop_tabs.each do |tab|
.tab{ id: "tab_#{tab[:name]}", name: tab[:name] }
.page{ id: "tab_#{tab[:name]}", name: tab[:name] }
%a{ href: 'javascript:void(0)' }=tab[:title]
.tab-view
.page-view