Skip to content

Commit f64d9ee

Browse files
committed
supports window resize
1 parent cb69276 commit f64d9ee

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

lib/minimap-view.coffee

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
{View} = require 'atom'
1+
{$, View} = require 'atom'
22

33
MinimapEditorView = require './minimap-editor-view'
44

55
CONFIGS = require './config'
66

7+
require './resizeend.js'
8+
79
minTop = 0
810
maxTop = 0
911

@@ -25,11 +27,12 @@ class MinimapView extends View
2527
initialize: ->
2628
@attach()
2729

28-
@on 'mousewheel', @mouseWheel.bind(this)
29-
@on 'mousedown', @mouseDown.bind(this)
30+
@on 'mousewheel', @mouseWheel
31+
@on 'mousedown', @mouseDown
3032

3133
@subscribe @paneView.model.$activeItem, @onActiveItemChanged
3234
@subscribe @paneView.model, 'destroy', => @destroy()
35+
@subscribe $(window), 'resize:end', @resizeend
3336

3437
#@subscribe atom.workspaceView, 'cursor:moved', =>
3538
# @update()
@@ -64,6 +67,12 @@ class MinimapView extends View
6467
@scrollView = @editorView.find('.scroll-view')
6568
@scrollViewLines = @scrollView.find('.lines')
6669

70+
# current editor bind scrollTop event
71+
@editor.off 'scroll-top-changed.editor'
72+
@editor.on 'scroll-top-changed.editor', @scrollTop
73+
@editor.off 'scroll-left-changed.editor'
74+
@editor.on 'scroll-left-changed.editor', @scrollLeft
75+
6776

6877
# wtf? Long long function!
6978
updateMinimapView: ->
@@ -91,12 +100,6 @@ class MinimapView extends View
91100
# offset minimap
92101
@offset({ 'top': @editorView.offset().top })
93102

94-
# current editor bind scrollTop event
95-
@editor.off('scroll-top-changed.editor')
96-
@editor.on('scroll-top-changed.editor', @scrollTop.bind(this))
97-
@editor.off('scroll-left-changed.editor')
98-
@editor.on('scroll-left-changed.editor', @scrollLeft.bind(this))
99-
100103
# reset minimap layer size
101104
@reset()
102105

@@ -135,18 +138,18 @@ class MinimapView extends View
135138
getScrollViewClientRect: ->
136139
@scrollViewLines[0].getBoundingClientRect()
137140

138-
mouseWheel: (e) ->
141+
mouseWheel: (e) =>
139142
return if @isClicked
140143
{wheelDeltaX, wheelDeltaY} = e.originalEvent
141144
if wheelDeltaX
142145
@editorView.scrollLeft(@editorView.scrollLeft() - wheelDeltaX)
143146
if wheelDeltaY
144147
@editorView.scrollTop(@editorView.scrollTop() - wheelDeltaY)
145148

146-
scrollLeft: (left) ->
149+
scrollLeft: (left) =>
147150
@miniScrollView.scrollLeft(left * scaleX)
148151

149-
scrollTop: (top) ->
152+
scrollTop: (top) =>
150153
h = @miniEditorView.height() * scaleY
151154
miniOverLayerHeight = @miniOverlayer.height()
152155
n = top / (@scrollViewLines.outerHeight() - miniOverLayerHeight)
@@ -164,7 +167,7 @@ class MinimapView extends View
164167
@miniOverlayer[0].style.transform = 'translate3d(0, ' + (n * (@miniEditorView.height() - miniOverLayerHeight)) + 'px, 0)'
165168

166169
isClicked: false
167-
mouseDown: (e) ->
170+
mouseDown: (e) =>
168171
@isClicked = true
169172
e.preventDefault()
170173
e.stopPropagation
@@ -190,3 +193,6 @@ class MinimapView extends View
190193
@[0].style.width = width + 'px'
191194
@[0].style.webkitTransform =
192195
@[0].style.transform = scaleStr + ' ' + translateStr
196+
197+
resizeend: (status) =>
198+
@updateMinimapView()

lib/resizeend.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Thanks @porada, https://github.com/porada/resizeend
2+
3+
(function(window) {
4+
var currentOrientation, debounce, dispatchResizeEndEvent, document, events, getCurrentOrientation, initialOrientation, resizeDebounceTimeout;
5+
document = window.document;
6+
if (!(window.addEventListener && document.createEvent)) {
7+
return;
8+
}
9+
events = ['resize:end', 'resizeend'].map(function(name) {
10+
var event;
11+
event = document.createEvent('Event');
12+
event.initEvent(name, false, false);
13+
return event;
14+
});
15+
dispatchResizeEndEvent = function() {
16+
return events.forEach(window.dispatchEvent.bind(window));
17+
};
18+
getCurrentOrientation = function() {
19+
return Math.abs(+window.orientation || 0) % 180;
20+
};
21+
initialOrientation = getCurrentOrientation();
22+
currentOrientation = null;
23+
resizeDebounceTimeout = null;
24+
debounce = function() {
25+
currentOrientation = getCurrentOrientation();
26+
if (currentOrientation !== initialOrientation) {
27+
dispatchResizeEndEvent();
28+
return initialOrientation = currentOrientation;
29+
} else {
30+
clearTimeout(resizeDebounceTimeout);
31+
return resizeDebounceTimeout = setTimeout(dispatchResizeEndEvent, 100);
32+
}
33+
};
34+
return window.addEventListener('resize', debounce, false);
35+
})(window);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "minimap",
33
"main": "./lib/minimap",
4-
"version": "0.2.0",
4+
"version": "0.2.1",
55
"private": true,
66
"description": "A preview of the full source code.",
77
"activationEvents": [

0 commit comments

Comments
 (0)