Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: Source/devtools/front_end/resources/ResourcesPanel.js

Issue 362273002: DevTools: Reduce code via using document.createElementWithClass and document.createChild. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 4 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 819
820 WebInspector.BaseStorageTreeElement.prototype = { 820 WebInspector.BaseStorageTreeElement.prototype = {
821 onattach: function() 821 onattach: function()
822 { 822 {
823 this.listItemElement.removeChildren(); 823 this.listItemElement.removeChildren();
824 if (this._iconClasses) { 824 if (this._iconClasses) {
825 for (var i = 0; i < this._iconClasses.length; ++i) 825 for (var i = 0; i < this._iconClasses.length; ++i)
826 this.listItemElement.classList.add(this._iconClasses[i]); 826 this.listItemElement.classList.add(this._iconClasses[i]);
827 } 827 }
828 828
829 var selectionElement = document.createElement("div"); 829 this.listItemElement.createChild("div", "selection");
830 selectionElement.className = "selection";
831 this.listItemElement.appendChild(selectionElement);
832 830
833 if (!this._noIcon) { 831 if (!this._noIcon)
834 this.imageElement = document.createElement("img"); 832 this.imageElement = this.listItemElement.createChild("img", "icon");
835 this.imageElement.className = "icon";
836 this.listItemElement.appendChild(this.imageElement);
837 }
838 833
839 this.titleElement = document.createElement("div"); 834 this.titleElement = this.listItemElement.createChild("div", "base-storag e-tree-element-title");
840 this.titleElement.className = "base-storage-tree-element-title"; 835 this._titleTextNode = this.titleElement.createTextChild("");
841 this._titleTextNode = document.createTextNode("");
842 this.titleElement.appendChild(this._titleTextNode);
843 this._updateTitle(); 836 this._updateTitle();
844 this._updateSubtitle(); 837 this._updateSubtitle();
845 this.listItemElement.appendChild(this.titleElement);
846 }, 838 },
847 839
848 get displayName() 840 get displayName()
849 { 841 {
850 return this._displayName; 842 return this._displayName;
851 }, 843 },
852 844
853 _updateDisplayName: function() 845 _updateDisplayName: function()
854 { 846 {
855 this._displayName = this._titleText || ""; 847 this._displayName = this._titleText || "";
(...skipping 12 matching lines...) Expand all
868 }, 860 },
869 861
870 _updateSubtitle: function() 862 _updateSubtitle: function()
871 { 863 {
872 this._updateDisplayName(); 864 this._updateDisplayName();
873 865
874 if (!this.titleElement) 866 if (!this.titleElement)
875 return; 867 return;
876 868
877 if (this._subtitleText) { 869 if (this._subtitleText) {
878 if (!this._subtitleElement) { 870 if (!this._subtitleElement)
879 this._subtitleElement = document.createElement("span"); 871 this._subtitleElement = this.titleElement.createChild("span", "b ase-storage-tree-element-subtitle");
880 this._subtitleElement.className = "base-storage-tree-element-sub title";
881 this.titleElement.appendChild(this._subtitleElement);
882 }
883 this._subtitleElement.textContent = "(" + this._subtitleText + ")"; 872 this._subtitleElement.textContent = "(" + this._subtitleText + ")";
884 } else if (this._subtitleElement) { 873 } else if (this._subtitleElement) {
885 this.titleElement.removeChild(this._subtitleElement); 874 this._subtitleElement.remove();
886 delete this._subtitleElement; 875 delete this._subtitleElement;
887 } 876 }
888 }, 877 },
889 878
890 /** 879 /**
891 * @override 880 * @override
892 * @return {boolean} 881 * @return {boolean}
893 */ 882 */
894 onselect: function(selectedByUser) 883 onselect: function(selectedByUser)
895 { 884 {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 }, 1166 },
1178 1167
1179 /** 1168 /**
1180 * @override 1169 * @override
1181 */ 1170 */
1182 onattach: function() 1171 onattach: function()
1183 { 1172 {
1184 WebInspector.BaseStorageTreeElement.prototype.onattach.call(this); 1173 WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
1185 1174
1186 if (this._resource.type === WebInspector.resourceTypes.Image) { 1175 if (this._resource.type === WebInspector.resourceTypes.Image) {
1187 var previewImage = document.createElement("img"); 1176 var iconElement = document.createElementWithClass("div", "icon");
1188 previewImage.className = "image-resource-icon-preview"; 1177 var previewImage = iconElement.createChild("img", "image-resource-ic on-preview");
1189 this._resource.populateImageSource(previewImage); 1178 this._resource.populateImageSource(previewImage);
1190
1191 var iconElement = document.createElement("div");
1192 iconElement.className = "icon";
1193 iconElement.appendChild(previewImage);
1194 this.listItemElement.replaceChild(iconElement, this.imageElement); 1179 this.listItemElement.replaceChild(iconElement, this.imageElement);
1195 } 1180 }
1196 1181
1197 this._statusElement = document.createElement("div"); 1182 this._statusElement = document.createElementWithClass("div", "status");
1198 this._statusElement.className = "status";
1199 this.listItemElement.insertBefore(this._statusElement, this.titleElement ); 1183 this.listItemElement.insertBefore(this._statusElement, this.titleElement );
1200 1184
1201 this.listItemElement.draggable = true; 1185 this.listItemElement.draggable = true;
1202 this.listItemElement.addEventListener("dragstart", this._ondragstart.bin d(this), false); 1186 this.listItemElement.addEventListener("dragstart", this._ondragstart.bin d(this), false);
1203 this.listItemElement.addEventListener("contextmenu", this._handleContext MenuEvent.bind(this), true); 1187 this.listItemElement.addEventListener("contextmenu", this._handleContext MenuEvent.bind(this), true);
1204 1188
1205 this._updateErrorsAndWarningsBubbles(); 1189 this._updateErrorsAndWarningsBubbles();
1206 }, 1190 },
1207 1191
1208 /** 1192 /**
1209 * @param {!MouseEvent} event 1193 * @param {!MouseEvent} event
1210 * @return {boolean} 1194 * @return {boolean}
1211 */ 1195 */
1212 _ondragstart: function(event) 1196 _ondragstart: function(event)
1213 { 1197 {
1214 event.dataTransfer.setData("text/plain", this._resource.content); 1198 event.dataTransfer.setData("text/plain", this._resource.content);
1215 event.dataTransfer.effectAllowed = "copy"; 1199 event.dataTransfer.effectAllowed = "copy";
1216 return true; 1200 return true;
1217 }, 1201 },
1218 1202
1219 _handleContextMenuEvent: function(event) 1203 _handleContextMenuEvent: function(event)
1220 { 1204 {
1221 var contextMenu = new WebInspector.ContextMenu(event); 1205 var contextMenu = new WebInspector.ContextMenu(event);
1222 contextMenu.appendApplicableItems(this._resource); 1206 contextMenu.appendApplicableItems(this._resource);
1223 contextMenu.show(); 1207 contextMenu.show();
1224 }, 1208 },
1225 1209
1210 /**
1211 * @param {string} x
1212 */
1226 _setBubbleText: function(x) 1213 _setBubbleText: function(x)
1227 { 1214 {
1228 if (!this._bubbleElement) { 1215 if (!this._bubbleElement)
1229 this._bubbleElement = document.createElement("div"); 1216 this._bubbleElement = this._statusElement.createChild("div", "bubble ");
1230 this._bubbleElement.className = "bubble";
1231 this._statusElement.appendChild(this._bubbleElement);
1232 }
1233
1234 this._bubbleElement.textContent = x; 1217 this._bubbleElement.textContent = x;
1235 }, 1218 },
1236 1219
1237 _resetBubble: function() 1220 _resetBubble: function()
1238 { 1221 {
1239 if (this._bubbleElement) { 1222 if (this._bubbleElement) {
1240 this._bubbleElement.textContent = ""; 1223 this._bubbleElement.textContent = "";
1241 this._bubbleElement.classList.remove("warning"); 1224 this._bubbleElement.classList.remove("warning");
1242 this._bubbleElement.classList.remove("error"); 1225 this._bubbleElement.classList.remove("error");
1243 } 1226 }
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
2121 } 2104 }
2122 2105
2123 WebInspector.StorageCategoryView.prototype = { 2106 WebInspector.StorageCategoryView.prototype = {
2124 setText: function(text) 2107 setText: function(text)
2125 { 2108 {
2126 this._emptyView.text = text; 2109 this._emptyView.text = text;
2127 }, 2110 },
2128 2111
2129 __proto__: WebInspector.VBox.prototype 2112 __proto__: WebInspector.VBox.prototype
2130 } 2113 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/common/DOMExtension.js ('k') | Source/devtools/front_end/source_frame/ImageView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698