]>
git.wh0rd.org - tt-rss.git/blob - js/functions.js
1 var loading_progress
= 0 ;
2 var sanity_check_done
= false ;
4 var _label_base_index
= - 1024 ;
5 var notify_hide_timerid
= false ;
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
;
54 new Ajax
. Request ( "backend.php" , {
55 parameters
: { op
: "rpc" , method
: "log" , logmsg
: msg
},
56 onComplete : function ( transport
) {
57 console
. log ( transport
. responseText
);
61 console
. log ( "Exception while trying to log the error." );
65 msg
+= "<p>" + __ ( "The error will be reported to the configured log destination." ) +
68 var content
= "<div class= \" fatalError \" >" +
69 "<pre>" + msg
+ "</pre>" ;
71 content
+= "<form name= \" exceptionForm \" id= \" exceptionForm \" target= \" _blank \" " +
72 "action= \" http://tt-rss.org/report.php \" method= \" POST \" >" ;
74 content
+= "<textarea style= \" display : none \" name= \" message \" >" + msg
+ "</textarea>" ;
75 content
+= "<textarea style= \" display : none \" name= \" params \" >N/A</textarea>" ;
78 content
+= "<div><b>Additional information:</b></div>" +
79 "<textarea name= \" xinfo \" readonly= \" 1 \" >" + ext_info
+ "</textarea>" ;
82 content
+= "<div><b>Stack trace:</b></div>" +
83 "<textarea name= \" stack \" readonly= \" 1 \" >" + e
. stack
+ "</textarea>" ;
89 content
+= "<div class='dlgButtons'>" ;
91 content
+= "<button dojoType= \" dijit.form.Button \" " +
92 "onclick= \" dijit.byId('exceptionDlg').report() \" >" +
93 __ ( 'Report to tt-rss.org' ) + "</button> " ;
94 content
+= "<button dojoType= \" dijit.form.Button \" " +
95 "onclick= \" dijit.byId('exceptionDlg').hide() \" >" +
96 __ ( 'Close' ) + "</button>" ;
99 if ( dijit
. byId ( "exceptionDlg" ))
100 dijit
. byId ( "exceptionDlg" ). destroyRecursive ();
102 var dialog
= new dijit
. Dialog ({
104 title
: "Unhandled exception" ,
105 style
: "width: 600px" ,
107 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." ))) {
109 document
. forms
[ 'exceptionForm' ]. params
. value
= $ H ({
110 browserName
: navigator
. appName
,
111 browserVersion
: navigator
. appVersion
,
112 browserPlatform
: navigator
. platform
,
113 browserCookies
: navigator
. cookieEnabled
,
114 ttrssVersion
: __ttrss_version
,
115 initParams
: JSON
. stringify ( init_params
),
118 document
. forms
[ 'exceptionForm' ]. submit ();
127 console
. log ( "Exception while trying to report an exception. Oh boy." );
129 console
. log ( "Original exception:" );
132 msg
+= " \n\n Additional exception caught while trying to show the error dialog. \n\n " + format_exception_error ( 'exception_error' , ei
);
135 new Ajax
. Request ( "backend.php" , {
136 parameters
: { op
: "rpc" , method
: "log" , logmsg
: msg
},
137 onComplete : function ( transport
) {
138 console
. log ( transport
. responseText
);
142 console
. log ( "Third exception while trying to log the error! Seriously?" );
146 msg
+= " \n\n The error will be reported to the configured log destination." ;
153 function format_exception_error ( location
, e
) {
157 var base_fname
= e
. fileName
. substring ( e
. fileName
. lastIndexOf ( "/" ) + 1 );
159 msg
= "Exception: " + e
. name
+ ", " + e
. message
+
160 " \n Function: " + location
+ "()" +
161 " \n Location: " + base_fname
+ ":" + e
. lineNumber
;
163 } else if ( e
. description
) {
164 msg
= "Exception: " + e
. description
+ " \n Function: " + location
+ "()" ;
166 msg
= "Exception: " + e
+ " \n Function: " + location
+ "()" ;
169 console
. error ( "EXCEPTION: " + msg
);
174 function param_escape ( arg
) {
175 if ( typeof encodeURIComponent
!= 'undefined' )
176 return encodeURIComponent ( arg
);
181 function param_unescape ( arg
) {
182 if ( typeof decodeURIComponent
!= 'undefined' )
183 return decodeURIComponent ( arg
);
185 return unescape ( arg
);
189 function hide_notify () {
190 Element
. hide ( 'notify' );
193 function notify_real ( msg
, no_hide
, n_type
) {
199 if ( notify_hide_timerid
) {
200 window
. clearTimeout ( notify_hide_timerid
);
204 if ( Element
. visible ( n
)) {
205 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 0 );
221 msg
= "<span class= \" msg \" > " + __ ( msg
) + "</span>" ;
224 n
. className
= "notify" ;
225 } else if ( n_type
== 2 ) {
226 n
. className
= "notify progress" ;
227 msg
= "<span><img src='images/indicator_white.gif'></span>" + msg
;
229 } else if ( n_type
== 3 ) {
230 n
. className
= "notify error" ;
231 msg
= "<span><img src='images/alert.png'></span>" + msg
;
232 } else if ( n_type
== 4 ) {
233 n
. className
= "notify info" ;
234 msg
= "<span><img src='images/information.png'></span>" + msg
;
237 msg
+= " <span><img src= \" images/cross.png \" class= \" close \" title= \" " +
238 __ ( "Click to close" ) + " \" onclick= \" notify('') \" ></span>" ;
240 // msg = "<img src='images/live_com_loading.gif'> " + msg;
245 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 5 * 1000 );
249 function notify ( msg
, no_hide
) {
250 notify_real ( msg
, no_hide
, 1 );
253 function notify_progress ( msg
, no_hide
) {
254 notify_real ( msg
, no_hide
, 2 );
257 function notify_error ( msg
, no_hide
) {
258 notify_real ( msg
, no_hide
, 3 );
262 function notify_info ( msg
, no_hide
) {
263 notify_real ( msg
, no_hide
, 4 );
266 function setCookie ( name
, value
, lifetime
, path
, domain
, secure
) {
272 d
. setTime ( d
. getTime () + ( lifetime
* 1000 ));
275 console
. log ( "setCookie: " + name
+ " => " + value
+ ": " + d
);
277 int_setCookie ( name
, value
, d
, path
, domain
, secure
);
281 function int_setCookie ( name
, value
, expires
, path
, domain
, secure
) {
282 document
. cookie
= name
+ "=" + escape ( value
) +
283 (( expires
) ? "; expires=" + expires
. toGMTString () : "" ) +
284 (( path
) ? "; path=" + path
: "" ) +
285 (( domain
) ? "; domain=" + domain
: "" ) +
286 (( secure
) ? "; secure" : "" );
289 function delCookie ( name
, path
, domain
) {
290 if ( getCookie ( name
)) {
291 document
. cookie
= name
+ "=" +
292 (( path
) ? ";path=" + path
: "" ) +
293 (( domain
) ? ";domain=" + domain
: "" ) +
294 ";expires=Thu, 01-Jan-1970 00:00:01 GMT" ;
299 function getCookie ( name
) {
301 var dc
= document
. cookie
;
302 var prefix
= name
+ "=" ;
303 var begin
= dc
. indexOf ( "; " + prefix
);
305 begin
= dc
. indexOf ( prefix
);
306 if ( begin
!= 0 ) return null ;
311 var end
= document
. cookie
. indexOf ( ";" , begin
);
315 return unescape ( dc
. substring ( begin
+ prefix
. length
, end
));
318 function gotoPreferences () {
319 document
. location
. href
= "prefs.php" ;
322 function gotoLogout () {
323 document
. location
. href
= "backend.php?op=logout" ;
326 function gotoMain () {
327 document
. location
. href
= "index.php" ;
330 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
331 * * @author Sundar Dorai-Raj
332 * * Email: sdoraira@vt.edu
333 * * This program is free software; you can redistribute it and/or
334 * * modify it under the terms of the GNU General Public License
335 * * as published by the Free Software Foundation; either version 2
336 * * of the License, or (at your option) any later version,
337 * * provided that any use properly credits the author.
338 * * This program is distributed in the hope that it will be useful,
339 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
340 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
341 * * GNU General Public License for more details at http://www.gnu.org * * */
343 var numbers
= ".0123456789" ;
344 function isNumeric ( x
) {
345 // is x a String or a character?
347 // remove negative sign
349 for ( var j
= 0 ; j
< x
. length
; j
++) {
350 // call isNumeric recursively for each character
351 number
= isNumeric ( x
. substring ( j
, j
+ 1 ));
352 if (! number
) return number
;
357 // if x is number return true
358 if ( numbers
. indexOf ( x
)>= 0 ) return true ;
364 function toggleSelectRowById ( sender
, id
) {
366 return toggleSelectRow ( sender
, row
);
369 function toggleSelectListRow ( sender
) {
370 var row
= sender
. parentNode
;
371 return toggleSelectRow ( sender
, row
);
374 /* this is for dijit Checkbox */
375 function toggleSelectListRow2 ( sender
) {
376 var row
= sender
. domNode
. parentNode
;
377 return toggleSelectRow ( sender
, row
);
380 /* this is for dijit Checkbox */
381 function toggleSelectRow2 ( sender
, row
, is_cdm
) {
385 row
= sender
. domNode
. parentNode
. parentNode
;
387 row
= sender
. domNode
. parentNode
. parentNode
. parentNode
; // oh ffs
389 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
390 row
. addClassName ( 'Selected' );
392 row
. removeClassName ( 'Selected' );
394 if ( typeof updateSelectedPrompt
!= undefined )
395 updateSelectedPrompt ();
399 function toggleSelectRow ( sender
, row
) {
401 if (! row
) row
= sender
. parentNode
. parentNode
;
403 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
404 row
. addClassName ( 'Selected' );
406 row
. removeClassName ( 'Selected' );
408 if ( typeof updateSelectedPrompt
!= undefined )
409 updateSelectedPrompt ();
412 function checkboxToggleElement ( elem
, id
) {
414 Effect
. Appear ( id
, { duration
: 0.5 });
416 Effect
. Fade ( id
, { duration
: 0.5 });
420 function dropboxSelect ( e
, v
) {
421 for ( var i
= 0 ; i
< e
. length
; i
++) {
422 if ( e
[ i
]. value
== v
) {
429 function getURLParam ( param
){
430 return String ( window
. location
. href
). parseQuery ()[ param
];
433 function closeInfoBox ( cleanup
) {
435 dialog
= dijit
. byId ( "infoBox" );
437 if ( dialog
) dialog
. hide ();
440 //exception_error("closeInfoBox", e);
446 function displayDlg ( title
, id
, param
, callback
) {
448 notify_progress ( "Loading, please wait..." , true );
450 var query
= "?op=dlg&method=" +
451 param_escape ( id
) + "¶m=" + param_escape ( param
);
453 new Ajax
. Request ( "backend.php" , {
455 onComplete : function ( transport
) {
456 infobox_callback2 ( transport
, title
);
457 if ( callback
) callback ( transport
);
463 function infobox_callback2 ( transport
, title
) {
467 if ( dijit
. byId ( "infoBox" )) {
468 dialog
= dijit
. byId ( "infoBox" );
471 //console.log("infobox_callback2");
474 var content
= transport
. responseText
;
477 dialog
= new dijit
. Dialog ({
480 style
: "width: 600px" ,
481 onCancel : function () {
484 onExecute : function () {
487 onClose : function () {
492 dialog
. attr ( 'title' , title
);
493 dialog
. attr ( 'content' , content
);
500 exception_error ( "infobox_callback2" , e
);
504 function filterCR ( e
, f
)
509 key
= window
. event
. keyCode
; //IE
511 key
= e
. which
; //firefox
514 if ( typeof f
!= 'undefined' ) {
525 function getInitParam ( key
) {
526 return init_params
[ key
];
529 function setInitParam ( key
, value
) {
530 init_params
[ key
] = value
;
533 function fatalError ( code
, msg
, ext_info
) {
537 window
. location
. href
= "index.php" ;
538 } else if ( code
== 5 ) {
539 window
. location
. href
= "public.php?op=dbupdate" ;
542 if ( msg
== "" ) msg
= "Unknown error" ;
545 if ( ext_info
. responseText
) {
546 ext_info
= ext_info
. responseText
;
550 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
554 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
555 "<p>" + msg
+ "</p>" ;
558 content
= content
+ "<div><b>Additional information:</b></div>" +
559 "<textarea style='width: 100%' readonly= \" 1 \" >" +
560 ext_info
+ "</textarea>" ;
563 var dialog
= new dijit
. Dialog ({
564 title
: "Fatal error" ,
565 style
: "width: 600px" ,
575 exception_error ( "fatalError" , 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
);
613 function explainError ( code
) {
614 return displayDlg ( __ ( "Error explained" ), "explainError" , code
);
617 function loading_set_progress ( p
) {
619 loading_progress
+= p
;
621 if ( dijit
. byId ( "loading_bar" ))
622 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
624 if ( loading_progress
>= 90 )
628 exception_error ( "loading_set_progress" , e
);
632 function remove_splash () {
634 if ( Element
. visible ( "overlay" )) {
635 console
. log ( "about to remove splash, OMG!" );
636 Element
. hide ( "overlay" );
637 console
. log ( "removed splash!" );
641 function transport_error_check ( transport
) {
643 if ( transport
. responseXML
) {
644 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
647 var code
= error
. getAttribute ( "error-code" );
648 var msg
= error
. getAttribute ( "error-msg" );
650 fatalError ( code
, msg
);
656 exception_error ( "check_for_error_xml" , e
);
661 function strip_tags ( s
) {
662 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
665 function truncate_string ( s
, length
) {
666 if (! length
) length
= 30 ;
667 var tmp
= s
. substring ( 0 , length
);
668 if ( s
. length
> length
) tmp
+= "…" ;
672 function hotkey_prefix_timeout () {
675 var date
= new Date ();
676 var ts
= Math
. round ( date
. getTime () / 1000 );
678 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
679 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
680 hotkey_prefix_pressed
= false ;
681 hotkey_prefix
= false ;
682 Element
. hide ( 'cmdline' );
685 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
688 exception_error ( "hotkey_prefix_timeout" , e
);
692 function uploadIconHandler ( rc
) {
696 notify_info ( "Upload complete." );
697 if ( inPreferences ()) {
700 setTimeout ( 'updateFeedList(false, false)' , 50 );
704 notify_error ( "Upload failed: icon is too big." );
707 notify_error ( "Upload failed." );
712 exception_error ( "uploadIconHandler" , e
);
716 function removeFeedIcon ( id
) {
720 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
721 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
725 notify_progress ( "Removing feed icon..." , true );
727 new Ajax
. Request ( "backend.php" , {
729 onComplete : function ( transport
) {
730 notify_info ( "Feed icon removed." );
731 if ( inPreferences ()) {
734 setTimeout ( 'updateFeedList(false, false)' , 50 );
741 exception_error ( "removeFeedIcon" , e
);
745 function uploadFeedIcon () {
749 var file
= $( "icon_file" );
751 if ( file
. value
. length
== 0 ) {
752 alert ( __ ( "Please select an image file to upload." ));
754 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
755 notify_progress ( "Uploading, please wait..." , true );
763 exception_error ( "uploadFeedIcon" , e
);
767 function addLabel ( select
, callback
) {
771 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
773 if ( caption
!= undefined ) {
776 alert ( __ ( "Can't create label: missing caption." ));
780 var query
= "?op=pref-labels&method=add&caption=" +
781 param_escape ( caption
);
784 query
+= "&output=select" ;
786 notify_progress ( "Loading, please wait..." , true );
788 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
790 new Ajax
. Request ( "backend.php" , {
792 onComplete : function ( transport
) {
795 } else if ( inPreferences ()) {
805 exception_error ( "addLabel" , e
);
809 function quickAddFeed () {
811 var query
= "backend.php?op=feeds&method=quickAddFeed" ;
813 // overlapping widgets
814 if ( dijit
. byId ( "batchSubDlg" )) dijit
. byId ( "batchSubDlg" ). destroyRecursive ();
815 if ( dijit
. byId ( "feedAddDlg" )) dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
817 var dialog
= new dijit
. Dialog ({
819 title
: __ ( "Subscribe to Feed" ),
820 style
: "width: 600px" ,
821 execute : function () {
822 if ( this . validate ()) {
823 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
825 var feed_url
= this . attr ( 'value' ). feed
;
827 Element
. show ( "feed_add_spinner" );
829 new Ajax
. Request ( "backend.php" , {
830 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
831 onComplete : function ( transport
) {
835 var reply
= JSON
. parse ( transport
. responseText
);
837 Element
. hide ( "feed_add_spinner" );
838 alert ( __ ( "Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console." ));
839 console
. log ( 'quickAddFeed, backend returned:' + transport
. responseText
);
843 var rc
= reply
[ 'result' ];
846 Element
. hide ( "feed_add_spinner" );
850 switch ( parseInt ( rc
[ 'code' ])) {
853 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
858 alert ( __ ( "Specified URL seems to be invalid." ));
861 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
866 Element
. show ( "fadd_multiple_notify" );
868 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
870 while ( select
. getOptions (). length
> 0 )
871 select
. removeOption ( 0 );
873 select
. addOption ({ value
: '' , label
: __ ( "Expand to select feed" )});
876 for ( var feedUrl
in feeds
) {
877 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
881 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
885 alert ( __ ( "Couldn't download the specified URL: %s" ).
886 replace ( "%s" , rc
[ 'message' ]));
889 alert ( __ ( "XML validation failed: %s" ).
890 replace ( "%s" , rc
[ 'message' ]));
894 alert ( __ ( "You are already subscribed to this feed." ));
899 exception_error ( "subscribeToFeed" , e
, transport
);
910 exception_error ( "quickAddFeed" , e
);
914 function createNewRuleElement ( parentNode
, replaceNode
) {
916 var form
= document
. forms
[ "filter_new_rule_form" ];
918 form
. reg_exp
. value
= form
. reg_exp
. value
. replace ( /(<([^>]+)>)/ig , "" );
920 var query
= "backend.php?op=pref-filters&method=printrulename&rule=" +
921 param_escape ( dojo
. formToJson ( form
));
925 new Ajax
. Request ( "backend.php" , {
927 onComplete : function ( transport
) {
929 var li
= dojo
. create ( "li" );
931 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
933 new dijit
. form
. CheckBox ({
934 onChange : function () {
935 toggleSelectListRow2 ( this ) },
938 dojo
. create ( "input" , { type
: "hidden" ,
940 value
: dojo
. formToJson ( form
) }, li
);
942 dojo
. create ( "span" , {
943 onclick : function () {
944 dijit
. byId ( 'filterEditDlg' ). editRule ( this );
946 innerHTML
: transport
. responseText
}, li
);
949 parentNode
. replaceChild ( li
, replaceNode
);
951 parentNode
. appendChild ( li
);
954 exception_error ( "createNewRuleElement" , e
);
958 exception_error ( "createNewRuleElement" , e
);
962 function createNewActionElement ( parentNode
, replaceNode
) {
964 var form
= document
. forms
[ "filter_new_action_form" ];
966 if ( form
. action_id
. value
== 7 ) {
967 form
. action_param
. value
= form
. action_param_label
. value
;
970 var query
= "backend.php?op=pref-filters&method=printactionname&action=" +
971 param_escape ( dojo
. formToJson ( form
));
975 new Ajax
. Request ( "backend.php" , {
977 onComplete : function ( transport
) {
979 var li
= dojo
. create ( "li" );
981 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
983 new dijit
. form
. CheckBox ({
984 onChange : function () {
985 toggleSelectListRow2 ( this ) },
988 dojo
. create ( "input" , { type
: "hidden" ,
990 value
: dojo
. formToJson ( form
) }, li
);
992 dojo
. create ( "span" , {
993 onclick : function () {
994 dijit
. byId ( 'filterEditDlg' ). editAction ( this );
996 innerHTML
: transport
. responseText
}, li
);
999 parentNode
. replaceChild ( li
, replaceNode
);
1001 parentNode
. appendChild ( li
);
1005 exception_error ( "createNewActionElement" , e
);
1009 exception_error ( "createNewActionElement" , e
);
1014 function addFilterRule ( replaceNode
, ruleStr
) {
1016 if ( dijit
. byId ( "filterNewRuleDlg" ))
1017 dijit
. byId ( "filterNewRuleDlg" ). destroyRecursive ();
1019 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
1020 param_escape ( ruleStr
);
1022 var rule_dlg
= new dijit
. Dialog ({
1023 id
: "filterNewRuleDlg" ,
1024 title
: ruleStr
? __ ( "Edit rule" ) : __ ( "Add rule" ),
1025 style
: "width: 600px" ,
1026 execute : function () {
1027 if ( this . validate ()) {
1028 createNewRuleElement ($( "filterDlg_Matches" ), replaceNode
);
1036 exception_error ( "addFilterRule" , e
);
1040 function addFilterAction ( replaceNode
, actionStr
) {
1042 if ( dijit
. byId ( "filterNewActionDlg" ))
1043 dijit
. byId ( "filterNewActionDlg" ). destroyRecursive ();
1045 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
1046 param_escape ( actionStr
);
1048 var rule_dlg
= new dijit
. Dialog ({
1049 id
: "filterNewActionDlg" ,
1050 title
: actionStr
? __ ( "Edit action" ) : __ ( "Add action" ),
1051 style
: "width: 600px" ,
1052 execute : function () {
1053 if ( this . validate ()) {
1054 createNewActionElement ($( "filterDlg_Actions" ), replaceNode
);
1062 exception_error ( "addFilterAction" , e
);
1066 function quickAddFilter () {
1069 if (! inPreferences ()) {
1070 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
1071 param_escape ( getActiveFeedId ()) + "&is_cat=" +
1072 param_escape ( activeFeedIsCat ());
1074 query
= "backend.php?op=pref-filters&method=newfilter" ;
1079 if ( dijit
. byId ( "feedEditDlg" ))
1080 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1082 if ( dijit
. byId ( "filterEditDlg" ))
1083 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1085 dialog
= new dijit
. Dialog ({
1086 id
: "filterEditDlg" ,
1087 title
: __ ( "Create Filter" ),
1088 style
: "width: 600px" ,
1090 var query
= "backend.php?" + dojo
. formToQuery ( "filter_new_form" ) + "&savemode=test" ;
1092 if ( dijit
. byId ( "filterTestDlg" ))
1093 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
1095 var test_dlg
= new dijit
. Dialog ({
1096 id
: "filterTestDlg" ,
1097 title
: "Test Filter" ,
1098 style
: "width: 600px" ,
1103 selectRules : function ( select
) {
1104 $$( "#filterDlg_Matches input[type=checkbox]" ). each ( function ( e
) {
1107 e
. parentNode
. addClassName ( "Selected" );
1109 e
. parentNode
. removeClassName ( "Selected" );
1112 selectActions : function ( select
) {
1113 $$( "#filterDlg_Actions input[type=checkbox]" ). each ( function ( e
) {
1117 e
. parentNode
. addClassName ( "Selected" );
1119 e
. parentNode
. removeClassName ( "Selected" );
1123 editRule : function ( e
) {
1124 var li
= e
. parentNode
;
1125 var rule
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1126 addFilterRule ( li
, rule
);
1128 editAction : function ( e
) {
1129 var li
= e
. parentNode
;
1130 var action
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1131 addFilterAction ( li
, action
);
1133 addAction : function () { addFilterAction (); },
1134 addRule : function () { addFilterRule (); },
1135 deleteAction : function () {
1136 $$( "#filterDlg_Actions li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1138 deleteRule : function () {
1139 $$( "#filterDlg_Matches li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1141 execute : function () {
1142 if ( this . validate ()) {
1144 var query
= dojo
. formToQuery ( "filter_new_form" );
1148 new Ajax
. Request ( "backend.php" , {
1150 onComplete : function ( transport
) {
1151 if ( inPreferences ()) {
1161 if (! inPreferences ()) {
1162 var selectedText
= getSelectionText ();
1164 var lh
= dojo
. connect ( dialog
, "onLoad" , function (){
1165 dojo
. disconnect ( lh
);
1167 if ( selectedText
!= "" ) {
1169 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1172 var rule
= { reg_exp
: selectedText
, feed_id
: feed_id
, filter_type
: 1 };
1174 addFilterRule ( null , dojo
. toJson ( rule
));
1178 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId ();
1180 new Ajax
. Request ( "backend.php" , {
1182 onComplete : function ( transport
) {
1183 var reply
= JSON
. parse ( transport
. responseText
);
1187 if ( reply
&& reply
) title
= reply
. title
;
1189 if ( title
|| getActiveFeedId () || activeFeedIsCat ()) {
1191 console
. log ( title
+ " " + getActiveFeedId ());
1193 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1196 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1198 addFilterRule ( null , dojo
. toJson ( rule
));
1211 exception_error ( "quickAddFilter" , e
);
1215 function resetPubSub ( feed_id
, title
) {
1217 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1219 if ( title
== undefined || confirm ( msg
)) {
1220 notify_progress ( "Loading, please wait..." );
1222 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1224 new Ajax
. Request ( "backend.php" , {
1226 onComplete : function ( transport
) {
1227 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1228 notify_info ( "Subscription reset." );
1236 function unsubscribeFeed ( feed_id
, title
) {
1238 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1240 if ( title
== undefined || confirm ( msg
)) {
1241 notify_progress ( "Removing feed..." );
1243 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1245 new Ajax
. Request ( "backend.php" , {
1247 onComplete : function ( transport
) {
1249 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1251 if ( inPreferences ()) {
1254 if ( feed_id
== getActiveFeedId ())
1255 setTimeout ( "viewfeed(-5)" , 100 );
1257 if ( feed_id
< 0 ) updateFeedList ();
1267 function backend_sanity_check_callback ( transport
) {
1271 if ( sanity_check_done
) {
1272 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1273 "presence of Firebug or some other disrupting extension. " +
1274 "Please disable it and try again." );
1278 var reply
= JSON
. parse ( transport
. responseText
);
1281 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1285 var error_code
= reply
[ 'error' ][ 'code' ];
1287 if ( error_code
&& error_code
!= 0 ) {
1288 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1291 console
. log ( "sanity check ok" );
1293 var params
= reply
[ 'init-params' ];
1296 console
. log ( 'reading init-params...' );
1300 console
. log ( "IP: " + k
+ " => " + v
);
1302 if ( k
== "label_base_index" ) _label_base_index
= parseInt ( v
);
1305 init_params
= params
;
1307 // PluginHost might not be available on non-index pages
1308 window
. PluginHost
&& PluginHost
. run ( PluginHost
. HOOK_PARAMS_LOADED
, init_params
);
1311 sanity_check_done
= true ;
1313 init_second_stage ();
1316 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1320 /*function has_local_storage() {
1322 return 'sessionStorage' in window && window['sessionStorage'] != null;
1328 function catSelectOnChange ( elem
) {
1330 /* var value = elem[elem.selectedIndex].value;
1331 var def = elem.getAttribute('default');
1333 if (value == "ADD_CAT") {
1336 dropboxSelect(elem, def);
1338 elem.selectedIndex = 0;
1344 exception_error ( "catSelectOnChange" , e
);
1348 function quickAddCat ( elem
) {
1350 var cat
= prompt ( __ ( "Please enter category title:" ));
1354 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1356 notify_progress ( "Loading, please wait..." , true );
1358 new Ajax
. Request ( "backend.php" , {
1360 onComplete : function ( transport
) {
1361 var response
= transport
. responseXML
;
1362 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1363 var options
= select
. getElementsByTagName ( "option" );
1365 dropbox_replace_options ( elem
, options
);
1374 exception_error ( "quickAddCat" , e
);
1378 function genUrlChangeKey ( feed
, is_cat
) {
1381 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1385 notify_progress ( "Trying to change address..." , true );
1387 var query
= "?op=pref-feeds&method=regenFeedKey&id=" + param_escape ( feed
) +
1388 "&is_cat=" + param_escape ( is_cat
);
1390 new Ajax
. Request ( "backend.php" , {
1392 onComplete : function ( transport
) {
1393 var reply
= JSON
. parse ( transport
. responseText
);
1394 var new_link
= reply
. link
;
1396 var e
= $( 'gen_feed_url' );
1400 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1401 "&key=" + new_link
);
1403 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1404 "&key=" + new_link
);
1406 new Effect
. Highlight ( e
);
1411 notify_error ( "Could not change feed URL." );
1416 exception_error ( "genUrlChangeKey" , e
);
1421 function labelSelectOnChange ( elem
) {
1423 /* var value = elem[elem.selectedIndex].value;
1424 var def = elem.getAttribute('default');
1426 if (value == "ADD_LABEL") {
1429 dropboxSelect(elem, def);
1431 elem.selectedIndex = 0;
1433 addLabel(elem, function(transport) {
1437 var response = transport.responseXML;
1438 var select = response.getElementsByTagName("select")[0];
1439 var options = select.getElementsByTagName("option");
1441 dropbox_replace_options(elem, options);
1445 exception_error("addLabel", e);
1451 exception_error ( "labelSelectOnChange" , e
);
1455 function dropbox_replace_options ( elem
, options
) {
1458 while ( elem
. hasChildNodes ())
1459 elem
. removeChild ( elem
. firstChild
);
1463 for ( var i
= 0 ; i
< options
. length
; i
++) {
1464 var text
= options
[ i
]. firstChild
. nodeValue
;
1465 var value
= options
[ i
]. getAttribute ( "value" );
1467 if ( value
== undefined ) value
= text
;
1469 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1471 var option
= new Option ( text
, value
, issel
);
1473 if ( options
[ i
]. getAttribute ( "disabled" ))
1474 option
. setAttribute ( "disabled" , true );
1476 elem
. insert ( option
);
1478 if ( issel
) sel_idx
= i
;
1481 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1482 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1485 exception_error ( "dropbox_replace_options" , e
);
1489 // mode = all, none, invert
1490 function selectTableRows ( id
, mode
) {
1492 var rows
= $( id
). rows
;
1494 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1499 if ( row
. id
&& row
. className
) {
1500 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1501 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1503 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1504 var input
= inputs
[ j
];
1506 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1507 input
. id
. match ( bare_id
)) {
1510 dcb
= dijit
. getEnclosingWidget ( cb
);
1516 var issel
= row
. hasClassName ( "Selected" );
1518 if ( mode
== "all" && ! issel
) {
1519 row
. addClassName ( "Selected" );
1521 if ( dcb
) dcb
. set ( "checked" , true );
1522 } else if ( mode
== "none" && issel
) {
1523 row
. removeClassName ( "Selected" );
1525 if ( dcb
) dcb
. set ( "checked" , false );
1527 } else if ( mode
== "invert" ) {
1530 row
. removeClassName ( "Selected" );
1532 if ( dcb
) dcb
. set ( "checked" , false );
1534 row
. addClassName ( "Selected" );
1536 if ( dcb
) dcb
. set ( "checked" , true );
1544 exception_error ( "selectTableRows" , e
);
1549 function getSelectedTableRowIds ( id
) {
1553 var elem_rows
= $( id
). rows
;
1555 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1556 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1557 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1563 exception_error ( "getSelectedTableRowIds" , e
);
1569 function editFeed ( feed
, event
) {
1572 return alert ( __ ( "You can't edit this kind of feed." ));
1574 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1579 if ( dijit
. byId ( "filterEditDlg" ))
1580 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1582 if ( dijit
. byId ( "feedEditDlg" ))
1583 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1585 dialog
= new dijit
. Dialog ({
1587 title
: __ ( "Edit Feed" ),
1588 style
: "width: 600px" ,
1589 execute : function () {
1590 if ( this . validate ()) {
1591 // console.log(dojo.objectToQuery(this.attr('value')));
1593 notify_progress ( "Saving data..." , true );
1595 new Ajax
. Request ( "backend.php" , {
1596 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1597 onComplete : function ( transport
) {
1609 exception_error ( "editFeed" , e
);
1613 function feedBrowser () {
1615 var query
= "backend.php?op=feeds&method=feedBrowser" ;
1617 if ( dijit
. byId ( "feedAddDlg" ))
1618 dijit
. byId ( "feedAddDlg" ). hide ();
1620 if ( dijit
. byId ( "feedBrowserDlg" ))
1621 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1623 var dialog
= new dijit
. Dialog ({
1624 id
: "feedBrowserDlg" ,
1625 title
: __ ( "More Feeds" ),
1626 style
: "width: 600px" ,
1627 getSelectedFeedIds : function () {
1628 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1629 var selected
= new Array ();
1631 list
. each ( function ( child
) {
1632 var id
= child
. id
. replace ( "FBROW-" , "" );
1634 if ( child
. hasClassName ( 'Selected' )) {
1641 getSelectedFeeds : function () {
1642 var list
= $$( "#browseFeedList li.Selected" );
1643 var selected
= new Array ();
1645 list
. each ( function ( child
) {
1646 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1647 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1649 selected
. push ([ title
, url
]);
1656 subscribe : function () {
1657 var mode
= this . attr ( 'value' ). mode
;
1661 selected
= this . getSelectedFeeds ();
1663 selected
= this . getSelectedFeedIds ();
1665 if ( selected
. length
> 0 ) {
1666 dijit
. byId ( "feedBrowserDlg" ). hide ();
1668 notify_progress ( "Loading, please wait..." , true );
1670 // we use dojo.toJson instead of JSON.stringify because
1671 // it somehow escapes everything TWICE, at least in Chrome 9
1673 var query
= "?op=rpc&method=massSubscribe&payload=" +
1674 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1678 new Ajax
. Request ( "backend.php" , {
1680 onComplete : function ( transport
) {
1686 alert ( __ ( "No feeds are selected." ));
1690 update : function () {
1691 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1693 Element
. show ( 'feed_browser_spinner' );
1695 new Ajax
. Request ( "backend.php" , {
1697 onComplete : function ( transport
) {
1700 Element
. hide ( 'feed_browser_spinner' );
1702 var c
= $( "browseFeedList" );
1704 var reply
= JSON
. parse ( transport
. responseText
);
1706 var r
= reply
[ 'content' ];
1707 var mode
= reply
[ 'mode' ];
1713 dojo
. parser
. parse ( "browseFeedList" );
1716 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1718 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1723 removeFromArchive : function () {
1724 var selected
= this . getSelectedFeedIds ();
1726 if ( selected
. length
> 0 ) {
1728 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1731 Element
. show ( 'feed_browser_spinner' );
1733 var query
= "?op=rpc&method=remarchive&ids=" +
1734 param_escape ( selected
. toString ());;
1736 new Ajax
. Request ( "backend.php" , {
1738 onComplete : function ( transport
) {
1744 execute : function () {
1745 if ( this . validate ()) {
1754 exception_error ( "editFeed" , e
);
1758 function showFeedsWithErrors () {
1760 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors" ;
1762 if ( dijit
. byId ( "errorFeedsDlg" ))
1763 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1765 dialog
= new dijit
. Dialog ({
1766 id
: "errorFeedsDlg" ,
1767 title
: __ ( "Feeds with update errors" ),
1768 style
: "width: 600px" ,
1769 getSelectedFeeds : function () {
1770 return getSelectedTableRowIds ( "prefErrorFeedList" );
1772 removeSelected : function () {
1773 var sel_rows
= this . getSelectedFeeds ();
1775 console
. log ( sel_rows
);
1777 if ( sel_rows
. length
> 0 ) {
1778 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1781 notify_progress ( "Removing selected feeds..." , true );
1783 var query
= "?op=pref-feeds&method=remove&ids=" +
1784 param_escape ( sel_rows
. toString ());
1786 new Ajax
. Request ( "backend.php" , {
1788 onComplete : function ( transport
) {
1796 alert ( __ ( "No feeds are selected." ));
1799 execute : function () {
1800 if ( this . validate ()) {
1808 exception_error ( "showFeedsWithErrors" , e
);
1813 /* new support functions for SelectByTag */
1815 function get_all_tags ( selObj
){
1817 if ( ! selObj
) return "" ;
1820 var len
= selObj
. options
. length
;
1822 for ( var i
= 0 ; i
< len
; i
++){
1823 if ( selObj
. options
[ i
]. selected
) {
1824 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1828 if ( result
. length
> 0 ){
1829 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1835 exception_error ( "get_all_tags" , e
);
1839 function get_radio_checked ( radioObj
) {
1841 if (! radioObj
) return "" ;
1843 var len
= radioObj
. length
;
1845 if ( len
== undefined ){
1846 if ( radioObj
. checked
){
1847 return ( radioObj
. value
);
1853 for ( var i
= 0 ; i
< len
; i
++ ){
1854 if ( radioObj
[ i
]. checked
){
1855 return ( radioObj
[ i
]. value
);
1860 exception_error ( "get_radio_checked" , e
);
1865 function get_timestamp () {
1866 var date
= new Date ();
1867 return Math
. round ( date
. getTime () / 1000 );
1870 function helpDialog ( topic
) {
1872 var query
= "backend.php?op=backend&method=help&topic=" + param_escape ( topic
);
1874 if ( dijit
. byId ( "helpDlg" ))
1875 dijit
. byId ( "helpDlg" ). destroyRecursive ();
1877 dialog
= new dijit
. Dialog ({
1880 style
: "width: 600px" ,
1887 exception_error ( "helpDialog" , e
);
1891 function htmlspecialchars_decode ( string
, quote_style
) {
1892 // http://kevin.vanzonneveld.net
1893 // + original by: Mirek Slugen
1894 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1895 // + bugfixed by: Mateusz "loonquawl" Zalega
1896 // + input by: ReverseSyntax
1897 // + input by: Slawomir Kaniecki
1898 // + input by: Scott Cariss
1899 // + input by: Francois
1900 // + bugfixed by: Onno Marsman
1901 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1902 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1903 // + input by: Ratheous
1904 // + input by: Mailfaker (http://www.weedem.fr/)
1905 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1906 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1907 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1908 // * returns 1: '<p>this -> "</p>'
1909 // * example 2: htmlspecialchars_decode("&quot;");
1910 // * returns 2: '"'
1914 if ( typeof quote_style
=== 'undefined' ) {
1917 string
= string
. toString (). replace ( /</g , '<' ). replace ( />/g , '>' );
1920 'ENT_HTML_QUOTE_SINGLE' : 1 ,
1921 'ENT_HTML_QUOTE_DOUBLE' : 2 ,
1926 if ( quote_style
=== 0 ) {
1929 if ( typeof quote_style
!== 'number' ) { // Allow for a single string or an array of string flags
1930 quote_style
= []. concat ( quote_style
);
1931 for ( i
= 0 ; i
< quote_style
. length
; i
++) {
1932 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1933 if ( OPTS
[ quote_style
[ i
]] === 0 ) {
1935 } else if ( OPTS
[ quote_style
[ i
]]) {
1936 optTemp
= optTemp
| OPTS
[ quote_style
[ i
]];
1939 quote_style
= optTemp
;
1941 if ( quote_style
& OPTS
. ENT_HTML_QUOTE_SINGLE
) {
1942 string
= string
. replace ( /�*39;/g , "'" ); // PHP doesn't currently escape if more than one 0, but it should
1943 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1946 string
= string
. replace ( /"/g , '"' );
1948 // Put this in last place to avoid escape being double-decoded
1949 string
= string
. replace ( /&/g , '&' );
1955 function label_to_feed_id ( label
) {
1956 return _label_base_index
- 1 - Math
. abs ( label
);
1959 function feed_to_label_id ( feed
) {
1960 return _label_base_index
- 1 + Math
. abs ( feed
);
1963 // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
1965 function getSelectionText () {
1968 if ( typeof window
. getSelection
!= "undefined" ) {
1969 var sel
= window
. getSelection ();
1970 if ( sel
. rangeCount
) {
1971 var container
= document
. createElement ( "div" );
1972 for ( var i
= 0 , len
= sel
. rangeCount
; i
< len
; ++ i
) {
1973 container
. appendChild ( sel
. getRangeAt ( i
). cloneContents ());
1975 text
= container
. innerHTML
;
1977 } else if ( typeof document
. selection
!= "undefined" ) {
1978 if ( document
. selection
. type
== "Text" ) {
1979 text
= document
. selection
. createRange (). textText
;
1983 return text
. stripTags ();