@@ -45,19 +45,21 @@ var ResizeObserver = { render: function render() {
45
45
name : 'resize-observer' ,
46
46
47
47
methods : {
48
- notify : function notify ( ) {
49
- this . $emit ( 'notify' ) ;
50
- } ,
51
- addResizeHandlers : function addResizeHandlers ( ) {
52
- this . _resizeObject . contentDocument . defaultView . addEventListener ( 'resize' , this . notify ) ;
48
+ compareAndNotify : function compareAndNotify ( ) {
53
49
if ( this . _w !== this . $el . offsetWidth || this . _h !== this . $el . offsetHeight ) {
54
- this . notify ( ) ;
50
+ this . _w = this . $el . offsetWidth ;
51
+ this . _h = this . $el . offsetHeight ;
52
+ this . $emit ( 'notify' ) ;
55
53
}
56
54
} ,
55
+ addResizeHandlers : function addResizeHandlers ( ) {
56
+ this . _resizeObject . contentDocument . defaultView . addEventListener ( 'resize' , this . compareAndNotify ) ;
57
+ this . compareAndNotify ( ) ;
58
+ } ,
57
59
removeResizeHandlers : function removeResizeHandlers ( ) {
58
60
if ( this . _resizeObject && this . _resizeObject . onload ) {
59
61
if ( ! isIE && this . _resizeObject . contentDocument ) {
60
- this . _resizeObject . contentDocument . defaultView . removeEventListener ( 'resize' , this . notify ) ;
62
+ this . _resizeObject . contentDocument . defaultView . removeEventListener ( 'resize' , this . compareAndNotify ) ;
61
63
}
62
64
delete this . _resizeObject . onload ;
63
65
}
@@ -74,7 +76,6 @@ var ResizeObserver = { render: function render() {
74
76
} ) ;
75
77
var object = document . createElement ( 'object' ) ;
76
78
this . _resizeObject = object ;
77
- object . setAttribute ( 'style' , 'display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;' ) ;
78
79
object . setAttribute ( 'aria-hidden' , 'true' ) ;
79
80
object . setAttribute ( 'tabindex' , - 1 ) ;
80
81
object . onload = this . addResizeHandlers ;
@@ -95,16 +96,13 @@ var ResizeObserver = { render: function render() {
95
96
// Install the components
96
97
function install ( Vue ) {
97
98
Vue . component ( 'resize-observer' , ResizeObserver ) ;
98
- /* -- Add more components here -- */
99
+ Vue . component ( 'ResizeObserver' , ResizeObserver ) ;
99
100
}
100
101
101
- /* -- Plugin definition & Auto-install -- */
102
- /* You shouldn't have to modify the code below */
103
-
104
102
// Plugin
105
103
var plugin = {
106
104
// eslint-disable-next-line no-undef
107
- version : "0.4.4 " ,
105
+ version : "0.4.5 " ,
108
106
install : install
109
107
} ;
110
108
0 commit comments