123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2015, 2018
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', './Absolute'], function ($, BaseLayout) {
- var PageLayout = null;
- /**
- * Top level container that contains a template.
- */
- PageLayout = BaseLayout.extend({
- init: function init() {
- PageLayout.inherited('init', this, arguments);
- this.scrollPosition = {
- top: this.domNode.scrollTop,
- left: this.domNode.scrollLeft
- };
- this.$el.on('scroll.' + this.id, this._onScroll.bind(this));
- },
- destroy: function destroy() {
- PageLayout.inherited('destroy', this, arguments);
- this.$el.off('scroll.' + this.id);
- },
- // Prevent adding widgets outside of the page boundaries
- createDropZone: function createDropZone() {
- // No-op, override the inherited behaviour.
- },
- _onScroll: function _onScroll() {
- var scrollTop = this.domNode.scrollTop;
- var scrollLeft = this.domNode.scrollLeft;
- this._dndManager.scrollChildrenCandidateDropTargets(this.domNode, this.scrollPosition.top - scrollTop, this.scrollPosition.left - scrollLeft);
- this.scrollPosition.top = scrollTop;
- this.scrollPosition.left = scrollLeft;
- },
- _getTemplateLayoutView: function _getTemplateLayoutView() {
- var templateLayout = null;
- if (this.model.items && this.model.items.length > 0) {
- var model = this.model.items[0];
- templateLayout = $('#' + this.layoutController.modelIdToNodeId(model.id), this.layoutController.$el)[0]._layout;
- }
- return templateLayout;
- },
- _addWidget: function _addWidget(widgetSpec, isTouch) {
- var templateView = this._getTemplateLayoutView();
- if (templateView) {
- // Set new parent id to the template id.
- widgetSpec.parentId = templateView.model.id;
- // Calculate new position
- var top = parseInt(widgetSpec.layoutProperties.style.top, 10);
- var left = parseInt(widgetSpec.layoutProperties.style.left, 10);
- // Calculate new top and left
- var position = templateView.$el.position();
- var newTop = top - position.top - this.domNode.scrollTop;
- var newLeft = left - position.left - this.domNode.scrollLeft;
- // Take into account the minimum top/left supported by the templateView that we are adding to.
- widgetSpec.layoutProperties.style.top = Math.round(Math.max(newTop, templateView.getMinimumTop())) + 'px';
- widgetSpec.layoutProperties.style.left = Math.round(Math.max(newLeft, templateView.getMinimumLeft())) + 'px';
- // Add the widget the template layout
- templateView.authorHelper._addWidget(widgetSpec, isTouch);
- }
- },
- setPreferredLocation: function setPreferredLocation(options) {
- var view = this._getTemplateLayoutView();
- if (view && view.setPreferredLocation) {
- view.setPreferredLocation(options);
- }
- }
- });
- return PageLayout;
- });
- //# sourceMappingURL=TemplateContainer.js.map
|