GridGuidelines.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. *
  7. * Grid Guidelines
  8. */
  9. define(['jquery', 'underscore', '../../../../lib/@waca/core-client/js/core-client/ui/core/Class'], function ($, _, Class) {
  10. var SQUARES_INFO = 60;
  11. var SQUARES = 100;
  12. var GridGuidelines = Class.extend({
  13. gridSize: 0,
  14. init: function init(options) {
  15. var $page = $(options.page);
  16. this.layoutController = options.controller;
  17. var layoutModel = this.layoutController.boardModel.layout.findModel(options.page.id);
  18. if (!layoutModel) {
  19. layoutModel = this.layoutController.boardModel.layout;
  20. }
  21. this.snapGrid = layoutModel.getValueFromSelfOrParent('snapGrid');
  22. this.snapGrid = this.snapGrid === undefined ? false : this.snapGrid;
  23. var layoutPositioning = layoutModel.getValueFromSelfOrParent('layoutPositioning');
  24. if (layoutPositioning === 'absolute') {
  25. this.gridSize = 10;
  26. } else if (layoutPositioning === 'relative') {
  27. this.gridSize = this.getGridSize($page);
  28. }
  29. },
  30. getGridSize: function getGridSize($page) {
  31. var gridSize = 0;
  32. if ($page) {
  33. var width = $page.width();
  34. if ($page.hasClass('infoGraphic')) {
  35. gridSize = width / SQUARES_INFO;
  36. } else {
  37. gridSize = width / SQUARES;
  38. }
  39. }
  40. return gridSize;
  41. },
  42. calculateSnapPoint: function calculateSnapPoint(dragEdge) {
  43. if (this.snapGrid) {
  44. var distance = dragEdge % this.gridSize;
  45. if (distance > this.gridSize - 0.5) {
  46. distance = 0;
  47. }
  48. return { 'distance': distance };
  49. }
  50. return { 'distance': null };
  51. }
  52. });
  53. return GridGuidelines;
  54. });
  55. //# sourceMappingURL=GridGuidelines.js.map