You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

485 lines
14 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-Layer-method-constructor'><span id='Ext-Layer-cfg-useDisplay'><span id='Ext-Layer-cfg-shadowOffset'><span id='Ext-Layer-cfg-zindex'><span id='Ext-Layer-cfg-cls'><span id='Ext-Layer-cfg-constrain'><span id='Ext-Layer-cfg-dh'><span id='Ext-Layer-cfg-shadow'><span id='Ext-Layer-cfg-shim'><span id='Ext-Layer'>/**
  19. </span></span></span></span></span></span></span></span></span></span> * @class Ext.Layer
  20. * @extends Ext.Element
  21. * An extended {@link Ext.Element} object that supports a shadow and shim, constrain to viewport and
  22. * automatic maintaining of shadow/shim positions.
  23. * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
  24. * @cfg {String/Boolean} shadow True to automatically create an {@link Ext.Shadow}, or a string indicating the
  25. * shadow's display {@link Ext.Shadow#mode}. False to disable the shadow. (defaults to false)
  26. * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: 'div', cls: 'x-layer'}).
  27. * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
  28. * @cfg {String} cls CSS class to add to the element
  29. * @cfg {Number} zindex Starting z-index (defaults to 11000)
  30. * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 4)
  31. * @cfg {Boolean} useDisplay
  32. * Defaults to use css offsets to hide the Layer. Specify &lt;tt&gt;true&lt;/tt&gt;
  33. * to use css style &lt;tt&gt;'display:none;'&lt;/tt&gt; to hide the Layer.
  34. * @constructor
  35. * @param {Object} config An object with config options.
  36. * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
  37. */
  38. (function(){
  39. Ext.Layer = function(config, existingEl){
  40. config = config || {};
  41. var dh = Ext.DomHelper,
  42. cp = config.parentEl, pel = cp ? Ext.getDom(cp) : document.body;
  43. if (existingEl) {
  44. this.dom = Ext.getDom(existingEl);
  45. }
  46. if(!this.dom){
  47. var o = config.dh || {tag: 'div', cls: 'x-layer'};
  48. this.dom = dh.append(pel, o);
  49. }
  50. if(config.cls){
  51. this.addClass(config.cls);
  52. }
  53. this.constrain = config.constrain !== false;
  54. this.setVisibilityMode(Ext.Element.VISIBILITY);
  55. if(config.id){
  56. this.id = this.dom.id = config.id;
  57. }else{
  58. this.id = Ext.id(this.dom);
  59. }
  60. this.zindex = config.zindex || this.getZIndex();
  61. this.position('absolute', this.zindex);
  62. if(config.shadow){
  63. this.shadowOffset = config.shadowOffset || 4;
  64. this.shadow = new Ext.Shadow({
  65. offset : this.shadowOffset,
  66. mode : config.shadow
  67. });
  68. }else{
  69. this.shadowOffset = 0;
  70. }
  71. this.useShim = config.shim !== false &amp;&amp; Ext.useShims;
  72. this.useDisplay = config.useDisplay;
  73. this.hide();
  74. };
  75. var supr = Ext.Element.prototype;
  76. // shims are shared among layer to keep from having 100 iframes
  77. var shims = [];
  78. Ext.extend(Ext.Layer, Ext.Element, {
  79. getZIndex : function(){
  80. return this.zindex || parseInt((this.getShim() || this).getStyle('z-index'), 10) || 11000;
  81. },
  82. getShim : function(){
  83. if(!this.useShim){
  84. return null;
  85. }
  86. if(this.shim){
  87. return this.shim;
  88. }
  89. var shim = shims.shift();
  90. if(!shim){
  91. shim = this.createShim();
  92. shim.enableDisplayMode('block');
  93. shim.dom.style.display = 'none';
  94. shim.dom.style.visibility = 'visible';
  95. }
  96. var pn = this.dom.parentNode;
  97. if(shim.dom.parentNode != pn){
  98. pn.insertBefore(shim.dom, this.dom);
  99. }
  100. shim.setStyle('z-index', this.getZIndex()-2);
  101. this.shim = shim;
  102. return shim;
  103. },
  104. hideShim : function(){
  105. if(this.shim){
  106. this.shim.setDisplayed(false);
  107. shims.push(this.shim);
  108. delete this.shim;
  109. }
  110. },
  111. disableShadow : function(){
  112. if(this.shadow){
  113. this.shadowDisabled = true;
  114. this.shadow.hide();
  115. this.lastShadowOffset = this.shadowOffset;
  116. this.shadowOffset = 0;
  117. }
  118. },
  119. enableShadow : function(show){
  120. if(this.shadow){
  121. this.shadowDisabled = false;
  122. if(Ext.isDefined(this.lastShadowOffset)) {
  123. this.shadowOffset = this.lastShadowOffset;
  124. delete this.lastShadowOffset;
  125. }
  126. if(show){
  127. this.sync(true);
  128. }
  129. }
  130. },
  131. // private
  132. // this code can execute repeatedly in milliseconds (i.e. during a drag) so
  133. // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
  134. sync : function(doShow){
  135. var shadow = this.shadow;
  136. if(!this.updating &amp;&amp; this.isVisible() &amp;&amp; (shadow || this.useShim)){
  137. var shim = this.getShim(),
  138. w = this.getWidth(),
  139. h = this.getHeight(),
  140. l = this.getLeft(true),
  141. t = this.getTop(true);
  142. if(shadow &amp;&amp; !this.shadowDisabled){
  143. if(doShow &amp;&amp; !shadow.isVisible()){
  144. shadow.show(this);
  145. }else{
  146. shadow.realign(l, t, w, h);
  147. }
  148. if(shim){
  149. if(doShow){
  150. shim.show();
  151. }
  152. // fit the shim behind the shadow, so it is shimmed too
  153. var shadowAdj = shadow.el.getXY(), shimStyle = shim.dom.style,
  154. shadowSize = shadow.el.getSize();
  155. shimStyle.left = (shadowAdj[0])+'px';
  156. shimStyle.top = (shadowAdj[1])+'px';
  157. shimStyle.width = (shadowSize.width)+'px';
  158. shimStyle.height = (shadowSize.height)+'px';
  159. }
  160. }else if(shim){
  161. if(doShow){
  162. shim.show();
  163. }
  164. shim.setSize(w, h);
  165. shim.setLeftTop(l, t);
  166. }
  167. }
  168. },
  169. // private
  170. destroy : function(){
  171. this.hideShim();
  172. if(this.shadow){
  173. this.shadow.hide();
  174. }
  175. this.removeAllListeners();
  176. Ext.removeNode(this.dom);
  177. delete this.dom;
  178. },
  179. remove : function(){
  180. this.destroy();
  181. },
  182. // private
  183. beginUpdate : function(){
  184. this.updating = true;
  185. },
  186. // private
  187. endUpdate : function(){
  188. this.updating = false;
  189. this.sync(true);
  190. },
  191. // private
  192. hideUnders : function(negOffset){
  193. if(this.shadow){
  194. this.shadow.hide();
  195. }
  196. this.hideShim();
  197. },
  198. // private
  199. constrainXY : function(){
  200. if(this.constrain){
  201. var vw = Ext.lib.Dom.getViewWidth(),
  202. vh = Ext.lib.Dom.getViewHeight();
  203. var s = Ext.getDoc().getScroll();
  204. var xy = this.getXY();
  205. var x = xy[0], y = xy[1];
  206. var so = this.shadowOffset;
  207. var w = this.dom.offsetWidth+so, h = this.dom.offsetHeight+so;
  208. // only move it if it needs it
  209. var moved = false;
  210. // first validate right/bottom
  211. if((x + w) &gt; vw+s.left){
  212. x = vw - w - so;
  213. moved = true;
  214. }
  215. if((y + h) &gt; vh+s.top){
  216. y = vh - h - so;
  217. moved = true;
  218. }
  219. // then make sure top/left isn't negative
  220. if(x &lt; s.left){
  221. x = s.left;
  222. moved = true;
  223. }
  224. if(y &lt; s.top){
  225. y = s.top;
  226. moved = true;
  227. }
  228. if(moved){
  229. if(this.avoidY){
  230. var ay = this.avoidY;
  231. if(y &lt;= ay &amp;&amp; (y+h) &gt;= ay){
  232. y = ay-h-5;
  233. }
  234. }
  235. xy = [x, y];
  236. this.storeXY(xy);
  237. supr.setXY.call(this, xy);
  238. this.sync();
  239. }
  240. }
  241. return this;
  242. },
  243. getConstrainOffset : function(){
  244. return this.shadowOffset;
  245. },
  246. isVisible : function(){
  247. return this.visible;
  248. },
  249. // private
  250. showAction : function(){
  251. this.visible = true; // track visibility to prevent getStyle calls
  252. if(this.useDisplay === true){
  253. this.setDisplayed('');
  254. }else if(this.lastXY){
  255. supr.setXY.call(this, this.lastXY);
  256. }else if(this.lastLT){
  257. supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
  258. }
  259. },
  260. // private
  261. hideAction : function(){
  262. this.visible = false;
  263. if(this.useDisplay === true){
  264. this.setDisplayed(false);
  265. }else{
  266. this.setLeftTop(-10000,-10000);
  267. }
  268. },
  269. // overridden Element method
  270. setVisible : function(v, a, d, c, e){
  271. if(v){
  272. this.showAction();
  273. }
  274. if(a &amp;&amp; v){
  275. var cb = function(){
  276. this.sync(true);
  277. if(c){
  278. c();
  279. }
  280. }.createDelegate(this);
  281. supr.setVisible.call(this, true, true, d, cb, e);
  282. }else{
  283. if(!v){
  284. this.hideUnders(true);
  285. }
  286. var cb = c;
  287. if(a){
  288. cb = function(){
  289. this.hideAction();
  290. if(c){
  291. c();
  292. }
  293. }.createDelegate(this);
  294. }
  295. supr.setVisible.call(this, v, a, d, cb, e);
  296. if(v){
  297. this.sync(true);
  298. }else if(!a){
  299. this.hideAction();
  300. }
  301. }
  302. return this;
  303. },
  304. storeXY : function(xy){
  305. delete this.lastLT;
  306. this.lastXY = xy;
  307. },
  308. storeLeftTop : function(left, top){
  309. delete this.lastXY;
  310. this.lastLT = [left, top];
  311. },
  312. // private
  313. beforeFx : function(){
  314. this.beforeAction();
  315. return Ext.Layer.superclass.beforeFx.apply(this, arguments);
  316. },
  317. // private
  318. afterFx : function(){
  319. Ext.Layer.superclass.afterFx.apply(this, arguments);
  320. this.sync(this.isVisible());
  321. },
  322. // private
  323. beforeAction : function(){
  324. if(!this.updating &amp;&amp; this.shadow){
  325. this.shadow.hide();
  326. }
  327. },
  328. // overridden Element method
  329. setLeft : function(left){
  330. this.storeLeftTop(left, this.getTop(true));
  331. supr.setLeft.apply(this, arguments);
  332. this.sync();
  333. return this;
  334. },
  335. setTop : function(top){
  336. this.storeLeftTop(this.getLeft(true), top);
  337. supr.setTop.apply(this, arguments);
  338. this.sync();
  339. return this;
  340. },
  341. setLeftTop : function(left, top){
  342. this.storeLeftTop(left, top);
  343. supr.setLeftTop.apply(this, arguments);
  344. this.sync();
  345. return this;
  346. },
  347. setXY : function(xy, a, d, c, e){
  348. this.fixDisplay();
  349. this.beforeAction();
  350. this.storeXY(xy);
  351. var cb = this.createCB(c);
  352. supr.setXY.call(this, xy, a, d, cb, e);
  353. if(!a){
  354. cb();
  355. }
  356. return this;
  357. },
  358. // private
  359. createCB : function(c){
  360. var el = this;
  361. return function(){
  362. el.constrainXY();
  363. el.sync(true);
  364. if(c){
  365. c();
  366. }
  367. };
  368. },
  369. // overridden Element method
  370. setX : function(x, a, d, c, e){
  371. this.setXY([x, this.getY()], a, d, c, e);
  372. return this;
  373. },
  374. // overridden Element method
  375. setY : function(y, a, d, c, e){
  376. this.setXY([this.getX(), y], a, d, c, e);
  377. return this;
  378. },
  379. // overridden Element method
  380. setSize : function(w, h, a, d, c, e){
  381. this.beforeAction();
  382. var cb = this.createCB(c);
  383. supr.setSize.call(this, w, h, a, d, cb, e);
  384. if(!a){
  385. cb();
  386. }
  387. return this;
  388. },
  389. // overridden Element method
  390. setWidth : function(w, a, d, c, e){
  391. this.beforeAction();
  392. var cb = this.createCB(c);
  393. supr.setWidth.call(this, w, a, d, cb, e);
  394. if(!a){
  395. cb();
  396. }
  397. return this;
  398. },
  399. // overridden Element method
  400. setHeight : function(h, a, d, c, e){
  401. this.beforeAction();
  402. var cb = this.createCB(c);
  403. supr.setHeight.call(this, h, a, d, cb, e);
  404. if(!a){
  405. cb();
  406. }
  407. return this;
  408. },
  409. // overridden Element method
  410. setBounds : function(x, y, w, h, a, d, c, e){
  411. this.beforeAction();
  412. var cb = this.createCB(c);
  413. if(!a){
  414. this.storeXY([x, y]);
  415. supr.setXY.call(this, [x, y]);
  416. supr.setSize.call(this, w, h, a, d, cb, e);
  417. cb();
  418. }else{
  419. supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
  420. }
  421. return this;
  422. },
  423. <span id='Ext-Layer-method-setZIndex'> /**
  424. </span> * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
  425. * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
  426. * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
  427. * @param {Number} zindex The new z-index to set
  428. * @return {this} The Layer
  429. */
  430. setZIndex : function(zindex){
  431. this.zindex = zindex;
  432. this.setStyle('z-index', zindex + 2);
  433. if(this.shadow){
  434. this.shadow.setZIndex(zindex + 1);
  435. }
  436. if(this.shim){
  437. this.shim.setStyle('z-index', zindex);
  438. }
  439. return this;
  440. }
  441. });
  442. })();
  443. </pre>
  444. </body>
  445. </html>