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