mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Duplicate shop tab code for rewrite
The old code is still used on the user page.
This commit is contained in:
12
app/assets/javascripts/darkswarm/directives/page.js.coffee
Normal file
12
app/assets/javascripts/darkswarm/directives/page.js.coffee
Normal 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)
|
||||
@@ -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
|
||||
@@ -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)
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user