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