| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * Helper utility functions for manipulating the element classes. | |
| 7 */ | |
| 8 var ClassUtil = {}; | |
| 9 | |
| 10 /** | |
| 11 * Finds an element based on its class name. | |
| 12 **/ | |
| 13 ClassUtil.FindElementByClassName = function(className) { | |
| 14 var items = document.getElementsByClassName(className); | |
| 15 if (items.length != 1) { | |
| 16 throw "Found " + items.length + " item(s) by class " + className; | |
| 17 } | |
| 18 return items[0].id; | |
| 19 }; | |
| 20 | |
| 21 /** | |
| 22 * Resets class type of all items except one. | |
| 23 **/ | |
| 24 ClassUtil.ResetClass = function(className, specialId, specialClass) { | |
| 25 var items = document.getElementsByClassName(className); | |
| 26 var fail = function(msg) { | |
| 27 throw "Internal error in ResetClass(" + className + ", " + specialId + | |
| 28 ", " + specialClass + ")\nEnumerated " + items.length + " items.\n" + | |
| 29 msg; | |
| 30 } | |
| 31 var found; | |
| 32 for (var i in items) { | |
| 33 var item = items[i]; | |
| 34 if (item.id == specialId) { | |
| 35 item.className = className + " " + specialClass; | |
| 36 if (found) { | |
| 37 fail("Found 2 times"); | |
| 38 } | |
| 39 found = i; | |
| 40 } else { | |
| 41 item.className = className; | |
| 42 } | |
| 43 } | |
| 44 if (!found) { | |
| 45 fail("Found 0 time"); | |
| 46 } | |
| 47 }; | |
| OLD | NEW |