1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Polymer('core-splitter', {
4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    /**
6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * Possible values are "left", "right", "up" and "down".
7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     *
8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * @attribute direction
9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * @type string
10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * @default 'left'
11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     */
12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    direction: 'left',
13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    /**
15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * Minimum width to which the splitter target can be sized
16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     *
17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * @attribute minSize
18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * @type number
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * @default 0
20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     */
21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    minSize: 0,
22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    /**
24a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * Locks the split bar so it can't be dragged.
25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     *
26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * @attribute locked
27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * @type boolean
28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * @default false
29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     */
30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    locked: false,
31
32    /**
33     * By default the parent and siblings of the splitter are set to overflow hidden. This helps
34     * avoid elements bleeding outside the splitter regions. Set this property to true to allow
35     * these elements to overflow.
36     *
37     * @attribute allowOverflow
38     * @type boolean
39     * @default false
40     */
41    allowOverflow: false,
42
43    ready: function() {
44      this.directionChanged();
45    },
46
47    domReady: function() {
48      if (!this.allowOverflow) {
49        this.parentNode.style.overflow = this.nextElementSibling.style.overflow =
50            this.previousElementSibling.style.overflow = 'hidden';
51      }
52    },
53
54    directionChanged: function() {
55      this.isNext = this.direction === 'right' || this.direction === 'down';
56      this.horizontal = this.direction === 'up' || this.direction === 'down';
57      this.update();
58    },
59
60    update: function() {
61      this.target = this.isNext ? this.nextElementSibling : this.previousElementSibling;
62      this.dimension = this.horizontal ? 'height' : 'width';
63      this.classList.toggle('horizontal', this.horizontal);
64    },
65
66    targetChanged: function(old) {
67      if (old) {
68        old.style[old.__splitterMinSize] = '';
69      }
70      var min = this.target.__splitterMinSize = this.horizontal ? 'minHeight' : 'minWidth';
71      this.target.style[min] = this.minSize + 'px';
72    },
73
74    trackStart: function() {
75      this.update();
76      this.size = parseInt(getComputedStyle(this.target)[this.dimension]);
77    },
78
79    track: function(e) {
80      if (this.locked) {
81        return;
82      }
83      var d = e[this.horizontal ? 'dy' : 'dx'];
84      this.target.style[this.dimension] =
85          this.size + (this.isNext ? -d : d) + 'px';
86    },
87
88    preventSelection: function(e) {
89      e.preventDefault();
90    }
91  });
92
93