|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import CodeBuilder from '../../utils/CodeBuilder';
|
|
|
|
|
import deindent from '../../utils/deindent';
|
|
|
|
|
import { stringify } from '../../utils/stringify';
|
|
|
|
|
import flattenReference from '../../utils/flattenReference';
|
|
|
|
@ -106,6 +107,7 @@ export default class Window extends Node {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const lock = block.getUniqueName(`window_updating`);
|
|
|
|
|
const timeout = block.getUniqueName(`window_updating_timeout`);
|
|
|
|
|
|
|
|
|
|
Object.keys(events).forEach(event => {
|
|
|
|
|
const handlerName = block.getUniqueName(`onwindow${event}`);
|
|
|
|
@ -114,10 +116,14 @@ export default class Window extends Node {
|
|
|
|
|
if (event === 'scroll') {
|
|
|
|
|
// TODO other bidirectional bindings...
|
|
|
|
|
block.addVariable(lock, 'false');
|
|
|
|
|
block.addVariable(timeout,);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handlerBody = deindent`
|
|
|
|
|
${event === 'scroll' && `${lock} = true;`}
|
|
|
|
|
${event === 'scroll' && deindent`
|
|
|
|
|
if (${lock}) return;
|
|
|
|
|
${lock} = true;
|
|
|
|
|
`}
|
|
|
|
|
${generator.options.dev && `component._updatingReadonlyProperty = true;`}
|
|
|
|
|
|
|
|
|
|
#component.set({
|
|
|
|
@ -146,7 +152,8 @@ export default class Window extends Node {
|
|
|
|
|
|
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
|
function ${observerCallback}() {
|
|
|
|
|
if (${lock}) return;
|
|
|
|
|
${lock} = true;
|
|
|
|
|
clearTimeout(${timeout});
|
|
|
|
|
var x = ${bindings.scrollX
|
|
|
|
|
? `#component.get("${bindings.scrollX}")`
|
|
|
|
|
: `window.scrollX`};
|
|
|
|
@ -154,6 +161,7 @@ export default class Window extends Node {
|
|
|
|
|
? `#component.get("${bindings.scrollY}")`
|
|
|
|
|
: `window.scrollY`};
|
|
|
|
|
window.scrollTo(x, y);
|
|
|
|
|
${timeout} = setTimeout(function() { ${lock} = false; }, 100);
|
|
|
|
|
}
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
@ -170,8 +178,10 @@ export default class Window extends Node {
|
|
|
|
|
|
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
|
#component.observe("${bindings.scrollX || bindings.scrollY}", function(${isX ? 'x' : 'y'}) {
|
|
|
|
|
if (${lock}) return;
|
|
|
|
|
${lock} = true;
|
|
|
|
|
clearTimeout(${timeout});
|
|
|
|
|
window.scrollTo(${isX ? 'x, window.scrollY' : 'window.scrollX, y'});
|
|
|
|
|
${timeout} = setTimeout(function() { ${lock} = false; }, 100);
|
|
|
|
|
});
|
|
|
|
|
`);
|
|
|
|
|
}
|
|
|
|
|