123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- 'use strict';
- goog.provide('Blockly.WidgetDiv');
- goog.require('Blockly.Css');
- goog.require('goog.dom');
- goog.require('goog.dom.TagName');
- goog.require('goog.style');
- Blockly.WidgetDiv.DIV = null;
- Blockly.WidgetDiv.owner_ = null;
- Blockly.WidgetDiv.dispose_ = null;
- Blockly.WidgetDiv.createDom = function() {
- if (Blockly.WidgetDiv.DIV) {
- return;
- }
-
- Blockly.WidgetDiv.DIV =
- goog.dom.createDom(goog.dom.TagName.DIV, 'blocklyWidgetDiv');
- document.body.appendChild(Blockly.WidgetDiv.DIV);
- };
- Blockly.WidgetDiv.show = function(newOwner, rtl, dispose) {
- Blockly.WidgetDiv.hide();
- Blockly.WidgetDiv.owner_ = newOwner;
- Blockly.WidgetDiv.dispose_ = dispose;
-
-
- var xy = goog.style.getViewportPageOffset(document);
- Blockly.WidgetDiv.DIV.style.top = xy.y + 'px';
- Blockly.WidgetDiv.DIV.style.direction = rtl ? 'rtl' : 'ltr';
- Blockly.WidgetDiv.DIV.style.display = 'block';
- };
- Blockly.WidgetDiv.hide = function() {
- if (Blockly.WidgetDiv.owner_) {
- Blockly.WidgetDiv.owner_ = null;
- Blockly.WidgetDiv.DIV.style.display = 'none';
- Blockly.WidgetDiv.DIV.style.left = '';
- Blockly.WidgetDiv.DIV.style.top = '';
- Blockly.WidgetDiv.dispose_ && Blockly.WidgetDiv.dispose_();
- Blockly.WidgetDiv.dispose_ = null;
- goog.dom.removeChildren(Blockly.WidgetDiv.DIV);
- }
- };
- Blockly.WidgetDiv.isVisible = function() {
- return !!Blockly.WidgetDiv.owner_;
- };
- Blockly.WidgetDiv.hideIfOwner = function(oldOwner) {
- if (Blockly.WidgetDiv.owner_ == oldOwner) {
- Blockly.WidgetDiv.hide();
- }
- };
- Blockly.WidgetDiv.position = function(anchorX, anchorY, windowSize,
- scrollOffset, rtl) {
-
- if (anchorY < scrollOffset.y) {
- anchorY = scrollOffset.y;
- }
- if (rtl) {
-
- if (anchorX > windowSize.width + scrollOffset.x) {
- anchorX = windowSize.width + scrollOffset.x;
- }
- } else {
-
- if (anchorX < scrollOffset.x) {
- anchorX = scrollOffset.x;
- }
- }
- Blockly.WidgetDiv.DIV.style.left = anchorX + 'px';
- Blockly.WidgetDiv.DIV.style.top = anchorY + 'px';
- Blockly.WidgetDiv.DIV.style.height = windowSize.height + 'px';
- };
|