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