init.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. Ext.ns('Ext.samples');
  2. (function() {
  3. Ext.define('Ext.samples.SamplePanel', {
  4. extend: 'Ext.view.View',
  5. alias: 'widget.samplepanel',
  6. autoHeight : true,
  7. frame : false,
  8. cls : 'demos',
  9. itemSelector : 'dl',
  10. overItemCls : 'over',
  11. trackOver : true,
  12. tpl : Ext.create('Ext.XTemplate',
  13. '<div id="sample-ct">',
  14. '<tpl for=".">',
  15. '<div><a name="{id}"></a><h2><div>{title}</div></h2>',
  16. '<dl>',
  17. '<tpl for="items">',
  18. '<dd ext:url="{url}"><img src="shared/screens/{icon}"/>',
  19. '<div><h4>{text}',
  20. '<tpl if="this.isNew(values.status)">',
  21. '<span class="new-sample"> (New)</span>',
  22. '<tpl elseif="this.isUpdated(values.status)">',
  23. '<span class="updated-sample"> (Updated)</span>',
  24. '<tpl elseif="this.isExperimental(values.status)">',
  25. '<span class="new-sample"> (Experimental)</span>',
  26. '<tpl elseif="status">',
  27. '<span class="status"> ({status})</span>',
  28. '</tpl>',
  29. '</h4><p>{desc}</p></div>',
  30. '</dd>',
  31. '</tpl>',
  32. '<div style="clear:left"></div></dl></div>',
  33. '</tpl>',
  34. '</div>', {
  35. isExperimental: function(status){
  36. return status == 'experimental';
  37. },
  38. isNew: function(status){
  39. return status == 'new';
  40. },
  41. isUpdated: function(status){
  42. return status == 'updated';
  43. }
  44. }),
  45. onContainerClick: function(e) {
  46. var group = e.getTarget('h2', 3, true);
  47. if (group) {
  48. group.up('div').toggleCls('collapsed');
  49. }
  50. },
  51. onItemClick : function(record, item, index, e){
  52. var t = e.getTarget('dd', 5, true);
  53. if (t && !e.getTarget('a', 2)) {
  54. var url = t.getAttributeNS('ext', 'url');
  55. window.open(url);
  56. }
  57. return this.callParent(arguments);
  58. }
  59. });
  60. })();
  61. Ext.onReady(function() {
  62. (Ext.defer(function() {
  63. // Instantiate Ext.App instance
  64. var App = Ext.create('Ext.App', {});
  65. var catalog = Ext.samples.samplesCatalog;
  66. for (var i = 0, c; c = catalog[i]; i++) {
  67. c.id = 'sample-' + i;
  68. }
  69. var store = Ext.create('Ext.data.Store', {
  70. fields : ['id', 'title', 'items'],
  71. data : catalog
  72. });
  73. var panel = Ext.create('Ext.panel.Panel', {
  74. frame : false,
  75. renderTo : 'all-demos',
  76. height : 300,
  77. autoScroll : true,
  78. items : Ext.create('Ext.samples.SamplePanel', {
  79. store : store
  80. })
  81. });
  82. var tpl = Ext.create('Ext.XTemplate',
  83. '<tpl for="."><li><a href="#{id}">{title:stripTags}</a></li></tpl>'
  84. );
  85. tpl.overwrite('sample-menu', catalog);
  86. Ext.get('sample-spacer').remove();
  87. var headerEl = Ext.get('hd'),
  88. footerEl = Ext.get('ft'),
  89. bodyEl = Ext.get('bd'),
  90. sideBoxEl = bodyEl.down('div[class=side-box]'),
  91. titleEl = bodyEl.down('h1#pagetitle');
  92. var doResize = function() {
  93. var windowHeight = Ext.getDoc().getViewSize(false).height;
  94. var footerHeight = footerEl.getHeight() + footerEl.getMargin().top,
  95. titleElHeight = titleEl.getHeight() + titleEl.getMargin().top,
  96. headerHeight = headerEl.getHeight() + titleElHeight;
  97. var warnEl = Ext.get('fb');
  98. var warnHeight = warnEl ? warnEl.getHeight() : 0;
  99. var availHeight = windowHeight - ( footerHeight + headerHeight + 14) - warnHeight;
  100. var sideBoxHeight = sideBoxEl.getHeight();
  101. panel.setHeight((availHeight > sideBoxHeight) ? availHeight : sideBoxHeight);
  102. };
  103. // Resize on demand
  104. Ext.EventManager.onWindowResize(doResize);
  105. var firebugWarning = function () {
  106. var cp = Ext.create('Ext.state.CookieProvider');
  107. if(window.console && window.console.firebug && ! cp.get('hideFBWarning')){
  108. var tpl = Ext.create('Ext.Template',
  109. '<div id="fb" style="border: 1px solid #FF0000; background-color:#FFAAAA; display:none; padding:15px; color:#000000;"><b>Warning: </b> Firebug is known to cause performance issues with Ext JS. <a href="#" id="hideWarning">[ Hide ]</a></div>'
  110. );
  111. var newEl = tpl.insertFirst('all-demos');
  112. Ext.fly('hideWarning').on('click', function() {
  113. Ext.fly(newEl).slideOut('t',{remove:true});
  114. cp.set('hideFBWarning', true);
  115. doResize();
  116. });
  117. Ext.fly(newEl).slideIn();
  118. doResize();
  119. }
  120. };
  121. var hideMask = function () {
  122. Ext.get('loading').remove();
  123. Ext.fly('loading-mask').animate({
  124. opacity:0,
  125. remove:true,
  126. callback: firebugWarning
  127. });
  128. };
  129. Ext.defer(hideMask, 250);
  130. doResize();
  131. },500));
  132. });