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

Side by Side Diff: ui/webui/resources/js/cr/link_controller.js

Issue 2603443002: Clang format JS: Disallow single line functions, conditionals, loops, and switch statements (Closed)
Patch Set: update c/b/r/ as well Created 3 years, 12 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview This file provides a class that can be used to open URLs based 6 * @fileoverview This file provides a class that can be used to open URLs based
7 * on user interactions. It ensures a consistent behavior when it comes to 7 * on user interactions. It ensures a consistent behavior when it comes to
8 * holding down Ctrl and Shift while clicking or activating the a link. 8 * holding down Ctrl and Shift while clicking or activating the a link.
9 * 9 *
10 * This depends on the {@code chrome.windows} and {@code chrome.tabs} 10 * This depends on the {@code chrome.windows} and {@code chrome.tabs}
(...skipping 28 matching lines...) Expand all
39 * Opens the link in a new window. 39 * Opens the link in a new window.
40 * 40 *
41 * On Mac, uses Command instead of Ctrl. 41 * On Mac, uses Command instead of Ctrl.
42 * For keyboard support you need to use keydown. 42 * For keyboard support you need to use keydown.
43 * 43 *
44 * @param {!LoadTimeData} localStrings The local strings object which is used 44 * @param {!LoadTimeData} localStrings The local strings object which is used
45 * to localize the warning prompt in case the user tries to open a lot of 45 * to localize the warning prompt in case the user tries to open a lot of
46 * links. 46 * links.
47 * @constructor 47 * @constructor
48 */ 48 */
49 function LinkController(localStrings) { this.localStrings_ = localStrings; } 49 function LinkController(localStrings) {
50 this.localStrings_ = localStrings;
51 }
50 52
51 LinkController.prototype = { 53 LinkController.prototype = {
52 /** 54 /**
53 * The number of links that can be opened before showing a warning confirm 55 * The number of links that can be opened before showing a warning confirm
54 * message. 56 * message.
55 */ 57 */
56 warningLimit: 15, 58 warningLimit: 15,
57 59
58 /** 60 /**
59 * The DOM window that we want to open links into in case we are opening 61 * The DOM window that we want to open links into in case we are opening
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 this.openUrls([url], kind); 94 this.openUrls([url], kind);
93 } 95 }
94 }, 96 },
95 97
96 98
97 /** 99 /**
98 * Opens a URL in a new tab, window or incognito window. 100 * Opens a URL in a new tab, window or incognito window.
99 * @param {string} url The URL to open. 101 * @param {string} url The URL to open.
100 * @param {cr.LinkKind} kind The kind of open we want to do. 102 * @param {cr.LinkKind} kind The kind of open we want to do.
101 */ 103 */
102 openUrl: function(url, kind) { this.openUrls([url], kind); }, 104 openUrl: function(url, kind) {
105 this.openUrls([url], kind);
106 },
103 107
104 /** 108 /**
105 * Opens URLs in new tab, window or incognito mode. 109 * Opens URLs in new tab, window or incognito mode.
106 * @param {!Array<string>} urls The URLs to open. 110 * @param {!Array<string>} urls The URLs to open.
107 * @param {cr.LinkKind} kind The kind of open we want to do. 111 * @param {cr.LinkKind} kind The kind of open we want to do.
108 */ 112 */
109 openUrls: function(urls, kind) { 113 openUrls: function(urls, kind) {
110 if (urls.length < 1) 114 if (urls.length < 1)
111 return; 115 return;
112 116
113 if (urls.length > this.warningLimit) { 117 if (urls.length > this.warningLimit) {
114 if (!this.window.confirm(this.getWarningMessage(urls.length))) 118 if (!this.window.confirm(this.getWarningMessage(urls.length)))
115 return; 119 return;
116 } 120 }
117 121
118 // Fix '#124' URLs since opening those in a new window does not work. We 122 // Fix '#124' URLs since opening those in a new window does not work. We
119 // prepend the base URL when we encounter those. 123 // prepend the base URL when we encounter those.
120 var base = this.window.location.href.split('#')[0]; 124 var base = this.window.location.href.split('#')[0];
121 urls = 125 urls = urls.map(function(url) {
122 urls.map(function(url) { return url[0] == '#' ? base + url : url; }); 126 return url[0] == '#' ? base + url : url;
127 });
123 128
124 var incognito = kind == cr.LinkKind.INCOGNITO; 129 var incognito = kind == cr.LinkKind.INCOGNITO;
125 if (kind == cr.LinkKind.WINDOW || incognito) { 130 if (kind == cr.LinkKind.WINDOW || incognito) {
126 chrome.windows.create({url: urls, incognito: incognito}); 131 chrome.windows.create({url: urls, incognito: incognito});
127 } else if ( 132 } else if (
128 kind == cr.LinkKind.FOREGROUND_TAB || 133 kind == cr.LinkKind.FOREGROUND_TAB ||
129 kind == cr.LinkKind.BACKGROUND_TAB) { 134 kind == cr.LinkKind.BACKGROUND_TAB) {
130 urls.forEach(function(url, i) { 135 urls.forEach(function(url, i) {
131 chrome.tabs.create( 136 chrome.tabs.create(
132 {url: url, selected: kind == cr.LinkKind.FOREGROUND_TAB && !i}); 137 {url: url, selected: kind == cr.LinkKind.FOREGROUND_TAB && !i});
133 }); 138 });
134 } else { 139 } else {
135 this.window.location.href = urls[0]; 140 this.window.location.href = urls[0];
136 } 141 }
137 } 142 }
138 }; 143 };
139 144
140 // Export 145 // Export
141 return { 146 return {
142 LinkController: LinkController, 147 LinkController: LinkController,
143 }; 148 };
144 }); 149 });
OLDNEW
« no previous file with comments | « ui/webui/resources/js/cr/event_target.js ('k') | ui/webui/resources/js/cr/ui/array_data_model.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698