-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from it3s/news_feed
News feed
- Loading branch information
Showing
25 changed files
with
452 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
App.components.selector = -> | ||
initialize: -> | ||
@baseURL = @attr.url ? "#{window.location.pathname}" | ||
@getQueryValues() | ||
@getParams() | ||
@updateValues() | ||
@bindEvents() | ||
@updateDisplay() | ||
|
||
getQueryValues: -> | ||
@queryValues = _.reduce(window.location.search.substr(1).split('&'), (ret, param) -> | ||
parts = param.replace(/\+/g, ' ').split('=') | ||
key = decodeURIComponent(parts[0]) | ||
val = parts[1] | ||
val = if not val? then null else decodeURIComponent(val) | ||
if not ret[key]? | ||
ret[key] = val | ||
else if _.isArray ret[key] | ||
ret[key].push val | ||
else | ||
ret[key] = [ret[key], val] | ||
return ret | ||
, {}) | ||
|
||
getParams: -> | ||
selectors = $(".options") | ||
@params ?= {} | ||
for selector in selectors | ||
selector = $ selector | ||
paramName = selector.data "selector-param" | ||
defaultValue = selector.find('.option[data-selector-default]').data "selector-value" | ||
@params[paramName] ?= | ||
name: paramName | ||
selector: selector | ||
default: defaultValue | ||
value: @queryValues[paramName] | ||
@params | ||
|
||
updateValue: (param) -> | ||
value = param.value ? param.default | ||
selectedOption = param.selector.find(".option").filter -> | ||
$(this).data("selector-selected") is true | ||
value = selectedOption.data "selector-value" if selectedOption.length > 0 | ||
param.value = value | ||
|
||
updateValues: -> | ||
for paramName, param of @params | ||
@updateValue param | ||
|
||
updateDisplay: -> | ||
for paramName, param of @params | ||
param.selector.find(".option").each (idx, el) -> | ||
el = $ el | ||
selected = el.data("selector-value") is param.value | ||
el.data "selector-selected", selected | ||
if not selected then el.removeClass("selected") else el.addClass("selected") | ||
|
||
changeValue: (param, value) -> | ||
return if param.value is value | ||
param.value = value | ||
App.mediator.publish "selector:changed", @getURLParams() | ||
@loadURL() if @attr.autoload | ||
@updateDisplay() | ||
|
||
bindEvents: -> | ||
that = this | ||
for paramName, param of @params | ||
param.selector.find(".option").click ((param) -> | ||
(evt) -> | ||
evt.preventDefault() | ||
value = $(this).data "selector-value" | ||
that.changeValue param, value | ||
)(param) | ||
|
||
onSuccess: (data) -> | ||
content = $(data).find(@attr.target) | ||
$(@attr.target).replaceWith content | ||
App.mediator.publish "components:start", content | ||
App.utils.spinner.hide() | ||
|
||
getURLParams: -> | ||
params = {} | ||
for paramName, param of @params | ||
params[paramName] = param.value if param.value? | ||
params | ||
|
||
getURL: -> | ||
params = $.param @getURLParams() | ||
"#{@baseURL}?#{params}#{window.location.hash}" | ||
|
||
loadURL: -> | ||
App.utils.spinner.show() | ||
if @attr.remote | ||
$.get @getURL(), @onSuccess.bind(this) | ||
else | ||
window.location = @getURL() |
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
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 |
---|---|---|
@@ -1,21 +1,61 @@ | ||
.option { | ||
display: inline-block; | ||
cursor: pointer; | ||
text-align: center; | ||
margin: 0 5px; | ||
padding: 20px 0; | ||
font-size: 1.2em; | ||
font-weight: bold; | ||
text-decoration: none; | ||
color: white; | ||
background-color: $meppit-dark-blue; | ||
border-radius: 5px; | ||
border: solid 1px $meppit-data-color; | ||
|
||
&:first-child { margin-left: 0;} | ||
&:last-child { margin-right: 0;} | ||
|
||
&:hover { | ||
background-color: lighten($meppit-dark-blue, 10%); | ||
.options { | ||
display: table; | ||
min-height: 60px; | ||
border-spacing: 5px; | ||
|
||
.option { | ||
display: table-cell; | ||
cursor: pointer; | ||
text-align: center; | ||
margin: 0 5px; | ||
padding: 5px; | ||
font-size: 1.2em; | ||
font-weight: bold; | ||
text-decoration: none; | ||
color: white; | ||
background-color: $meppit-dark-blue; | ||
border-radius: 5px; | ||
border: solid 1px $meppit-data-color; | ||
vertical-align: middle; | ||
|
||
&:first-child { margin-left: 0;} | ||
&:last-child { margin-right: 0;} | ||
|
||
&:hover { | ||
background-color: lighten($meppit-dark-blue, 10%); | ||
border: solid 1px $meppit-data-color; | ||
} | ||
} | ||
} | ||
|
||
.selector { | ||
margin: 10px 0; | ||
|
||
.options-label { | ||
font-weight: bold; | ||
} | ||
|
||
.options-label, | ||
.options-container { | ||
display: inline-block; | ||
vertical-align: middle; | ||
} | ||
|
||
.options { | ||
min-height: 40px; | ||
|
||
.option { | ||
color: $medium-grey; | ||
background-color: $ultra-soft-grey; | ||
border: solid 1px $soft-grey; | ||
font-weight: normal; | ||
padding: 10px; | ||
|
||
&.selected { | ||
color: $white; | ||
background-color: $meppit-dark-blue; | ||
border: solid 1px $meppit-data-color; | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.