mirror of
https://github.com/wassname/side-by-side.git
synced 2026-09-09 11:34:24 +08:00
Almost configurable base
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
angular.module('sideBySide', ['sideBySide.controllers', 'ngRoute', 'ngSanitize'])
|
||||
.config [ '$routeProvider', ($routeProvider) ->
|
||||
$routeProvider.when '/:base?/:section?', {
|
||||
templateUrl: 'partials/comparison.html'
|
||||
controller: 'ComparisonController'
|
||||
}
|
||||
.config [ '$locationProvider', ($locationProvider) ->
|
||||
$locationProvider.html5Mode true
|
||||
]
|
||||
|
||||
@@ -2,21 +2,25 @@ angular.module("sideBySide.controllers", [])
|
||||
.controller "AppController", [
|
||||
'$location', '$scope', 'poems'
|
||||
($location, $scope, poems) ->
|
||||
$scope.$on "$routeChangeSuccess", ($currentRoute, $previousRoute) ->
|
||||
$scope.base = if $previousRoute.params.base \
|
||||
then '/' + $previousRoute.params.base
|
||||
else ''
|
||||
urlParams = $location.url()
|
||||
.split('/')
|
||||
.filter((item) -> item)
|
||||
.map (item) ->
|
||||
item.split(':')
|
||||
.reduce((prev, current) ->
|
||||
prev[current[0]] = current[1]
|
||||
prev
|
||||
, {})
|
||||
|
||||
if 'base' of urlParams
|
||||
urlParams.base = urlParams.base.replace(/\./g, '/')
|
||||
else
|
||||
urlParams.base = ''
|
||||
|
||||
appUrl = $location.absUrl()
|
||||
.substring(0, $location.absUrl().length - $location.url().length)
|
||||
.replace(/[^\/]*?#$/, '')
|
||||
|
||||
base = appUrl + $location.url()
|
||||
.slice(1)
|
||||
.replace(/(.*)\/.*/, '$1')
|
||||
.replace(/\./g, '/')
|
||||
|
||||
poems.load base
|
||||
poems.load appUrl + '/' + urlParams.base
|
||||
]
|
||||
|
||||
.controller "ComparisonController", [
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
angular.module("sideBySide").factory "fetch", ['$http', '$q', 'readerFactory', ($http, $q, readerFactory) ->
|
||||
# Fetch
|
||||
#
|
||||
# @param file [String] Path to config file
|
||||
# @param base [String] Path to config file directory
|
||||
# @return [Object] Promises and heading
|
||||
(file = "/config.json") ->
|
||||
(base) ->
|
||||
file = base + '/config.json'
|
||||
$http.get(file).then (config) ->
|
||||
promises = config.data.files.map (poem) ->
|
||||
$http.get(poem).then (response) ->
|
||||
$http.get(base + '/' + poem).then (response) ->
|
||||
readerFactory(poem) response.data
|
||||
|
||||
{
|
||||
|
||||
@@ -32,8 +32,8 @@ angular.module("sideBySide").service "poems", ['fetch', (fetch) ->
|
||||
# Load poems
|
||||
#
|
||||
# @param base [String]
|
||||
@load = (base = '') =>
|
||||
fetch(base + "/config.json").then (config) =>
|
||||
@load = (base) =>
|
||||
fetch(base).then (config) =>
|
||||
config.fetchPoems.then (poems) =>
|
||||
@all = (activize(poem, config.active) for poem in poems)
|
||||
@heading = config.heading
|
||||
|
||||
Reference in New Issue
Block a user