]>
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
;
51 ext_info
= JSON
. stringify ( ext_info
);
56 new Ajax
. Request ( "backend.php" , {
57 parameters
: { op
: "rpc" , method
: "log" , logmsg
: msg
},
58 onComplete : function ( transport
) {
59 console
. log ( transport
. responseText
);
63 console
. log ( "Exception while trying to log the error." );
67 msg
+= "<p>" + __ ( "The error will be reported to the configured log destination." ) +
70 var content
= "<div class= \" fatalError \" >" +
71 "<pre>" + msg
+ "</pre>" ;
73 content
+= "<form name= \" exceptionForm \" id= \" exceptionForm \" target= \" _blank \" " +
74 "action= \" http://tt-rss.org/report.php \" method= \" POST \" >" ;
76 content
+= "<textarea style= \" display : none \" name= \" message \" >" + msg
+ "</textarea>" ;
77 content
+= "<textarea style= \" display : none \" name= \" params \" >N/A</textarea>" ;
80 content
+= "<div><b>Additional information:</b></div>" +
81 "<textarea name= \" xinfo \" readonly= \" 1 \" >" + ext_info
+ "</textarea>" ;
84 content
+= "<div><b>Stack trace:</b></div>" +
85 "<textarea name= \" stack \" readonly= \" 1 \" >" + e
. stack
+ "</textarea>" ;
91 content
+= "<div class='dlgButtons'>" ;
93 content
+= "<button dojoType= \" dijit.form.Button \" " +
94 "onclick= \" dijit.byId('exceptionDlg').report() \" >" +
95 __ ( 'Report to tt-rss.org' ) + "</button> " ;
96 content
+= "<button dojoType= \" dijit.form.Button \" " +
97 "onclick= \" dijit.byId('exceptionDlg').hide() \" >" +
98 __ ( 'Close' ) + "</button>" ;
101 if ( dijit
. byId ( "exceptionDlg" ))
102 dijit
. byId ( "exceptionDlg" ). destroyRecursive ();
104 var dialog
= new dijit
. Dialog ({
106 title
: "Unhandled exception" ,
107 style
: "width: 600px" ,
109 if ( confirm ( __ ( "Are you sure to report this exception to tt-rss.org? The report will include information about your web browser and tt-rss configuration. Your IP will be saved in the database." ))) {
111 document
. forms
[ 'exceptionForm' ]. params
. value
= $ H ({
112 browserName
: navigator
. appName
,
113 browserVersion
: navigator
. appVersion
,
114 browserPlatform
: navigator
. platform
,
115 browserCookies
: navigator
. cookieEnabled
,
116 ttrssVersion
: __ttrss_version
,
117 initParams
: JSON
. stringify ( init_params
),
120 document
. forms
[ 'exceptionForm' ]. submit ();
129 console
. log ( "Exception while trying to report an exception. Oh boy." );
131 console
. log ( "Original exception:" );
134 msg
+= " \n\n Additional exception caught while trying to show the error dialog. \n\n " + format_exception_error ( 'exception_error' , ei
);
137 new Ajax
. Request ( "backend.php" , {
138 parameters
: { op
: "rpc" , method
: "log" , logmsg
: msg
},
139 onComplete : function ( transport
) {
140 console
. log ( transport
. responseText
);
144 console
. log ( "Third exception while trying to log the error! Seriously?" );
148 msg
+= " \n\n The error will be reported to the configured log destination." ;
155 function format_exception_error ( location
, e
) {
159 var base_fname
= e
. fileName
. substring ( e
. fileName
. lastIndexOf ( "/" ) + 1 );
161 msg
= "Exception: " + e
. name
+ ", " + e
. message
+
162 " \n Function: " + location
+ "()" +
163 " \n Location: " + base_fname
+ ":" + e
. lineNumber
;
165 } else if ( e
. description
) {
166 msg
= "Exception: " + e
. description
+ " \n Function: " + location
+ "()" ;
168 msg
= "Exception: " + e
+ " \n Function: " + location
+ "()" ;
171 console
. error ( "EXCEPTION: " + msg
);
176 function param_escape ( arg
) {
177 if ( typeof encodeURIComponent
!= 'undefined' )
178 return encodeURIComponent ( arg
);
183 function param_unescape ( arg
) {
184 if ( typeof decodeURIComponent
!= 'undefined' )
185 return decodeURIComponent ( arg
);
187 return unescape ( arg
);
191 function hide_notify () {
192 Element
. hide ( 'notify' );
195 function notify_real ( msg
, no_hide
, n_type
) {
201 if ( notify_hide_timerid
) {
202 window
. clearTimeout ( notify_hide_timerid
);
206 if ( Element
. visible ( n
)) {
207 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 0 );
223 msg
= "<span class= \" msg \" > " + __ ( msg
) + "</span>" ;
226 n
. className
= "notify" ;
227 } else if ( n_type
== 2 ) {
228 n
. className
= "notify progress" ;
229 msg
= "<span><img src='images/indicator_white.gif'></span>" + msg
;
231 } else if ( n_type
== 3 ) {
232 n
. className
= "notify error" ;
233 msg
= "<span><img src='images/alert.png'></span>" + msg
;
234 } else if ( n_type
== 4 ) {
235 n
. className
= "notify info" ;
236 msg
= "<span><img src='images/information.png'></span>" + msg
;
239 msg
+= " <span><img src= \" images/cross.png \" class= \" close \" title= \" " +
240 __ ( "Click to close" ) + " \" onclick= \" notify('') \" ></span>" ;
242 // msg = "<img src='images/live_com_loading.gif'> " + msg;
247 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 5 * 1000 );
251 function notify ( msg
, no_hide
) {
252 notify_real ( msg
, no_hide
, 1 );
255 function notify_progress ( msg
, no_hide
) {
256 notify_real ( msg
, no_hide
, 2 );
259 function notify_error ( msg
, no_hide
) {
260 notify_real ( msg
, no_hide
, 3 );
264 function notify_info ( msg
, no_hide
) {
265 notify_real ( msg
, no_hide
, 4 );
268 function setCookie ( name
, value
, lifetime
, path
, domain
, secure
) {
274 d
. setTime ( d
. getTime () + ( lifetime
* 1000 ));
277 console
. log ( "setCookie: " + name
+ " => " + value
+ ": " + d
);
279 int_setCookie ( name
, value
, d
, path
, domain
, secure
);
283 function int_setCookie ( name
, value
, expires
, path
, domain
, secure
) {
284 document
. cookie
= name
+ "=" + escape ( value
) +
285 (( expires
) ? "; expires=" + expires
. toGMTString () : "" ) +
286 (( path
) ? "; path=" + path
: "" ) +
287 (( domain
) ? "; domain=" + domain
: "" ) +
288 (( secure
) ? "; secure" : "" );
291 function delCookie ( name
, path
, domain
) {
292 if ( getCookie ( name
)) {
293 document
. cookie
= name
+ "=" +
294 (( path
) ? ";path=" + path
: "" ) +
295 (( domain
) ? ";domain=" + domain
: "" ) +
296 ";expires=Thu, 01-Jan-1970 00:00:01 GMT" ;
301 function getCookie ( name
) {
303 var dc
= document
. cookie
;
304 var prefix
= name
+ "=" ;
305 var begin
= dc
. indexOf ( "; " + prefix
);
307 begin
= dc
. indexOf ( prefix
);
308 if ( begin
!= 0 ) return null ;
313 var end
= document
. cookie
. indexOf ( ";" , begin
);
317 return unescape ( dc
. substring ( begin
+ prefix
. length
, end
));
320 function gotoPreferences () {
321 document
. location
. href
= "prefs.php" ;
324 function gotoLogout () {
325 document
. location
. href
= "backend.php?op=logout" ;
328 function gotoMain () {
329 document
. location
. href
= "index.php" ;
332 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
333 * * @author Sundar Dorai-Raj
334 * * Email: sdoraira@vt.edu
335 * * This program is free software; you can redistribute it and/or
336 * * modify it under the terms of the GNU General Public License
337 * * as published by the Free Software Foundation; either version 2
338 * * of the License, or (at your option) any later version,
339 * * provided that any use properly credits the author.
340 * * This program is distributed in the hope that it will be useful,
341 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
342 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
343 * * GNU General Public License for more details at http://www.gnu.org * * */
345 var numbers
= ".0123456789" ;
346 function isNumeric ( x
) {
347 // is x a String or a character?
349 // remove negative sign
351 for ( var j
= 0 ; j
< x
. length
; j
++) {
352 // call isNumeric recursively for each character
353 number
= isNumeric ( x
. substring ( j
, j
+ 1 ));
354 if (! number
) return number
;
359 // if x is number return true
360 if ( numbers
. indexOf ( x
)>= 0 ) return true ;
366 function toggleSelectRowById ( sender
, id
) {
368 return toggleSelectRow ( sender
, row
);
371 function toggleSelectListRow ( sender
) {
372 var row
= sender
. parentNode
;
373 return toggleSelectRow ( sender
, row
);
376 /* this is for dijit Checkbox */
377 function toggleSelectListRow2 ( sender
) {
378 var row
= sender
. domNode
. parentNode
;
379 return toggleSelectRow ( sender
, row
);
382 /* this is for dijit Checkbox */
383 function toggleSelectRow2 ( sender
, row
, is_cdm
) {
387 row
= sender
. domNode
. parentNode
. parentNode
;
389 row
= sender
. domNode
. parentNode
. parentNode
. parentNode
; // oh ffs
391 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
392 row
. addClassName ( 'Selected' );
394 row
. removeClassName ( 'Selected' );
396 if ( typeof updateSelectedPrompt
!= undefined )
397 updateSelectedPrompt ();
401 function toggleSelectRow ( sender
, row
) {
403 if (! row
) row
= sender
. parentNode
. parentNode
;
405 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
406 row
. addClassName ( 'Selected' );
408 row
. removeClassName ( 'Selected' );
410 if ( typeof updateSelectedPrompt
!= undefined )
411 updateSelectedPrompt ();
414 function checkboxToggleElement ( elem
, id
) {
416 Effect
. Appear ( id
, { duration
: 0.5 });
418 Effect
. Fade ( id
, { duration
: 0.5 });
422 function dropboxSelect ( e
, v
) {
423 for ( var i
= 0 ; i
< e
. length
; i
++) {
424 if ( e
[ i
]. value
== v
) {
431 function getURLParam ( param
){
432 return String ( window
. location
. href
). parseQuery ()[ param
];
435 function closeInfoBox ( cleanup
) {
437 dialog
= dijit
. byId ( "infoBox" );
439 if ( dialog
) dialog
. hide ();
442 //exception_error("closeInfoBox", e);
448 function displayDlg ( title
, id
, param
, callback
) {
450 notify_progress ( "Loading, please wait..." , true );
452 var query
= "?op=dlg&method=" +
453 param_escape ( id
) + "¶m=" + param_escape ( param
);
455 new Ajax
. Request ( "backend.php" , {
457 onComplete : function ( transport
) {
458 infobox_callback2 ( transport
, title
);
459 if ( callback
) callback ( transport
);
465 function infobox_callback2 ( transport
, title
) {
469 if ( dijit
. byId ( "infoBox" )) {
470 dialog
= dijit
. byId ( "infoBox" );
473 //console.log("infobox_callback2");
476 var content
= transport
. responseText
;
479 dialog
= new dijit
. Dialog ({
482 style
: "width: 600px" ,
483 onCancel : function () {
486 onExecute : function () {
489 onClose : function () {
494 dialog
. attr ( 'title' , title
);
495 dialog
. attr ( 'content' , content
);
502 exception_error ( "infobox_callback2" , e
);
506 function filterCR ( e
, f
)
511 key
= window
. event
. keyCode
; //IE
513 key
= e
. which
; //firefox
516 if ( typeof f
!= 'undefined' ) {
527 function getInitParam ( key
) {
528 return init_params
[ key
];
531 function setInitParam ( key
, value
) {
532 init_params
[ key
] = value
;
535 function fatalError ( code
, msg
, ext_info
) {
539 window
. location
. href
= "index.php" ;
540 } else if ( code
== 5 ) {
541 window
. location
. href
= "public.php?op=dbupdate" ;
544 if ( msg
== "" ) msg
= "Unknown error" ;
547 if ( ext_info
. responseText
) {
548 ext_info
= ext_info
. responseText
;
552 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
556 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
557 "<p>" + msg
+ "</p>" ;
560 content
= content
+ "<div><b>Additional information:</b></div>" +
561 "<textarea style='width: 100%' readonly= \" 1 \" >" +
562 ext_info
+ "</textarea>" ;
565 var dialog
= new dijit
. Dialog ({
566 title
: "Fatal error" ,
567 style
: "width: 600px" ,
577 exception_error ( "fatalError" , e
);
581 function filterDlgCheckAction ( sender
) {
585 var action
= sender
. value
;
587 var action_param
= $( "filterDlg_paramBox" );
590 console
. log ( "filterDlgCheckAction: can't find action param box!" );
594 // if selected action supports parameters, enable params field
595 if ( action
== 4 || action
== 6 || action
== 7 ) {
596 new Effect
. Appear ( action_param
, { duration
: 0.5 });
598 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
599 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
601 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
602 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
605 Element
. hide ( action_param
);
609 exception_error ( "filterDlgCheckAction" , e
);
615 function explainError ( code
) {
616 return displayDlg ( __ ( "Error explained" ), "explainError" , code
);
619 function loading_set_progress ( p
) {
621 loading_progress
+= p
;
623 if ( dijit
. byId ( "loading_bar" ))
624 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
626 if ( loading_progress
>= 90 )
630 exception_error ( "loading_set_progress" , e
);
634 function remove_splash () {
636 if ( Element
. visible ( "overlay" )) {
637 console
. log ( "about to remove splash, OMG!" );
638 Element
. hide ( "overlay" );
639 console
. log ( "removed splash!" );
643 function transport_error_check ( transport
) {
645 if ( transport
. responseXML
) {
646 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
649 var code
= error
. getAttribute ( "error-code" );
650 var msg
= error
. getAttribute ( "error-msg" );
652 fatalError ( code
, msg
);
658 exception_error ( "check_for_error_xml" , e
);
663 function strip_tags ( s
) {
664 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
667 function truncate_string ( s
, length
) {
668 if (! length
) length
= 30 ;
669 var tmp
= s
. substring ( 0 , length
);
670 if ( s
. length
> length
) tmp
+= "…" ;
674 function hotkey_prefix_timeout () {
677 var date
= new Date ();
678 var ts
= Math
. round ( date
. getTime () / 1000 );
680 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
681 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
682 hotkey_prefix_pressed
= false ;
683 hotkey_prefix
= false ;
684 Element
. hide ( 'cmdline' );
687 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
690 exception_error ( "hotkey_prefix_timeout" , e
);
694 function uploadIconHandler ( rc
) {
698 notify_info ( "Upload complete." );
699 if ( inPreferences ()) {
702 setTimeout ( 'updateFeedList(false, false)' , 50 );
706 notify_error ( "Upload failed: icon is too big." );
709 notify_error ( "Upload failed." );
714 exception_error ( "uploadIconHandler" , e
);
718 function removeFeedIcon ( id
) {
722 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
723 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
727 notify_progress ( "Removing feed icon..." , true );
729 new Ajax
. Request ( "backend.php" , {
731 onComplete : function ( transport
) {
732 notify_info ( "Feed icon removed." );
733 if ( inPreferences ()) {
736 setTimeout ( 'updateFeedList(false, false)' , 50 );
743 exception_error ( "removeFeedIcon" , e
);
747 function uploadFeedIcon () {
751 var file
= $( "icon_file" );
753 if ( file
. value
. length
== 0 ) {
754 alert ( __ ( "Please select an image file to upload." ));
756 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
757 notify_progress ( "Uploading, please wait..." , true );
765 exception_error ( "uploadFeedIcon" , e
);
769 function addLabel ( select
, callback
) {
773 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
775 if ( caption
!= undefined ) {
778 alert ( __ ( "Can't create label: missing caption." ));
782 var query
= "?op=pref-labels&method=add&caption=" +
783 param_escape ( caption
);
786 query
+= "&output=select" ;
788 notify_progress ( "Loading, please wait..." , true );
790 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
792 new Ajax
. Request ( "backend.php" , {
794 onComplete : function ( transport
) {
797 } else if ( inPreferences ()) {
807 exception_error ( "addLabel" , e
);
811 function quickAddFeed () {
813 var query
= "backend.php?op=feeds&method=quickAddFeed" ;
815 // overlapping widgets
816 if ( dijit
. byId ( "batchSubDlg" )) dijit
. byId ( "batchSubDlg" ). destroyRecursive ();
817 if ( dijit
. byId ( "feedAddDlg" )) dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
819 var dialog
= new dijit
. Dialog ({
821 title
: __ ( "Subscribe to Feed" ),
822 style
: "width: 600px" ,
823 execute : function () {
824 if ( this . validate ()) {
825 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
827 var feed_url
= this . attr ( 'value' ). feed
;
829 Element
. show ( "feed_add_spinner" );
831 new Ajax
. Request ( "backend.php" , {
832 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
833 onComplete : function ( transport
) {
837 var reply
= JSON
. parse ( transport
. responseText
);
839 Element
. hide ( "feed_add_spinner" );
840 alert ( __ ( "Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console." ));
841 console
. log ( 'quickAddFeed, backend returned:' + transport
. responseText
);
845 var rc
= reply
[ 'result' ];
848 Element
. hide ( "feed_add_spinner" );
852 switch ( parseInt ( rc
[ 'code' ])) {
855 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
860 alert ( __ ( "Specified URL seems to be invalid." ));
863 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
868 Element
. show ( "fadd_multiple_notify" );
870 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
872 while ( select
. getOptions (). length
> 0 )
873 select
. removeOption ( 0 );
875 select
. addOption ({ value
: '' , label
: __ ( "Expand to select feed" )});
878 for ( var feedUrl
in feeds
) {
879 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
883 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
887 alert ( __ ( "Couldn't download the specified URL: %s" ).
888 replace ( "%s" , rc
[ 'message' ]));
891 alert ( __ ( "XML validation failed: %s" ).
892 replace ( "%s" , rc
[ 'message' ]));
896 alert ( __ ( "You are already subscribed to this feed." ));
901 exception_error ( "subscribeToFeed" , e
, transport
);
912 exception_error ( "quickAddFeed" , e
);
916 function createNewRuleElement ( parentNode
, replaceNode
) {
918 var form
= document
. forms
[ "filter_new_rule_form" ];
920 form
. reg_exp
. value
= form
. reg_exp
. value
. replace ( /(<([^>]+)>)/ig , "" );
922 var query
= "backend.php?op=pref-filters&method=printrulename&rule=" +
923 param_escape ( dojo
. formToJson ( form
));
927 new Ajax
. Request ( "backend.php" , {
929 onComplete : function ( transport
) {
931 var li
= dojo
. create ( "li" );
933 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
935 new dijit
. form
. CheckBox ({
936 onChange : function () {
937 toggleSelectListRow2 ( this ) },
940 dojo
. create ( "input" , { type
: "hidden" ,
942 value
: dojo
. formToJson ( form
) }, li
);
944 dojo
. create ( "span" , {
945 onclick : function () {
946 dijit
. byId ( 'filterEditDlg' ). editRule ( this );
948 innerHTML
: transport
. responseText
}, li
);
951 parentNode
. replaceChild ( li
, replaceNode
);
953 parentNode
. appendChild ( li
);
956 exception_error ( "createNewRuleElement" , e
);
960 exception_error ( "createNewRuleElement" , e
);
964 function createNewActionElement ( parentNode
, replaceNode
) {
966 var form
= document
. forms
[ "filter_new_action_form" ];
968 if ( form
. action_id
. value
== 7 ) {
969 form
. action_param
. value
= form
. action_param_label
. value
;
972 var query
= "backend.php?op=pref-filters&method=printactionname&action=" +
973 param_escape ( dojo
. formToJson ( form
));
977 new Ajax
. Request ( "backend.php" , {
979 onComplete : function ( transport
) {
981 var li
= dojo
. create ( "li" );
983 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
985 new dijit
. form
. CheckBox ({
986 onChange : function () {
987 toggleSelectListRow2 ( this ) },
990 dojo
. create ( "input" , { type
: "hidden" ,
992 value
: dojo
. formToJson ( form
) }, li
);
994 dojo
. create ( "span" , {
995 onclick : function () {
996 dijit
. byId ( 'filterEditDlg' ). editAction ( this );
998 innerHTML
: transport
. responseText
}, li
);
1001 parentNode
. replaceChild ( li
, replaceNode
);
1003 parentNode
. appendChild ( li
);
1007 exception_error ( "createNewActionElement" , e
);
1011 exception_error ( "createNewActionElement" , e
);
1016 function addFilterRule ( replaceNode
, ruleStr
) {
1018 if ( dijit
. byId ( "filterNewRuleDlg" ))
1019 dijit
. byId ( "filterNewRuleDlg" ). destroyRecursive ();
1021 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
1022 param_escape ( ruleStr
);
1024 var rule_dlg
= new dijit
. Dialog ({
1025 id
: "filterNewRuleDlg" ,
1026 title
: ruleStr
? __ ( "Edit rule" ) : __ ( "Add rule" ),
1027 style
: "width: 600px" ,
1028 execute : function () {
1029 if ( this . validate ()) {
1030 createNewRuleElement ($( "filterDlg_Matches" ), replaceNode
);
1038 exception_error ( "addFilterRule" , e
);
1042 function addFilterAction ( replaceNode
, actionStr
) {
1044 if ( dijit
. byId ( "filterNewActionDlg" ))
1045 dijit
. byId ( "filterNewActionDlg" ). destroyRecursive ();
1047 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
1048 param_escape ( actionStr
);
1050 var rule_dlg
= new dijit
. Dialog ({
1051 id
: "filterNewActionDlg" ,
1052 title
: actionStr
? __ ( "Edit action" ) : __ ( "Add action" ),
1053 style
: "width: 600px" ,
1054 execute : function () {
1055 if ( this . validate ()) {
1056 createNewActionElement ($( "filterDlg_Actions" ), replaceNode
);
1064 exception_error ( "addFilterAction" , e
);
1068 function quickAddFilter () {
1071 if (! inPreferences ()) {
1072 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
1073 param_escape ( getActiveFeedId ()) + "&is_cat=" +
1074 param_escape ( activeFeedIsCat ());
1076 query
= "backend.php?op=pref-filters&method=newfilter" ;
1081 if ( dijit
. byId ( "feedEditDlg" ))
1082 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1084 if ( dijit
. byId ( "filterEditDlg" ))
1085 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1087 dialog
= new dijit
. Dialog ({
1088 id
: "filterEditDlg" ,
1089 title
: __ ( "Create Filter" ),
1090 style
: "width: 600px" ,
1092 var query
= "backend.php?" + dojo
. formToQuery ( "filter_new_form" ) + "&savemode=test" ;
1094 if ( dijit
. byId ( "filterTestDlg" ))
1095 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
1097 var test_dlg
= new dijit
. Dialog ({
1098 id
: "filterTestDlg" ,
1099 title
: "Test Filter" ,
1100 style
: "width: 600px" ,
1105 selectRules : function ( select
) {
1106 $$( "#filterDlg_Matches input[type=checkbox]" ). each ( function ( e
) {
1109 e
. parentNode
. addClassName ( "Selected" );
1111 e
. parentNode
. removeClassName ( "Selected" );
1114 selectActions : function ( select
) {
1115 $$( "#filterDlg_Actions input[type=checkbox]" ). each ( function ( e
) {
1119 e
. parentNode
. addClassName ( "Selected" );
1121 e
. parentNode
. removeClassName ( "Selected" );
1125 editRule : function ( e
) {
1126 var li
= e
. parentNode
;
1127 var rule
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1128 addFilterRule ( li
, rule
);
1130 editAction : function ( e
) {
1131 var li
= e
. parentNode
;
1132 var action
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1133 addFilterAction ( li
, action
);
1135 addAction : function () { addFilterAction (); },
1136 addRule : function () { addFilterRule (); },
1137 deleteAction : function () {
1138 $$( "#filterDlg_Actions li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1140 deleteRule : function () {
1141 $$( "#filterDlg_Matches li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1143 execute : function () {
1144 if ( this . validate ()) {
1146 var query
= dojo
. formToQuery ( "filter_new_form" );
1150 new Ajax
. Request ( "backend.php" , {
1152 onComplete : function ( transport
) {
1153 if ( inPreferences ()) {
1163 if (! inPreferences ()) {
1164 var selectedText
= getSelectionText ();
1166 var lh
= dojo
. connect ( dialog
, "onLoad" , function (){
1167 dojo
. disconnect ( lh
);
1169 if ( selectedText
!= "" ) {
1171 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1174 var rule
= { reg_exp
: selectedText
, feed_id
: feed_id
, filter_type
: 1 };
1176 addFilterRule ( null , dojo
. toJson ( rule
));
1180 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId ();
1182 new Ajax
. Request ( "backend.php" , {
1184 onComplete : function ( transport
) {
1185 var reply
= JSON
. parse ( transport
. responseText
);
1189 if ( reply
&& reply
) title
= reply
. title
;
1191 if ( title
|| getActiveFeedId () || activeFeedIsCat ()) {
1193 console
. log ( title
+ " " + getActiveFeedId ());
1195 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1198 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1200 addFilterRule ( null , dojo
. toJson ( rule
));
1213 exception_error ( "quickAddFilter" , e
);
1217 function resetPubSub ( feed_id
, title
) {
1219 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1221 if ( title
== undefined || confirm ( msg
)) {
1222 notify_progress ( "Loading, please wait..." );
1224 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1226 new Ajax
. Request ( "backend.php" , {
1228 onComplete : function ( transport
) {
1229 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1230 notify_info ( "Subscription reset." );
1238 function unsubscribeFeed ( feed_id
, title
) {
1240 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1242 if ( title
== undefined || confirm ( msg
)) {
1243 notify_progress ( "Removing feed..." );
1245 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1247 new Ajax
. Request ( "backend.php" , {
1249 onComplete : function ( transport
) {
1251 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1253 if ( inPreferences ()) {
1256 if ( feed_id
== getActiveFeedId ())
1257 setTimeout ( "viewfeed(-5)" , 100 );
1259 if ( feed_id
< 0 ) updateFeedList ();
1269 function backend_sanity_check_callback ( transport
) {
1273 if ( sanity_check_done
) {
1274 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1275 "presence of Firebug or some other disrupting extension. " +
1276 "Please disable it and try again." );
1280 var reply
= JSON
. parse ( transport
. responseText
);
1283 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1287 var error_code
= reply
[ 'error' ][ 'code' ];
1289 if ( error_code
&& error_code
!= 0 ) {
1290 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1293 console
. log ( "sanity check ok" );
1295 var params
= reply
[ 'init-params' ];
1298 console
. log ( 'reading init-params...' );
1302 console
. log ( "IP: " + k
+ " => " + v
);
1304 if ( k
== "label_base_index" ) _label_base_index
= parseInt ( v
);
1307 init_params
= params
;
1309 // PluginHost might not be available on non-index pages
1310 window
. PluginHost
&& PluginHost
. run ( PluginHost
. HOOK_PARAMS_LOADED
, init_params
);
1313 sanity_check_done
= true ;
1315 init_second_stage ();
1318 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1322 /*function has_local_storage() {
1324 return 'sessionStorage' in window && window['sessionStorage'] != null;
1330 function catSelectOnChange ( elem
) {
1332 /* var value = elem[elem.selectedIndex].value;
1333 var def = elem.getAttribute('default');
1335 if (value == "ADD_CAT") {
1338 dropboxSelect(elem, def);
1340 elem.selectedIndex = 0;
1346 exception_error ( "catSelectOnChange" , e
);
1350 function quickAddCat ( elem
) {
1352 var cat
= prompt ( __ ( "Please enter category title:" ));
1356 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1358 notify_progress ( "Loading, please wait..." , true );
1360 new Ajax
. Request ( "backend.php" , {
1362 onComplete : function ( transport
) {
1363 var response
= transport
. responseXML
;
1364 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1365 var options
= select
. getElementsByTagName ( "option" );
1367 dropbox_replace_options ( elem
, options
);
1376 exception_error ( "quickAddCat" , e
);
1380 function genUrlChangeKey ( feed
, is_cat
) {
1383 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1387 notify_progress ( "Trying to change address..." , true );
1389 var query
= "?op=pref-feeds&method=regenFeedKey&id=" + param_escape ( feed
) +
1390 "&is_cat=" + param_escape ( is_cat
);
1392 new Ajax
. Request ( "backend.php" , {
1394 onComplete : function ( transport
) {
1395 var reply
= JSON
. parse ( transport
. responseText
);
1396 var new_link
= reply
. link
;
1398 var e
= $( 'gen_feed_url' );
1402 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1403 "&key=" + new_link
);
1405 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1406 "&key=" + new_link
);
1408 new Effect
. Highlight ( e
);
1413 notify_error ( "Could not change feed URL." );
1418 exception_error ( "genUrlChangeKey" , e
);
1423 function labelSelectOnChange ( elem
) {
1425 /* var value = elem[elem.selectedIndex].value;
1426 var def = elem.getAttribute('default');
1428 if (value == "ADD_LABEL") {
1431 dropboxSelect(elem, def);
1433 elem.selectedIndex = 0;
1435 addLabel(elem, function(transport) {
1439 var response = transport.responseXML;
1440 var select = response.getElementsByTagName("select")[0];
1441 var options = select.getElementsByTagName("option");
1443 dropbox_replace_options(elem, options);
1447 exception_error("addLabel", e);
1453 exception_error ( "labelSelectOnChange" , e
);
1457 function dropbox_replace_options ( elem
, options
) {
1460 while ( elem
. hasChildNodes ())
1461 elem
. removeChild ( elem
. firstChild
);
1465 for ( var i
= 0 ; i
< options
. length
; i
++) {
1466 var text
= options
[ i
]. firstChild
. nodeValue
;
1467 var value
= options
[ i
]. getAttribute ( "value" );
1469 if ( value
== undefined ) value
= text
;
1471 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1473 var option
= new Option ( text
, value
, issel
);
1475 if ( options
[ i
]. getAttribute ( "disabled" ))
1476 option
. setAttribute ( "disabled" , true );
1478 elem
. insert ( option
);
1480 if ( issel
) sel_idx
= i
;
1483 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1484 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1487 exception_error ( "dropbox_replace_options" , e
);
1491 // mode = all, none, invert
1492 function selectTableRows ( id
, mode
) {
1494 var rows
= $( id
). rows
;
1496 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1501 if ( row
. id
&& row
. className
) {
1502 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1503 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1505 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1506 var input
= inputs
[ j
];
1508 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1509 input
. id
. match ( bare_id
)) {
1512 dcb
= dijit
. getEnclosingWidget ( cb
);
1518 var issel
= row
. hasClassName ( "Selected" );
1520 if ( mode
== "all" && ! issel
) {
1521 row
. addClassName ( "Selected" );
1523 if ( dcb
) dcb
. set ( "checked" , true );
1524 } else if ( mode
== "none" && issel
) {
1525 row
. removeClassName ( "Selected" );
1527 if ( dcb
) dcb
. set ( "checked" , false );
1529 } else if ( mode
== "invert" ) {
1532 row
. removeClassName ( "Selected" );
1534 if ( dcb
) dcb
. set ( "checked" , false );
1536 row
. addClassName ( "Selected" );
1538 if ( dcb
) dcb
. set ( "checked" , true );
1546 exception_error ( "selectTableRows" , e
);
1551 function getSelectedTableRowIds ( id
) {
1555 var elem_rows
= $( id
). rows
;
1557 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1558 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1559 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1565 exception_error ( "getSelectedTableRowIds" , e
);
1571 function editFeed ( feed
, event
) {
1574 return alert ( __ ( "You can't edit this kind of feed." ));
1576 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1581 if ( dijit
. byId ( "filterEditDlg" ))
1582 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1584 if ( dijit
. byId ( "feedEditDlg" ))
1585 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1587 dialog
= new dijit
. Dialog ({
1589 title
: __ ( "Edit Feed" ),
1590 style
: "width: 600px" ,
1591 execute : function () {
1592 if ( this . validate ()) {
1593 // console.log(dojo.objectToQuery(this.attr('value')));
1595 notify_progress ( "Saving data..." , true );
1597 new Ajax
. Request ( "backend.php" , {
1598 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1599 onComplete : function ( transport
) {
1611 exception_error ( "editFeed" , e
);
1615 function feedBrowser () {
1617 var query
= "backend.php?op=feeds&method=feedBrowser" ;
1619 if ( dijit
. byId ( "feedAddDlg" ))
1620 dijit
. byId ( "feedAddDlg" ). hide ();
1622 if ( dijit
. byId ( "feedBrowserDlg" ))
1623 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1625 var dialog
= new dijit
. Dialog ({
1626 id
: "feedBrowserDlg" ,
1627 title
: __ ( "More Feeds" ),
1628 style
: "width: 600px" ,
1629 getSelectedFeedIds : function () {
1630 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1631 var selected
= new Array ();
1633 list
. each ( function ( child
) {
1634 var id
= child
. id
. replace ( "FBROW-" , "" );
1636 if ( child
. hasClassName ( 'Selected' )) {
1643 getSelectedFeeds : function () {
1644 var list
= $$( "#browseFeedList li.Selected" );
1645 var selected
= new Array ();
1647 list
. each ( function ( child
) {
1648 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1649 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1651 selected
. push ([ title
, url
]);
1658 subscribe : function () {
1659 var mode
= this . attr ( 'value' ). mode
;
1663 selected
= this . getSelectedFeeds ();
1665 selected
= this . getSelectedFeedIds ();
1667 if ( selected
. length
> 0 ) {
1668 dijit
. byId ( "feedBrowserDlg" ). hide ();
1670 notify_progress ( "Loading, please wait..." , true );
1672 // we use dojo.toJson instead of JSON.stringify because
1673 // it somehow escapes everything TWICE, at least in Chrome 9
1675 var query
= "?op=rpc&method=massSubscribe&payload=" +
1676 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1680 new Ajax
. Request ( "backend.php" , {
1682 onComplete : function ( transport
) {
1688 alert ( __ ( "No feeds are selected." ));
1692 update : function () {
1693 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1695 Element
. show ( 'feed_browser_spinner' );
1697 new Ajax
. Request ( "backend.php" , {
1699 onComplete : function ( transport
) {
1702 Element
. hide ( 'feed_browser_spinner' );
1704 var c
= $( "browseFeedList" );
1706 var reply
= JSON
. parse ( transport
. responseText
);
1708 var r
= reply
[ 'content' ];
1709 var mode
= reply
[ 'mode' ];
1715 dojo
. parser
. parse ( "browseFeedList" );
1718 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1720 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1725 removeFromArchive : function () {
1726 var selected
= this . getSelectedFeedIds ();
1728 if ( selected
. length
> 0 ) {
1730 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1733 Element
. show ( 'feed_browser_spinner' );
1735 var query
= "?op=rpc&method=remarchive&ids=" +
1736 param_escape ( selected
. toString ());;
1738 new Ajax
. Request ( "backend.php" , {
1740 onComplete : function ( transport
) {
1746 execute : function () {
1747 if ( this . validate ()) {
1756 exception_error ( "editFeed" , e
);
1760 function showFeedsWithErrors () {
1762 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors" ;
1764 if ( dijit
. byId ( "errorFeedsDlg" ))
1765 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1767 dialog
= new dijit
. Dialog ({
1768 id
: "errorFeedsDlg" ,
1769 title
: __ ( "Feeds with update errors" ),
1770 style
: "width: 600px" ,
1771 getSelectedFeeds : function () {
1772 return getSelectedTableRowIds ( "prefErrorFeedList" );
1774 removeSelected : function () {
1775 var sel_rows
= this . getSelectedFeeds ();
1777 console
. log ( sel_rows
);
1779 if ( sel_rows
. length
> 0 ) {
1780 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1783 notify_progress ( "Removing selected feeds..." , true );
1785 var query
= "?op=pref-feeds&method=remove&ids=" +
1786 param_escape ( sel_rows
. toString ());
1788 new Ajax
. Request ( "backend.php" , {
1790 onComplete : function ( transport
) {
1798 alert ( __ ( "No feeds are selected." ));
1801 execute : function () {
1802 if ( this . validate ()) {
1810 exception_error ( "showFeedsWithErrors" , e
);
1815 /* new support functions for SelectByTag */
1817 function get_all_tags ( selObj
){
1819 if ( ! selObj
) return "" ;
1822 var len
= selObj
. options
. length
;
1824 for ( var i
= 0 ; i
< len
; i
++){
1825 if ( selObj
. options
[ i
]. selected
) {
1826 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1830 if ( result
. length
> 0 ){
1831 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1837 exception_error ( "get_all_tags" , e
);
1841 function get_radio_checked ( radioObj
) {
1843 if (! radioObj
) return "" ;
1845 var len
= radioObj
. length
;
1847 if ( len
== undefined ){
1848 if ( radioObj
. checked
){
1849 return ( radioObj
. value
);
1855 for ( var i
= 0 ; i
< len
; i
++ ){
1856 if ( radioObj
[ i
]. checked
){
1857 return ( radioObj
[ i
]. value
);
1862 exception_error ( "get_radio_checked" , e
);
1867 function get_timestamp () {
1868 var date
= new Date ();
1869 return Math
. round ( date
. getTime () / 1000 );
1872 function helpDialog ( topic
) {
1874 var query
= "backend.php?op=backend&method=help&topic=" + param_escape ( topic
);
1876 if ( dijit
. byId ( "helpDlg" ))
1877 dijit
. byId ( "helpDlg" ). destroyRecursive ();
1879 dialog
= new dijit
. Dialog ({
1882 style
: "width: 600px" ,
1889 exception_error ( "helpDialog" , e
);
1893 function htmlspecialchars_decode ( string
, quote_style
) {
1894 // http://kevin.vanzonneveld.net
1895 // + original by: Mirek Slugen
1896 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1897 // + bugfixed by: Mateusz "loonquawl" Zalega
1898 // + input by: ReverseSyntax
1899 // + input by: Slawomir Kaniecki
1900 // + input by: Scott Cariss
1901 // + input by: Francois
1902 // + bugfixed by: Onno Marsman
1903 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1904 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1905 // + input by: Ratheous
1906 // + input by: Mailfaker (http://www.weedem.fr/)
1907 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1908 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1909 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1910 // * returns 1: '<p>this -> "</p>'
1911 // * example 2: htmlspecialchars_decode("&quot;");
1912 // * returns 2: '"'
1916 if ( typeof quote_style
=== 'undefined' ) {
1919 string
= string
. toString (). replace ( /</g , '<' ). replace ( />/g , '>' );
1922 'ENT_HTML_QUOTE_SINGLE' : 1 ,
1923 'ENT_HTML_QUOTE_DOUBLE' : 2 ,
1928 if ( quote_style
=== 0 ) {
1931 if ( typeof quote_style
!== 'number' ) { // Allow for a single string or an array of string flags
1932 quote_style
= []. concat ( quote_style
);
1933 for ( i
= 0 ; i
< quote_style
. length
; i
++) {
1934 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1935 if ( OPTS
[ quote_style
[ i
]] === 0 ) {
1937 } else if ( OPTS
[ quote_style
[ i
]]) {
1938 optTemp
= optTemp
| OPTS
[ quote_style
[ i
]];
1941 quote_style
= optTemp
;
1943 if ( quote_style
& OPTS
. ENT_HTML_QUOTE_SINGLE
) {
1944 string
= string
. replace ( /�*39;/g , "'" ); // PHP doesn't currently escape if more than one 0, but it should
1945 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1948 string
= string
. replace ( /"/g , '"' );
1950 // Put this in last place to avoid escape being double-decoded
1951 string
= string
. replace ( /&/g , '&' );
1957 function label_to_feed_id ( label
) {
1958 return _label_base_index
- 1 - Math
. abs ( label
);
1961 function feed_to_label_id ( feed
) {
1962 return _label_base_index
- 1 + Math
. abs ( feed
);
1965 // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
1967 function getSelectionText () {
1970 if ( typeof window
. getSelection
!= "undefined" ) {
1971 var sel
= window
. getSelection ();
1972 if ( sel
. rangeCount
) {
1973 var container
= document
. createElement ( "div" );
1974 for ( var i
= 0 , len
= sel
. rangeCount
; i
< len
; ++ i
) {
1975 container
. appendChild ( sel
. getRangeAt ( i
). cloneContents ());
1977 text
= container
. innerHTML
;
1979 } else if ( typeof document
. selection
!= "undefined" ) {
1980 if ( document
. selection
. type
== "Text" ) {
1981 text
= document
. selection
. createRange (). textText
;
1985 return text
. stripTags ();