Changeset ed60fef in github
- Timestamp:
- Apr 13, 2010 6:17:39 AM (3 years ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
- Children:
- 6c11ee2
- Parents:
- 8e3a603
- File:
-
- 1 edited
-
skins/default/splitter.js (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
skins/default/splitter.js
ra4865ad red60fef 6 6 */ 7 7 function rcube_splitter(attrib) 8 {8 { 9 9 this.p1id = attrib.p1; 10 10 this.p2id = attrib.p2; … … 18 18 19 19 this.init = function() 20 {20 { 21 21 this.p1 = document.getElementById(this.p1id); 22 22 this.p2 = document.getElementById(this.p2id); … … 26 26 this.p2pos = this.relative ? $(this.p2).position() : $(this.p2).offset(); 27 27 28 if (this.horizontal) 29 { 28 if (this.horizontal) { 30 29 var top = this.p1pos.top + this.p1.offsetHeight; 31 30 this.layer = new rcube_layer(this.id, {x: 0, y: top, height: 10, 32 31 width: '100%', vis: 1, parent: this.p1.parentNode}); 33 } 34 else 35 { 32 } 33 else { 36 34 var left = this.p1pos.left + this.p1.offsetWidth; 37 35 this.layer = new rcube_layer(this.id, {x: left, y: 0, width: 10, 38 36 height: '100%', vis: 1, parent: this.p1.parentNode}); 39 }37 } 40 38 41 39 this.elm = this.layer.elm; … … 50 48 // read saved position from cookie 51 49 var cookie = bw.get_cookie(this.id); 52 if (cookie && !isNaN(cookie)) 53 { 50 if (cookie && !isNaN(cookie)) { 54 51 this.pos = parseFloat(cookie); 55 52 this.resize(); 56 } 57 else if (this.pos) 58 { 53 } 54 else if (this.pos) { 59 55 this.resize(); 60 56 this.set_cookie(); 61 }62 };57 } 58 }; 63 59 64 60 /** … … 67 63 */ 68 64 this.resize = function() 69 { 70 if (this.horizontal) 71 { 65 { 66 if (this.horizontal) { 72 67 var lh = this.layer.height - this.offset * 2; 73 68 this.p1.style.height = Math.floor(this.pos - this.p1pos.top - lh / 2) + 'px'; 74 69 this.p2.style.top = Math.ceil(this.pos + lh / 2) + 'px'; 75 70 this.layer.move(this.layer.x, Math.round(this.pos - lh / 2 + 1)); 76 if (bw.ie) 77 { 71 if (bw.ie) { 78 72 var new_height = parseInt(this.p2.parentNode.offsetHeight, 10) - parseInt(this.p2.style.top, 10) - (bw.ie8 ? 2 : 0); 79 this.p2.style.height = (new_height > 0 ? new_height : 0) +'px'; 80 } 73 this.p2.style.height = (new_height > 0 ? new_height : 0) + 'px'; 81 74 } 82 else83 {75 } 76 else { 84 77 this.p1.style.width = Math.floor(this.pos - this.p1pos.left - this.layer.width / 2) + 'px'; 85 78 this.p2.style.left = Math.ceil(this.pos + this.layer.width / 2) + 'px'; 86 79 this.layer.move(Math.round(this.pos - this.layer.width / 2 + 1), this.layer.y); 87 if (bw.ie) 88 this.p2.style.width = parseInt(this.p2.parentNode.offsetWidth, 10) - parseInt(this.p2.style.left, 10) + 'px'; 80 if (bw.ie) { 81 var new_width = parseInt(this.p2.parentNode.offsetWidth, 10) - parseInt(this.p2.style.left, 10) ; 82 this.p2.style.width = (new_width > 0 ? new_width : 0) + 'px'; 89 83 } 90 }; 84 } 85 }; 91 86 92 87 /** … … 94 89 */ 95 90 this.onDragStart = function(e) 96 {91 { 97 92 // disable text selection while dragging the splitter 98 93 if (window.webkit || bw.safari) … … 107 102 rcube_event.add_listener({element:document, event:'mouseup', object:this, method:'onDragStop'}); 108 103 109 // need to listen in any iframe documents too, b/c otherwise the splitter stops moving when we move over an iframe 110 var iframes = document.getElementsByTagName('iframe'); 111 this.iframe_events = Object(); 112 for (var n in iframes) 113 { 114 var iframedoc = null; 115 if (iframes[n].contentDocument) 116 iframedoc = iframes[n].contentDocument; 117 else if (iframes[n].contentWindow) 118 iframedoc = iframes[n].contentWindow.document; 119 else if (iframes[n].document) 120 iframedoc = iframes[n].document; 121 if (iframedoc) 122 { 123 // I don't use the add_listener function for this one because I need to create closures to fetch 124 // the position of each iframe when the event is received 125 var s = this; 126 var id = '#'+iframes[n].id; 127 this.iframe_events[n] = function(e){ e._offset = $(id).offset(); return s.onDrag(e); }; 128 129 if (iframedoc.addEventListener) 130 iframedoc.addEventListener('mousemove', this.iframe_events[n], false); 131 else if (iframes[n].attachEvent) 132 iframedoc.attachEvent('onmousemove', this.iframe_events[n]); 133 else 134 iframedoc.onmousemove = this.iframe_events[n]; 135 136 rcube_event.add_listener({element:iframedoc, event:'mouseup', object:this, method:'onDragStop'}); 137 } 138 } 139 } 104 // enable dragging above iframes 105 $('iframe').each(function() { 106 $('<div class="iframe-splitter-fix"></div>') 107 .css({background: '#fff', 108 width: this.offsetWidth+'px', height: this.offsetHeight+'px', 109 position: 'absolute', opacity: '0.001', zIndex: 1000 110 }) 111 .css($(this).offset()) 112 .appendTo('body'); 113 }); 114 }; 140 115 141 116 /** … … 143 118 */ 144 119 this.onDrag = function(e) 145 { 146 if (!this.drag_active) return false; 120 { 121 if (!this.drag_active) 122 return false; 147 123 148 124 var pos = rcube_event.get_mouse_pos(e); 149 125 150 if (this.relative) 151 { 126 if (this.relative) { 152 127 var parent = $(this.p1.parentNode).offset(); 153 128 pos.x -= parent.left; 154 129 pos.y -= parent.top; 155 }130 } 156 131 157 if (this.horizontal) 158 { 159 if (((pos.y - this.layer.height * 1.5) > this.p1pos.top) && ((pos.y + this.layer.height * 1.5) < (this.p2pos.top + this.p2.offsetHeight))) 160 { 132 if (this.horizontal) { 133 if (((pos.y - this.layer.height * 1.5) > this.p1pos.top) && ((pos.y + this.layer.height * 1.5) < (this.p2pos.top + this.p2.offsetHeight))) { 161 134 this.pos = pos.y; 162 135 this.resize(); 163 }164 136 } 165 else 166 { 167 if (((pos.x - this.layer.width * 1.5) > this.p1pos.left) && ((pos.x + this.layer.width * 1.5) < (this.p2pos.left + this.p2.offsetWidth))) 168 { 137 } 138 else { 139 if (((pos.x - this.layer.width * 1.5) > this.p1pos.left) && ((pos.x + this.layer.width * 1.5) < (this.p2pos.left + this.p2.offsetWidth))) { 169 140 this.pos = pos.x; 170 141 this.resize(); 171 }172 142 } 143 } 173 144 174 145 this.p1pos = this.relative ? $(this.p1).position() : $(this.p1).offset(); 175 146 this.p2pos = this.relative ? $(this.p2).position() : $(this.p2).offset(); 176 147 return false; 177 };148 }; 178 149 179 150 /** … … 181 152 */ 182 153 this.onDragStop = function(e) 183 {154 { 184 155 // resume the ability to highlight text 185 if (window.webkit || bw.safari)156 if (window.webkit || bw.safari) 186 157 document.body.style.webkitUserSelect = 'auto'; 187 158 … … 191 162 this.drag_active = false; 192 163 193 var iframes = document.getElementsByTagName('iframe'); 194 195 for (var n in iframes) 196 { 197 var iframedoc; 198 if (iframes[n].contentDocument) 199 iframedoc = iframes[n].contentDocument; 200 else if (iframes[n].contentWindow) 201 iframedoc = iframes[n].contentWindow.document; 202 else if (iframes[n].document) 203 iframedoc = iframes[n].document; 204 205 if (iframedoc) 206 { 207 if (this.iframe_events[n]) { 208 if (iframedoc.removeEventListener) 209 iframedoc.removeEventListener('mousemove', this.iframe_events[n], false); 210 else if (iframedoc.detachEvent) 211 iframedoc.detachEvent('onmousemove', this.iframe_events[n]); 212 else 213 iframedoc.onmousemove = null; 214 } 215 216 rcube_event.remove_listener({element:iframedoc, event:'mouseup', object:this, method:'onDragStop'}); 217 } 218 } 164 // remove temp divs 165 $('div.iframe-splitter-fix').each(function() { this.parentNode.removeChild(this); }); 219 166 220 167 this.set_cookie(); 221 168 222 169 return bw.safari ? true : rcube_event.cancel(e); 223 };170 }; 224 171 225 172 /** … … 227 174 */ 228 175 this.onResize = function(e) 229 { 230 if (this.horizontal) 231 { 176 { 177 if (this.horizontal) { 232 178 var new_height = parseInt(this.p2.parentNode.offsetHeight, 10) - parseInt(this.p2.style.top, 10) - (bw.ie8 ? 2 : 0); 233 179 this.p2.style.height = (new_height > 0 ? new_height : 0) +'px'; 234 } 235 else 236 this.p2.style.width = parseInt(this.p2.parentNode.offsetWidth, 10) - parseInt(this.p2.style.left, 10) + 'px'; 237 }; 180 } 181 else { 182 var new_width = parseInt(this.p2.parentNode.offsetWidth, 10) - parseInt(this.p2.style.left, 10); 183 this.p2.style.width = (new_width > 0 ? new_width : 0) + 'px'; 184 } 185 }; 238 186 187 /** 188 * Saves splitter position in cookie 189 */ 239 190 this.set_cookie = function() 240 { 241 // save state in cookie 191 { 242 192 var exp = new Date(); 243 193 exp.setYear(exp.getFullYear() + 1); 244 194 bw.set_cookie(this.id, this.pos, exp); 245 };195 }; 246 196 247 }// end class rcube_splitter197 } // end class rcube_splitter
Note: See TracChangeset
for help on using the changeset viewer.
