]>
Commit | Line | Data |
---|---|---|
1 | var global_unread = -1; | |
2 | var hotkey_prefix = false; | |
3 | var hotkey_prefix_pressed = false; | |
4 | var hotkey_actions = {}; | |
5 | var _widescreen_mode = false; | |
6 | var _rpc_seq = 0; | |
7 | var _active_feed_id = 0; | |
8 | var _active_feed_is_cat = false; | |
9 | ||
10 | function next_seq() { | |
11 | _rpc_seq += 1; | |
12 | return _rpc_seq; | |
13 | } | |
14 | ||
15 | function get_seq() { | |
16 | return _rpc_seq; | |
17 | } | |
18 | ||
19 | function activeFeedIsCat() { | |
20 | return _active_feed_is_cat; | |
21 | } | |
22 | ||
23 | function getActiveFeedId() { | |
24 | return _active_feed_id; | |
25 | } | |
26 | ||
27 | function setActiveFeedId(id, is_cat) { | |
28 | hash_set('f', id); | |
29 | hash_set('c', is_cat ? 1 : 0); | |
30 | ||
31 | _active_feed_id = id; | |
32 | _active_feed_is_cat = is_cat; | |
33 | ||
34 | $("headlines-frame").setAttribute("feed-id", id); | |
35 | $("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0); | |
36 | ||
37 | selectFeed(id, is_cat); | |
38 | ||
39 | PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, _active_article_id); | |
40 | } | |
41 | ||
42 | ||
43 | function updateFeedList() { | |
44 | ||
45 | Element.show("feedlistLoading"); | |
46 | ||
47 | resetCounterCache(); | |
48 | ||
49 | if (dijit.byId("feedTree")) { | |
50 | dijit.byId("feedTree").destroyRecursive(); | |
51 | } | |
52 | ||
53 | var store = new dojo.data.ItemFileWriteStore({ | |
54 | url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"}); | |
55 | ||
56 | var treeModel = new fox.FeedStoreModel({ | |
57 | store: store, | |
58 | query: { | |
59 | "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed" | |
60 | }, | |
61 | rootId: "root", | |
62 | rootLabel: "Feeds", | |
63 | childrenAttrs: ["items"] | |
64 | }); | |
65 | ||
66 | var tree = new fox.FeedTree({ | |
67 | model: treeModel, | |
68 | onClick: function (item, node) { | |
69 | var id = String(item.id); | |
70 | var is_cat = id.match("^CAT:"); | |
71 | var feed = id.substr(id.indexOf(":")+1); | |
72 | viewfeed({feed: feed, is_cat: is_cat}); | |
73 | return false; | |
74 | }, | |
75 | openOnClick: false, | |
76 | showRoot: false, | |
77 | persist: true, | |
78 | id: "feedTree", | |
79 | }, "feedTree"); | |
80 | ||
81 | /* var menu = new dijit.Menu({id: 'feedMenu'}); | |
82 | ||
83 | menu.addChild(new dijit.MenuItem({ | |
84 | label: "Simple menu item" | |
85 | })); | |
86 | ||
87 | // menu.bindDomNode(tree.domNode); */ | |
88 | ||
89 | var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) { | |
90 | console.log(dijit.getEnclosingWidget(event.target)); | |
91 | dojo.disconnect(tmph); | |
92 | }); | |
93 | ||
94 | $("feeds-holder").appendChild(tree.domNode); | |
95 | ||
96 | var tmph = dojo.connect(tree, 'onLoad', function() { | |
97 | dojo.disconnect(tmph); | |
98 | Element.hide("feedlistLoading"); | |
99 | ||
100 | try { | |
101 | feedlist_init(); | |
102 | ||
103 | loading_set_progress(25); | |
104 | } catch (e) { | |
105 | exception_error(e); | |
106 | } | |
107 | }); | |
108 | ||
109 | tree.startup(); | |
110 | } | |
111 | ||
112 | function catchupAllFeeds() { | |
113 | ||
114 | var str = __("Mark all articles as read?"); | |
115 | ||
116 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { | |
117 | ||
118 | var query_str = "backend.php?op=feeds&method=catchupAll"; | |
119 | ||
120 | notify_progress("Marking all feeds as read..."); | |
121 | ||
122 | //console.log("catchupAllFeeds Q=" + query_str); | |
123 | ||
124 | new Ajax.Request("backend.php", { | |
125 | parameters: query_str, | |
126 | onComplete: function(transport) { | |
127 | request_counters(true); | |
128 | viewCurrentFeed(); | |
129 | } }); | |
130 | ||
131 | global_unread = 0; | |
132 | updateTitle(""); | |
133 | } | |
134 | } | |
135 | ||
136 | function viewCurrentFeed(method) { | |
137 | console.log("viewCurrentFeed: " + method); | |
138 | ||
139 | if (getActiveFeedId() != undefined) { | |
140 | viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), method: method}); | |
141 | } | |
142 | return false; // block unneeded form submits | |
143 | } | |
144 | ||
145 | function timeout() { | |
146 | if (getInitParam("bw_limit") != "1") { | |
147 | request_counters(); | |
148 | setTimeout(timeout, 60*1000); | |
149 | } | |
150 | } | |
151 | ||
152 | function search() { | |
153 | var query = "backend.php?op=feeds&method=search¶m=" + | |
154 | param_escape(getActiveFeedId() + ":" + activeFeedIsCat()); | |
155 | ||
156 | if (dijit.byId("searchDlg")) | |
157 | dijit.byId("searchDlg").destroyRecursive(); | |
158 | ||
159 | dialog = new dijit.Dialog({ | |
160 | id: "searchDlg", | |
161 | title: __("Search"), | |
162 | style: "width: 600px", | |
163 | execute: function() { | |
164 | if (this.validate()) { | |
165 | _search_query = dojo.objectToQuery(this.attr('value')); | |
166 | this.hide(); | |
167 | viewCurrentFeed(); | |
168 | } | |
169 | }, | |
170 | href: query}); | |
171 | ||
172 | dialog.show(); | |
173 | } | |
174 | ||
175 | function updateTitle() { | |
176 | var tmp = "Tiny Tiny RSS"; | |
177 | ||
178 | if (global_unread > 0) { | |
179 | tmp = "(" + global_unread + ") " + tmp; | |
180 | } | |
181 | ||
182 | if (window.fluid) { | |
183 | if (global_unread > 0) { | |
184 | window.fluid.dockBadge = global_unread; | |
185 | } else { | |
186 | window.fluid.dockBadge = ""; | |
187 | } | |
188 | } | |
189 | ||
190 | document.title = tmp; | |
191 | } | |
192 | ||
193 | function genericSanityCheck() { | |
194 | setCookie("ttrss_test", "TEST"); | |
195 | ||
196 | if (getCookie("ttrss_test") != "TEST") { | |
197 | return fatalError(2); | |
198 | } | |
199 | ||
200 | return true; | |
201 | } | |
202 | ||
203 | ||
204 | function init() { | |
205 | ||
206 | window.onerror = function(message, filename, lineno, colno, error) { | |
207 | report_error(message, filename, lineno, colno, error); | |
208 | }; | |
209 | ||
210 | require(["dojo/_base/kernel", | |
211 | "dojo/ready", | |
212 | "dojo/parser", | |
213 | "dojo/_base/loader", | |
214 | "dojo/_base/html", | |
215 | "dojo/query", | |
216 | "dijit/ProgressBar", | |
217 | "dijit/ColorPalette", | |
218 | "dijit/Dialog", | |
219 | "dijit/form/Button", | |
220 | "dijit/form/ComboButton", | |
221 | "dijit/form/CheckBox", | |
222 | "dijit/form/DropDownButton", | |
223 | "dijit/form/FilteringSelect", | |
224 | "dijit/form/Form", | |
225 | "dijit/form/RadioButton", | |
226 | "dijit/form/Select", | |
227 | "dijit/form/SimpleTextarea", | |
228 | "dijit/form/TextBox", | |
229 | "dijit/form/ComboBox", | |
230 | "dijit/form/ValidationTextBox", | |
231 | "dijit/InlineEditBox", | |
232 | "dijit/layout/AccordionContainer", | |
233 | "dijit/layout/BorderContainer", | |
234 | "dijit/layout/ContentPane", | |
235 | "dijit/layout/TabContainer", | |
236 | "dijit/PopupMenuItem", | |
237 | "dijit/Menu", | |
238 | "dijit/Toolbar", | |
239 | "dijit/Tree", | |
240 | "dijit/tree/dndSource", | |
241 | "dijit/tree/ForestStoreModel", | |
242 | "dojo/data/ItemFileWriteStore", | |
243 | "fox/FeedTree" ], function (dojo, ready, parser) { | |
244 | ||
245 | ready(function() { | |
246 | ||
247 | try { | |
248 | parser.parse(); | |
249 | ||
250 | if (!genericSanityCheck()) | |
251 | return false; | |
252 | ||
253 | loading_set_progress(30); | |
254 | ||
255 | var a = document.createElement('audio'); | |
256 | ||
257 | var hasAudio = !!a.canPlayType; | |
258 | var hasSandbox = "sandbox" in document.createElement("iframe"); | |
259 | var hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')); | |
260 | var clientTzOffset = new Date().getTimezoneOffset() * 60; | |
261 | ||
262 | init_hotkey_actions(); | |
263 | ||
264 | new Ajax.Request("backend.php", { | |
265 | parameters: { | |
266 | op: "rpc", method: "sanityCheck", hasAudio: hasAudio, | |
267 | hasMp3: hasMp3, | |
268 | clientTzOffset: clientTzOffset, | |
269 | hasSandbox: hasSandbox | |
270 | }, | |
271 | onComplete: function (transport) { | |
272 | backend_sanity_check_callback(transport); | |
273 | } | |
274 | }); | |
275 | } catch (e) { | |
276 | exception_error(e); | |
277 | } | |
278 | ||
279 | }); | |
280 | ||
281 | ||
282 | }); | |
283 | } | |
284 | ||
285 | function init_hotkey_actions() { | |
286 | hotkey_actions["next_feed"] = function() { | |
287 | var rv = dijit.byId("feedTree").getNextFeed( | |
288 | getActiveFeedId(), activeFeedIsCat()); | |
289 | ||
290 | if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) | |
291 | }; | |
292 | hotkey_actions["prev_feed"] = function() { | |
293 | var rv = dijit.byId("feedTree").getPreviousFeed( | |
294 | getActiveFeedId(), activeFeedIsCat()); | |
295 | ||
296 | if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) | |
297 | }; | |
298 | hotkey_actions["next_article"] = function() { | |
299 | moveToPost('next'); | |
300 | }; | |
301 | hotkey_actions["prev_article"] = function() { | |
302 | moveToPost('prev'); | |
303 | }; | |
304 | hotkey_actions["next_article_noscroll"] = function() { | |
305 | moveToPost('next', true); | |
306 | }; | |
307 | hotkey_actions["prev_article_noscroll"] = function() { | |
308 | moveToPost('prev', true); | |
309 | }; | |
310 | hotkey_actions["next_article_noexpand"] = function() { | |
311 | moveToPost('next', true, true); | |
312 | }; | |
313 | hotkey_actions["prev_article_noexpand"] = function() { | |
314 | moveToPost('prev', true, true); | |
315 | }; | |
316 | hotkey_actions["collapse_article"] = function() { | |
317 | var id = getActiveArticleId(); | |
318 | var elem = $("CICD-"+id); | |
319 | ||
320 | if (elem) { | |
321 | if (elem.visible()) { | |
322 | cdmCollapseArticle(null, id); | |
323 | } | |
324 | else { | |
325 | cdmExpandArticle(id); | |
326 | } | |
327 | } | |
328 | }; | |
329 | hotkey_actions["toggle_expand"] = function() { | |
330 | var id = getActiveArticleId(); | |
331 | var elem = $("CICD-"+id); | |
332 | ||
333 | if (elem) { | |
334 | if (elem.visible()) { | |
335 | cdmCollapseArticle(null, id, false); | |
336 | } | |
337 | else { | |
338 | cdmExpandArticle(id); | |
339 | } | |
340 | } | |
341 | }; | |
342 | hotkey_actions["search_dialog"] = function() { | |
343 | search(); | |
344 | }; | |
345 | hotkey_actions["toggle_mark"] = function() { | |
346 | selectionToggleMarked(undefined, false, true); | |
347 | }; | |
348 | hotkey_actions["toggle_publ"] = function() { | |
349 | selectionTogglePublished(undefined, false, true); | |
350 | }; | |
351 | hotkey_actions["toggle_unread"] = function() { | |
352 | selectionToggleUnread(undefined, false, true); | |
353 | }; | |
354 | hotkey_actions["edit_tags"] = function() { | |
355 | var id = getActiveArticleId(); | |
356 | if (id) { | |
357 | editArticleTags(id); | |
358 | }; | |
359 | } | |
360 | hotkey_actions["open_in_new_window"] = function() { | |
361 | if (getActiveArticleId()) { | |
362 | openArticleInNewWindow(getActiveArticleId()); | |
363 | return; | |
364 | } | |
365 | }; | |
366 | hotkey_actions["catchup_below"] = function() { | |
367 | catchupRelativeToArticle(1); | |
368 | }; | |
369 | hotkey_actions["catchup_above"] = function() { | |
370 | catchupRelativeToArticle(0); | |
371 | }; | |
372 | hotkey_actions["article_scroll_down"] = function() { | |
373 | var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame"); | |
374 | ||
375 | scrollArticle(40); | |
376 | }; | |
377 | hotkey_actions["article_scroll_up"] = function() { | |
378 | var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame"); | |
379 | ||
380 | scrollArticle(-40); | |
381 | }; | |
382 | hotkey_actions["close_article"] = function() { | |
383 | if (isCdmMode()) { | |
384 | if (!getInitParam("cdm_expanded")) { | |
385 | cdmCollapseArticle(false, getActiveArticleId()); | |
386 | } | |
387 | } else { | |
388 | closeArticlePanel(); | |
389 | } | |
390 | }; | |
391 | hotkey_actions["email_article"] = function() { | |
392 | if (typeof emailArticle != "undefined") { | |
393 | emailArticle(); | |
394 | } else if (typeof mailtoArticle != "undefined") { | |
395 | mailtoArticle(); | |
396 | } else { | |
397 | alert(__("Please enable mail plugin first.")); | |
398 | } | |
399 | }; | |
400 | hotkey_actions["select_all"] = function() { | |
401 | selectArticles('all'); | |
402 | }; | |
403 | hotkey_actions["select_unread"] = function() { | |
404 | selectArticles('unread'); | |
405 | }; | |
406 | hotkey_actions["select_marked"] = function() { | |
407 | selectArticles('marked'); | |
408 | }; | |
409 | hotkey_actions["select_published"] = function() { | |
410 | selectArticles('published'); | |
411 | }; | |
412 | hotkey_actions["select_invert"] = function() { | |
413 | selectArticles('invert'); | |
414 | }; | |
415 | hotkey_actions["select_none"] = function() { | |
416 | selectArticles('none'); | |
417 | }; | |
418 | hotkey_actions["feed_refresh"] = function() { | |
419 | if (getActiveFeedId() != undefined) { | |
420 | viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat()}); | |
421 | return; | |
422 | } | |
423 | }; | |
424 | hotkey_actions["feed_unhide_read"] = function() { | |
425 | toggleDispRead(); | |
426 | }; | |
427 | hotkey_actions["feed_subscribe"] = function() { | |
428 | quickAddFeed(); | |
429 | }; | |
430 | hotkey_actions["feed_debug_update"] = function() { | |
431 | if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) { | |
432 | window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() + | |
433 | "&csrf_token=" + getInitParam("csrf_token")); | |
434 | } else { | |
435 | alert("You can't debug this kind of feed."); | |
436 | } | |
437 | }; | |
438 | ||
439 | hotkey_actions["feed_debug_viewfeed"] = function() { | |
440 | viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), viewfeed_debug: true}); | |
441 | }; | |
442 | ||
443 | hotkey_actions["feed_edit"] = function() { | |
444 | if (activeFeedIsCat()) | |
445 | alert(__("You can't edit this kind of feed.")); | |
446 | else | |
447 | editFeed(getActiveFeedId()); | |
448 | }; | |
449 | hotkey_actions["feed_catchup"] = function() { | |
450 | if (getActiveFeedId() != undefined) { | |
451 | catchupCurrentFeed(); | |
452 | return; | |
453 | } | |
454 | }; | |
455 | hotkey_actions["feed_reverse"] = function() { | |
456 | reverseHeadlineOrder(); | |
457 | }; | |
458 | hotkey_actions["feed_toggle_vgroup"] = function() { | |
459 | var query_str = "?op=rpc&method=togglepref&key=VFEED_GROUP_BY_FEED"; | |
460 | ||
461 | new Ajax.Request("backend.php", { | |
462 | parameters: query_str, | |
463 | onComplete: function(transport) { | |
464 | viewCurrentFeed(); | |
465 | } }); | |
466 | ||
467 | }; | |
468 | hotkey_actions["catchup_all"] = function() { | |
469 | catchupAllFeeds(); | |
470 | }; | |
471 | hotkey_actions["cat_toggle_collapse"] = function() { | |
472 | if (activeFeedIsCat()) { | |
473 | dijit.byId("feedTree").collapseCat(getActiveFeedId()); | |
474 | return; | |
475 | } | |
476 | }; | |
477 | hotkey_actions["goto_all"] = function() { | |
478 | viewfeed({feed: -4}); | |
479 | }; | |
480 | hotkey_actions["goto_fresh"] = function() { | |
481 | viewfeed({feed: -3}); | |
482 | }; | |
483 | hotkey_actions["goto_marked"] = function() { | |
484 | viewfeed({feed: -1}); | |
485 | }; | |
486 | hotkey_actions["goto_published"] = function() { | |
487 | viewfeed({feed: -2}); | |
488 | }; | |
489 | hotkey_actions["goto_tagcloud"] = function() { | |
490 | displayDlg(__("Tag cloud"), "printTagCloud"); | |
491 | }; | |
492 | hotkey_actions["goto_prefs"] = function() { | |
493 | gotoPreferences(); | |
494 | }; | |
495 | hotkey_actions["select_article_cursor"] = function() { | |
496 | var id = getArticleUnderPointer(); | |
497 | if (id) { | |
498 | var row = $("RROW-" + id); | |
499 | ||
500 | if (row) { | |
501 | var cb = dijit.getEnclosingWidget( | |
502 | row.getElementsByClassName("rchk")[0]); | |
503 | ||
504 | if (cb) { | |
505 | cb.attr("checked", !cb.attr("checked")); | |
506 | toggleSelectRowById(cb, "RROW-" + id); | |
507 | return false; | |
508 | } | |
509 | } | |
510 | } | |
511 | }; | |
512 | hotkey_actions["create_label"] = function() { | |
513 | addLabel(); | |
514 | }; | |
515 | hotkey_actions["create_filter"] = function() { | |
516 | quickAddFilter(); | |
517 | }; | |
518 | hotkey_actions["collapse_sidebar"] = function() { | |
519 | collapse_feedlist(); | |
520 | }; | |
521 | hotkey_actions["toggle_embed_original"] = function() { | |
522 | if (typeof embedOriginalArticle != "undefined") { | |
523 | if (getActiveArticleId()) | |
524 | embedOriginalArticle(getActiveArticleId()); | |
525 | } else { | |
526 | alert(__("Please enable embed_original plugin first.")); | |
527 | } | |
528 | }; | |
529 | hotkey_actions["toggle_widescreen"] = function() { | |
530 | if (!isCdmMode()) { | |
531 | _widescreen_mode = !_widescreen_mode; | |
532 | ||
533 | // reset stored sizes because geometry changed | |
534 | setCookie("ttrss_ci_width", 0); | |
535 | setCookie("ttrss_ci_height", 0); | |
536 | ||
537 | switchPanelMode(_widescreen_mode); | |
538 | } else { | |
539 | alert(__("Widescreen is not available in combined mode.")); | |
540 | } | |
541 | }; | |
542 | hotkey_actions["help_dialog"] = function() { | |
543 | helpDialog("main"); | |
544 | }; | |
545 | hotkey_actions["toggle_combined_mode"] = function() { | |
546 | notify_progress("Loading, please wait..."); | |
547 | ||
548 | var value = isCdmMode() ? "false" : "true"; | |
549 | var query = "?op=rpc&method=setpref&key=COMBINED_DISPLAY_MODE&value=" + value; | |
550 | ||
551 | new Ajax.Request("backend.php", { | |
552 | parameters: query, | |
553 | onComplete: function(transport) { | |
554 | setInitParam("combined_display_mode", | |
555 | !getInitParam("combined_display_mode")); | |
556 | ||
557 | closeArticlePanel(); | |
558 | viewCurrentFeed(); | |
559 | ||
560 | } }); | |
561 | }; | |
562 | hotkey_actions["toggle_cdm_expanded"] = function() { | |
563 | notify_progress("Loading, please wait..."); | |
564 | ||
565 | var value = getInitParam("cdm_expanded") ? "false" : "true"; | |
566 | var query = "?op=rpc&method=setpref&key=CDM_EXPANDED&value=" + value; | |
567 | ||
568 | new Ajax.Request("backend.php", { | |
569 | parameters: query, | |
570 | onComplete: function(transport) { | |
571 | setInitParam("cdm_expanded", !getInitParam("cdm_expanded")); | |
572 | viewCurrentFeed(); | |
573 | } }); | |
574 | }; | |
575 | } | |
576 | ||
577 | function init_second_stage() { | |
578 | updateFeedList(); | |
579 | closeArticlePanel(); | |
580 | ||
581 | if (parseInt(getCookie("ttrss_fh_width")) > 0) { | |
582 | dijit.byId("feeds-holder").domNode.setStyle( | |
583 | {width: getCookie("ttrss_fh_width") + "px" }); | |
584 | } | |
585 | ||
586 | dijit.byId("main").resize(); | |
587 | ||
588 | var tmph = dojo.connect(dijit.byId('feeds-holder'), 'resize', | |
589 | function (args) { | |
590 | if (args && args.w >= 0) { | |
591 | setCookie("ttrss_fh_width", args.w, getInitParam("cookie_lifetime")); | |
592 | } | |
593 | }); | |
594 | ||
595 | var tmph = dojo.connect(dijit.byId('content-insert'), 'resize', | |
596 | function (args) { | |
597 | if (args && args.w >= 0 && args.h >= 0) { | |
598 | setCookie("ttrss_ci_width", args.w, getInitParam("cookie_lifetime")); | |
599 | setCookie("ttrss_ci_height", args.h, getInitParam("cookie_lifetime")); | |
600 | } | |
601 | }); | |
602 | ||
603 | delCookie("ttrss_test"); | |
604 | ||
605 | var toolbar = document.forms["main_toolbar_form"]; | |
606 | ||
607 | dijit.getEnclosingWidget(toolbar.view_mode).attr('value', | |
608 | getInitParam("default_view_mode")); | |
609 | ||
610 | dijit.getEnclosingWidget(toolbar.order_by).attr('value', | |
611 | getInitParam("default_view_order_by")); | |
612 | ||
613 | feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1; | |
614 | ||
615 | var hash_feed_id = hash_get('f'); | |
616 | var hash_feed_is_cat = hash_get('c') == "1"; | |
617 | ||
618 | if (hash_feed_id != undefined) { | |
619 | setActiveFeedId(hash_feed_id, hash_feed_is_cat); | |
620 | } | |
621 | ||
622 | loading_set_progress(50); | |
623 | ||
624 | // can't use cache_clear() here because viewfeed might not have initialized yet | |
625 | if ('sessionStorage' in window && window['sessionStorage'] !== null) | |
626 | sessionStorage.clear(); | |
627 | ||
628 | var hotkeys = getInitParam("hotkeys"); | |
629 | var tmp = []; | |
630 | ||
631 | for (sequence in hotkeys[1]) { | |
632 | filtered = sequence.replace(/\|.*$/, ""); | |
633 | tmp[filtered] = hotkeys[1][sequence]; | |
634 | } | |
635 | ||
636 | hotkeys[1] = tmp; | |
637 | setInitParam("hotkeys", hotkeys); | |
638 | ||
639 | _widescreen_mode = getInitParam("widescreen"); | |
640 | switchPanelMode(_widescreen_mode); | |
641 | ||
642 | console.log("second stage ok"); | |
643 | ||
644 | if (getInitParam("simple_update")) { | |
645 | console.log("scheduling simple feed updater..."); | |
646 | window.setTimeout(update_random_feed, 30*1000); | |
647 | } | |
648 | } | |
649 | ||
650 | function quickMenuGo(opid) { | |
651 | switch (opid) { | |
652 | case "qmcPrefs": | |
653 | gotoPreferences(); | |
654 | break; | |
655 | case "qmcLogout": | |
656 | gotoLogout(); | |
657 | break; | |
658 | case "qmcTagCloud": | |
659 | displayDlg(__("Tag cloud"), "printTagCloud"); | |
660 | break; | |
661 | case "qmcSearch": | |
662 | search(); | |
663 | break; | |
664 | case "qmcAddFeed": | |
665 | quickAddFeed(); | |
666 | break; | |
667 | case "qmcDigest": | |
668 | window.location.href = "backend.php?op=digest"; | |
669 | break; | |
670 | case "qmcEditFeed": | |
671 | if (activeFeedIsCat()) | |
672 | alert(__("You can't edit this kind of feed.")); | |
673 | else | |
674 | editFeed(getActiveFeedId()); | |
675 | break; | |
676 | case "qmcRemoveFeed": | |
677 | var actid = getActiveFeedId(); | |
678 | ||
679 | if (activeFeedIsCat()) { | |
680 | alert(__("You can't unsubscribe from the category.")); | |
681 | return; | |
682 | } | |
683 | ||
684 | if (!actid) { | |
685 | alert(__("Please select some feed first.")); | |
686 | return; | |
687 | } | |
688 | ||
689 | var fn = getFeedName(actid); | |
690 | ||
691 | var pr = __("Unsubscribe from %s?").replace("%s", fn); | |
692 | ||
693 | if (confirm(pr)) { | |
694 | unsubscribeFeed(actid); | |
695 | } | |
696 | break; | |
697 | case "qmcCatchupAll": | |
698 | catchupAllFeeds(); | |
699 | break; | |
700 | case "qmcShowOnlyUnread": | |
701 | toggleDispRead(); | |
702 | break; | |
703 | case "qmcAddFilter": | |
704 | quickAddFilter(); | |
705 | break; | |
706 | case "qmcAddLabel": | |
707 | addLabel(); | |
708 | break; | |
709 | case "qmcRescoreFeed": | |
710 | rescoreCurrentFeed(); | |
711 | break; | |
712 | case "qmcToggleWidescreen": | |
713 | if (!isCdmMode()) { | |
714 | _widescreen_mode = !_widescreen_mode; | |
715 | ||
716 | // reset stored sizes because geometry changed | |
717 | setCookie("ttrss_ci_width", 0); | |
718 | setCookie("ttrss_ci_height", 0); | |
719 | ||
720 | switchPanelMode(_widescreen_mode); | |
721 | } else { | |
722 | alert(__("Widescreen is not available in combined mode.")); | |
723 | } | |
724 | break; | |
725 | case "qmcHKhelp": | |
726 | helpDialog("main"); | |
727 | break; | |
728 | default: | |
729 | console.log("quickMenuGo: unknown action: " + opid); | |
730 | } | |
731 | } | |
732 | ||
733 | function toggleDispRead() { | |
734 | ||
735 | var hide = !(getInitParam("hide_read_feeds") == "1"); | |
736 | ||
737 | hideOrShowFeeds(hide); | |
738 | ||
739 | var query = "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" + | |
740 | param_escape(hide); | |
741 | ||
742 | setInitParam("hide_read_feeds", hide); | |
743 | ||
744 | new Ajax.Request("backend.php", { | |
745 | parameters: query, | |
746 | onComplete: function(transport) { | |
747 | } }); | |
748 | ||
749 | } | |
750 | ||
751 | function parse_runtime_info(data) { | |
752 | ||
753 | //console.log("parsing runtime info..."); | |
754 | ||
755 | for (k in data) { | |
756 | var v = data[k]; | |
757 | ||
758 | // console.log("RI: " + k + " => " + v); | |
759 | ||
760 | if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) { | |
761 | if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) { | |
762 | window.location.reload(); | |
763 | } | |
764 | } | |
765 | ||
766 | if (k == "daemon_is_running" && v != 1) { | |
767 | notify_error("<span onclick=\"explainError(1)\">Update daemon is not running.</span>", true); | |
768 | return; | |
769 | } | |
770 | ||
771 | if (k == "update_result") { | |
772 | var updatesIcon = dijit.byId("updatesIcon").domNode; | |
773 | ||
774 | if (v) { | |
775 | Element.show(updatesIcon); | |
776 | } else { | |
777 | Element.hide(updatesIcon); | |
778 | } | |
779 | } | |
780 | ||
781 | if (k == "daemon_stamp_ok" && v != 1) { | |
782 | notify_error("<span onclick=\"explainError(3)\">Update daemon is not updating feeds.</span>", true); | |
783 | return; | |
784 | } | |
785 | ||
786 | if (k == "max_feed_id" || k == "num_feeds") { | |
787 | if (init_params[k] != v) { | |
788 | console.log("feed count changed, need to reload feedlist."); | |
789 | updateFeedList(); | |
790 | } | |
791 | } | |
792 | ||
793 | init_params[k] = v; | |
794 | notify(''); | |
795 | } | |
796 | ||
797 | PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data); | |
798 | } | |
799 | ||
800 | function collapse_feedlist() { | |
801 | Element.toggle("feeds-holder"); | |
802 | ||
803 | var splitter = $("feeds-holder_splitter"); | |
804 | ||
805 | Element.visible("feeds-holder") ? splitter.show() : splitter.hide(); | |
806 | ||
807 | dijit.byId("main").resize(); | |
808 | } | |
809 | ||
810 | function viewModeChanged() { | |
811 | cache_clear(); | |
812 | return viewCurrentFeed(''); | |
813 | } | |
814 | ||
815 | function rescoreCurrentFeed() { | |
816 | ||
817 | var actid = getActiveFeedId(); | |
818 | ||
819 | if (activeFeedIsCat() || actid < 0) { | |
820 | alert(__("You can't rescore this kind of feed.")); | |
821 | return; | |
822 | } | |
823 | ||
824 | if (!actid) { | |
825 | alert(__("Please select some feed first.")); | |
826 | return; | |
827 | } | |
828 | ||
829 | var fn = getFeedName(actid); | |
830 | var pr = __("Rescore articles in %s?").replace("%s", fn); | |
831 | ||
832 | if (confirm(pr)) { | |
833 | notify_progress("Rescoring articles..."); | |
834 | ||
835 | var query = "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid; | |
836 | ||
837 | new Ajax.Request("backend.php", { | |
838 | parameters: query, | |
839 | onComplete: function(transport) { | |
840 | viewCurrentFeed(); | |
841 | } }); | |
842 | } | |
843 | } | |
844 | ||
845 | function hotkey_handler(e) { | |
846 | ||
847 | if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return; | |
848 | ||
849 | var keycode = false; | |
850 | var shift_key = false; | |
851 | var ctrl_key = false; | |
852 | var alt_key = false; | |
853 | var meta_key = false; | |
854 | ||
855 | var cmdline = $('cmdline'); | |
856 | ||
857 | shift_key = e.shiftKey; | |
858 | ctrl_key = e.ctrlKey; | |
859 | alt_key = e.altKey; | |
860 | meta_key = e.metaKey; | |
861 | ||
862 | if (window.event) { | |
863 | keycode = window.event.keyCode; | |
864 | } else if (e) { | |
865 | keycode = e.which; | |
866 | } | |
867 | ||
868 | var keychar = String.fromCharCode(keycode); | |
869 | ||
870 | if (keycode == 27) { // escape | |
871 | hotkey_prefix = false; | |
872 | } | |
873 | ||
874 | if (keycode == 16) return; // ignore lone shift | |
875 | if (keycode == 17) return; // ignore lone ctrl | |
876 | ||
877 | keychar = keychar.toLowerCase(); | |
878 | ||
879 | var hotkeys = getInitParam("hotkeys"); | |
880 | ||
881 | if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) { | |
882 | ||
883 | var date = new Date(); | |
884 | var ts = Math.round(date.getTime() / 1000); | |
885 | ||
886 | hotkey_prefix = keychar; | |
887 | hotkey_prefix_pressed = ts; | |
888 | ||
889 | cmdline.innerHTML = keychar; | |
890 | Element.show(cmdline); | |
891 | ||
892 | return true; | |
893 | } | |
894 | ||
895 | Element.hide(cmdline); | |
896 | ||
897 | var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")"; | |
898 | ||
899 | // ensure ^*char notation | |
900 | if (shift_key) hotkey = "*" + hotkey; | |
901 | if (ctrl_key) hotkey = "^" + hotkey; | |
902 | if (alt_key) hotkey = "+" + hotkey; | |
903 | if (meta_key) hotkey = "%" + hotkey; | |
904 | ||
905 | hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey; | |
906 | hotkey_prefix = false; | |
907 | ||
908 | var hotkey_action = false; | |
909 | var hotkeys = getInitParam("hotkeys"); | |
910 | ||
911 | for (sequence in hotkeys[1]) { | |
912 | if (sequence == hotkey) { | |
913 | hotkey_action = hotkeys[1][sequence]; | |
914 | break; | |
915 | } | |
916 | } | |
917 | ||
918 | var action = hotkey_actions[hotkey_action]; | |
919 | ||
920 | if (action != null) { | |
921 | action(); | |
922 | return false; | |
923 | } | |
924 | } | |
925 | ||
926 | function inPreferences() { | |
927 | return false; | |
928 | } | |
929 | ||
930 | function reverseHeadlineOrder() { | |
931 | ||
932 | var toolbar = document.forms["main_toolbar_form"]; | |
933 | var order_by = dijit.getEnclosingWidget(toolbar.order_by); | |
934 | ||
935 | var value = order_by.attr('value'); | |
936 | ||
937 | if (value == "date_reverse") | |
938 | value = "default"; | |
939 | else | |
940 | value = "date_reverse"; | |
941 | ||
942 | order_by.attr('value', value); | |
943 | ||
944 | viewCurrentFeed(); | |
945 | ||
946 | } | |
947 | ||
948 | function handle_rpc_json(transport, scheduled_call) { | |
949 | ||
950 | var netalert_dijit = dijit.byId("net-alert"); | |
951 | var netalert = false; | |
952 | ||
953 | if (netalert_dijit) netalert = netalert_dijit.domNode; | |
954 | ||
955 | try { | |
956 | var reply = JSON.parse(transport.responseText); | |
957 | ||
958 | if (reply) { | |
959 | ||
960 | var error = reply['error']; | |
961 | ||
962 | if (error) { | |
963 | var code = error['code']; | |
964 | var msg = error['msg']; | |
965 | ||
966 | console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg); | |
967 | ||
968 | if (code != 0) { | |
969 | fatalError(code, msg); | |
970 | return false; | |
971 | } | |
972 | } | |
973 | ||
974 | var seq = reply['seq']; | |
975 | ||
976 | if (seq) { | |
977 | if (get_seq() != seq) { | |
978 | console.log("[handle_rpc_json] sequence mismatch: " + seq + | |
979 | " (want: " + get_seq() + ")"); | |
980 | return true; | |
981 | } | |
982 | } | |
983 | ||
984 | var message = reply['message']; | |
985 | ||
986 | if (message) { | |
987 | if (message == "UPDATE_COUNTERS") { | |
988 | console.log("need to refresh counters..."); | |
989 | setInitParam("last_article_id", -1); | |
990 | request_counters(true); | |
991 | } | |
992 | } | |
993 | ||
994 | var counters = reply['counters']; | |
995 | ||
996 | if (counters) | |
997 | parse_counters(counters, scheduled_call); | |
998 | ||
999 | var runtime_info = reply['runtime-info']; | |
1000 | ||
1001 | if (runtime_info) | |
1002 | parse_runtime_info(runtime_info); | |
1003 | ||
1004 | if (netalert) netalert.hide(); | |
1005 | ||
1006 | } else { | |
1007 | if (netalert) | |
1008 | netalert.show(); | |
1009 | else | |
1010 | notify_error("Communication problem with server."); | |
1011 | } | |
1012 | ||
1013 | } catch (e) { | |
1014 | if (netalert) | |
1015 | netalert.show(); | |
1016 | else | |
1017 | notify_error("Communication problem with server."); | |
1018 | ||
1019 | console.error(e); | |
1020 | } | |
1021 | ||
1022 | return true; | |
1023 | } | |
1024 | ||
1025 | function switchPanelMode(wide) { | |
1026 | if (isCdmMode()) return; | |
1027 | ||
1028 | article_id = getActiveArticleId(); | |
1029 | ||
1030 | if (wide) { | |
1031 | dijit.byId("headlines-wrap-inner").attr("design", 'sidebar'); | |
1032 | dijit.byId("content-insert").attr("region", "trailing"); | |
1033 | ||
1034 | dijit.byId("content-insert").domNode.setStyle({width: '50%', | |
1035 | height: 'auto', | |
1036 | borderTopWidth: '0px' }); | |
1037 | ||
1038 | if (parseInt(getCookie("ttrss_ci_width")) > 0) { | |
1039 | dijit.byId("content-insert").domNode.setStyle( | |
1040 | {width: getCookie("ttrss_ci_width") + "px" }); | |
1041 | } | |
1042 | ||
1043 | $("headlines-frame").setStyle({ borderBottomWidth: '0px' }); | |
1044 | $("headlines-frame").addClassName("wide"); | |
1045 | ||
1046 | } else { | |
1047 | ||
1048 | dijit.byId("content-insert").attr("region", "bottom"); | |
1049 | ||
1050 | dijit.byId("content-insert").domNode.setStyle({width: 'auto', | |
1051 | height: '50%', | |
1052 | borderTopWidth: '0px'}); | |
1053 | ||
1054 | if (parseInt(getCookie("ttrss_ci_height")) > 0) { | |
1055 | dijit.byId("content-insert").domNode.setStyle( | |
1056 | {height: getCookie("ttrss_ci_height") + "px" }); | |
1057 | } | |
1058 | ||
1059 | $("headlines-frame").setStyle({ borderBottomWidth: '1px' }); | |
1060 | $("headlines-frame").removeClassName("wide"); | |
1061 | ||
1062 | } | |
1063 | ||
1064 | closeArticlePanel(); | |
1065 | ||
1066 | if (article_id) view(article_id); | |
1067 | ||
1068 | new Ajax.Request("backend.php", { | |
1069 | parameters: "op=rpc&method=setpanelmode&wide=" + (wide ? 1 : 0), | |
1070 | onComplete: function(transport) { | |
1071 | console.log(transport.responseText); | |
1072 | } }); | |
1073 | } | |
1074 | ||
1075 | function update_random_feed() { | |
1076 | console.log("in update_random_feed"); | |
1077 | ||
1078 | new Ajax.Request("backend.php", { | |
1079 | parameters: "op=rpc&method=updateRandomFeed", | |
1080 | onComplete: function(transport) { | |
1081 | handle_rpc_json(transport, true); | |
1082 | window.setTimeout(update_random_feed, 30*1000); | |
1083 | } }); | |
1084 | } | |
1085 | ||
1086 | function hash_get(key) { | |
1087 | kv = window.location.hash.substring(1).toQueryParams(); | |
1088 | return kv[key]; | |
1089 | } | |
1090 | function hash_set(key, value) { | |
1091 | kv = window.location.hash.substring(1).toQueryParams(); | |
1092 | kv[key] = value; | |
1093 | window.location.hash = $H(kv).toQueryString(); | |
1094 | } |