mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-09 23:06:06 +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)
|
||||
Reference in New Issue
Block a user