]>
git.wh0rd.org - tt-rss.git/blob - js/functions.js
1 var notify_silent
= false ;
2 var loading_progress
= 0 ;
3 var sanity_check_done
= false ;
5 var _label_base_index
= - 1024 ;
7 Ajax
. Base
. prototype . initialize
= Ajax
. Base
. prototype . initialize
. wrap (
8 function ( callOriginal
, options
) {
10 if ( getInitParam ( "csrf_token" ) != undefined ) {
11 Object
. extend ( options
, options
|| { });
13 if ( Object
. isString ( options
. parameters
))
14 options
. parameters
= options
. parameters
. toQueryParams ();
15 else if ( Object
. isHash ( options
. parameters
))
16 options
. parameters
= options
. parameters
. toObject ();
18 options
. parameters
[ "csrf_token" ] = getInitParam ( "csrf_token" );
21 return callOriginal ( options
);
25 /* add method to remove element from array */
27 Array
. prototype . remove = function ( s
) {
28 for ( var i
= 0 ; i
< this . length
; i
++) {
29 if ( s
== this [ i
]) this . splice ( i
, 1 );
33 /* create console.log if it doesn't exist */
35 if (! window
. console
) console
= {};
36 console
. log
= console
. log
|| function ( msg
) { };
37 console
. warn
= console
. warn
|| function ( msg
) { };
38 console
. error
= console
. error
|| function ( msg
) { };
40 function exception_error ( location
, e
, ext_info
) {
41 var msg
= format_exception_error ( location
, e
);
43 if (! ext_info
) ext_info
= false ;
48 if ( ext_info
. responseText
) {
49 ext_info
= ext_info
. responseText
;
53 var content
= "<div class= \" fatalError \" >" +
54 "<pre>" + msg
+ "</pre>" ;
56 content
+= "<form name= \" exceptionForm \" id= \" exceptionForm \" target= \" _blank \" " +
57 "action= \" http://tt-rss.org/report.php \" method= \" POST \" >" ;
59 content
+= "<textarea style= \" display : none \" name= \" message \" >" + msg
+ "</textarea>" ;
60 content
+= "<textarea style= \" display : none \" name= \" params \" >N/A</textarea>" ;
63 content
+= "<div><b>Additional information:</b></div>" +
64 "<textarea name= \" xinfo \" readonly= \" 1 \" >" + ext_info
+ "</textarea>" ;
67 content
+= "<div><b>Stack trace:</b></div>" +
68 "<textarea name= \" stack \" readonly= \" 1 \" >" + e
. stack
+ "</textarea>" ;
74 content
+= "<div class='dlgButtons'>" ;
76 content
+= "<button dojoType= \" dijit.form.Button \" " +
77 "onclick= \" dijit.byId('exceptionDlg').report() \" >" +
78 __ ( 'Report to tt-rss.org' ) + "</button> " ;
79 content
+= "<button dojoType= \" dijit.form.Button \" " +
80 "onclick= \" dijit.byId('exceptionDlg').hide() \" >" +
81 __ ( 'Close' ) + "</button>" ;
84 if ( dijit
. byId ( "exceptionDlg" ))
85 dijit
. byId ( "exceptionDlg" ). destroyRecursive ();
87 var dialog
= new dijit
. Dialog ({
89 title
: "Unhandled exception" ,
90 style
: "width: 600px" ,
92 if ( confirm ( __ ( "Are you sure to report this exception to tt-rss.org? The report will include your browser information. Your IP would be saved in the database." ))) {
94 document
. forms
[ 'exceptionForm' ]. params
. value
= $ H ({
95 browserName
: navigator
. appName
,
96 browserVersion
: navigator
. appVersion
,
97 browserPlatform
: navigator
. platform
,
98 browserCookies
: navigator
. cookieEnabled
,
101 document
. forms
[ 'exceptionForm' ]. submit ();
115 function format_exception_error ( location
, e
) {
119 var base_fname
= e
. fileName
. substring ( e
. fileName
. lastIndexOf ( "/" ) + 1 );
121 msg
= "Exception: " + e
. name
+ ", " + e
. message
+
122 " \n Function: " + location
+ "()" +
123 " \n Location: " + base_fname
+ ":" + e
. lineNumber
;
125 } else if ( e
. description
) {
126 msg
= "Exception: " + e
. description
+ " \n Function: " + location
+ "()" ;
128 msg
= "Exception: " + e
+ " \n Function: " + location
+ "()" ;
131 console
. error ( "EXCEPTION: " + msg
);
136 function param_escape ( arg
) {
137 if ( typeof encodeURIComponent
!= 'undefined' )
138 return encodeURIComponent ( arg
);
143 function param_unescape ( arg
) {
144 if ( typeof decodeURIComponent
!= 'undefined' )
145 return decodeURIComponent ( arg
);
147 return unescape ( arg
);
150 var notify_hide_timerid
= false ;
152 function hide_notify () {
155 n
. style
. display
= "none" ;
159 function notify_silent_next () {
160 notify_silent
= true ;
163 function notify_real ( msg
, no_hide
, n_type
) {
166 notify_silent
= false ;
171 var nb
= $( "notify_body" );
173 if (! n
|| ! nb
) return ;
175 if ( notify_hide_timerid
) {
176 window
. clearTimeout ( notify_hide_timerid
);
180 if ( n
. style
. display
== "block" ) {
181 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 0 );
185 n
. style
. display
= "block" ;
200 n
. className
= "notify" ;
201 } else if ( n_type
== 2 ) {
202 n
. className
= "notify progress" ;
203 msg
= "<img src='images/indicator_white.gif'> " + msg
;
204 } else if ( n_type
== 3 ) {
205 n
. className
= "notify error" ;
206 msg
= "<img src='images/sign_excl.svg'> " + msg
;
207 } else if ( n_type
== 4 ) {
208 n
. className
= "notify info" ;
209 msg
= "<img src='images/sign_info.svg'> " + msg
;
213 msg
+= " <span>(<a href='#' onclick= \" notify('') \" >" +
214 __ ( "close" ) + "</a>)</span>" ;
218 // msg = "<img src='images/live_com_loading.gif'> " + msg;
223 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 3000 );
227 function notify ( msg
, no_hide
) {
228 notify_real ( msg
, no_hide
, 1 );
231 function notify_progress ( msg
, no_hide
) {
232 notify_real ( msg
, no_hide
, 2 );
235 function notify_error ( msg
, no_hide
) {
236 notify_real ( msg
, no_hide
, 3 );
240 function notify_info ( msg
, no_hide
) {
241 notify_real ( msg
, no_hide
, 4 );
244 function setCookie ( name
, value
, lifetime
, path
, domain
, secure
) {
250 d
. setTime ( d
. getTime () + ( lifetime
* 1000 ));
253 console
. log ( "setCookie: " + name
+ " => " + value
+ ": " + d
);
255 int_setCookie ( name
, value
, d
, path
, domain
, secure
);
259 function int_setCookie ( name
, value
, expires
, path
, domain
, secure
) {
260 document
. cookie
= name
+ "=" + escape ( value
) +
261 (( expires
) ? "; expires=" + expires
. toGMTString () : "" ) +
262 (( path
) ? "; path=" + path
: "" ) +
263 (( domain
) ? "; domain=" + domain
: "" ) +
264 (( secure
) ? "; secure" : "" );
267 function delCookie ( name
, path
, domain
) {
268 if ( getCookie ( name
)) {
269 document
. cookie
= name
+ "=" +
270 (( path
) ? ";path=" + path
: "" ) +
271 (( domain
) ? ";domain=" + domain
: "" ) +
272 ";expires=Thu, 01-Jan-1970 00:00:01 GMT" ;
277 function getCookie ( name
) {
279 var dc
= document
. cookie
;
280 var prefix
= name
+ "=" ;
281 var begin
= dc
. indexOf ( "; " + prefix
);
283 begin
= dc
. indexOf ( prefix
);
284 if ( begin
!= 0 ) return null ;
289 var end
= document
. cookie
. indexOf ( ";" , begin
);
293 return unescape ( dc
. substring ( begin
+ prefix
. length
, end
));
296 function gotoPreferences () {
297 document
. location
. href
= "prefs.php" ;
300 function gotoLogout () {
301 document
. location
. href
= "backend.php?op=logout" ;
304 function gotoMain () {
305 document
. location
. href
= "index.php" ;
308 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
309 * * @author Sundar Dorai-Raj
310 * * Email: sdoraira@vt.edu
311 * * This program is free software; you can redistribute it and/or
312 * * modify it under the terms of the GNU General Public License
313 * * as published by the Free Software Foundation; either version 2
314 * * of the License, or (at your option) any later version,
315 * * provided that any use properly credits the author.
316 * * This program is distributed in the hope that it will be useful,
317 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
318 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
319 * * GNU General Public License for more details at http://www.gnu.org * * */
321 var numbers
= ".0123456789" ;
322 function isNumeric ( x
) {
323 // is x a String or a character?
325 // remove negative sign
327 for ( var j
= 0 ; j
< x
. length
; j
++) {
328 // call isNumeric recursively for each character
329 number
= isNumeric ( x
. substring ( j
, j
+ 1 ));
330 if (! number
) return number
;
335 // if x is number return true
336 if ( numbers
. indexOf ( x
)>= 0 ) return true ;
342 function toggleSelectRowById ( sender
, id
) {
344 return toggleSelectRow ( sender
, row
);
347 function toggleSelectListRow ( sender
) {
348 var row
= sender
. parentNode
;
349 return toggleSelectRow ( sender
, row
);
352 /* this is for dijit Checkbox */
353 function toggleSelectListRow2 ( sender
) {
354 var row
= sender
. domNode
. parentNode
;
355 return toggleSelectRow ( sender
, row
);
358 /* this is for dijit Checkbox */
359 function toggleSelectRow2 ( sender
, row
, is_cdm
) {
363 row
= sender
. domNode
. parentNode
. parentNode
;
365 row
= sender
. domNode
. parentNode
. parentNode
. parentNode
; // oh ffs
367 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
368 row
. addClassName ( 'Selected' );
370 row
. removeClassName ( 'Selected' );
374 function toggleSelectRow ( sender
, row
) {
376 if (! row
) row
= sender
. parentNode
. parentNode
;
378 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
379 row
. addClassName ( 'Selected' );
381 row
. removeClassName ( 'Selected' );
384 function checkboxToggleElement ( elem
, id
) {
386 Effect
. Appear ( id
, { duration
: 0.5 });
388 Effect
. Fade ( id
, { duration
: 0.5 });
392 function dropboxSelect ( e
, v
) {
393 for ( var i
= 0 ; i
< e
. length
; i
++) {
394 if ( e
[ i
]. value
== v
) {
401 function getURLParam ( param
){
402 return String ( window
. location
. href
). parseQuery ()[ param
];
405 function closeInfoBox ( cleanup
) {
407 dialog
= dijit
. byId ( "infoBox" );
409 if ( dialog
) dialog
. hide ();
412 //exception_error("closeInfoBox", e);
418 function displayDlg ( id
, param
, callback
) {
420 notify_progress ( "Loading, please wait..." , true );
422 var query
= "?op=dlg&method=" +
423 param_escape ( id
) + "¶m=" + param_escape ( param
);
425 new Ajax
. Request ( "backend.php" , {
427 onComplete : function ( transport
) {
428 infobox_callback2 ( transport
);
429 if ( callback
) callback ( transport
);
435 function infobox_callback2 ( transport
) {
439 if ( dijit
. byId ( "infoBox" )) {
440 dialog
= dijit
. byId ( "infoBox" );
443 //console.log("infobox_callback2");
446 var title
= transport
. responseXML
. getElementsByTagName ( "title" )[ 0 ];
448 title
= title
. firstChild
. nodeValue
;
450 var content
= transport
. responseXML
. getElementsByTagName ( "content" )[ 0 ];
452 content
= content
. firstChild
. nodeValue
;
455 dialog
= new dijit
. Dialog ({
458 style
: "width: 600px" ,
459 onCancel : function () {
462 onExecute : function () {
465 onClose : function () {
470 dialog
. attr ( 'title' , title
);
471 dialog
. attr ( 'content' , content
);
478 exception_error ( "infobox_callback2" , e
);
482 function filterCR ( e
, f
)
487 key
= window
. event
. keyCode
; //IE
489 key
= e
. which
; //firefox
492 if ( typeof f
!= 'undefined' ) {
503 function getInitParam ( key
) {
504 return init_params
[ key
];
507 function setInitParam ( key
, value
) {
508 init_params
[ key
] = value
;
511 function fatalError ( code
, msg
, ext_info
) {
515 window
. location
. href
= "index.php" ;
516 } else if ( code
== 5 ) {
517 window
. location
. href
= "db-updater.php" ;
520 if ( msg
== "" ) msg
= "Unknown error" ;
523 if ( ext_info
. responseText
) {
524 ext_info
= ext_info
. responseText
;
528 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
532 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
533 "<p>" + msg
+ "</p>" ;
536 content
= content
+ "<div><b>Additional information:</b></div>" +
537 "<textarea style='width: 100%' readonly= \" 1 \" >" +
538 ext_info
+ "</textarea>" ;
541 var dialog
= new dijit
. Dialog ({
542 title
: "Fatal error" ,
543 style
: "width: 600px" ,
553 exception_error ( "fatalError" , e
);
557 /* function filterDlgCheckType(sender) {
561 var ftype = sender.value;
563 // if selected filter type is 5 (Date) enable the modifier dropbox
565 Element.show("filterDlg_dateModBox");
566 Element.show("filterDlg_dateChkBox");
568 Element.hide("filterDlg_dateModBox");
569 Element.hide("filterDlg_dateChkBox");
574 exception_error("filterDlgCheckType", e);
579 function filterDlgCheckAction ( sender
) {
583 var action
= sender
. value
;
585 var action_param
= $( "filterDlg_paramBox" );
588 console
. log ( "filterDlgCheckAction: can't find action param box!" );
592 // if selected action supports parameters, enable params field
593 if ( action
== 4 || action
== 6 || action
== 7 ) {
594 new Effect
. Appear ( action_param
, { duration
: 0.5 });
596 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
597 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
599 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
600 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
603 Element
. hide ( action_param
);
607 exception_error ( "filterDlgCheckAction" , e
);
612 function filterDlgCheckDate () {
614 var dialog
= dijit
. byId ( "filterEditDlg" );
616 var reg_exp
= dialog
. attr ( 'value' ). reg_exp
;
618 var query
= "?op=rpc&method=checkDate&date=" + reg_exp
;
620 new Ajax
. Request ( "backend.php" , {
622 onComplete : function ( transport
) {
624 var reply
= JSON
. parse ( transport
. responseText
);
626 if ( reply
[ 'result' ] == true ) {
627 alert ( __ ( "Date syntax appears to be correct:" ) + " " + reply
[ 'date' ]);
630 alert ( __ ( "Date syntax is incorrect." ));
637 exception_error ( "filterDlgCheckDate" , e
);
641 function explainError ( code
) {
642 return displayDlg ( "explainError" , code
);
645 function loading_set_progress ( p
) {
647 loading_progress
+= p
;
649 if ( dijit
. byId ( "loading_bar" ))
650 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
652 if ( loading_progress
>= 90 )
656 exception_error ( "loading_set_progress" , e
);
660 function remove_splash () {
662 if ( Element
. visible ( "overlay" )) {
663 console
. log ( "about to remove splash, OMG!" );
664 Element
. hide ( "overlay" );
665 console
. log ( "removed splash!" );
669 function transport_error_check ( transport
) {
671 if ( transport
. responseXML
) {
672 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
675 var code
= error
. getAttribute ( "error-code" );
676 var msg
= error
. getAttribute ( "error-msg" );
678 fatalError ( code
, msg
);
684 exception_error ( "check_for_error_xml" , e
);
689 function strip_tags ( s
) {
690 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
693 function truncate_string ( s
, length
) {
694 if (! length
) length
= 30 ;
695 var tmp
= s
. substring ( 0 , length
);
696 if ( s
. length
> length
) tmp
+= "…" ;
700 function hotkey_prefix_timeout () {
703 var date
= new Date ();
704 var ts
= Math
. round ( date
. getTime () / 1000 );
706 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
707 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
708 hotkey_prefix_pressed
= false ;
709 hotkey_prefix
= false ;
710 Element
. hide ( 'cmdline' );
713 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
716 exception_error ( "hotkey_prefix_timeout" , e
);
720 function hideAuxDlg () {
722 Element
. hide ( 'auxDlg' );
724 exception_error ( "hideAuxDlg" , e
);
729 function uploadIconHandler ( rc
) {
733 notify_info ( "Upload complete." );
734 if ( inPreferences ()) {
737 setTimeout ( 'updateFeedList(false, false)' , 50 );
741 notify_error ( "Upload failed: icon is too big." );
744 notify_error ( "Upload failed." );
749 exception_error ( "uploadIconHandler" , e
);
753 function removeFeedIcon ( id
) {
757 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
758 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
762 notify_progress ( "Removing feed icon..." , true );
764 new Ajax
. Request ( "backend.php" , {
766 onComplete : function ( transport
) {
767 notify_info ( "Feed icon removed." );
768 if ( inPreferences ()) {
771 setTimeout ( 'updateFeedList(false, false)' , 50 );
778 exception_error ( "removeFeedIcon" , e
);
782 function uploadFeedIcon () {
786 var file
= $( "icon_file" );
788 if ( file
. value
. length
== 0 ) {
789 alert ( __ ( "Please select an image file to upload." ));
791 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
792 notify_progress ( "Uploading, please wait..." , true );
800 exception_error ( "uploadFeedIcon" , e
);
804 function addLabel ( select
, callback
) {
808 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
810 if ( caption
!= undefined ) {
813 alert ( __ ( "Can't create label: missing caption." ));
817 var query
= "?op=pref-labels&method=add&caption=" +
818 param_escape ( caption
);
821 query
+= "&output=select" ;
823 notify_progress ( "Loading, please wait..." , true );
825 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
827 new Ajax
. Request ( "backend.php" , {
829 onComplete : function ( transport
) {
832 } else if ( inPreferences ()) {
842 exception_error ( "addLabel" , e
);
846 function quickAddFeed () {
848 var query
= "backend.php?op=dlg&method=quickAddFeed" ;
850 // overlapping widgets
851 if ( dijit
. byId ( "batchSubDlg" )) dijit
. byId ( "batchSubDlg" ). destroyRecursive ();
852 if ( dijit
. byId ( "feedAddDlg" )) dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
854 var dialog
= new dijit
. Dialog ({
856 title
: __ ( "Subscribe to Feed" ),
857 style
: "width: 600px" ,
858 execute : function () {
859 if ( this . validate ()) {
860 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
862 var feed_url
= this . attr ( 'value' ). feed
;
864 Element
. show ( "feed_add_spinner" );
866 new Ajax
. Request ( "backend.php" , {
867 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
868 onComplete : function ( transport
) {
871 var reply
= JSON
. parse ( transport
. responseText
);
873 var rc
= reply
[ 'result' ];
876 Element
. hide ( "feed_add_spinner" );
878 console
. log ( "GOT RC: " + rc
);
880 switch ( parseInt ( rc
[ 'code' ])) {
883 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
888 alert ( __ ( "Specified URL seems to be invalid." ));
891 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
894 /* notify_progress("Searching for feed urls...", true);
896 new Ajax.Request("backend.php", {
897 parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url),
898 onComplete: function(transport, dialog, feed_url) {
902 var reply = JSON.parse(transport.responseText);
904 var feeds = reply['urls'];
906 console.log(transport.responseText);
908 var select = dijit.byId("feedDlg_feedContainerSelect");
910 while (select.getOptions().length > 0)
911 select.removeOption(0);
914 for (var feedUrl in feeds) {
915 select.addOption({value: feedUrl, label: feeds[feedUrl]});
919 // if (count > 5) count = 5;
920 // select.size = count;
922 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
929 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
931 while ( select
. getOptions (). length
> 0 )
932 select
. removeOption ( 0 );
935 for ( var feedUrl
in feeds
) {
936 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
940 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
944 alert ( __ ( "Couldn't download the specified URL: %s" ).
945 replace ( "%s" , rc
[ 'message' ]));
948 alert ( __ ( "You are already subscribed to this feed." ));
953 exception_error ( "subscribeToFeed" , e
, transport
);
964 exception_error ( "quickAddFeed" , e
);
968 function createNewRuleElement ( parentNode
, replaceNode
) {
970 var form
= document
. forms
[ "filter_new_rule_form" ];
972 form
. reg_exp
. value
= form
. reg_exp
. value
. replace ( /(<([^>]+)>)/ig , "" );
974 var query
= "backend.php?op=pref-filters&method=printrulename&rule=" +
975 param_escape ( dojo
. formToJson ( form
));
979 new Ajax
. Request ( "backend.php" , {
981 onComplete : function ( transport
) {
983 var li
= dojo
. create ( "li" );
985 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
987 new dijit
. form
. CheckBox ({
988 onChange : function () {
989 toggleSelectListRow2 ( this ) },
992 dojo
. create ( "input" , { type
: "hidden" ,
994 value
: dojo
. formToJson ( form
) }, li
);
996 dojo
. create ( "span" , {
997 onclick : function () {
998 dijit
. byId ( 'filterEditDlg' ). editRule ( this );
1000 innerHTML
: transport
. responseText
}, li
);
1003 parentNode
. replaceChild ( li
, replaceNode
);
1005 parentNode
. appendChild ( li
);
1008 exception_error ( "createNewRuleElement" , e
);
1012 exception_error ( "createNewRuleElement" , e
);
1016 function createNewActionElement ( parentNode
, replaceNode
) {
1018 var form
= document
. forms
[ "filter_new_action_form" ];
1020 if ( form
. action_id
. value
== 7 ) {
1021 form
. action_param
. value
= form
. action_param_label
. value
;
1024 var query
= "backend.php?op=pref-filters&method=printactionname&action=" +
1025 param_escape ( dojo
. formToJson ( form
));
1029 new Ajax
. Request ( "backend.php" , {
1031 onComplete : function ( transport
) {
1033 var li
= dojo
. create ( "li" );
1035 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
1037 new dijit
. form
. CheckBox ({
1038 onChange : function () {
1039 toggleSelectListRow2 ( this ) },
1042 dojo
. create ( "input" , { type
: "hidden" ,
1044 value
: dojo
. formToJson ( form
) }, li
);
1046 dojo
. create ( "span" , {
1047 onclick : function () {
1048 dijit
. byId ( 'filterEditDlg' ). editAction ( this );
1050 innerHTML
: transport
. responseText
}, li
);
1053 parentNode
. replaceChild ( li
, replaceNode
);
1055 parentNode
. appendChild ( li
);
1059 exception_error ( "createNewActionElement" , e
);
1063 exception_error ( "createNewActionElement" , e
);
1068 function addFilterRule ( replaceNode
, ruleStr
) {
1070 if ( dijit
. byId ( "filterNewRuleDlg" ))
1071 dijit
. byId ( "filterNewRuleDlg" ). destroyRecursive ();
1073 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
1074 param_escape ( ruleStr
);
1076 var rule_dlg
= new dijit
. Dialog ({
1077 id
: "filterNewRuleDlg" ,
1078 title
: ruleStr
? __ ( "Edit rule" ) : __ ( "Add rule" ),
1079 style
: "width: 600px" ,
1080 execute : function () {
1081 if ( this . validate ()) {
1082 createNewRuleElement ($( "filterDlg_Matches" ), replaceNode
);
1090 exception_error ( "addFilterRule" , e
);
1094 function addFilterAction ( replaceNode
, actionStr
) {
1096 if ( dijit
. byId ( "filterNewActionDlg" ))
1097 dijit
. byId ( "filterNewActionDlg" ). destroyRecursive ();
1099 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
1100 param_escape ( actionStr
);
1102 var rule_dlg
= new dijit
. Dialog ({
1103 id
: "filterNewActionDlg" ,
1104 title
: actionStr
? __ ( "Edit action" ) : __ ( "Add action" ),
1105 style
: "width: 600px" ,
1106 execute : function () {
1107 if ( this . validate ()) {
1108 createNewActionElement ($( "filterDlg_Actions" ), replaceNode
);
1116 exception_error ( "addFilterAction" , e
);
1120 function quickAddFilter () {
1123 if (! inPreferences ()) {
1124 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
1125 param_escape ( getActiveFeedId ()) + "&is_cat=" +
1126 param_escape ( activeFeedIsCat ());
1128 query
= "backend.php?op=pref-filters&method=newfilter" ;
1133 if ( dijit
. byId ( "feedEditDlg" ))
1134 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1136 if ( dijit
. byId ( "filterEditDlg" ))
1137 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1139 dialog
= new dijit
. Dialog ({
1140 id
: "filterEditDlg" ,
1141 title
: __ ( "Create Filter" ),
1142 style
: "width: 600px" ,
1144 var query
= "backend.php?" + dojo
. formToQuery ( "filter_new_form" ) + "&savemode=test" ;
1146 if ( dijit
. byId ( "filterTestDlg" ))
1147 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
1149 var test_dlg
= new dijit
. Dialog ({
1150 id
: "filterTestDlg" ,
1151 title
: "Test Filter" ,
1152 style
: "width: 600px" ,
1157 selectRules : function ( select
) {
1158 $$( "#filterDlg_Matches input[type=checkbox]" ). each ( function ( e
) {
1161 e
. parentNode
. addClassName ( "Selected" );
1163 e
. parentNode
. removeClassName ( "Selected" );
1166 selectActions : function ( select
) {
1167 $$( "#filterDlg_Actions input[type=checkbox]" ). each ( function ( e
) {
1171 e
. parentNode
. addClassName ( "Selected" );
1173 e
. parentNode
. removeClassName ( "Selected" );
1177 editRule : function ( e
) {
1178 var li
= e
. parentNode
;
1179 var rule
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1180 addFilterRule ( li
, rule
);
1182 editAction : function ( e
) {
1183 var li
= e
. parentNode
;
1184 var action
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1185 addFilterAction ( li
, action
);
1187 addAction : function () { addFilterAction (); },
1188 addRule : function () { addFilterRule (); },
1189 deleteAction : function () {
1190 $$( "#filterDlg_Actions li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1192 deleteRule : function () {
1193 $$( "#filterDlg_Matches li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1195 execute : function () {
1196 if ( this . validate ()) {
1198 var query
= dojo
. formToQuery ( "filter_new_form" );
1202 new Ajax
. Request ( "backend.php" , {
1204 onComplete : function ( transport
) {
1205 if ( inPreferences ()) {
1215 if (! inPreferences ()) {
1216 var lh
= dojo
. connect ( dialog
, "onLoad" , function (){
1217 dojo
. disconnect ( lh
);
1219 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId ();
1221 new Ajax
. Request ( "backend.php" , {
1223 onComplete : function ( transport
) {
1224 var reply
= JSON
. parse ( transport
. responseText
);
1228 if ( reply
&& reply
) title
= reply
. title
;
1230 if ( title
|| getActiveFeedId () || activeFeedIsCat ()) {
1232 console
. log ( title
+ " " + getActiveFeedId ());
1234 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1237 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1239 addFilterRule ( null , dojo
. toJson ( rule
));
1250 exception_error ( "quickAddFilter" , e
);
1254 function resetPubSub ( feed_id
, title
) {
1256 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1258 if ( title
== undefined || confirm ( msg
)) {
1259 notify_progress ( "Loading, please wait..." );
1261 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1263 new Ajax
. Request ( "backend.php" , {
1265 onComplete : function ( transport
) {
1266 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1267 notify_info ( "Subscription reset." );
1275 function unsubscribeFeed ( feed_id
, title
) {
1277 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1279 if ( title
== undefined || confirm ( msg
)) {
1280 notify_progress ( "Removing feed..." );
1282 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1284 new Ajax
. Request ( "backend.php" , {
1286 onComplete : function ( transport
) {
1288 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1290 if ( inPreferences ()) {
1293 if ( feed_id
== getActiveFeedId ())
1294 setTimeout ( "viewfeed(-5)" , 100 );
1296 if ( feed_id
< 0 ) updateFeedList ();
1306 function backend_sanity_check_callback ( transport
) {
1310 if ( sanity_check_done
) {
1311 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1312 "presence of Firebug or some other disrupting extension. " +
1313 "Please disable it and try again." );
1317 var reply
= JSON
. parse ( transport
. responseText
);
1320 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1324 var error_code
= reply
[ 'error' ][ 'code' ];
1326 if ( error_code
&& error_code
!= 0 ) {
1327 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1330 console
. log ( "sanity check ok" );
1332 var params
= reply
[ 'init-params' ];
1335 console
. log ( 'reading init-params...' );
1340 console
. log ( "IP: " + k
+ " => " + v
);
1342 if ( k
== "label_base_index" ) _label_base_index
= parseInt ( v
);
1346 init_params
= params
;
1349 sanity_check_done
= true ;
1351 init_second_stage ();
1354 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1358 /*function has_local_storage() {
1360 return 'sessionStorage' in window && window['sessionStorage'] != null;
1366 function catSelectOnChange ( elem
) {
1368 /* var value = elem[elem.selectedIndex].value;
1369 var def = elem.getAttribute('default');
1371 if (value == "ADD_CAT") {
1374 dropboxSelect(elem, def);
1376 elem.selectedIndex = 0;
1382 exception_error ( "catSelectOnChange" , e
);
1386 function quickAddCat ( elem
) {
1388 var cat
= prompt ( __ ( "Please enter category title:" ));
1392 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1394 notify_progress ( "Loading, please wait..." , true );
1396 new Ajax
. Request ( "backend.php" , {
1398 onComplete : function ( transport
) {
1399 var response
= transport
. responseXML
;
1400 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1401 var options
= select
. getElementsByTagName ( "option" );
1403 dropbox_replace_options ( elem
, options
);
1412 exception_error ( "quickAddCat" , e
);
1416 function genUrlChangeKey ( feed
, is_cat
) {
1419 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1423 notify_progress ( "Trying to change address..." , true );
1425 var query
= "?op=rpc&method=regenFeedKey&id=" + param_escape ( feed
) +
1426 "&is_cat=" + param_escape ( is_cat
);
1428 new Ajax
. Request ( "backend.php" , {
1430 onComplete : function ( transport
) {
1431 var reply
= JSON
. parse ( transport
. responseText
);
1432 var new_link
= reply
. link
;
1434 var e
= $( 'gen_feed_url' );
1438 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1439 "&key=" + new_link
);
1441 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1442 "&key=" + new_link
);
1444 new Effect
. Highlight ( e
);
1449 notify_error ( "Could not change feed URL." );
1454 exception_error ( "genUrlChangeKey" , e
);
1459 function labelSelectOnChange ( elem
) {
1461 /* var value = elem[elem.selectedIndex].value;
1462 var def = elem.getAttribute('default');
1464 if (value == "ADD_LABEL") {
1467 dropboxSelect(elem, def);
1469 elem.selectedIndex = 0;
1471 addLabel(elem, function(transport) {
1475 var response = transport.responseXML;
1476 var select = response.getElementsByTagName("select")[0];
1477 var options = select.getElementsByTagName("option");
1479 dropbox_replace_options(elem, options);
1483 exception_error("addLabel", e);
1489 exception_error ( "labelSelectOnChange" , e
);
1493 function dropbox_replace_options ( elem
, options
) {
1496 while ( elem
. hasChildNodes ())
1497 elem
. removeChild ( elem
. firstChild
);
1501 for ( var i
= 0 ; i
< options
. length
; i
++) {
1502 var text
= options
[ i
]. firstChild
. nodeValue
;
1503 var value
= options
[ i
]. getAttribute ( "value" );
1505 if ( value
== undefined ) value
= text
;
1507 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1509 var option
= new Option ( text
, value
, issel
);
1511 if ( options
[ i
]. getAttribute ( "disabled" ))
1512 option
. setAttribute ( "disabled" , true );
1514 elem
. insert ( option
);
1516 if ( issel
) sel_idx
= i
;
1519 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1520 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1523 exception_error ( "dropbox_replace_options" , e
);
1527 // mode = all, none, invert
1528 function selectTableRows ( id
, mode
) {
1530 var rows
= $( id
). rows
;
1532 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1537 if ( row
. id
&& row
. className
) {
1538 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1539 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1541 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1542 var input
= inputs
[ j
];
1544 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1545 input
. id
. match ( bare_id
)) {
1548 dcb
= dijit
. getEnclosingWidget ( cb
);
1554 var issel
= row
. hasClassName ( "Selected" );
1556 if ( mode
== "all" && ! issel
) {
1557 row
. addClassName ( "Selected" );
1559 if ( dcb
) dcb
. set ( "checked" , true );
1560 } else if ( mode
== "none" && issel
) {
1561 row
. removeClassName ( "Selected" );
1563 if ( dcb
) dcb
. set ( "checked" , false );
1565 } else if ( mode
== "invert" ) {
1568 row
. removeClassName ( "Selected" );
1570 if ( dcb
) dcb
. set ( "checked" , false );
1572 row
. addClassName ( "Selected" );
1574 if ( dcb
) dcb
. set ( "checked" , true );
1582 exception_error ( "selectTableRows" , e
);
1587 function getSelectedTableRowIds ( id
) {
1591 var elem_rows
= $( id
). rows
;
1593 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1594 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1595 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1601 exception_error ( "getSelectedTableRowIds" , e
);
1607 function editFeed ( feed
, event
) {
1610 return alert ( __ ( "You can't edit this kind of feed." ));
1612 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1617 if ( dijit
. byId ( "filterEditDlg" ))
1618 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1620 if ( dijit
. byId ( "feedEditDlg" ))
1621 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1623 dialog
= new dijit
. Dialog ({
1625 title
: __ ( "Edit Feed" ),
1626 style
: "width: 600px" ,
1627 execute : function () {
1628 if ( this . validate ()) {
1629 // console.log(dojo.objectToQuery(this.attr('value')));
1631 notify_progress ( "Saving data..." , true );
1633 new Ajax
. Request ( "backend.php" , {
1634 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1635 onComplete : function ( transport
) {
1647 exception_error ( "editFeed" , e
);
1651 function feedBrowser () {
1653 var query
= "backend.php?op=dlg&method=feedBrowser" ;
1655 if ( dijit
. byId ( "feedAddDlg" ))
1656 dijit
. byId ( "feedAddDlg" ). hide ();
1658 if ( dijit
. byId ( "feedBrowserDlg" ))
1659 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1661 var dialog
= new dijit
. Dialog ({
1662 id
: "feedBrowserDlg" ,
1663 title
: __ ( "More Feeds" ),
1664 style
: "width: 600px" ,
1665 getSelectedFeedIds : function () {
1666 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1667 var selected
= new Array ();
1669 list
. each ( function ( child
) {
1670 var id
= child
. id
. replace ( "FBROW-" , "" );
1672 if ( child
. hasClassName ( 'Selected' )) {
1679 getSelectedFeeds : function () {
1680 var list
= $$( "#browseFeedList li.Selected" );
1681 var selected
= new Array ();
1683 list
. each ( function ( child
) {
1684 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1685 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1687 selected
. push ([ title
, url
]);
1694 subscribe : function () {
1695 var mode
= this . attr ( 'value' ). mode
;
1699 selected
= this . getSelectedFeeds ();
1701 selected
= this . getSelectedFeedIds ();
1703 if ( selected
. length
> 0 ) {
1704 dijit
. byId ( "feedBrowserDlg" ). hide ();
1706 notify_progress ( "Loading, please wait..." , true );
1708 // we use dojo.toJson instead of JSON.stringify because
1709 // it somehow escapes everything TWICE, at least in Chrome 9
1711 var query
= "?op=rpc&method=massSubscribe&payload=" +
1712 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1716 new Ajax
. Request ( "backend.php" , {
1718 onComplete : function ( transport
) {
1724 alert ( __ ( "No feeds are selected." ));
1728 update : function () {
1729 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1731 Element
. show ( 'feed_browser_spinner' );
1733 new Ajax
. Request ( "backend.php" , {
1735 onComplete : function ( transport
) {
1738 Element
. hide ( 'feed_browser_spinner' );
1740 var c
= $( "browseFeedList" );
1742 var reply
= JSON
. parse ( transport
. responseText
);
1744 var r
= reply
[ 'content' ];
1745 var mode
= reply
[ 'mode' ];
1751 dojo
. parser
. parse ( "browseFeedList" );
1754 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1756 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1761 removeFromArchive : function () {
1762 var selected
= this . getSelectedFeedIds ();
1764 if ( selected
. length
> 0 ) {
1766 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1769 Element
. show ( 'feed_browser_spinner' );
1771 var query
= "?op=rpc&method=remarchive&ids=" +
1772 param_escape ( selected
. toString ());;
1774 new Ajax
. Request ( "backend.php" , {
1776 onComplete : function ( transport
) {
1782 execute : function () {
1783 if ( this . validate ()) {
1792 exception_error ( "editFeed" , e
);
1796 function showFeedsWithErrors () {
1798 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors" ;
1800 if ( dijit
. byId ( "errorFeedsDlg" ))
1801 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1803 dialog
= new dijit
. Dialog ({
1804 id
: "errorFeedsDlg" ,
1805 title
: __ ( "Feeds with update errors" ),
1806 style
: "width: 600px" ,
1807 getSelectedFeeds : function () {
1808 return getSelectedTableRowIds ( "prefErrorFeedList" );
1810 removeSelected : function () {
1811 var sel_rows
= this . getSelectedFeeds ();
1813 console
. log ( sel_rows
);
1815 if ( sel_rows
. length
> 0 ) {
1816 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1819 notify_progress ( "Removing selected feeds..." , true );
1821 var query
= "?op=pref-feeds&method=remove&ids=" +
1822 param_escape ( sel_rows
. toString ());
1824 new Ajax
. Request ( "backend.php" , {
1826 onComplete : function ( transport
) {
1834 alert ( __ ( "No feeds are selected." ));
1837 execute : function () {
1838 if ( this . validate ()) {
1846 exception_error ( "showFeedsWithErrors" , e
);
1851 /* new support functions for SelectByTag */
1853 function get_all_tags ( selObj
){
1855 if ( ! selObj
) return "" ;
1858 var len
= selObj
. options
. length
;
1860 for ( var i
= 0 ; i
< len
; i
++){
1861 if ( selObj
. options
[ i
]. selected
) {
1862 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1866 if ( result
. length
> 0 ){
1867 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1873 exception_error ( "get_all_tags" , e
);
1877 function get_radio_checked ( radioObj
) {
1879 if (! radioObj
) return "" ;
1881 var len
= radioObj
. length
;
1883 if ( len
== undefined ){
1884 if ( radioObj
. checked
){
1885 return ( radioObj
. value
);
1891 for ( var i
= 0 ; i
< len
; i
++ ){
1892 if ( radioObj
[ i
]. checked
){
1893 return ( radioObj
[ i
]. value
);
1898 exception_error ( "get_radio_checked" , e
);
1903 function get_timestamp () {
1904 var date
= new Date ();
1905 return Math
. round ( date
. getTime () / 1000 );
1908 function helpDialog ( topic
) {
1910 var query
= "backend.php?op=backend&method=help&topic=" + param_escape ( topic
);
1912 if ( dijit
. byId ( "helpDlg" ))
1913 dijit
. byId ( "helpDlg" ). destroyRecursive ();
1915 dialog
= new dijit
. Dialog ({
1918 style
: "width: 600px" ,
1925 exception_error ( "helpDialog" , e
);
1929 function htmlspecialchars_decode ( string
, quote_style
) {
1930 // http://kevin.vanzonneveld.net
1931 // + original by: Mirek Slugen
1932 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1933 // + bugfixed by: Mateusz "loonquawl" Zalega
1934 // + input by: ReverseSyntax
1935 // + input by: Slawomir Kaniecki
1936 // + input by: Scott Cariss
1937 // + input by: Francois
1938 // + bugfixed by: Onno Marsman
1939 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1940 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1941 // + input by: Ratheous
1942 // + input by: Mailfaker (http://www.weedem.fr/)
1943 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1944 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1945 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1946 // * returns 1: '<p>this -> "</p>'
1947 // * example 2: htmlspecialchars_decode("&quot;");
1948 // * returns 2: '"'
1952 if ( typeof quote_style
=== 'undefined' ) {
1955 string
= string
. toString (). replace ( /</g , '<' ). replace ( />/g , '>' );
1958 'ENT_HTML_QUOTE_SINGLE' : 1 ,
1959 'ENT_HTML_QUOTE_DOUBLE' : 2 ,
1964 if ( quote_style
=== 0 ) {
1967 if ( typeof quote_style
!== 'number' ) { // Allow for a single string or an array of string flags
1968 quote_style
= []. concat ( quote_style
);
1969 for ( i
= 0 ; i
< quote_style
. length
; i
++) {
1970 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1971 if ( OPTS
[ quote_style
[ i
]] === 0 ) {
1973 } else if ( OPTS
[ quote_style
[ i
]]) {
1974 optTemp
= optTemp
| OPTS
[ quote_style
[ i
]];
1977 quote_style
= optTemp
;
1979 if ( quote_style
& OPTS
. ENT_HTML_QUOTE_SINGLE
) {
1980 string
= string
. replace ( /�*39;/g , "'" ); // PHP doesn't currently escape if more than one 0, but it should
1981 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1984 string
= string
. replace ( /"/g , '"' );
1986 // Put this in last place to avoid escape being double-decoded
1987 string
= string
. replace ( /&/g , '&' );
1993 function label_to_feed_id ( label
) {
1994 return _label_base_index
- 1 - Math
. abs ( label
);
1997 function feed_to_label_id ( feed
) {
1998 return _label_base_index
- 1 + Math
. abs ( feed
);