Skip to content

Commit

Permalink
Simplify codes
Browse files Browse the repository at this point in the history
  • Loading branch information
KochiyaOcean committed Jun 18, 2016
1 parent 8b9b478 commit 75224ad
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 54 deletions.
58 changes: 54 additions & 4 deletions assets/js/webview-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,59 @@ window.onclick = (e) => {
`)
}

// Faster zoomLevel setting
window.webFrame = electron.webFrame
// Faster align setting
webFrame = electron.webFrame
var ROOT = remote.getGlobal('ROOT')
var config = remote.require(`${ROOT}/lib/config`)
zoom = config.get('poi.webview.width', 800) / 800
webFrame.setZoomFactor(zoom)

var alertCSS =
`#alert {
transform: scale(0.8);
left: 80px !important;
top: -80px !important;
}
`

var alignCSS = document.createElement('style')

window.align = () => {
var zoom
zoom = config.get('poi.webview.width', 800) / 800
webFrame.setZoomFactor(zoom)
window.scrollTo(0, 0)
alignCSS.innerHTML =
`html {
overflow: hidden;
}
#w, #main-ntg {
position: absolute !important;
top: 0;
left: 0;
z-index: 100;
margin-left: 0 !important;
margin-top: 0 !important;
}
#game_frame {
width: 800px !important;
position: absolute;
top: -16px;
left: 0;
}
#spacing_top {
display: none;
}
.naviapp {
z-index: -1;
}
`
}
window.unalign = () => {
alignCSS.innerHTML = ""
}

window.align()

remote.getCurrentWebContents().insertCSS(alertCSS)
document.addEventListener("DOMContentLoaded", (e) => {
document.querySelector('body').appendChild(alignCSS)
})
20 changes: 3 additions & 17 deletions views/components/info/control.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,9 @@ PoiControl = React.createClass
window.dispatchEvent new Event('resize')
e.preventDefault()
handleUnlockWebview: ->
$('kan-game webview').insertCSS """
html {
overflow: auto;
}
#w, #main-ntg {
position: relative !important;
top: 0;
left: 0;
z-index: 100;
margin-left: 0 !important;
margin-top: 0 !important;
}
#game_frame {
width: 900px !important;
position: relative;
}
"""
$('kan-game webview').executeJavaScript '''
window.unalign()
'''
handleSetExtend: ->
extend = !@state.extend
@setState {extend}
Expand Down
34 changes: 1 addition & 33 deletions views/services/layout.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -107,41 +107,9 @@ adjustSize = ->
$('kan-game #webview-wrapper')?.style?.height = "#{Math.ceil(480 * window.webviewFactor)}px"
factor = null
return
# Insert CSS
webview.insertCSS """
html {
overflow: hidden;
}
#w, #main-ntg {
position: absolute !important;
top: 0;
left: 0;
z-index: 100;
margin-left: 0 !important;
margin-top: 0 !important;
}
#game_frame {
width: 800px !important;
position: absolute;
top: -16px;
left: 0;
}
#spacing_top {
display: none;
}
.naviapp {
z-index: -1;
}
#alert {
transform: scale(0.8);
left: 80px !important;
top: -80px !important;
}
"""
# Set zoom factor
webview.executeJavaScript """
window.scrollTo(0, 0);
window.webFrame.setZoomFactor(#{factor})
window.align()
"""

adjustSize()
Expand Down

0 comments on commit 75224ad

Please sign in to comment.