| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 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 cr.define('pp', function() { |
| 7 // require cr.ui.define |
| 8 // require cr.ui.limitInputWidth. |
| 9 // require cr.ui.contextMenuHandler |
| 10 const List = cr.ui.List; |
| 11 const ListItem = cr.ui.ListItem; |
| 12 |
| 13 var listLookup = {}; |
| 14 |
| 15 /** |
| 16 * Removes all children and appends a new child. |
| 17 * @param {!Node} parent The node to remove all children from. |
| 18 * @param {!Node} newChild The new child to append. |
| 19 */ |
| 20 function replaceAllChildren(parent, newChild) { |
| 21 var n; |
| 22 while ((n = parent.lastChild)) { |
| 23 parent.removeChild(n); |
| 24 } |
| 25 parent.appendChild(newChild); |
| 26 } |
| 27 |
| 28 /** |
| 29 * Creates a new print preview list. |
| 30 * @param {Object=} opt_propertyBag Optional properties. |
| 31 * @constructor |
| 32 * @extends {HTMLButtonElement} |
| 33 */ |
| 34 var PreviewList = cr.ui.define('list'); |
| 35 |
| 36 PreviewList.prototype = { |
| 37 __proto__: List.prototype, |
| 38 set items(pages) { |
| 39 this.pages = pages; |
| 40 pages.forEach(function(page) { |
| 41 var li = createListItem(page); |
| 42 this.add(li); |
| 43 }, this); |
| 44 }, |
| 45 |
| 46 decorate: function() { |
| 47 List.prototype.decorate.call(this); |
| 48 this.addEventListener('click', this.handleClick_); |
| 49 }, |
| 50 |
| 51 createItem: function(page) { |
| 52 return createListItem(page); |
| 53 }, |
| 54 |
| 55 |
| 56 /** |
| 57 * Handles the clicks on the list so that we can check if the user clicked |
| 58 * on a link or a folder. |
| 59 * @private |
| 60 * @param {Event} e The click event object. |
| 61 */ |
| 62 handleClick_: function(e) { |
| 63 var self = this; |
| 64 var event = new cr.Event('pageClicked', true, false); |
| 65 var el = e.target; |
| 66 while (el.parentNode != this) { |
| 67 el = el.parentNode; |
| 68 } |
| 69 event.page = el.page; |
| 70 event.originalEvent = e; |
| 71 self.dispatchEvent(event); |
| 72 }, |
| 73 |
| 74 }; |
| 75 |
| 76 /** |
| 77 * The contextMenu property. |
| 78 * @type {cr.ui.Menu} |
| 79 */ |
| 80 cr.ui.contextMenuHandler.addContextMenuProperty(PreviewList); |
| 81 |
| 82 /** |
| 83 * Creates a new bookmark list item. |
| 84 * @param {Object=} opt_propertyBag Optional properties. |
| 85 * @constructor |
| 86 * @extends {cr.ui.ListItem} |
| 87 */ |
| 88 var PreviewListItem = cr.ui.define('li'); |
| 89 |
| 90 PreviewListItem.prototype = { |
| 91 __proto__: ListItem.prototype, |
| 92 }; |
| 93 |
| 94 function createListItem(page) { |
| 95 var li = listItemPromo.cloneNode(true); |
| 96 PreviewListItem.decorate(li); |
| 97 updateListItem(li, page); |
| 98 li.page = page; |
| 99 return li; |
| 100 } |
| 101 |
| 102 function updateListItem(el, page) { |
| 103 if (page.thumb) { |
| 104 var holder = el.getElementsByClassName("placeholder")[0]; |
| 105 var img = cr.doc.createElement("img"); |
| 106 img.className = "preview-image"; |
| 107 img.src = page.thumb; |
| 108 holder.appendChild(img); |
| 109 } |
| 110 el.page = page; |
| 111 } |
| 112 |
| 113 var listItemPromo = (function() { |
| 114 var div = cr.doc.createElement('div'); |
| 115 div.innerHTML = '<div class="preview-holder"><div class="placeholder"></div>
</div>'; |
| 116 return div; |
| 117 })(); |
| 118 |
| 119 return { |
| 120 createListItem: createListItem, |
| 121 PreviewList: PreviewList, |
| 122 listLookup: listLookup |
| 123 }; |
| 124 }); |
| OLD | NEW |