Set first color automatically. Fetch more colors, just up to 8 colors in fronted.

This commit is contained in:
Martin Edenhofer 2015-11-24 02:52:41 +01:00
parent c0720b041b
commit 62d4ead6a4

View file

@ -43,7 +43,7 @@ class App.ChannelChat extends App.Controller
} }
{ {
name: 'host' name: 'host'
default: "(Empty)" default: '(Empty)'
type: 'String' type: 'String'
description: "If left empty, the host gets auto-detected - in this case %s. The auto-detection reads out the host from the <script> tag. If you don't include it via a <script> tag you need to specify the host." description: "If left empty, the host gets auto-detected - in this case %s. The auto-detection reads out the host from the <script> tag. If you don't include it via a <script> tag you need to specify the host."
descriptionSubstitute: window.location.origin descriptionSubstitute: window.location.origin
@ -62,7 +62,7 @@ class App.ChannelChat extends App.Controller
} }
{ {
name: 'fontSize' name: 'fontSize'
default: "undefined" default: 'undefined'
type: 'String' type: 'String'
description: 'CSS font-size with a unit like 12px, 1.5em. If left to undefined it inherits the font-size of the website.' description: 'CSS font-size with a unit like 12px, 1.5em. If left to undefined it inherits the font-size of the website.'
} }
@ -134,13 +134,13 @@ class App.ChannelChat extends App.Controller
width = parseInt value, 10 width = parseInt value, 10
# reset zoom # reset zoom
@chat.css('transform', "") @chat.css('transform', '')
@browser.css('width', "") @browser.css('width', '')
@chat.removeClass('is-fullscreen') @chat.removeClass('is-fullscreen')
@iframe.css @iframe.css
transform: "" transform: ''
width: "" width: ''
height: "" height: ''
return if value is 'fit' return if value is 'fit'
@ -160,7 +160,7 @@ class App.ChannelChat extends App.Controller
# fire both on enter and blur # fire both on enter and blur
# but cache url # but cache url
return if @urlInput.val() is "" or @urlInput.val() is @url return if @urlInput.val() is '' or @urlInput.val() is @url
@url = @urlInput.val() @url = @urlInput.val()
src = @url src = @url
@ -174,7 +174,7 @@ class App.ChannelChat extends App.Controller
url: 'https://images.zammad.com/api/v1/webpage/colors' url: 'https://images.zammad.com/api/v1/webpage/colors'
data: data:
url: src url: src
count: 6 count: 20
success: @renderSwatches success: @renderSwatches
dataType: 'json' dataType: 'json'
@ -184,14 +184,21 @@ class App.ChannelChat extends App.Controller
data = _.filter data, (color) => data = _.filter data, (color) =>
@getLuminance(color) < 0.85 @getLuminance(color) < 0.85
htmlString = "" htmlString = ''
count = 0
countMax = 8
for color in data for color in data
count += 1
htmlString += App.view('channel/color_swatch') htmlString += App.view('channel/color_swatch')
color: color color: color
break if count == countMax
@swatches.html htmlString @swatches.html htmlString
if data[0]
@useSwatchColor(undefined, data[0])
getLuminance: (hex) -> getLuminance: (hex) ->
# input: #ffffff, output: 1 # input: #ffffff, output: 1
result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec hex result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec hex
@ -200,8 +207,10 @@ class App.ChannelChat extends App.Controller
b = parseInt(result[3], 16) b = parseInt(result[3], 16)
return (0.2126*r + 0.7152*g + 0.0722*b)/255 return (0.2126*r + 0.7152*g + 0.0722*b)/255
useSwatchColor: (event) -> useSwatchColor: (event, code) ->
@colorField.val $(event.currentTarget).attr('data-color') if event
code = $(event.currentTarget).attr('data-color')
@colorField.val code
@updateParams() @updateParams()
new: (e) => new: (e) =>
@ -238,7 +247,7 @@ class App.ChannelChat extends App.Controller
callback: @load callback: @load
) )
widget: (e) => widget: (e) ->
e.preventDefault() e.preventDefault()
id = $(e.target).closest('.action').data('id') id = $(e.target).closest('.action').data('id')
new Widget( new Widget(
@ -266,7 +275,9 @@ class App.ChannelChat extends App.Controller
for key, value of params for key, value of params
if value != '' if value != ''
if paramString != '' if paramString != ''
# coffeelint: disable=no_unnecessary_double_quotes
paramString += ",\n" paramString += ",\n"
# coffeelint: enable=no_unnecessary_double_quotes
if value == 'true' || value == 'false' || _.isNumber(value) if value == 'true' || value == 'false' || _.isNumber(value)
paramString += " #{key}: #{value}" paramString += " #{key}: #{value}"
else else