azimuth.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. var parsers = require('../parsers');
  3. module.exports.definition = {
  4. set: function (v) {
  5. var valueType = parsers.valueType(v);
  6. if (valueType === parsers.TYPES.ANGLE) {
  7. return this._setProperty('azimuth', parsers.parseAngle(v));
  8. }
  9. if (valueType === parsers.TYPES.KEYWORD) {
  10. var keywords = v.toLowerCase().trim().split(/\s+/);
  11. var hasBehind = false;
  12. if (keywords.length > 2) {
  13. return;
  14. }
  15. var behindIndex = keywords.indexOf('behind');
  16. hasBehind = (behindIndex !== -1);
  17. if (keywords.length === 2) {
  18. if (!hasBehind) {
  19. return;
  20. }
  21. keywords.splice(behindIndex, 1);
  22. }
  23. if (keywords[0] === 'leftwards' || keywords[0] === 'rightwards') {
  24. if (hasBehind) {
  25. return;
  26. }
  27. return this._setProperty('azimuth', keywords[0]);
  28. }
  29. if (keywords[0] === 'behind') {
  30. return this._setProperty('azimuth', '180deg');
  31. }
  32. var deg;
  33. switch (keywords[0]) {
  34. case 'left-side':
  35. return this._setProperty('azimuth', '270deg');
  36. case 'far-left':
  37. return this._setProperty('azimuth', (hasBehind ? 240 : 300) + 'deg');
  38. case 'left':
  39. return this._setProperty('azimuth', (hasBehind ? 220 : 320) + 'deg');
  40. case 'center-left':
  41. return this._setProperty('azimuth', (hasBehind ? 200 : 340) + 'deg');
  42. case 'center':
  43. return this._setProperty('azimuth', (hasBehind ? 180 : 0) + 'deg');
  44. case 'center-right':
  45. return this._setProperty('azimuth', (hasBehind ? 160 : 20) + 'deg');
  46. case 'right':
  47. return this._setProperty('azimuth', (hasBehind ? 140 : 40) + 'deg');
  48. case 'far-right':
  49. return this._setProperty('azimuth', (hasBehind ? 120 : 60) + 'deg');
  50. case 'right-side':
  51. return this._setProperty('azimuth', '90deg');
  52. default:
  53. return;
  54. }
  55. }
  56. },
  57. get: function () {
  58. return this.getPropertyValue('azimuth');
  59. },
  60. enumerable: true,
  61. configurable: true
  62. };