chat designer: fix loader, add new api
This commit is contained in:
parent
d3605697df
commit
cde67e113b
3 changed files with 72 additions and 35 deletions
|
@ -9,7 +9,7 @@ class App.ChannelChat extends App.Controller
|
||||||
'submit .js-testurl': 'changeDemoWebsite'
|
'submit .js-testurl': 'changeDemoWebsite'
|
||||||
'blur .js-testurl-input': 'changeDemoWebsite'
|
'blur .js-testurl-input': 'changeDemoWebsite'
|
||||||
'click .js-selectBrowserWidth': 'selectBrowserWidth'
|
'click .js-selectBrowserWidth': 'selectBrowserWidth'
|
||||||
'click .js-swatch': 'useSwatchColor'
|
'click .js-swatch': 'usePaletteColor'
|
||||||
|
|
||||||
elements:
|
elements:
|
||||||
'.js-browser': 'browser'
|
'.js-browser': 'browser'
|
||||||
|
@ -19,8 +19,10 @@ class App.ChannelChat extends App.Controller
|
||||||
'.js-backgroundColor': 'chatBackground'
|
'.js-backgroundColor': 'chatBackground'
|
||||||
'.js-paramsBlock': 'paramsBlock'
|
'.js-paramsBlock': 'paramsBlock'
|
||||||
'.js-code': 'code'
|
'.js-code': 'code'
|
||||||
'.js-swatches': 'swatches'
|
'.js-palette': 'palette'
|
||||||
'.js-color': 'colorField'
|
'.js-color': 'colorField'
|
||||||
|
'.js-screenshot': 'screenshot'
|
||||||
|
'.js-website': 'website'
|
||||||
|
|
||||||
apiOptions: [
|
apiOptions: [
|
||||||
{
|
{
|
||||||
|
@ -140,10 +142,11 @@ class App.ChannelChat extends App.Controller
|
||||||
width = parseInt value, 10
|
width = parseInt value, 10
|
||||||
|
|
||||||
# reset zoom
|
# reset zoom
|
||||||
@chat.css('transform', '')
|
@chat
|
||||||
|
.css('transform', '')
|
||||||
|
.removeClass('is-fullscreen')
|
||||||
@browser.css('width', '')
|
@browser.css('width', '')
|
||||||
@chat.removeClass('is-fullscreen')
|
@website.css
|
||||||
@iframe.css
|
|
||||||
transform: ''
|
transform: ''
|
||||||
width: ''
|
width: ''
|
||||||
height: ''
|
height: ''
|
||||||
|
@ -156,7 +159,7 @@ class App.ChannelChat extends App.Controller
|
||||||
else
|
else
|
||||||
percentage = @el.width()/width
|
percentage = @el.width()/width
|
||||||
@chat.css('transform', "scale(#{ percentage })")
|
@chat.css('transform', "scale(#{ percentage })")
|
||||||
@iframe.css
|
@website.css
|
||||||
transform: "scale(#{ percentage })"
|
transform: "scale(#{ percentage })"
|
||||||
width: @el.width() / percentage
|
width: @el.width() / percentage
|
||||||
height: @el.height() / percentage
|
height: @el.height() / percentage
|
||||||
|
@ -166,56 +169,67 @@ 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 @urlCache
|
||||||
@url = @urlInput.val()
|
@urlCache = @urlInput.val()
|
||||||
|
|
||||||
src = @url
|
@url = @urlCache
|
||||||
if !src.startsWith('http')
|
if !@url.startsWith('http')
|
||||||
src = "http://#{ src }"
|
@url = "http://#{ @url }"
|
||||||
|
|
||||||
@urlInput.addClass('is-loading')
|
@urlInput.addClass('is-loading')
|
||||||
|
|
||||||
# clear swatches and iframe
|
# clear palette and iframe
|
||||||
@swatches.empty()
|
@palette.empty()
|
||||||
@iframe.attr('src', '').css('background-image', '')
|
@website.attr('data-mode', '')
|
||||||
|
@iframe.attr('src', '')
|
||||||
|
@screenshot.attr('src', '')
|
||||||
|
|
||||||
$.ajax
|
$.ajax
|
||||||
url: 'https://images.zammad.com/api/v1/webpage/colors'
|
url: 'https://images.zammad.com/api/v1/webpage/combined'
|
||||||
data:
|
data:
|
||||||
url: src
|
url: @url
|
||||||
|
count: 20
|
||||||
success: @renderDemoWebsite
|
success: @renderDemoWebsite
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
|
|
||||||
renderDemoWebsite: (data) =>
|
renderDemoWebsite: (data) =>
|
||||||
|
imageSource = data['data_url']
|
||||||
|
|
||||||
# @iframe.attr 'src', src
|
if imageSource
|
||||||
@renderSwatches data
|
console.log "renderDemoWebsite", typeof imageSource, imageSource
|
||||||
|
@screenshot.attr 'src', imageSource
|
||||||
|
@website.attr('data-mode', 'screenshot')
|
||||||
|
else
|
||||||
|
@iframe.attr 'src', @url
|
||||||
|
@website.attr('data-mode', 'iframe')
|
||||||
|
|
||||||
|
@renderPalette data['palette']
|
||||||
|
|
||||||
@urlInput.removeClass('is-loading')
|
@urlInput.removeClass('is-loading')
|
||||||
|
|
||||||
renderSwatches: (swatches) ->
|
renderPalette: (palette) ->
|
||||||
|
|
||||||
swatches = _.map swatches, tinycolor
|
palette = _.map palette, tinycolor
|
||||||
|
|
||||||
# filter white
|
# filter white
|
||||||
swatches = _.filter swatches, (color) =>
|
palette = _.filter palette, (color) =>
|
||||||
0.25 < color.getLuminance() < 0.85
|
color.getLuminance() < 0.85
|
||||||
|
|
||||||
htmlString = ''
|
htmlString = ''
|
||||||
|
|
||||||
max = 8
|
max = 8
|
||||||
for color, i in swatches
|
for color, i in palette
|
||||||
htmlString += App.view('channel/color_swatch')
|
htmlString += App.view('channel/color_swatch')
|
||||||
color: color.toHexString()
|
color: color.toHexString()
|
||||||
break if i is max
|
break if i is max
|
||||||
|
|
||||||
@swatches.html htmlString
|
@palette.html htmlString
|
||||||
|
|
||||||
# auto use first color
|
# auto use first color
|
||||||
if swatches[0]
|
if palette[0]
|
||||||
@useSwatchColor undefined, swatches[0].toHexString()
|
@usePaletteColor undefined, palette[0].toHexString()
|
||||||
|
|
||||||
useSwatchColor: (event, code) ->
|
usePaletteColor: (event, code) ->
|
||||||
if event
|
if event
|
||||||
code = $(event.currentTarget).attr('data-color')
|
code = $(event.currentTarget).attr('data-color')
|
||||||
@colorField.val code
|
@colorField.val code
|
||||||
|
|
|
@ -63,11 +63,14 @@
|
||||||
<div class="browser-head">
|
<div class="browser-head">
|
||||||
<form class="browser-input js-testurl" novalidate>
|
<form class="browser-input js-testurl" novalidate>
|
||||||
<input type="url" class="js-testurl-input" id="preview-iframe" placeholder="zammad.org">
|
<input type="url" class="js-testurl-input" id="preview-iframe" placeholder="zammad.org">
|
||||||
<div class="loading icon small"></div>
|
<div class="loading icon small muted"></div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="browser-body js-demo">
|
<div class="browser-body js-demo">
|
||||||
<iframe class="js-iframe"></iframe>
|
<div class="browser-website js-website">
|
||||||
|
<iframe class="js-iframe" sandbox></iframe>
|
||||||
|
<img class="js-screenshot">
|
||||||
|
</div>
|
||||||
<style>@import "/assets/chat/chat.css";</style>
|
<style>@import "/assets/chat/chat.css";</style>
|
||||||
<div class="chat-demo-animationHolder">
|
<div class="chat-demo-animationHolder">
|
||||||
<div class="js-chat zammad-chat zammad-chat-is-visible zammad-chat-is-open" style="bottom: 0px;">
|
<div class="js-chat zammad-chat zammad-chat-is-visible zammad-chat-is-open" style="bottom: 0px;">
|
||||||
|
@ -122,7 +125,7 @@
|
||||||
<div class="input form-group formGroup--halfSize">
|
<div class="input form-group formGroup--halfSize">
|
||||||
<div class="formGroup-label">
|
<div class="formGroup-label">
|
||||||
<label for="form-chat-background"><%- @T('Background color') %></label>
|
<label for="form-chat-background"><%- @T('Background color') %></label>
|
||||||
<div class="align-right horizontal js-swatches"></div>
|
<div class="align-right horizontal js-palette"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input class="js-color" type="text" id="form-chat-background" name="background" value="">
|
<input class="js-color" type="text" id="form-chat-background" name="background" value="">
|
||||||
|
|
|
@ -2317,6 +2317,10 @@ ol.tabs li {
|
||||||
height: 12px;
|
height: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loading.icon.muted {
|
||||||
|
background: hsl(195,20%,96%);
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes rotateplane {
|
@keyframes rotateplane {
|
||||||
0% {
|
0% {
|
||||||
transform: perspective(120px) rotateX(0deg) rotateY(0deg);
|
transform: perspective(120px) rotateX(0deg) rotateY(0deg);
|
||||||
|
@ -7431,6 +7435,18 @@ output {
|
||||||
height: 450px;
|
height: 450px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
.browser-website {
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
transform-origin: left top;
|
||||||
|
overflow: auto;
|
||||||
|
|
||||||
|
&[data-mode=screenshot] iframe,
|
||||||
|
&[data-mode=iframe] img {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
iframe {
|
iframe {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
border: none;
|
border: none;
|
||||||
|
@ -7438,7 +7454,11 @@ output {
|
||||||
top: 0;
|
top: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
transform-origin: left top;
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
vertical-align: bottom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7455,6 +7475,10 @@ output {
|
||||||
input {
|
input {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
padding-right: 40px;
|
padding-right: 40px;
|
||||||
|
|
||||||
|
&.is-loading + .loading.icon {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading.icon {
|
.loading.icon {
|
||||||
|
@ -7463,10 +7487,6 @@ output {
|
||||||
top: 11px;
|
top: 11px;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.is-loading .loading.icon {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.help-block {
|
.help-block {
|
||||||
|
|
Loading…
Reference in a new issue