2010-06-08 11:19:41 -04:00
2011-11-04 18:12:28 -07:00
( function ( $ ) {
2010-06-08 11:19:41 -04:00
NEWSBLUR . Reader = function ( ) {
var self = this ;
2010-06-14 13:17:38 -04:00
// ===========
// = Globals =
// ===========
2010-06-08 11:19:41 -04:00
this . model = NEWSBLUR . AssetModel . reader ( ) ;
this . story _view = 'page' ;
2010-06-14 13:17:38 -04:00
this . $s = {
2010-06-14 14:00:46 -04:00
$body : $ ( 'body' ) ,
2010-06-14 13:17:38 -04:00
$feed _list : $ ( '#feed_list' ) ,
$story _titles : $ ( '#story_titles' ) ,
2010-06-15 18:29:13 -04:00
$content _pane : $ ( '.content-pane' ) ,
2011-01-31 20:50:33 -05:00
$story _taskbar : $ ( '#story_taskbar' ) ,
2010-06-14 13:17:38 -04:00
$story _pane : $ ( '#story_pane .NB-story-pane-container' ) ,
$feed _view : $ ( '.NB-feed-story-view' ) ,
2011-01-24 23:50:38 -05:00
$feed _stories : $ ( '.NB-feed-stories' ) ,
2010-12-06 10:41:24 -05:00
$feed _iframe : $ ( '.NB-feed-iframe' ) ,
$story _iframe : $ ( '.NB-story-iframe' ) ,
2010-06-14 13:17:38 -04:00
$intelligence _slider : $ ( '.NB-intelligence-slider' ) ,
2010-08-09 20:44:36 -04:00
$mouse _indicator : $ ( '#mouse-indicator' ) ,
2010-08-11 11:43:48 -04:00
$feed _link _loader : $ ( '#NB-feeds-list-loader' ) ,
2010-11-22 10:44:52 -05:00
$feeds _progress : $ ( '#NB-progress' ) ,
2011-03-15 23:42:27 -04:00
$dashboard : $ ( '.NB-feeds-header-dashboard' ) ,
2010-12-10 15:26:50 -05:00
$river _header : $ ( '.NB-feeds-header-river' ) ,
2011-03-15 10:21:47 -04:00
$starred _header : $ ( '.NB-feeds-header-starred' ) ,
$tryfeed _header : $ ( '.NB-feeds-header-tryfeed' ) ,
2011-01-19 08:54:59 -05:00
$taskbar : $ ( '.taskbar_nav' ) ,
2011-03-15 23:42:27 -04:00
$feed _floater : $ ( '.NB-feed-story-view-floater' )
2010-06-14 13:17:38 -04:00
} ;
2010-06-08 11:19:41 -04:00
this . flags = {
'feed_view_images_loaded' : { } ,
2010-08-11 11:43:48 -04:00
'bouncing_callout' : false ,
2011-02-01 00:23:44 -05:00
'has_unfetched_feeds' : false ,
'count_unreads_after_import_working' : false ,
2011-04-05 19:24:12 -04:00
'import_from_google_reader_working' : false ,
'favicons_downloaded' : false
2010-06-08 11:19:41 -04:00
} ;
this . locks = { } ;
2010-08-11 11:43:48 -04:00
this . counts = {
2010-06-30 12:17:22 -04:00
'feature_page' : 0 ,
2010-08-11 11:43:48 -04:00
'unfetched_feeds' : 0 ,
2011-03-09 09:48:24 -05:00
'fetched_feeds' : 0 ,
2011-03-13 16:24:49 -04:00
'page_fill_outs' : 0 ,
'recommended_feed_page' : 0
2010-08-11 11:43:48 -04:00
} ;
this . cache = {
2010-06-08 11:19:41 -04:00
'iframe_stories' : { } ,
'feed_view_stories' : { } ,
'iframe_story_positions' : { } ,
'feed_view_story_positions' : { } ,
'iframe_story_positions_keys' : [ ] ,
'feed_view_story_positions_keys' : [ ] ,
2010-12-12 22:52:15 -05:00
'river_feeds_with_unreads' : [ ] ,
2011-03-16 18:29:56 -04:00
'mouse_position_y' : parseInt ( this . model . preference ( 'lock_mouse_indicator' ) , 10 ) ,
'$feed_in_feed_list' : { } ,
'$feed_counts_in_feed_list' : { }
2010-06-08 11:19:41 -04:00
} ;
2011-09-27 22:16:09 -07:00
this . layout = { } ;
2011-04-12 11:02:02 -04:00
this . constants = {
FEED _REFRESH _INTERVAL : ( 1000 * 60 ) * 1 , // 1 minute
2011-04-24 20:48:16 -04:00
FILL _OUT _PAGES : 8 ,
RIVER _STORIES _FOR _STANDARD _ACCOUNT : 12
2011-04-12 11:02:02 -04:00
} ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
// ==================
// = Event Handlers =
// ==================
2011-04-30 23:33:36 -04:00
$ ( window ) . bind ( 'resize.reader' , _ . throttle ( $ . rescope ( this . resize _window , this ) , 1000 ) ) ;
2010-06-14 14:00:46 -04:00
this . $s . $body . bind ( 'dblclick.reader' , $ . rescope ( this . handle _dblclicks , this ) ) ;
this . $s . $body . bind ( 'click.reader' , $ . rescope ( this . handle _clicks , this ) ) ;
2011-01-12 22:45:52 -05:00
this . $s . $body . live ( 'contextmenu.reader' , $ . rescope ( this . handle _rightclicks , this ) ) ;
2010-06-14 14:00:46 -04:00
this . $s . $story _titles . scroll ( $ . rescope ( this . handle _scroll _story _titles , this ) ) ;
2011-01-24 23:50:38 -05:00
this . $s . $feed _stories . scroll ( $ . rescope ( this . handle _scroll _feed _view , this ) ) ;
this . $s . $feed _stories . bind ( 'mousemove' , $ . rescope ( this . handle _mousemove _feed _view , this ) ) ;
2010-06-14 14:00:46 -04:00
this . handle _keystrokes ( ) ;
2010-06-14 13:17:38 -04:00
// ==================
// = Initialization =
// ==================
2011-03-04 12:27:31 -05:00
this . load _javascript _elements _on _page ( ) ;
2010-12-06 10:41:24 -05:00
this . unload _feed _iframe ( ) ;
this . unload _story _iframe ( ) ;
2010-11-24 15:01:35 -05:00
this . apply _resizable _layout ( ) ;
2011-01-25 09:17:15 -05:00
this . add _body _classes ( ) ;
2010-08-17 20:59:47 -04:00
if ( NEWSBLUR . Flags [ 'start_import_from_google_reader' ] ) {
this . start _import _from _google _reader ( ) ;
} else {
this . load _feeds ( ) ;
}
2010-06-08 11:19:41 -04:00
this . cornerize _buttons ( ) ;
this . setup _feed _page _iframe _load ( ) ;
this . load _intelligence _slider ( ) ;
2010-06-11 16:55:07 -04:00
this . handle _mouse _indicator _hover ( ) ;
2010-06-11 20:55:38 -04:00
this . position _mouse _indicator ( ) ;
2010-07-05 16:05:54 -04:00
this . handle _login _and _signup _forms ( ) ;
2010-10-06 18:44:53 -04:00
this . iframe _buster _buster ( ) ;
2010-11-25 15:34:06 -05:00
this . apply _story _styling ( ) ;
2011-02-22 19:11:29 -05:00
this . apply _tipsy _titles ( ) ;
2011-03-02 12:05:58 -05:00
this . load _recommended _feeds ( ) ;
2011-04-24 22:47:20 -04:00
this . setup _dashboard _graphs ( ) ;
2011-12-18 18:03:40 -08:00
this . setup _feedback _table ( ) ;
2011-03-29 21:56:15 -04:00
this . setup _howitworks _hovers ( ) ;
2011-09-21 21:51:25 -07:00
this . load _url _next _param ( ) ;
2010-06-08 11:19:41 -04:00
} ;
NEWSBLUR . Reader . prototype = {
2010-06-14 13:17:38 -04:00
2010-06-08 11:19:41 -04:00
// ========
// = Page =
// ========
2011-03-04 12:27:31 -05:00
load _javascript _elements _on _page : function ( ) {
$ ( '.NB-javascript' ) . removeClass ( 'NB-javascript' ) ;
} ,
2011-02-22 19:11:29 -05:00
resize _window : function ( ) {
var flag ;
var view = this . story _view ;
if ( this . flags [ 'page_view_showing_feed_view' ] ) {
view = 'feed' ;
flag = 'page' ;
} else if ( this . flags [ 'feed_view_showing_story_view' ] ) {
view = 'story' ;
flag = 'story' ;
}
2011-09-29 22:12:46 -07:00
this . flags . scrolling _by _selecting _story _title = true ;
clearTimeout ( this . locks . scrolling ) ;
this . locks . scrolling = _ . delay ( _ . bind ( function ( ) {
this . flags . scrolling _by _selecting _story _title = false ;
} , this ) , 1000 ) ;
2011-02-22 19:11:29 -05:00
this . switch _taskbar _view ( view , flag ) ;
2011-09-27 22:16:09 -07:00
this . check _story _titles _last _story ( ) ;
2011-09-29 22:12:46 -07:00
this . flags . fetch _story _locations _in _feed _view = this . flags . fetch _story _locations _in _feed _view ||
_ . throttle ( _ . bind ( this . fetch _story _locations _in _feed _view , this ) , 2000 ) ;
this . flags . fetch _story _locations _in _feed _view ( ) ;
2011-02-22 19:11:29 -05:00
} ,
2011-09-29 09:53:55 -07:00
apply _resizable _layout : function ( refresh ) {
2011-09-26 10:27:21 -07:00
var story _anchor = this . model . preference ( 'story_pane_anchor' ) ;
2011-09-29 22:12:46 -07:00
var right _pane _hidden = ! $ ( '.right-pane' ) . is ( ':visible' ) ;
2010-06-08 11:19:41 -04:00
2011-09-29 09:53:55 -07:00
if ( refresh ) {
this . layout . contentLayout && this . layout . contentLayout . destroy ( ) ;
this . layout . rightLayout && this . layout . rightLayout . destroy ( ) ;
2011-09-29 22:12:46 -07:00
this . layout . leftCenterLayout && this . layout . leftCenterLayout . destroy ( ) ;
this . layout . leftLayout && this . layout . leftLayout . destroy ( ) ;
this . layout . outerLayout && this . layout . outerLayout . destroy ( ) ;
2011-09-29 09:53:55 -07:00
var feed _stories _bin = $ . make ( 'div' ) . append ( this . $s . $feed _stories . children ( ) ) ;
var story _titles _bin = $ . make ( 'div' ) . append ( this . $s . $story _titles . children ( ) ) ;
}
2010-06-08 11:19:41 -04:00
2011-09-29 09:53:55 -07:00
$ ( '.right-pane' ) . removeClass ( 'NB-story-pane-west' )
. removeClass ( 'NB-story-pane-north' )
. removeClass ( 'NB-story-pane-south' )
. addClass ( 'NB-story-pane-' + story _anchor ) ;
2011-09-27 22:16:09 -07:00
this . layout . outerLayout = this . $s . $body . layout ( {
2010-06-13 18:57:20 -04:00
closable : true ,
center _ _paneSelector : ".right-pane" ,
west _ _paneSelector : ".left-pane" ,
2010-08-13 19:50:56 -04:00
west _ _size : this . model . preference ( 'feed_pane_size' ) ,
west _ _onresize _end : $ . rescope ( this . save _feed _pane _size , this ) ,
2010-06-13 18:57:20 -04:00
spacing _open : 4 ,
2011-03-09 18:23:55 -05:00
resizerDragOpacity : 0.6 ,
2011-09-26 10:27:21 -07:00
resizeWhileDragging : true ,
2011-03-09 18:23:55 -05:00
enableCursorHotkey : false
2010-06-13 18:57:20 -04:00
} ) ;
2011-09-27 22:16:09 -07:00
this . layout . leftLayout = $ ( '.left-pane' ) . layout ( {
2010-06-13 18:57:20 -04:00
closable : false ,
2011-09-26 10:27:21 -07:00
resizeWhileDragging : true ,
2010-12-10 09:32:06 -05:00
fxName : "scale" ,
fxSettings : { duration : 500 , easing : "easeInOutQuint" } ,
2011-03-13 16:24:49 -04:00
north _ _paneSelector : ".left-north" ,
north _ _size : 18 ,
north _ _resizeable : false ,
north _ _spacing _open : 0 ,
2010-06-13 18:57:20 -04:00
center _ _paneSelector : ".left-center" ,
center _ _resizable : false ,
south _ _paneSelector : ".left-south" ,
2010-08-11 23:02:17 -04:00
south _ _size : 31 ,
2010-06-13 18:57:20 -04:00
south _ _resizable : false ,
2011-03-09 18:23:55 -05:00
south _ _spacing _open : 0 ,
enableCursorHotkey : false
2010-06-13 18:57:20 -04:00
} ) ;
2010-11-22 10:44:52 -05:00
2011-09-27 22:16:09 -07:00
this . layout . leftCenterLayout = $ ( '.left-center' ) . layout ( {
2010-11-22 10:44:52 -05:00
closable : false ,
slidable : false ,
2011-09-26 10:27:21 -07:00
resizeWhileDragging : true ,
2010-11-22 10:44:52 -05:00
center _ _paneSelector : ".left-center-content" ,
center _ _resizable : false ,
south _ _paneSelector : ".left-center-footer" ,
2010-11-24 13:16:10 -05:00
south _ _size : 'auto' ,
2010-11-22 10:44:52 -05:00
south _ _resizable : false ,
south _ _slidable : true ,
south _ _spacing _open : 0 ,
south _ _spacing _closed : 0 ,
south _ _closable : true ,
south _ _initClosed : true ,
2010-12-10 09:32:06 -05:00
fxName : "slide" ,
fxSpeed : 1000 ,
2011-03-09 18:23:55 -05:00
fxSettings : { duration : 1000 , easing : "easeInOutQuint" } ,
enableCursorHotkey : false
2010-11-22 10:44:52 -05:00
} ) ;
2011-09-26 10:27:21 -07:00
var rightLayoutOptions = {
resizeWhileDragging : true ,
2010-06-13 18:57:20 -04:00
center _ _paneSelector : ".content-pane" ,
2011-09-27 22:16:09 -07:00
spacing _open : story _anchor == 'west' ? 4 : 10 ,
2011-03-09 18:23:55 -05:00
resizerDragOpacity : 0.6 ,
enableCursorHotkey : false
2011-09-26 10:27:21 -07:00
} ;
rightLayoutOptions [ story _anchor + '__paneSelector' ] = '.right-north' ;
rightLayoutOptions [ story _anchor + '__size' ] = this . model . preference ( 'story_titles_pane_size' ) ;
rightLayoutOptions [ story _anchor + '__onresize_end' ] = $ . rescope ( this . save _story _titles _pane _size , this ) ;
2011-09-27 22:16:09 -07:00
this . layout . rightLayout = $ ( '.right-pane' ) . layout ( rightLayoutOptions ) ;
2010-06-08 11:19:41 -04:00
2011-09-26 10:27:21 -07:00
var contentLayoutOptions = {
resizeWhileDragging : true ,
2010-06-13 18:57:20 -04:00
center _ _paneSelector : ".content-center" ,
spacing _open : 0 ,
2011-03-09 18:23:55 -05:00
resizerDragOpacity : 0.6 ,
enableCursorHotkey : false
2011-09-26 10:27:21 -07:00
} ;
2011-09-27 22:16:09 -07:00
if ( story _anchor == 'west' ) {
contentLayoutOptions [ 'north__paneSelector' ] = '.content-north' ;
contentLayoutOptions [ 'north__size' ] = 30 ;
} else {
contentLayoutOptions [ story _anchor + '__paneSelector' ] = '.content-north' ;
contentLayoutOptions [ story _anchor + '__size' ] = 30 ;
}
this . layout . contentLayout = this . $s . $content _pane . layout ( contentLayoutOptions ) ;
2011-09-29 22:12:46 -07:00
2011-09-29 09:53:55 -07:00
if ( ! refresh ) {
$ ( '.right-pane' ) . hide ( ) ;
} else {
this . $s . $feed _stories . append ( feed _stories _bin . children ( ) ) ;
this . $s . $story _titles . append ( story _titles _bin . children ( ) ) ;
this . resize _window ( ) ;
2011-09-29 22:12:46 -07:00
if ( right _pane _hidden ) {
$ ( '.right-pane' ) . hide ( ) ;
}
2011-09-29 09:53:55 -07:00
}
2010-06-08 11:19:41 -04:00
} ,
2011-02-22 19:11:29 -05:00
apply _tipsy _titles : function ( ) {
2011-05-01 20:22:54 -04:00
if ( this . model . preference ( 'show_tooltips' ) ) {
$ ( '.NB-taskbar-sidebar-toggle-close' ) . tipsy ( {
gravity : 'se' ,
delayIn : 375
} ) ;
$ ( '.NB-taskbar-sidebar-toggle-open' ) . tipsy ( {
gravity : 'sw' ,
delayIn : 375
} ) ;
$ ( '.NB-task-add' ) . tipsy ( {
gravity : 'sw' ,
delayIn : 375
} ) ;
$ ( '.NB-task-manage' ) . tipsy ( {
gravity : 's' ,
delayIn : 375
} ) ;
} else {
$ ( '.NB-taskbar-sidebar-toggle-close' ) . tipsy ( 'disable' ) ;
$ ( '.NB-taskbar-sidebar-toggle-open' ) . tipsy ( 'disable' ) ;
$ ( '.NB-task-add' ) . tipsy ( 'disable' ) ;
$ ( '.NB-task-manage' ) . tipsy ( 'disable' ) ;
}
2011-02-22 19:11:29 -05:00
} ,
2010-08-13 19:50:56 -04:00
save _feed _pane _size : function ( w , pane , $pane , state , options , name ) {
2011-03-14 21:44:04 -04:00
var feed _pane _size = state . size ;
2011-05-09 18:30:11 -04:00
$ ( '#NB-splash' ) . css ( 'left' , feed _pane _size ) ;
2011-09-26 10:27:21 -07:00
this . flags . set _feed _pane _size = this . flags . set _feed _pane _size || _ . debounce ( _ . bind ( function ( ) {
2011-09-27 22:16:09 -07:00
var feed _pane _size = this . layout . outerLayout . state . west . size ;
2011-09-26 10:27:21 -07:00
this . model . preference ( 'feed_pane_size' , feed _pane _size ) ;
this . flags . set _feed _pane _size = null ;
} , this ) , 1000 ) ;
this . flags . set _feed _pane _size ( ) ;
2010-08-13 19:50:56 -04:00
} ,
save _story _titles _pane _size : function ( w , pane , $pane , state , options , name ) {
2011-09-29 22:12:46 -07:00
this . flags . scrolling _by _selecting _story _title = true ;
clearTimeout ( this . locks . scrolling ) ;
2011-09-27 22:16:09 -07:00
var offset = 0 ;
if ( this . story _view == 'feed' ) {
offset = this . $s . $feed _iframe . width ( ) ;
} else if ( this . story _view == 'story' ) {
offset = 2 * this . $s . $feed _iframe . width ( ) ;
}
this . $s . $story _pane . css ( 'left' , - 1 * offset ) ;
2011-09-29 22:12:46 -07:00
2011-09-27 22:16:09 -07:00
this . flags . set _story _titles _size = this . flags . set _story _titles _size || _ . debounce ( _ . bind ( function ( ) {
var story _titles _size = this . layout . rightLayout . state [ this . model . preference ( 'story_pane_anchor' ) ] . size ;
this . model . preference ( 'story_titles_pane_size' , story _titles _size ) ;
this . flags . set _story _titles _size = null ;
2011-09-29 22:12:46 -07:00
this . locks . scrolling = _ . delay ( _ . bind ( function ( ) {
this . flags . scrolling _by _selecting _story _title = false ;
} , this ) , 100 ) ;
2011-09-27 22:16:09 -07:00
} , this ) , 1000 ) ;
this . flags . set _story _titles _size ( ) ;
2011-09-29 22:12:46 -07:00
this . flags . resize _window = this . flags . resize _window || _ . debounce ( _ . bind ( function ( ) {
this . resize _window ( ) ;
this . flags . resize _window = null ;
} , this ) , 10 ) ;
this . flags . resize _window ( ) ;
2010-08-13 19:50:56 -04:00
} ,
2010-06-08 11:19:41 -04:00
cornerize _buttons : function ( ) {
$ ( '.button' ) . corner ( ) ;
} ,
2011-01-25 09:17:15 -05:00
add _body _classes : function ( ) {
2011-03-14 21:44:04 -04:00
this . $s . $body . toggleClass ( 'NB-is-premium' , NEWSBLUR . Globals . is _premium ) ;
this . $s . $body . toggleClass ( 'NB-is-anonymous' , NEWSBLUR . Globals . is _anonymous ) ;
2011-01-25 09:17:15 -05:00
this . $s . $body . toggleClass ( 'NB-is-authenticated' , NEWSBLUR . Globals . is _authenticated ) ;
} ,
2010-06-08 11:19:41 -04:00
hide _splash _page : function ( ) {
2010-08-13 19:21:29 -04:00
var self = this ;
2010-06-08 11:19:41 -04:00
$ ( '.right-pane' ) . show ( ) ;
$ ( '#NB-splash' ) . hide ( ) ;
2011-04-02 19:41:22 -04:00
$ ( '.NB-splash-info' ) . hide ( ) ;
2010-06-08 11:19:41 -04:00
$ ( '#NB-splash-overlay' ) . hide ( ) ;
2010-08-13 19:21:29 -04:00
this . $s . $body . layout ( ) . resizeAll ( ) ;
2011-03-15 23:42:27 -04:00
this . $s . $dashboard . addClass ( 'NB-active' ) ;
2010-06-08 11:19:41 -04:00
if ( NEWSBLUR . Globals . is _anonymous ) {
this . setup _ftux _signup _callout ( ) ;
}
} ,
show _splash _page : function ( ) {
2010-11-22 10:44:52 -05:00
this . reset _feed ( ) ;
2010-12-06 10:41:24 -05:00
this . unload _feed _iframe ( ) ;
this . unload _story _iframe ( ) ;
2010-11-22 10:44:52 -05:00
this . mark _feed _as _selected ( null , null ) ;
2010-06-08 11:19:41 -04:00
$ ( '.right-pane' ) . hide ( ) ;
2011-04-02 19:41:22 -04:00
$ ( '.NB-splash-info' ) . show ( ) ;
2010-06-08 11:19:41 -04:00
$ ( '#NB-splash' ) . show ( ) ;
$ ( '#NB-splash-overlay' ) . show ( ) ;
2011-03-15 23:42:27 -04:00
this . $s . $dashboard . removeClass ( 'NB-active' ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-08-13 19:21:29 -04:00
iframe _buster _buster : function ( ) {
var self = this ;
var prevent _bust = 0 ;
2010-10-06 18:44:53 -04:00
window . onbeforeunload = function ( ) {
2010-10-06 19:12:20 -04:00
prevent _bust ++ ;
2010-10-06 18:44:53 -04:00
} ;
2011-01-11 19:33:55 -05:00
clearInterval ( this . locks . iframe _buster _buster ) ;
this . locks . iframe _buster _buster = setInterval ( function ( ) {
2010-08-13 19:21:29 -04:00
if ( prevent _bust > 0 ) {
prevent _bust -= 2 ;
2011-04-01 22:05:56 -04:00
if ( ! self . flags [ 'iframe_view_loaded' ] &&
! self . flags [ 'iframe_view_not_busting' ] &&
_ . contains ( [ 'page' , 'story' ] , self . story _view ) &&
self . active _feed ) {
2010-10-06 19:12:20 -04:00
$ ( '.task_view_feed' ) . click ( ) ;
$ ( '.NB-feed-frame' ) . attr ( 'src' , '' ) ;
2010-10-06 19:26:04 -04:00
window . top . location = '/reader/buster' ;
2010-10-06 19:12:20 -04:00
}
2010-08-13 19:21:29 -04:00
}
} , 1 ) ;
} ,
2011-02-01 03:35:11 +01:00
2011-02-25 13:07:08 -05:00
add _url _from _querystring : function ( ) {
2011-03-11 20:05:41 -05:00
if ( this . flags [ 'added_url_from_querystring' ] ) return ;
2011-02-25 13:07:08 -05:00
var url = $ . getQueryString ( 'url' ) ;
2011-03-11 20:05:41 -05:00
this . flags [ 'added_url_from_querystring' ] = true ;
2011-02-25 13:07:08 -05:00
if ( url ) {
this . open _add _feed _modal ( { url : url } ) ;
2011-02-01 03:35:11 +01:00
}
} ,
2010-08-13 19:21:29 -04:00
2011-09-21 21:51:25 -07:00
load _url _next _param : function ( ) {
2011-09-21 17:49:26 -07:00
var next = $ . getQueryString ( 'next' ) ;
if ( next == 'optout' ) {
this . open _account _modal ( { 'animate_email' : true } ) ;
2011-09-21 21:51:25 -07:00
} else if ( next == 'goodies' ) {
this . open _goodies _modal ( ) ;
2011-09-22 09:23:42 -07:00
} else if ( next == 'password' ) {
this . open _account _modal ( { 'change_password' : true } ) ;
2011-09-21 17:49:26 -07:00
}
2011-09-23 18:13:16 -07:00
if ( window . history . replaceState ) {
window . history . replaceState ( { } , null , '/' ) ;
}
2011-09-21 17:49:26 -07:00
} ,
2011-01-31 19:51:39 -05:00
animate _progress _bar : function ( $bar , seconds , percentage ) {
var self = this ;
percentage = percentage || 0 ;
2011-01-31 20:50:33 -05:00
seconds = parseFloat ( Math . max ( 1 , parseInt ( seconds , 10 ) ) , 10 ) ;
2011-01-31 19:51:39 -05:00
if ( percentage > 90 ) {
time = seconds / 5 ;
} else if ( percentage > 80 ) {
time = seconds / 12 ;
} else if ( percentage > 70 ) {
time = seconds / 30 ;
} else if ( percentage > 60 ) {
2011-02-01 00:23:44 -05:00
time = seconds / 80 ;
2011-01-31 19:51:39 -05:00
} else if ( percentage > 50 ) {
2011-02-01 00:23:44 -05:00
time = seconds / 120 ;
2011-01-31 19:51:39 -05:00
} else if ( percentage > 40 ) {
2011-02-01 00:23:44 -05:00
time = seconds / 160 ;
2011-01-31 19:51:39 -05:00
} else if ( percentage > 30 ) {
2011-02-01 00:23:44 -05:00
time = seconds / 200 ;
2011-01-31 19:51:39 -05:00
} else if ( percentage > 20 ) {
2011-02-01 00:23:44 -05:00
time = seconds / 300 ;
2011-01-31 19:51:39 -05:00
} else if ( percentage > 10 ) {
2011-02-01 00:23:44 -05:00
time = seconds / 400 ;
2011-01-31 19:51:39 -05:00
} else {
2011-02-01 00:23:44 -05:00
time = seconds / 500 ;
2011-01-31 19:51:39 -05:00
}
if ( percentage <= 100 ) {
this . locks [ 'animate_progress_bar' ] = setTimeout ( function ( ) {
2011-02-01 00:23:44 -05:00
percentage += 1 ;
$bar . progressbar ( { value : percentage } ) ;
self . animate _progress _bar ( $bar , seconds , percentage ) ;
2011-01-31 19:51:39 -05:00
} , time * 1000 ) ;
}
} ,
2010-06-14 13:17:38 -04:00
// =======================
// = Getters and Finders =
// =======================
2010-12-08 20:53:45 -05:00
get _current _story _from _story _titles : function ( $feed _view _stories ) {
2010-06-14 13:17:38 -04:00
var $feed _view = this . $s . $feed _view ;
2010-12-08 20:53:45 -05:00
var $feed _view _stories = $feed _view _stories || $ ( ".NB-feed-story" , $feed _view ) ;
2010-06-14 13:17:38 -04:00
var story = this . active _story ;
var $current _story ;
if ( story ) {
$feed _view _stories . each ( function ( ) {
if ( $ ( this ) . data ( 'story' ) == story . id ) {
$current _story = $ ( this ) ;
return false ;
}
} ) ;
}
return $current _story ;
} ,
2011-10-30 22:15:04 -07:00
get _current _story _id : function ( ) {
var $story = this . get _current _story _from _story _titles ( ) ;
return $story && $story . data ( 'story_id' ) ;
} ,
2010-06-14 13:17:38 -04:00
find _feed _in _feed _list : function ( feed _id ) {
2011-06-07 16:08:59 -04:00
if ( _ . contains ( this . cache . $feed _in _feed _list , feed _id ) ) {
return this . cache . $feed _in _feed _list [ feed _id ] ;
}
2010-06-14 13:17:38 -04:00
var $feed _list = this . $s . $feed _list ;
var $feeds = $ ( [ ] ) ;
$ ( '.feed' , $feed _list ) . each ( function ( ) {
2011-03-30 09:30:45 -04:00
if ( parseInt ( $ ( this ) . attr ( 'data-id' ) , 10 ) == feed _id ) {
2010-06-14 13:17:38 -04:00
$feeds . push ( $ ( this ) . get ( 0 ) ) ;
}
} ) ;
2011-06-07 16:08:59 -04:00
this . cache . $feed _in _feed _list [ feed _id ] = $feeds ;
2010-06-14 13:17:38 -04:00
return $feeds ;
} ,
2010-09-14 20:49:28 -04:00
find _folder _in _feed _list : function ( folder _name ) {
var $feed _list = this . $s . $feed _list ;
var $folders = $ ( [ ] ) ;
$ ( '.folder_title_text' , $feed _list ) . each ( function ( ) {
if ( $ ( this ) . text ( ) == folder _name ) {
$folders . push ( $ ( this ) . parents ( 'li.folder' ) . eq ( 0 ) [ 0 ] ) ;
}
} ) ;
return $folders ;
} ,
2010-12-30 18:37:29 -05:00
find _story _in _story _titles : function ( story _id ) {
2011-12-06 19:12:45 -08:00
var story = story _id && this . model . get _story ( story _id ) || this . active _story ;
2010-06-14 13:17:38 -04:00
var $stories = $ ( '.story' , this . $s . $story _titles ) ;
var $story _title ;
if ( story ) {
$stories . each ( function ( ) {
var $this = $ ( this ) ;
if ( $this . data ( 'story_id' ) == story . id ) {
$story _title = $this ;
// NEWSBLUR.log(['Finding story in story titles', $this, story]);
return false ;
}
} ) ;
}
return $story _title ;
} ,
2011-11-15 18:37:42 -08:00
find _story _in _feed _view : function ( story _id ) {
if ( ! story _id ) return ;
2010-06-14 13:17:38 -04:00
var $feed _view = this . $s . $feed _view ;
var $stories = $ ( '.NB-feed-story' , $feed _view ) ;
var $story ;
for ( var s = 0 , s _count = $stories . length ; s < s _count ; s ++ ) {
2011-11-15 18:37:42 -08:00
if ( $stories . eq ( s ) . data ( 'story' ) == story _id ) {
2010-06-14 13:17:38 -04:00
$story = $stories . eq ( s ) ;
break ;
}
}
return $story ;
} ,
2010-12-06 10:41:24 -05:00
find _story _in _feed _iframe : function ( story , $iframe ) {
2010-06-14 13:17:38 -04:00
if ( ! story ) return $ ( [ ] ) ;
2010-12-06 10:41:24 -05:00
$iframe = $iframe || this . $s . $feed _iframe . contents ( ) ;
2010-06-14 13:17:38 -04:00
var $stories = $ ( [ ] ) ;
2011-10-03 18:19:50 -07:00
if ( this . flags [ 'iframe_story_locations_fetched' ] || story . id in this . cache . iframe _stories ) {
2010-06-14 13:17:38 -04:00
return this . cache . iframe _stories [ story . id ] ;
}
var title = story . story _title . replace ( / |[^a-z0-9-,]/gi , '' ) ;
var search _document = function ( node , title ) {
var skip = 0 ;
if ( node && node . nodeType == 3 ) {
var pos = node . data . replace ( / |[^a-z0-9-,]/gi , '' )
. indexOf ( title ) ;
if ( pos >= 0 ) {
$stories . push ( $ ( node ) . parent ( ) ) ;
}
}
else if ( node && node . nodeType == 1 && node . childNodes && ! ( /(script|style)/i . test ( node . tagName ) ) ) {
for ( var i = 0 ; i < node . childNodes . length ; ++ i ) {
i += search _document ( node . childNodes [ i ] , title ) ;
}
}
return skip ;
} ;
search _document ( $iframe . find ( 'body' ) [ 0 ] , title ) ;
$stories = $stories . filter ( function ( ) {
return $ ( this ) . is ( ':visible' ) ;
} ) ;
if ( ! $stories . length ) {
// Not found straight, so check all header tags with styling children removed.
2010-11-06 12:53:42 -04:00
this . cache . iframe [ 'headers' ] = this . cache . iframe [ 'headers' ]
|| $ ( 'h1,h2,h3,h4,h5,h6' , $iframe ) . filter ( ':visible' ) ;
this . cache . iframe [ 'headers' ] . each ( function ( ) {
2010-06-14 13:17:38 -04:00
pos = $ ( this ) . text ( ) . replace ( / |[^a-z0-9-,]/gi , '' )
. indexOf ( title ) ;
// NEWSBLUR.log(['Search headers', title, pos, $(this), $(this).text()]);
if ( pos >= 0 ) {
$stories . push ( $ ( this ) ) ;
return false ;
}
} ) ;
}
if ( ! $stories . length ) {
// Still not found, so check Tumblr style .post's
2010-11-06 12:53:42 -04:00
this . cache . iframe [ 'posts' ] = this . cache . iframe [ 'posts' ]
|| $ ( '.entry,.post,.postProp,#postContent,.article' ,
$iframe ) . filter ( ':visible' ) ;
this . cache . iframe [ 'posts' ] . each ( function ( ) {
2010-06-14 13:17:38 -04:00
pos = $ ( this ) . text ( ) . replace ( / |[^a-z0-9-,]/gi , '' )
. indexOf ( title ) ;
// NEWSBLUR.log(['Search .post', title, pos, $(this), $(this).text().replace(/ |[^a-z0-9-,]/gi, '')]);
if ( pos >= 0 ) {
$stories . push ( $ ( this ) ) ;
return false ;
}
} ) ;
}
2010-07-02 11:14:41 -04:00
2010-06-14 13:17:38 -04:00
// Find the story with the biggest font size
var max _size = 0 ;
2010-07-02 11:14:41 -04:00
var $same _size _stories = $ ( [ ] ) ;
2010-06-14 13:17:38 -04:00
$stories . each ( function ( ) {
2010-07-02 11:14:41 -04:00
var $this = $ ( this ) ;
var size = parseInt ( $this . css ( 'font-size' ) , 10 ) ;
2010-06-14 13:17:38 -04:00
if ( size > max _size ) {
max _size = size ;
2010-07-02 11:14:41 -04:00
$same _size _stories = $ ( [ ] ) ;
}
if ( size == max _size ) {
$same _size _stories . push ( $this ) ;
2010-06-14 13:17:38 -04:00
}
} ) ;
2010-07-02 11:14:41 -04:00
// NEWSBLUR.log(['Found stories', $stories.length, $same_size_stories.length, $same_size_stories, story.story_title]);
// Multiple stories at the same big font size? Determine story title overlap,
// and choose the smallest difference in title length.
var $story = $ ( [ ] ) ;
if ( $same _size _stories . length > 1 ) {
var story _similarity = 100 ;
$same _size _stories . each ( function ( ) {
var $this = $ ( this ) ;
var story _text = $this . text ( ) ;
var overlap = Math . abs ( story _text . length - story . story _title . length ) ;
if ( overlap < story _similarity ) {
story _similarity = overlap ;
$story = $this ;
}
} ) ;
}
if ( ! $story . length ) {
$story = $same _size _stories [ 0 ] ;
}
2010-06-14 13:17:38 -04:00
if ( $story && $story . length ) {
2010-12-04 23:26:52 -05:00
var self = this ;
2010-06-14 13:17:38 -04:00
this . cache . iframe _stories [ story . id ] = $story ;
var position _original = parseInt ( $story . offset ( ) . top , 10 ) ;
// var position_offset = parseInt($story.offsetParent().scrollTop(), 10);
var position = position _original ; // + position_offset;
this . cache . iframe _story _positions [ position ] = story ;
this . cache . iframe _story _positions _keys . push ( position ) ;
2010-12-04 23:26:52 -05:00
if ( ! this . flags [ 'iframe_view_not_busting' ] ) {
var feed _id = this . active _feed ;
_ . delay ( function ( ) {
if ( feed _id == self . active _feed ) {
self . flags [ 'iframe_view_not_busting' ] = true ;
}
} , 1000 ) ;
}
2010-06-14 13:17:38 -04:00
}
// NEWSBLUR.log(['Found story', $story]);
return $story ;
} ,
2010-09-21 11:16:22 -04:00
get _feed _ids _in _folder : function ( $folder ) {
2011-01-31 19:51:39 -05:00
var self = this ;
2010-09-21 11:16:22 -04:00
$folder = $folder || this . $s . $feed _list ;
2010-11-09 22:06:08 -05:00
var $feeds = $ ( '.feed:not(.NB-empty)' , $folder ) ;
2011-01-31 19:51:39 -05:00
var feeds = _ . compact ( _ . map ( $ ( '.feed:not(.NB-empty)' , $folder ) , function ( o ) {
2011-03-30 09:30:45 -04:00
var feed _id = parseInt ( $ ( o ) . attr ( 'data-id' ) , 10 ) ;
2011-01-31 19:51:39 -05:00
if ( self . model . get _feed ( feed _id ) . active ) {
return feed _id ;
}
} ) ) ;
2010-09-21 11:16:22 -04:00
return feeds ;
} ,
2011-11-28 12:13:09 -05:00
compute _story _score : function ( story ) {
if ( this . active _feed == 'starred' ) {
return 1 ;
} else {
return NEWSBLUR . utils . compute _story _score ( story ) ;
}
} ,
2010-06-08 11:19:41 -04:00
// ==============
// = Navigation =
// ==============
show _next _story : function ( direction ) {
2010-06-14 13:17:38 -04:00
var $story _titles = this . $s . $story _titles ;
2011-01-10 19:34:27 -05:00
var $current _story = $ ( '.selected:first' , $story _titles ) ;
2010-06-08 11:19:41 -04:00
var $next _story ;
if ( ! $current _story . length ) {
2010-06-14 13:17:38 -04:00
$current _story = $ ( '.story:first' , $story _titles ) ;
2010-06-08 11:19:41 -04:00
$next _story = $current _story ;
} else if ( direction == 1 ) {
$next _story = $current _story . nextAll ( '.story:visible' ) . eq ( 0 ) ;
} else if ( direction == - 1 ) {
$next _story = $current _story . prevAll ( '.story:visible' ) . eq ( 0 ) ;
}
var story _id = $next _story . data ( 'story_id' ) ;
if ( story _id ) {
2010-06-14 13:17:38 -04:00
var story = this . model . get _story ( story _id ) ;
2010-06-08 11:19:41 -04:00
this . push _current _story _on _history ( ) ;
this . open _story ( story , $next _story ) ;
this . scroll _story _titles _to _show _selected _story _title ( $next _story ) ;
}
} ,
2011-04-12 11:02:02 -04:00
show _next _unread _story : function ( ) {
2010-06-14 13:17:38 -04:00
var $story _titles = this . $s . $story _titles ;
var $current _story = $ ( '.selected' , $story _titles ) ;
2010-06-08 11:19:41 -04:00
var $next _story ;
var unread _count = this . get _unread _count ( true ) ;
2011-01-11 19:33:55 -05:00
// NEWSBLUR.log(['show_next_unread_story', unread_count, $current_story, second_pass]);
2011-01-10 09:49:26 -05:00
2010-06-08 11:19:41 -04:00
if ( unread _count ) {
if ( ! $current _story . length ) {
// Nothing selected, choose first unread.
2010-06-14 13:17:38 -04:00
$next _story = $ ( '.story:not(.read):visible:first' , $story _titles ) ;
2010-06-08 11:19:41 -04:00
} else {
// Start searching below, then search above current story.
$next _story = $current _story . nextAll ( '.story:not(.read):visible' ) . eq ( 0 ) ;
if ( ! $next _story . length ) {
$next _story = $current _story . prevAll ( '.story:not(.read):visible' ) . eq ( 0 ) ;
}
}
if ( $next _story && $next _story . length ) {
2011-04-12 11:02:02 -04:00
this . counts [ 'find_next_unread_on_page_of_feed_stories_load' ] = 0 ;
2010-06-08 11:19:41 -04:00
var story _id = $next _story . data ( 'story_id' ) ;
if ( story _id ) {
2010-06-14 13:17:38 -04:00
var story = this . model . get _story ( story _id ) ;
2010-06-08 11:19:41 -04:00
this . push _current _story _on _history ( ) ;
this . open _story ( story , $next _story ) ;
this . scroll _story _titles _to _show _selected _story _title ( $next _story ) ;
}
2011-05-01 15:53:26 -04:00
} else if ( this . counts [ 'find_next_unread_on_page_of_feed_stories_load' ] < this . constants . FILL _OUT _PAGES ) {
2010-06-08 11:19:41 -04:00
// Nothing up, nothing down, but still unread. Load 1 page then find it.
2011-04-12 11:02:02 -04:00
this . counts [ 'find_next_unread_on_page_of_feed_stories_load' ] += 1 ;
2010-06-08 11:19:41 -04:00
this . load _page _of _feed _stories ( ) ;
}
}
} ,
2011-04-12 11:02:02 -04:00
open _next _unread _story _across _feeds : function ( ) {
2011-11-02 08:49:58 -07:00
var unread _count = this . active _feed && this . get _unread _count ( true ) ;
if ( ! unread _count ) {
if ( this . flags . river _view && false ) {
// TODO: Make this work
// var $next_folder = this.get_next_unread_folder(1);
// var $folder = $next_folder.closest('li.folder');
// var folder_title = $folder.find('.folder_title_text').text();
// this.open_river_stories($folder, folder_title);
} else {
// Find next feed with unreads
var $next _feed = this . get _next _unread _feed ( 1 ) ;
var next _feed _id = parseInt ( $next _feed . attr ( 'data-id' ) , 10 ) ;
this . open _feed ( next _feed _id , true , $next _feed ) ;
}
}
2011-04-12 11:02:02 -04:00
this . show _next _unread _story ( ) ;
} ,
2011-11-02 09:43:06 -07:00
show _last _unread _story : function ( ) {
var $story _titles = this . $s . $story _titles ;
var $current _story = $ ( '.selected' , $story _titles ) ;
var $next _story ;
var unread _count = this . get _unread _count ( true ) ;
NEWSBLUR . log ( [ 'show_last_unread_story' , unread _count , $current _story ] ) ;
if ( unread _count ) {
var unread _stories _visible = $ ( '.story:not(.read):visible' , $story _titles ) . length ;
if ( unread _stories _visible >= unread _count ) {
// Choose the last unread story
$next _story = $ ( '.story:not(.read):visible:last' , $story _titles ) ;
}
if ( $next _story && $next _story . length ) {
this . counts [ 'find_last_unread_on_page_of_feed_stories_load' ] = 0 ;
var story _id = $next _story . data ( 'story_id' ) ;
if ( story _id ) {
var story = this . model . get _story ( story _id ) ;
this . push _current _story _on _history ( ) ;
this . open _story ( story , $next _story ) ;
this . scroll _story _titles _to _show _selected _story _title ( $next _story ) ;
}
} else if ( this . counts [ 'find_last_unread_on_page_of_feed_stories_load' ] < this . constants . FILL _OUT _PAGES ) {
// Nothing up, nothing down, but still unread. Load 1 page then find it.
this . counts [ 'find_last_unread_on_page_of_feed_stories_load' ] += 1 ;
this . load _page _of _feed _stories ( ) ;
}
}
2011-04-12 11:02:02 -04:00
} ,
2010-06-08 11:19:41 -04:00
show _previous _story : function ( ) {
if ( this . cache [ 'previous_stories_stack' ] . length ) {
var $previous _story = this . cache [ 'previous_stories_stack' ] . pop ( ) ;
if ( $previous _story . length && ! $previous _story . is ( ':visible' ) ) {
this . show _previous _story ( ) ;
return ;
}
var story _id = $previous _story . data ( 'story_id' ) ;
if ( story _id ) {
2010-06-14 13:17:38 -04:00
var story = this . model . get _story ( story _id ) ;
2010-06-08 11:19:41 -04:00
this . open _story ( story , $previous _story ) ;
this . scroll _story _titles _to _show _selected _story _title ( $previous _story ) ;
}
}
} ,
scroll _story _titles _to _show _selected _story _title : function ( $story ) {
2011-12-06 19:12:45 -08:00
var $story = $story || this . find _story _in _story _titles ( ) ;
if ( ! $story ) return ;
2010-06-14 13:17:38 -04:00
var $story _titles = this . $s . $story _titles ;
var story _title _visisble = $story _titles . isScrollVisible ( $story ) ;
2010-06-08 11:19:41 -04:00
if ( ! story _title _visisble ) {
2010-06-14 13:17:38 -04:00
var container _offset = $story _titles . position ( ) . top ;
2010-06-08 11:19:41 -04:00
var scroll = $story . position ( ) . top ;
2010-06-14 13:17:38 -04:00
var container = $story _titles . scrollTop ( ) ;
var height = $story _titles . outerHeight ( ) ;
$story _titles . scrollTop ( scroll + container - height / 5 ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2010-10-21 18:52:25 -04:00
show _next _feed : function ( direction , $current _feed ) {
2011-04-12 11:02:02 -04:00
var $feed _list = this . $s . $feed _list ;
var $next _feed = this . get _next _feed ( direction , $current _feed ) ;
var feed _id = parseInt ( $next _feed . attr ( 'data-id' ) , 10 ) ;
if ( feed _id && feed _id == this . active _feed ) {
this . show _next _feed ( direction , $next _feed ) ;
} else if ( feed _id ) {
var position = $feed _list . scrollTop ( ) + $next _feed . offset ( ) . top - $next _feed . outerHeight ( ) ;
var showing = $feed _list . height ( ) - 100 ;
if ( position > showing ) {
scroll = position ;
} else {
scroll = 0 ;
}
$feed _list . scrollTop ( scroll ) ;
this . open _feed ( feed _id , false , $next _feed , 350 ) ;
}
} ,
get _next _feed : function ( direction , $current _feed ) {
2010-11-24 13:16:10 -05:00
var self = this ;
2010-06-14 13:17:38 -04:00
var $feed _list = this . $s . $feed _list ;
2010-10-21 18:52:25 -04:00
var $current _feed = $current _feed || $ ( '.selected' , $feed _list ) ;
2010-06-08 11:19:41 -04:00
var $next _feed ,
scroll ;
2011-03-19 11:22:10 -04:00
var $feeds = $ ( '.feed:visible:not(.NB-empty)' , $feed _list ) . add ( '.feed.selected' ) ;
2010-06-08 11:19:41 -04:00
if ( ! $current _feed . length ) {
2011-03-20 20:12:21 -04:00
$current _feed = $ ( '.feed:visible:not(.NB-empty)' , $feed _list ) [ direction == 1 ? 'first' : 'last' ] ( ) ;
2010-06-08 11:19:41 -04:00
$next _feed = $current _feed ;
2010-10-21 18:52:25 -04:00
} else {
$feeds . each ( function ( i ) {
if ( this == $current _feed [ 0 ] ) {
current _feed = i ;
return false ;
}
} ) ;
2011-03-20 20:12:21 -04:00
$next _feed = $feeds . eq ( ( current _feed + direction ) % ( $feeds . length ) ) ;
2010-06-08 11:19:41 -04:00
}
2011-04-12 11:02:02 -04:00
return $next _feed ;
} ,
get _next _unread _feed : function ( direction , $current _feed ) {
var self = this ;
var $feed _list = this . $s . $feed _list ;
$current _feed = $current _feed || $ ( '.selected' , $feed _list ) ;
var unread _view = this . get _unread _view _name ( ) ;
var $next _feed ;
var $feeds = $ ( '.feed:visible:not(.NB-empty)' , $feed _list ) . filter ( function ( ) {
var $this = $ ( this ) ;
if ( unread _view == 'positive' ) {
return $this . is ( '.unread_positive' ) ;
} else if ( unread _view == 'neutral' ) {
return $this . is ( '.unread_positive,.unread_neutral' ) ;
} else if ( unread _view == 'negative' ) {
return $this . is ( '.unread_positive,.unread_neutral,.unread_negative' ) ;
}
} ) . add ( '.feed.selected' ) ;
if ( ! $current _feed . length ) {
$next _feed = $feeds . first ( ) ;
} else {
$feeds . each ( function ( i ) {
if ( this == $current _feed [ 0 ] ) {
current _feed = i ;
return false ;
}
} ) ;
$next _feed = $feeds . eq ( ( current _feed + direction ) % ( $feeds . length ) ) ;
2010-06-08 11:19:41 -04:00
}
2011-04-12 11:02:02 -04:00
return $next _feed ;
2010-06-08 11:19:41 -04:00
} ,
2011-10-31 18:40:07 -07:00
get _current _folder : function ( ) {
var $folder = $ ( '.folder.NB-selected' , this . $s . $feed _list ) ;
if ( $folder . length ) {
return $folder . eq ( 0 ) ;
}
2011-11-23 16:45:36 -05:00
return this . $s . $feed _list ;
2011-10-31 18:40:07 -07:00
} ,
2010-06-08 11:19:41 -04:00
navigate _story _titles _to _story : function ( story ) {
2011-01-10 09:49:26 -05:00
if ( ! story ) return ;
2010-12-30 18:37:29 -05:00
var $next _story _title = this . find _story _in _story _titles ( story . id ) ;
2010-12-14 18:48:52 -05:00
if ( $next _story _title &&
$next _story _title . length &&
$next _story _title . is ( ':visible' ) &&
! $next _story _title . hasClass ( 'selected' ) ) {
// NEWSBLUR.log(['navigate_story_titles_to_story', story, $next_story_title]);
2010-06-08 11:19:41 -04:00
2010-12-14 18:48:52 -05:00
this . scroll _story _titles _to _show _selected _story _title ( $next _story _title ) ;
if ( this . active _story != story ) {
this . push _current _story _on _history ( ) ;
this . active _story = story ;
this . mark _story _title _as _selected ( $next _story _title ) ;
2010-12-30 19:24:52 -05:00
this . mark _story _as _read ( story . id ) ;
2011-01-12 09:59:10 -05:00
this . mark _story _as _read _in _feed _view ( story , { 'animate' : this . story _view == 'feed' } ) ;
2010-12-14 18:48:52 -05:00
}
2010-06-08 11:19:41 -04:00
}
} ,
2011-01-11 21:37:38 -05:00
mark _story _as _read _in _feed _view : function ( story , options ) {
2011-01-10 19:34:27 -05:00
if ( ! story ) return ;
2011-01-11 21:37:38 -05:00
options = options || { } ;
2011-11-15 18:37:42 -08:00
$story = this . cache . feed _view _stories [ story . id ] || this . find _story _in _feed _view ( story . id ) ;
2011-10-31 18:40:07 -07:00
if ( $story ) {
$story . addClass ( 'read' ) ;
}
2011-01-11 21:37:38 -05:00
2011-02-23 11:40:25 -05:00
// This block animates the falling of the sentiment bullet. It's neat,
// but it stutters a fast scroll. Hence the delay.
//
2011-01-14 00:59:51 -05:00
// if (false && options.animate && !$story.hasClass('read')) {
// var $feed_view = this.$s.$feed_view;
// var start = $feed_view.scrollTop();
// (function(start) {
// _.delay(function() {
// $story.addClass('read');
// var end = $feed_view.scrollTop();
// if (end - start > 25) {
// $('.NB-feed-story-sentiment-animate', $story).remove();
// return;
// }
// var top = $('.NB-feed-story-header-info', $story).height();
// $('.NB-feed-story-sentiment-animate', $story).addClass('NB-animating').animate({
// 'top': top
// }, {
// 'duration': 550,
// 'easing': 'easeInOutQuint',
// 'complete': function() {
// $(this).remove();
// }
// });
// }, 20);
// })(start);
// }
2011-01-10 19:34:27 -05:00
} ,
2010-06-08 11:19:41 -04:00
page _in _story : function ( amount , direction ) {
2010-06-14 13:17:38 -04:00
var page _height = this . $s . $story _pane . height ( ) ;
2010-06-08 11:19:41 -04:00
var scroll _height = parseInt ( page _height * amount , 10 ) ;
var dir = '+' ;
if ( direction == - 1 ) {
dir = '-' ;
}
2010-06-14 13:17:38 -04:00
// NEWSBLUR.log(['page_in_story', this.$s.$story_pane, direction, page_height, scroll_height]);
2010-06-08 11:19:41 -04:00
if ( this . story _view == 'page' ) {
2011-11-25 11:06:07 -05:00
this . $s . $feed _iframe . scrollTo ( { top : dir + '=' + scroll _height , left : '+=0' } , 230 , { queue : false } ) ;
2010-12-08 20:53:45 -05:00
} else if ( this . story _view == 'feed' ) {
2011-11-25 11:06:07 -05:00
this . $s . $feed _stories . scrollTo ( { top : dir + '=' + scroll _height , left : '+=0' } , 340 , { queue : false } ) ;
2010-06-08 11:19:41 -04:00
}
} ,
push _current _story _on _history : function ( ) {
2010-06-14 13:17:38 -04:00
var $current _story = $ ( '.selected' , this . $s . $story _titles ) ;
2010-06-08 11:19:41 -04:00
if ( $current _story . length ) {
this . cache [ 'previous_stories_stack' ] . push ( $current _story ) ;
}
} ,
// =============
// = Feed Pane =
// =============
load _feeds : function ( ) {
var self = this ;
2010-10-15 09:21:46 -04:00
2010-06-08 11:19:41 -04:00
if ( $ ( '#feed_list' ) . length ) {
$ ( '.NB-callout-ftux .NB-callout-text' ) . text ( 'Loading feeds...' ) ;
2010-08-09 20:44:36 -04:00
this . $s . $feed _link _loader . css ( { 'display' : 'block' } ) ;
2011-04-05 19:24:12 -04:00
this . flags [ 'favicons_downloaded' ] = false ;
2010-06-08 11:19:41 -04:00
this . model . load _feeds ( $ . rescope ( this . make _feeds , this ) ) ;
}
} ,
make _feeds : function ( ) {
2010-09-22 19:26:56 -04:00
var self = this ;
2011-02-06 15:04:21 -05:00
var $feed _list = this . $s . $feed _list ;
2010-06-08 11:19:41 -04:00
var folders = this . model . folders ;
var feeds = this . model . feeds ;
2010-08-09 20:44:36 -04:00
2010-06-08 11:19:41 -04:00
// NEWSBLUR.log(['Making feeds', {'folders': folders, 'feeds': feeds}]);
2011-02-06 15:04:21 -05:00
$feed _list . empty ( ) ;
2010-06-08 11:19:41 -04:00
2011-01-31 20:50:33 -05:00
this . $s . $story _taskbar . css ( { 'display' : 'block' } ) ;
2010-10-05 19:05:01 -04:00
this . flags [ 'has_chosen_feeds' ] = this . detect _all _inactive _feeds ( ) ;
2011-03-30 09:30:45 -04:00
var $feeds = this . make _feeds _folder ( folders , 0 ) ;
2011-02-06 15:04:21 -05:00
$feed _list . css ( {
2010-12-31 14:35:00 -05:00
'display' : 'block' ,
'opacity' : 0
2011-03-30 09:30:45 -04:00
} ) ;
$feed _list . html ( $feeds ) ;
2011-04-25 20:53:29 -04:00
// this.sort_feeds($feed_list);
2011-03-30 09:30:45 -04:00
this . count _collapsed _unread _stories ( ) ;
$feed _list . animate ( { 'opacity' : 1 } , { 'duration' : 700 } ) ;
this . hover _over _feed _titles ( $feed _list ) ;
2010-08-11 23:02:17 -04:00
this . $s . $feed _link _loader . fadeOut ( 250 ) ;
2010-10-16 21:32:06 -04:00
2010-10-02 17:05:55 -04:00
if ( folders . length ) {
2010-06-08 11:19:41 -04:00
$ ( '.NB-task-manage' ) . removeClass ( 'NB-disabled' ) ;
$ ( '.NB-callout-ftux' ) . fadeOut ( 500 ) ;
}
2010-10-16 21:32:06 -04:00
2010-09-28 18:53:57 -04:00
if ( NEWSBLUR . Globals . is _authenticated && this . flags [ 'has_chosen_feeds' ] ) {
2010-12-31 14:35:00 -05:00
_ . delay ( _ . bind ( this . start _count _unreads _after _import , this ) , 1000 ) ;
2011-03-16 11:54:20 -04:00
this . force _feeds _refresh ( $ . rescope ( this . finish _count _unreads _after _import , this ) , true ) ;
2011-04-05 19:24:12 -04:00
} else if ( ! this . flags [ 'has_chosen_feeds' ] && this . flags [ 'favicons_downloaded' ] && folders . length ) {
2010-10-14 09:51:56 -04:00
_ . defer ( _ . bind ( this . open _feedchooser _modal , this ) , 100 ) ;
2010-10-16 21:32:06 -04:00
return ;
2011-04-05 19:24:12 -04:00
} else if ( NEWSBLUR . Globals . is _authenticated && ! folders . length ) {
2010-10-02 17:05:55 -04:00
this . setup _ftux _add _feed _callout ( ) ;
}
2010-10-16 21:32:06 -04:00
if ( folders . length ) {
this . load _sortable _feeds ( ) ;
2010-11-22 10:44:52 -05:00
this . update _header _counts ( ) ;
2010-12-01 14:11:42 -05:00
_ . delay ( _ . bind ( this . update _starred _count , this ) , 250 ) ;
2010-10-16 21:32:06 -04:00
}
2011-03-11 20:05:41 -05:00
2011-03-16 18:29:56 -04:00
if ( this . flags [ 'showing_feed_in_tryfeed_view' ] ) {
this . hide _tryfeed _view ( ) ;
this . force _feed _refresh ( ) ;
}
2011-03-11 20:05:41 -05:00
this . add _url _from _querystring ( ) ;
2011-04-05 19:24:12 -04:00
_ . defer ( _ . bind ( function ( ) {
this . model . load _feed _favicons ( $ . rescope ( this . make _feed _favicons , this ) , this . flags [ 'favicons_downloaded' ] , this . flags [ 'has_chosen_feeds' ] ) ;
2011-11-06 12:21:27 -08:00
this . setup _socket _realtime _unread _counts ( ) ;
2011-04-05 19:24:12 -04:00
} , this ) ) ;
} ,
make _feed _favicons : function ( ) {
var model = this . model ;
this . flags [ 'favicons_downloaded' ] = true ;
$ ( '.feed_favicon' , this . $s . $feed _list ) . each ( function ( ) {
var $feed _favicon = $ ( this ) ;
var feed _id = $feed _favicon . closest ( '.feed' ) . attr ( 'data-id' ) ;
$feed _favicon . attr ( 'src' , $ . favicon ( model . get _feed ( feed _id ) . favicon ) ) ;
} ) ;
if ( ! this . flags [ 'has_chosen_feeds' ] && this . model . folders . length ) {
_ . defer ( _ . bind ( this . open _feedchooser _modal , this ) , 100 ) ;
}
2010-06-08 11:19:41 -04:00
} ,
2011-04-25 20:53:29 -04:00
sort _items : function ( items ) {
var self = this ;
var sort _order = this . model . preference ( 'feed_order' ) ;
if ( sort _order == 'ALPHABETICAL' || ! sort _order ) {
return items . sort ( function ( a , b ) {
var feedA , feedB ;
if ( _ . isNumber ( a ) ) feedA = self . model . get _feed ( a ) ;
if ( _ . isNumber ( b ) ) feedB = self . model . get _feed ( b ) ;
if ( feedA && feedB ) {
2011-04-26 18:58:42 -04:00
return feedA . feed _title . toLowerCase ( ) > feedB . feed _title . toLowerCase ( ) ? 1 : - 1 ;
2011-04-25 20:53:29 -04:00
} else if ( feedA && ! feedB ) {
return - 1 ;
} else if ( ! feedA && feedB ) {
return 1 ;
2011-12-04 13:55:57 -08:00
} else if ( ! feedA && ! feedB && ! _ . isNumber ( a ) && ! _ . isNumber ( b ) && a && b ) {
// console.log(['a b 1', a, b, feedA, feedB]);
2011-04-25 20:53:29 -04:00
var folderA = _ . keys ( a ) [ 0 ] ;
var folderB = _ . keys ( b ) [ 0 ] ;
2011-04-26 18:58:42 -04:00
return folderA . toLowerCase ( ) > folderB . toLowerCase ( ) ? 1 : - 1 ;
2011-04-25 20:53:29 -04:00
}
} ) ;
} else if ( sort _order == 'MOSTUSED' ) {
return items . sort ( function ( a , b ) {
var feedA , feedB ;
if ( _ . isNumber ( a ) ) feedA = self . model . get _feed ( a ) ;
if ( _ . isNumber ( b ) ) feedB = self . model . get _feed ( b ) ;
if ( feedA && feedB ) {
return feedA . feed _opens < feedB . feed _opens ? 1 :
( feedA . feed _opens > feedB . feed _opens ? - 1 :
2011-04-26 18:58:42 -04:00
( feedA . feed _title . toLowerCase ( ) > feedB . feed _title . toLowerCase ( ) ? 1 : - 1 ) ) ;
2011-04-25 20:53:29 -04:00
} else if ( feedA && ! feedB ) {
return - 1 ;
} else if ( ! feedA && feedB ) {
return 1 ;
2011-04-26 10:25:44 -04:00
} else if ( ! feedA && ! feedB && ! _ . isNumber ( a ) && ! _ . isNumber ( b ) ) {
// console.log(['a b 2', a, b]);
2011-04-25 20:53:29 -04:00
var folderA = _ . keys ( a ) [ 0 ] ;
var folderB = _ . keys ( b ) [ 0 ] ;
2011-04-26 18:58:42 -04:00
return folderA . toLowerCase ( ) > folderB . toLowerCase ( ) ? 1 : - 1 ;
2011-04-25 20:53:29 -04:00
}
} ) ;
}
} ,
2011-03-30 09:30:45 -04:00
sort _feeds : function ( $feeds ) {
$ ( '.feed' , $feeds ) . tsort ( '.feed_title' ) ;
$ ( '.folder' , $feeds ) . tsort ( '.folder_title_text' ) ;
} ,
2010-10-05 19:05:01 -04:00
detect _all _inactive _feeds : function ( ) {
var feeds = this . model . feeds ;
var has _chosen _feeds = _ . any ( feeds , function ( feed ) {
return feed . active ;
} ) ;
return has _chosen _feeds ;
} ,
2011-03-30 09:30:45 -04:00
make _feeds _folder : function ( items , depth , collapsed _parent ) {
2010-08-11 23:52:17 -04:00
var self = this ;
2011-03-30 09:30:45 -04:00
var $feeds = "" ;
2010-08-11 23:52:17 -04:00
2011-04-25 20:53:29 -04:00
items = this . sort _items ( items ) ;
2010-06-08 11:19:41 -04:00
for ( var i in items ) {
var item = items [ i ] ;
if ( typeof item == "number" ) {
2010-08-25 10:18:08 -04:00
var feed = this . model . get _feed ( item ) ;
2010-08-16 16:30:04 -04:00
if ( ! feed ) continue ;
2011-03-30 09:30:45 -04:00
var $feed = this . make _feed _title _template ( feed , 'feed' , depth ) ;
$feeds += $feed ;
2010-08-11 11:43:48 -04:00
2011-11-28 18:01:39 -08:00
if ( feed . not _yet _fetched && feed . active ) {
NEWSBLUR . log ( [ 'Feed not fetched' , feed ] ) ;
2011-03-19 11:22:10 -04:00
this . flags [ 'has_unfetched_feeds' ] = true ;
2010-08-11 11:43:48 -04:00
}
2010-11-01 23:00:20 -04:00
} else if ( typeof item == "object" && item ) {
2010-06-08 11:19:41 -04:00
for ( var o in item ) {
2010-10-21 13:48:08 -04:00
var is _collapsed = _ . contains ( NEWSBLUR . Preferences . collapsed _folders , o ) ;
2011-03-30 09:30:45 -04:00
var folder = item [ o ] ;
var $folder _pre = _ . template ( ' \
< li class = "folder" > \
< div class = "folder_title <% if (depth == 0) { %>NB-toplevel<% } %>" > \
< div class = "NB-folder-icon" > < / d i v > \
2011-11-01 00:20:06 -07:00
< div class = "NB-feedlist-collapse-icon" title = "<% if (is_collapsed) { %>Expand Folder<% } else {%>Collapse Folder<% } %>" > < / d i v > \
2011-03-30 09:30:45 -04:00
< div class = "NB-feedlist-manage-icon" > < / d i v > \
< span class = "folder_title_text" > < %= folder _title % > < / s p a n > \
< / d i v > \
< ul class = "folder" < % if ( is _collapsed ) { % > style = "display: none" < % } % >> \
' , {
depth : depth ,
folder _title : o ,
is _collapsed : is _collapsed
} ) ;
var $folder _post = "</ul></li>" ;
$feeds += $folder _pre + this . make _feeds _folder ( folder , depth + 1 , is _collapsed ) + $folder _post ;
2010-06-08 11:19:41 -04:00
}
}
}
2011-03-30 09:30:45 -04:00
$feeds += '<li class="feed NB-empty"></li>' ;
return $feeds ;
2010-06-08 11:19:41 -04:00
} ,
2011-03-30 09:30:45 -04:00
make _feed _title _template : function ( feed , type , depth ) {
2010-06-08 11:19:41 -04:00
var unread _class = '' ;
2010-08-18 20:35:45 -04:00
var exception _class = '' ;
2010-06-08 11:19:41 -04:00
if ( feed . ps ) {
unread _class += ' unread_positive' ;
}
if ( feed . nt ) {
unread _class += ' unread_neutral' ;
}
if ( feed . ng ) {
unread _class += ' unread_negative' ;
}
2010-10-28 18:17:14 -04:00
if ( feed . has _exception && feed . exception _type == 'feed' ) {
2010-09-28 18:53:57 -04:00
exception _class += ' NB-feed-exception' ;
2010-08-18 20:35:45 -04:00
}
if ( feed . not _yet _fetched && ! feed . has _exception ) {
2010-09-28 18:53:57 -04:00
exception _class += ' NB-feed-unfetched' ;
2010-08-18 20:35:45 -04:00
}
2010-09-28 18:53:57 -04:00
if ( ! feed . active ) {
exception _class += ' NB-feed-inactive' ;
}
2011-03-30 09:30:45 -04:00
var feed _counts _floater = this . make _feed _counts _floater ( feed . ps , feed . nt , feed . ng , true ) ;
var $feed = _ . template ( ' \
<< %= list _type % > class = "feed <%= unread_class %> <%= exception_class %> <% if (toplevel) { %>NB-toplevel<% } %>" data - id = "<%= feed.id %>" > \
< div class = "feed_counts" > \
< %= feed _counts _floater % > \
< / d i v > \
2011-04-05 19:24:12 -04:00
< img class = "feed_favicon" src = "<%= $.favicon(feed.favicon, true) %>" > \
2011-03-30 09:30:45 -04:00
< span class = "feed_title" > \
< %= feed . feed _title % > \
< % if ( type == "story" ) { % > \
< span class = "NB-feedbar-train-feed" title = "Train Intelligence" > < / s p a n > \
< span class = "NB-feedbar-statistics" title = "Statistics" > < / s p a n > \
< % } % > \
< / s p a n > \
< % if ( type == "story" ) { % > \
< div class = "NB-feedbar-last-updated" > \
< span class = "NB-feedbar-last-updated-label" > Updated : < / s p a n > \
< span class = "NB-feedbar-last-updated-date" > \
< % if ( feed . updated ) { % > \
< %= feed . updated % > ago \
< % } else { % > \
Loading ... \
< % } % > \
< / s p a n > \
< / d i v > \
< div class = "NB-feedbar-mark-feed-read" > Mark All as Read < / d i v > \
< % } % > \
< div class = "NB-feed-exception-icon" > < / d i v > \
< div class = "NB-feed-unfetched-icon" > < / d i v > \
< div class = "NB-feedlist-manage-icon" > < / d i v > \
< / < % = l i s t _ t y p e % > > \
' , {
feed : feed ,
type : type ,
feed _counts _floater : feed _counts _floater ,
unread _class : unread _class ,
exception _class : exception _class ,
toplevel : depth == 0 ,
list _type : type == 'feed' ? 'li' : 'div'
2010-11-26 19:03:31 -05:00
} ) ;
2011-03-30 09:30:45 -04:00
return $feed ;
2010-06-08 11:19:41 -04:00
} ,
2011-03-30 09:30:45 -04:00
make _feed _counts _floater : function ( positive _count , neutral _count , negative _count , skip _render ) {
2010-09-05 18:08:08 -07:00
var unread _class = "" ;
if ( positive _count ) {
unread _class += ' unread_positive' ;
}
if ( neutral _count ) {
unread _class += ' unread_neutral' ;
}
if ( negative _count ) {
unread _class += ' unread_negative' ;
}
2011-03-30 09:30:45 -04:00
var $floater = _ . template ( ' \
< div class = "feed_counts_floater <%= unread_class %>" > \
< span class = "unread_count unread_count_positive <% if (positive_count) { %>unread_count_full<% } else { %>unread_count_empty<% } %>" > \
< %= positive _count % > \
< / s p a n > \
< span class = "unread_count unread_count_neutral <% if (neutral_count) { %>unread_count_full<% } else { %>unread_count_empty<% } %>" > \
< %= neutral _count % > \
< / s p a n > \
< span class = "unread_count unread_count_negative <% if (negative_count) { %>unread_count_full<% } else { %>unread_count_empty<% } %>" > \
< %= negative _count % > \
< / s p a n > \
< / d i v > \
' , {
positive _count : positive _count ,
neutral _count : neutral _count ,
negative _count : negative _count ,
unread _class : unread _class
} ) ;
if ( ! skip _render ) {
$floater = $ ( $floater ) ;
}
return $floater ;
2010-09-05 18:08:08 -07:00
} ,
2010-07-10 17:59:17 -04:00
load _sortable _feeds : function ( ) {
var self = this ;
2010-11-03 21:27:52 -04:00
this . $s . $feed _list . sortable ( {
2011-02-08 09:44:24 -05:00
items : '.feed,li.folder' ,
connectWith : 'ul.folder,.feed.NB-empty' ,
2010-07-10 17:59:17 -04:00
placeholder : 'NB-feeds-list-highlight' ,
axis : 'y' ,
2010-12-10 09:32:06 -05:00
distance : 4 ,
2010-07-11 11:10:45 -04:00
cursor : 'move' ,
2010-12-16 23:57:05 -05:00
containment : '.NB-feedlist' ,
2010-12-10 09:32:06 -05:00
tolerance : 'pointer' ,
2010-12-25 23:04:43 -05:00
scrollSensitivity : 35 ,
2010-07-10 17:59:17 -04:00
start : function ( e , ui ) {
self . flags [ 'sorting_feed' ] = true ;
ui . placeholder . attr ( 'class' , ui . item . attr ( 'class' ) + ' NB-feeds-list-highlight' ) ;
ui . item . addClass ( 'NB-feed-sorting' ) ;
2010-07-11 11:10:45 -04:00
self . $s . $feed _list . addClass ( 'NB-feed-sorting' ) ;
2010-12-16 23:57:05 -05:00
if ( ui . item . is ( '.folder' ) ) {
ui . placeholder . html ( ui . item . children ( ) . clone ( ) ) ;
ui . item . data ( 'previously_collapsed' , ui . item . data ( 'collapsed' ) ) ;
self . collapse _folder ( ui . item . children ( '.folder_title' ) , true ) ;
self . collapse _folder ( ui . placeholder . children ( '.folder_title' ) , true ) ;
ui . item . css ( 'height' , ui . item . children ( '.folder_title' ) . outerHeight ( true ) + 'px' ) ;
2010-12-25 23:04:43 -05:00
ui . helper . css ( 'height' , ui . helper . children ( '.folder_title' ) . outerHeight ( true ) + 'px' ) ;
2010-11-03 21:27:52 -04:00
} else {
ui . placeholder . html ( ui . item . children ( ) . clone ( ) ) ;
2010-09-05 18:08:08 -07:00
}
2010-07-10 17:59:17 -04:00
} ,
2010-11-01 19:28:57 -04:00
change : function ( e , ui ) {
2011-04-25 20:53:29 -04:00
var $feeds = ui . placeholder . closest ( 'ul.folder' ) ;
self . sort _feeds ( $feeds ) ;
2010-07-10 17:59:17 -04:00
} ,
stop : function ( e , ui ) {
setTimeout ( function ( ) {
self . flags [ 'sorting_feed' ] = false ;
} , 100 ) ;
ui . item . removeClass ( 'NB-feed-sorting' ) ;
2010-07-11 11:10:45 -04:00
self . $s . $feed _list . removeClass ( 'NB-feed-sorting' ) ;
2011-04-25 20:53:29 -04:00
self . sort _feeds ( e . target ) ;
2010-07-10 17:59:17 -04:00
self . save _feed _order ( ) ;
ui . item . css ( { 'backgroundColor' : '#D7DDE6' } )
2010-08-03 09:19:38 -04:00
. animate ( { 'backgroundColor' : '#F0F076' } , { 'duration' : 800 } )
2010-07-10 17:59:17 -04:00
. animate ( { 'backgroundColor' : '#D7DDE6' } , { 'duration' : 1000 } ) ;
2010-12-16 23:57:05 -05:00
if ( ui . item . is ( '.folder' ) && ! ui . item . data ( 'previously_collapsed' ) ) {
self . collapse _folder ( ui . item . children ( '.folder_title' ) ) ;
self . collapse _folder ( ui . placeholder . children ( '.folder_title' ) ) ;
2010-09-05 18:08:08 -07:00
}
2010-07-10 17:59:17 -04:00
}
} ) ;
} ,
save _feed _order : function ( ) {
2010-07-11 11:10:45 -04:00
var combine _folders = function ( $folder ) {
var folders = [ ] ;
var $items = $folder . children ( 'li.folder, .feed' ) ;
for ( var i = 0 , i _count = $items . length ; i < i _count ; i ++ ) {
var $item = $items . eq ( i ) ;
if ( $item . hasClass ( 'feed' ) ) {
2011-03-30 09:30:45 -04:00
var feed _id = parseInt ( $item . attr ( 'data-id' ) , 10 ) ;
2010-12-10 09:32:06 -05:00
if ( feed _id ) {
folders . push ( feed _id ) ;
}
2010-07-11 11:10:45 -04:00
} else if ( $item . hasClass ( 'folder' ) ) {
2010-09-05 18:08:08 -07:00
var folder _title = $item . find ( '.folder_title_text' ) . eq ( 0 ) . text ( ) ;
2010-07-11 11:10:45 -04:00
var child _folders = { } ;
child _folders [ folder _title ] = combine _folders ( $item . children ( 'ul.folder' ) . eq ( 0 ) ) ;
folders . push ( child _folders ) ;
}
}
return folders ;
} ;
2010-07-10 17:59:17 -04:00
2010-07-11 11:10:45 -04:00
var combined _folders = combine _folders ( this . $s . $feed _list ) ;
2010-10-30 00:27:52 -04:00
// NEWSBLUR.log(['Save new folder/feed order', {'combined': combined_folders}]);
2010-07-11 11:10:45 -04:00
this . model . save _feed _order ( combined _folders ) ;
2010-07-10 17:59:17 -04:00
} ,
2011-03-30 09:30:45 -04:00
count _collapsed _unread _stories : function ( ) {
2011-10-31 19:44:36 -07:00
var self = this ;
2011-11-01 00:20:06 -07:00
2011-03-30 09:30:45 -04:00
_ . each ( NEWSBLUR . Preferences . collapsed _folders , _ . bind ( function ( folder ) {
2011-11-01 00:20:06 -07:00
var $folder _title = $ ( '.folder_title_text' , this . $s . $feed _list ) . filter ( function ( ) {
return $ . trim ( $ ( this ) . text ( ) ) == $ . trim ( folder ) ;
} ) . closest ( '.folder_title' ) ;
2011-03-30 09:30:45 -04:00
this . collapse _folder ( $folder _title , true ) ;
2011-11-01 00:20:06 -07:00
var $folder = $folder _title . parent ( 'li.folder' ) ;
var $children = $folder . children ( 'ul.folder' ) ;
this . show _collapsed _folder _count ( $folder _title , $children , { 'skip_animation' : true } ) ;
2011-03-30 09:30:45 -04:00
} , this ) ) ;
2011-11-01 00:20:06 -07:00
2011-10-31 19:44:36 -07:00
if ( this . model . preference ( 'folder_counts' ) ) {
var $folder _titles = $ ( '.folder_title' , this . $s . $feed _list ) ;
$folder _titles . each ( function ( ) {
var $folder _title = $ ( this ) ;
2011-11-01 00:20:06 -07:00
if ( ! _ . contains ( NEWSBLUR . Preferences . collapsed _folders , $folder _title . text ( ) ) ) {
var $folder = $folder _title . parent ( 'li.folder' ) ;
var $children = $folder . children ( 'ul.folder' ) ;
self . show _collapsed _folder _count ( $folder _title , $children , { 'skip_animation' : true } ) ;
}
2011-03-30 09:30:45 -04:00
} ) ;
2011-10-31 19:44:36 -07:00
}
2011-03-30 09:30:45 -04:00
} ,
2010-09-05 18:08:08 -07:00
collapse _folder : function ( $folder _title , force _collapse ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-09-05 18:08:08 -07:00
var $feed _list = this . $s . $feed _list ;
2010-12-25 23:04:43 -05:00
var $folder = $folder _title . parent ( 'li.folder' ) ;
var $children = $folder . children ( 'ul.folder' ) ;
2010-09-05 18:08:08 -07:00
// Hiding / Collapsing
if ( force _collapse ||
( $children . length &&
$children . eq ( 0 ) . is ( ':visible' ) &&
! $folder . data ( 'collapsed' ) ) ) {
this . model . collapsed _folders ( $ ( '.folder_title_text' , $folder _title ) . text ( ) , true ) ;
2011-05-16 11:34:05 -04:00
$folder . data ( 'collapsed' , true ) . addClass ( 'NB-folder-collapsed' ) ;
2010-09-05 18:08:08 -07:00
$children . animate ( { 'opacity' : 0 } , {
'queue' : false ,
'duration' : force _collapse ? 0 : 200 ,
'complete' : function ( ) {
self . show _collapsed _folder _count ( $folder _title , $children ) ;
$children . slideUp ( {
2010-12-25 23:04:43 -05:00
'duration' : 270 ,
'easing' : 'easeOutQuart'
2010-09-05 18:08:08 -07:00
} ) ;
}
} ) ;
}
// Showing / Expanding
else if ( $children . length &&
( $folder . data ( 'collapsed' ) || ! $children . eq ( 0 ) . is ( ':visible' ) ) ) {
this . model . collapsed _folders ( $ ( '.folder_title_text' , $folder _title ) . text ( ) , false ) ;
2011-05-16 11:34:05 -04:00
$folder . data ( 'collapsed' , false ) . removeClass ( 'NB-folder-collapsed' ) ;
2011-10-31 19:44:36 -07:00
if ( ! this . model . preference ( 'folder_counts' ) ) {
this . hide _collapsed _folder _count ( $folder _title ) ;
}
2010-09-05 18:08:08 -07:00
$children . css ( { 'opacity' : 0 } ) . slideDown ( {
'duration' : 240 ,
2010-12-25 23:04:43 -05:00
'easing' : 'easeInOutCubic' ,
2010-09-05 18:08:08 -07:00
'complete' : function ( ) {
$children . animate ( { 'opacity' : 1 } , { 'queue' : false , 'duration' : 200 } ) ;
}
} ) ;
2010-06-08 11:19:41 -04:00
}
2010-09-05 18:08:08 -07:00
} ,
2011-11-01 00:20:06 -07:00
show _collapsed _folder _count : function ( $folder _title , $children , options ) {
options = options || { } ;
2010-09-05 18:08:08 -07:00
var $counts = $ ( '.feed_counts_floater' , $folder _title ) ;
$counts . remove ( ) ;
2010-10-06 09:42:59 -04:00
$children = $ ( 'li.feed' , $children ) . not ( '.NB-feed-inactive' ) ;
2011-10-31 18:04:25 -07:00
var $river = $ ( '.NB-feedlist-collapse-icon' , $folder _title ) ;
2010-06-08 11:19:41 -04:00
2010-09-05 18:08:08 -07:00
var positive _count = 0 ;
var neutral _count = 0 ;
var negative _count = 0 ;
$ ( '.unread_count_positive.unread_count_full' , $children ) . each ( function ( ) {
positive _count += parseInt ( $ ( this ) . text ( ) , 10 ) ;
} ) ;
$ ( '.unread_count_neutral.unread_count_full' , $children ) . each ( function ( ) {
neutral _count += parseInt ( $ ( this ) . text ( ) , 10 ) ;
} ) ;
$ ( '.unread_count_negative.unread_count_full' , $children ) . each ( function ( ) {
negative _count += parseInt ( $ ( this ) . text ( ) , 10 ) ;
} ) ;
2010-12-12 20:06:32 -05:00
if ( $folder _title . hasClass ( 'NB-hover' ) ) {
2011-11-01 00:20:06 -07:00
$river . animate ( { 'opacity' : 0 } , { 'duration' : options . skip _animation ? 0 : 100 } ) ;
2010-12-12 20:06:32 -05:00
$folder _title . addClass ( 'NB-feedlist-folder-title-recently-collapsed' ) ;
$folder _title . one ( 'mouseover' , function ( ) {
$river . css ( { 'opacity' : '' } ) ;
$folder _title . removeClass ( 'NB-feedlist-folder-title-recently-collapsed' ) ;
} ) ;
}
2010-09-05 18:08:08 -07:00
var $counts = this . make _feed _counts _floater ( positive _count , neutral _count , negative _count ) ;
$folder _title . prepend ( $counts . css ( {
'opacity' : 0
} ) ) ;
2011-11-01 00:20:06 -07:00
$counts . animate ( { 'opacity' : 1 } , { 'duration' : options . skip _animation ? 0 : 400 } ) ;
2010-09-05 18:08:08 -07:00
} ,
hide _collapsed _folder _count : function ( $folder _title ) {
var $counts = $ ( '.feed_counts_floater' , $folder _title ) ;
2011-10-31 18:04:25 -07:00
var $river = $ ( '.NB-feedlist-collapse-icon' , $folder _title ) ;
2010-12-12 20:06:32 -05:00
2010-09-05 18:08:08 -07:00
$counts . animate ( { 'opacity' : 0 } , {
'duration' : 300
2010-06-08 11:19:41 -04:00
} ) ;
2010-12-12 20:06:32 -05:00
$river . animate ( { 'opacity' : . 6 } , { 'duration' : 400 } ) ;
$folder _title . removeClass ( 'NB-feedlist-folder-title-recently-collapsed' ) ;
$folder _title . one ( 'mouseover' , function ( ) {
$river . css ( { 'opacity' : '' } ) ;
// $folder_title.removeClass('NB-feedlist-folder-title-recently-collapsed');
} ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-09-11 17:15:08 -04:00
hover _over _feed _titles : function ( $folder ) {
2010-10-06 22:22:32 -04:00
var self = this ;
var $feeds ;
$folder = $folder || this . $s . $feed _list ;
2010-09-13 00:38:25 -04:00
2010-10-06 22:22:32 -04:00
if ( $folder . is ( '.feed' ) ) {
$feeds = $folder ;
} else {
$feeds = $ ( '.feed, .folder_title' , $folder ) ;
}
2011-09-27 23:06:49 -07:00
2010-10-06 22:22:32 -04:00
// NEWSBLUR.log(['hover_over_feed_titles', $folder, $feeds]);
$feeds . unbind ( 'mouseenter' ) . unbind ( 'mouseleave' ) ;
2010-09-11 17:15:08 -04:00
$feeds . hover ( function ( ) {
2010-11-01 19:28:57 -04:00
if ( ! self . $s . $feed _list . hasClass ( 'NB-feed-sorting' ) ) {
var $this = $ ( this ) ;
2010-12-31 14:41:59 -05:00
// _.defer(function() { $('.NB-hover', $folder).not($this).removeClass('NB-hover'); });
2010-11-01 19:28:57 -04:00
// NEWSBLUR.log(['scroll', $this.scrollTop(), $this.offset(), $this.position()]);
2011-12-14 21:59:25 -08:00
if ( $this . offset ( ) . top > $ ( window ) . height ( ) - 314 ) {
2010-11-01 19:28:57 -04:00
$this . addClass ( 'NB-hover-inverse' ) ;
}
}
2010-09-11 17:15:08 -04:00
} , function ( ) {
2010-09-13 00:38:25 -04:00
var $this = $ ( this ) ;
$this . removeClass ( 'NB-hover-inverse' ) ;
2010-09-11 17:15:08 -04:00
} ) ;
} ,
2010-09-28 18:53:57 -04:00
show _feed _chooser _button : function ( ) {
var self = this ;
var $progress = this . $s . $feeds _progress ;
var $bar = $ ( '.NB-progress-bar' , $progress ) ;
var percentage = 0 ;
$ ( '.NB-progress-title' , $progress ) . text ( 'Get Started' ) ;
$ ( '.NB-progress-counts' , $progress ) . hide ( ) ;
$ ( '.NB-progress-percentage' , $progress ) . hide ( ) ;
2010-10-02 17:05:55 -04:00
$progress . addClass ( 'NB-progress-error' ) . addClass ( 'NB-progress-big' ) ;
2011-12-22 13:36:03 -08:00
$ ( '.NB-progress-link' , $progress ) . html ( $ . make ( 'a' , { href : '#' , className : 'NB-splash-link NB-menu-manage-feedchooser' } , 'Choose your 64 sites' ) ) ;
2010-09-28 18:53:57 -04:00
this . show _progress _bar ( ) ;
} ,
2010-10-02 17:05:55 -04:00
hide _feed _chooser _button : function ( ) {
var $progress = this . $s . $feeds _progress ;
var $bar = $ ( '.NB-progress-bar' , $progress ) ;
$progress . removeClass ( 'NB-progress-error' ) . removeClass ( 'NB-progress-big' ) ;
this . hide _progress _bar ( ) ;
} ,
2010-11-22 10:44:52 -05:00
// ================
// = Progress Bar =
// ================
check _feed _fetch _progress : function ( ) {
$ . extend ( this . counts , {
'unfetched_feeds' : 0 ,
'fetched_feeds' : 0
} ) ;
if ( this . flags [ 'has_unfetched_feeds' ] ) {
var counts = this . model . count _unfetched _feeds ( ) ;
this . counts [ 'unfetched_feeds' ] = counts [ 'unfetched_feeds' ] ;
this . counts [ 'fetched_feeds' ] = counts [ 'fetched_feeds' ] ;
if ( this . counts [ 'unfetched_feeds' ] == 0 ) {
this . flags [ 'has_unfetched_feeds' ] = false ;
this . hide _unfetched _feed _progress ( ) ;
} else {
this . flags [ 'has_unfetched_feeds' ] = true ;
this . show _unfetched _feed _progress ( ) ;
}
}
} ,
show _progress _bar : function ( ) {
2010-11-24 15:01:35 -05:00
var $layout = this . $s . $feeds _progress . parents ( '.left-center' ) . layout ( ) ;
2010-11-22 10:44:52 -05:00
if ( ! this . flags [ 'showing_progress_bar' ] ) {
this . flags [ 'showing_progress_bar' ] = true ;
2010-11-24 13:16:10 -05:00
$layout . open ( 'south' ) ;
2010-11-22 10:44:52 -05:00
}
2010-11-24 15:01:35 -05:00
$layout . sizePane ( 'south' ) ;
2010-11-22 10:44:52 -05:00
} ,
hide _progress _bar : function ( permanent ) {
var self = this ;
if ( permanent ) {
this . model . preference ( 'hide_fetch_progress' , true ) ;
}
this . flags [ 'showing_progress_bar' ] = false ;
this . $s . $feeds _progress . parents ( '.left-center' ) . layout ( ) . close ( 'south' ) ;
} ,
show _unfetched _feed _progress : function ( ) {
var self = this ;
var $progress = this . $s . $feeds _progress ;
var percentage = parseInt ( this . counts [ 'fetched_feeds' ] / ( this . counts [ 'unfetched_feeds' ] + this . counts [ 'fetched_feeds' ] ) * 100 , 10 ) ;
$ ( '.NB-progress-title' , $progress ) . text ( 'Fetching your feeds' ) ;
$ ( '.NB-progress-counts' , $progress ) . show ( ) ;
$ ( '.NB-progress-counts-fetched' , $progress ) . text ( this . counts [ 'fetched_feeds' ] ) ;
$ ( '.NB-progress-counts-total' , $progress ) . text ( this . counts [ 'unfetched_feeds' ] + this . counts [ 'fetched_feeds' ] ) ;
$ ( '.NB-progress-percentage' , $progress ) . show ( ) . text ( percentage + '%' ) ;
$ ( '.NB-progress-bar' , $progress ) . progressbar ( {
value : percentage
} ) ;
2011-03-19 11:22:10 -04:00
if ( ! $progress . is ( ':visible' ) && ! this . model . preference ( 'hide_fetch_progress' ) ) {
2010-11-22 10:44:52 -05:00
setTimeout ( function ( ) {
self . show _progress _bar ( ) ;
} , 1000 ) ;
}
2011-02-05 15:34:43 -05:00
this . setup _feed _refresh ( true ) ;
2010-11-22 10:44:52 -05:00
} ,
hide _unfetched _feed _progress : function ( permanent ) {
if ( permanent ) {
this . model . preference ( 'hide_fetch_progress' , true ) ;
}
2011-01-30 21:48:17 -05:00
this . setup _feed _refresh ( ) ;
2010-11-22 10:44:52 -05:00
this . hide _progress _bar ( ) ;
} ,
2010-12-04 23:06:35 -05:00
switch _preferences _hide _read _feeds : function ( ) {
var hide _read _feeds = parseInt ( this . model . preference ( 'hide_read_feeds' ) , 10 ) ;
2010-12-04 23:18:07 -05:00
var $button = $ ( '.NB-feeds-header-sites' ) ;
2010-12-04 23:06:35 -05:00
2011-05-01 20:22:54 -04:00
if ( this . model . preference ( 'show_tooltips' ) ) {
if ( hide _read _feeds ) {
$button . tipsy ( 'hide' ) ;
$button . attr ( 'title' , 'Show only unread stories' ) ;
$button . tipsy ( 'show' ) ;
} else {
$button . tipsy ( 'hide' ) ;
$button . attr ( 'title' , 'Show all sites' ) ;
$button . tipsy ( 'show' ) ;
}
2010-12-04 23:06:35 -05:00
}
this . model . preference ( 'hide_read_feeds' , hide _read _feeds ? 0 : 1 ) ;
this . switch _feed _view _unread _view ( ) ;
} ,
2010-09-05 18:08:08 -07:00
// ===============================
// = Feed bar - Individual Feeds =
// ===============================
2010-06-08 11:19:41 -04:00
reset _feed : function ( ) {
2010-07-02 12:02:10 -04:00
$ . extend ( this . flags , {
'iframe_story_locations_fetched' : false ,
'iframe_view_loaded' : false ,
2010-12-04 23:26:52 -05:00
'iframe_view_not_busting' : false ,
2010-07-02 12:02:10 -04:00
'feed_view_images_loaded' : { } ,
'feed_view_positions_calculated' : false ,
'scrolling_by_selecting_story_title' : false ,
'switching_to_feed_view' : false ,
'page_view_showing_feed_view' : false ,
2010-12-07 09:52:14 -05:00
'feed_view_showing_story_view' : false ,
2010-07-02 12:02:10 -04:00
'iframe_fetching_story_locations' : false ,
2010-07-06 18:30:16 -04:00
'story_titles_loaded' : false ,
2010-08-30 22:42:44 -04:00
'iframe_prevented_from_loading' : false ,
2010-09-12 13:50:27 -04:00
'pause_feed_refreshing' : false ,
2011-01-04 19:27:00 -05:00
'feed_list_showing_manage_menu' : false ,
2011-01-19 08:54:59 -05:00
'unread_threshold_temporarily' : null ,
2011-02-13 14:49:13 -05:00
'river_view' : false ,
'non_premium_river_view' : false
2010-07-02 12:02:10 -04:00
} ) ;
$ . extend ( this . cache , {
2010-11-06 12:53:42 -04:00
'iframe' : { } ,
2010-06-08 11:19:41 -04:00
'iframe_stories' : { } ,
'feed_view_stories' : { } ,
'iframe_story_positions' : { } ,
'feed_view_story_positions' : { } ,
'iframe_story_positions_keys' : [ ] ,
'feed_view_story_positions_keys' : [ ] ,
'previous_stories_stack' : [ ] ,
2010-12-12 22:52:15 -05:00
'river_feeds_with_unreads' : [ ] ,
2010-11-06 12:53:42 -04:00
'mouse_position_y' : parseInt ( this . model . preference ( 'lock_mouse_indicator' ) , 10 ) ,
'prefetch_last_story' : 0 ,
2011-01-25 22:59:38 -05:00
'prefetch_iteration' : 0 ,
'feed_title_floater_feed_id' : null ,
'feed_title_floater_story_id' : null ,
2011-03-09 20:04:50 -05:00
'last_feed_view_story_feed_id' : null ,
2011-03-16 18:29:56 -04:00
'$feed_in_feed_list' : { } ,
'$feed_counts_in_feed_list' : { }
2010-07-02 12:02:10 -04:00
} ) ;
2010-06-08 11:19:41 -04:00
2011-03-09 09:48:24 -05:00
$ . extend ( this . counts , {
2011-04-12 11:02:02 -04:00
'page_fill_outs' : 0 ,
2011-11-02 09:43:06 -07:00
'find_next_unread_on_page_of_feed_stories_load' : 0 ,
'find_last_unread_on_page_of_feed_stories_load' : 0
2010-07-02 12:02:10 -04:00
} ) ;
2010-06-08 11:19:41 -04:00
this . active _feed = null ;
2010-12-08 20:53:45 -05:00
this . active _story = null ;
2011-04-21 10:44:50 -04:00
this . $s . $story _titles . data ( 'page' , 1 ) ;
2010-06-14 13:17:38 -04:00
this . $s . $story _titles . data ( 'feed_id' , null ) ;
2011-01-26 20:51:29 -05:00
this . $s . $feed _stories . scrollTop ( 0 ) ;
this . $s . $feed _stories . empty ( ) ;
2011-09-29 09:53:55 -07:00
this . $s . $story _titles . empty ( ) ;
2010-12-02 11:09:09 -05:00
this . $s . $starred _header . removeClass ( 'NB-selected' ) ;
2010-12-10 15:26:50 -05:00
this . $s . $river _header . removeClass ( 'NB-selected' ) ;
2011-03-15 23:42:27 -04:00
this . $s . $tryfeed _header . removeClass ( 'NB-selected' ) ;
2010-12-12 20:06:32 -05:00
$ ( '.NB-selected' , this . $s . $feed _list ) . removeClass ( 'NB-selected' ) ;
2010-12-12 22:52:15 -05:00
this . $s . $body . removeClass ( 'NB-view-river' ) ;
2011-02-27 21:44:47 -05:00
$ ( '.task_view_page' , this . $s . $taskbar ) . removeClass ( 'NB-disabled' ) ;
2011-02-02 14:10:24 -05:00
$ ( '.task_view_page' , this . $s . $taskbar ) . removeClass ( 'NB-task-return' ) ;
2011-02-01 00:23:44 -05:00
this . hide _content _pane _feed _counter ( ) ;
2011-03-15 23:42:27 -04:00
if ( this . flags [ 'showing_feed_in_tryfeed_view' ] ) {
this . hide _tryfeed _view ( ) ;
}
2010-06-08 11:19:41 -04:00
} ,
2010-11-24 13:16:10 -05:00
open _feed : function ( feed _id , force , $feed _link , delay ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-06-14 13:17:38 -04:00
var $story _titles = this . $s . $story _titles ;
2010-06-08 11:19:41 -04:00
this . flags [ 'opening_feed' ] = true ;
2010-08-30 22:42:44 -04:00
if ( feed _id != this . active _feed || force ) {
2010-11-01 18:20:26 -04:00
$story _titles . empty ( ) . scrollTop ( 0 ) ;
2010-06-08 11:19:41 -04:00
this . reset _feed ( ) ;
this . hide _splash _page ( ) ;
this . active _feed = feed _id ;
2010-11-24 13:16:10 -05:00
this . next _feed = feed _id ;
2011-01-31 20:50:33 -05:00
this . show _stories _progress _bar ( ) ;
2011-04-21 10:44:50 -04:00
$story _titles . data ( 'page' , 1 ) ;
2010-06-14 13:17:38 -04:00
$story _titles . data ( 'feed_id' , feed _id ) ;
2010-06-08 11:19:41 -04:00
this . iframe _scroll = null ;
2010-10-28 18:17:14 -04:00
this . set _correct _story _view _for _feed ( feed _id ) ;
2010-10-13 09:08:42 -04:00
$feed _link = $feed _link || $ ( '.feed.selected' , this . $s . $feed _list ) . eq ( 0 ) ;
2010-06-08 11:19:41 -04:00
this . mark _feed _as _selected ( feed _id , $feed _link ) ;
2010-11-01 18:20:26 -04:00
this . show _feed _title _in _stories ( feed _id ) ;
2010-06-08 11:19:41 -04:00
this . show _feedbar _loading ( ) ;
this . switch _taskbar _view ( this . story _view ) ;
2010-11-24 13:16:10 -05:00
_ . delay ( _ . bind ( function ( ) {
if ( ! delay || feed _id == self . next _feed ) {
2011-11-15 18:19:09 -08:00
this . model . load _feed ( feed _id , 1 , true , $ . rescope ( this . post _open _feed , this ) ,
_ . bind ( this . show _stories _error , this ) ) ;
2010-11-24 13:16:10 -05:00
}
} , this ) , delay || 0 ) ;
2011-02-27 21:44:47 -05:00
if ( ! this . story _view || this . story _view == 'page' ) {
2010-11-24 13:16:10 -05:00
_ . delay ( _ . bind ( function ( ) {
2011-02-27 21:44:47 -05:00
if ( ! delay || feed _id == this . next _feed ) {
2010-12-06 10:41:24 -05:00
this . load _feed _iframe ( feed _id ) ;
2010-11-24 13:16:10 -05:00
}
} , this ) , delay || 0 ) ;
2010-07-06 18:30:16 -04:00
} else {
2010-12-06 10:41:24 -05:00
this . unload _feed _iframe ( ) ;
2010-07-06 18:30:16 -04:00
this . flags [ 'iframe_prevented_from_loading' ] = true ;
}
2010-12-02 11:09:09 -05:00
this . setup _mousemove _on _views ( ) ;
2010-06-08 11:19:41 -04:00
}
} ,
post _open _feed : function ( e , data , first _load ) {
2010-10-06 20:26:42 -04:00
if ( ! data ) {
2010-10-11 12:07:32 -04:00
return this . open _feed ( this . active _feed , true ) ;
2010-10-06 20:26:42 -04:00
}
2010-06-08 11:19:41 -04:00
var stories = data . stories ;
var tags = data . tags ;
2010-10-25 20:44:52 -04:00
var feed _id = data . feed _id ;
2010-06-08 11:19:41 -04:00
2011-01-14 00:59:51 -05:00
if ( data . dupe _feed _id && this . active _feed == data . dupe _feed _id ) {
this . active _feed = data . feed _id ;
}
2011-06-07 12:57:14 -04:00
if ( this . active _feed != feed _id ) return ;
2011-06-09 19:03:27 -04:00
2011-06-07 12:57:14 -04:00
// NEWSBLUR.log(['post_open_feed', data.stories, this.flags]);
this . flags [ 'opening_feed' ] = false ;
this . flags [ 'feed_view_positions_calculated' ] = false ;
this . story _titles _clear _loading _endbar ( ) ;
this . create _story _titles ( stories ) ;
this . make _story _feed _entries ( stories , first _load ) ;
this . show _feed _hidden _story _title _indicator ( true ) ;
this . show _story _titles _above _intelligence _level ( { 'animate' : false } ) ;
2011-12-14 21:56:27 -08:00
this . scroll _story _titles _to _show _selected _story _title ( ) ;
2011-06-07 12:57:14 -04:00
this . fill _out _story _titles ( ) ;
$ ( '.NB-feedbar-last-updated-date' ) . text ( data . last _update + ' ago' ) ;
if ( this . counts [ 'find_next_unread_on_page_of_feed_stories_load' ] ) {
this . show _next _unread _story ( true ) ;
2011-11-02 09:43:06 -07:00
} else if ( this . counts [ 'find_last_unread_on_page_of_feed_stories_load' ] ) {
this . show _last _unread _story ( true ) ;
2011-06-07 12:57:14 -04:00
}
this . flags [ 'story_titles_loaded' ] = true ;
if ( ! first _load ) {
var stories _count = this . cache [ 'iframe_story_positions_keys' ] . length ;
2011-10-03 18:19:50 -07:00
this . flags [ 'iframe_story_locations_fetched' ] = false ;
2011-06-07 12:57:14 -04:00
var $iframe = this . $s . $feed _iframe . contents ( ) ;
this . fetch _story _locations _in _story _frame ( stories _count , false , $iframe ) ;
2011-06-09 19:03:27 -04:00
if ( this . story _view == 'feed' || this . flags [ 'page_view_showing_feed_view' ] ) {
2011-06-07 12:57:14 -04:00
this . prefetch _story _locations _in _feed _view ( ) ;
2010-12-14 17:08:52 -05:00
}
2011-06-07 12:57:14 -04:00
} else {
if ( this . story _view == 'page' ) {
if ( this . flags [ 'iframe_view_loaded' ] ) {
// NEWSBLUR.log(['Titles loaded, iframe loaded']);
var $iframe = this . $s . $feed _iframe . contents ( ) ;
this . fetch _story _locations _in _story _frame ( 0 , true , $iframe ) ;
} else {
// NEWSBLUR.log(['Titles loaded, iframe NOT loaded -- prefetching now']);
_ . delay ( _ . bind ( function ( ) {
this . prefetch _story _locations _in _story _frame ( ) ;
2011-06-09 20:51:48 -04:00
} , this ) , 250 ) ;
2011-06-07 12:57:14 -04:00
}
} else if ( this . story _view == 'feed' ) {
this . prefetch _story _locations _in _feed _view ( ) ;
} else if ( this . story _view == 'story' ) {
this . show _next _story ( 1 ) ;
2011-03-15 23:42:27 -04:00
}
2010-06-08 11:19:41 -04:00
}
2011-06-07 12:57:14 -04:00
if ( this . flags [ 'open_unread_stories_in_tabs' ] ) {
_ . defer ( _ . bind ( this . open _unread _stories _in _tabs , this ) ) ;
}
this . hide _stories _progress _bar ( ) ;
if ( this . flags [ 'showing_feed_in_tryfeed_view' ] ) {
this . show _tryfeed _add _button ( ) ;
}
this . make _content _pane _feed _counter ( feed _id ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-12-02 11:09:09 -05:00
setup _mousemove _on _views : function ( ) {
2010-12-06 10:41:24 -05:00
var $iframe _contents = this . $s . $feed _iframe . contents ( ) ;
2010-12-02 11:09:09 -05:00
$iframe _contents
. unbind ( 'scroll' )
2010-12-06 10:41:24 -05:00
. scroll ( $ . rescope ( this . handle _scroll _feed _iframe , this ) ) ;
2010-12-02 11:09:09 -05:00
this . hide _mouse _indicator ( ) ;
$iframe _contents
. unbind ( 'mousemove.reader' )
. bind ( 'mousemove.reader' , $ . rescope ( this . handle _mousemove _iframe _view , this ) ) ;
this . $s . $content _pane
. unbind ( 'mouseleave.reader' )
. bind ( 'mouseleave.reader' , $ . rescope ( this . hide _mouse _indicator , this ) ) ;
this . $s . $content _pane
. unbind ( 'mouseenter.reader' )
. bind ( 'mouseenter.reader' , $ . rescope ( this . show _mouse _indicator , this ) ) ;
} ,
set _correct _story _view _for _feed : function ( feed _id , view ) {
2010-10-28 18:17:14 -04:00
var feed = this . model . get _feed ( feed _id ) ;
2010-12-02 11:09:09 -05:00
view = view || this . model . view _setting ( feed _id ) ;
2010-10-28 18:17:14 -04:00
2010-12-02 11:09:09 -05:00
if ( feed && feed . has _exception && feed . exception _type == 'page' ) {
2010-10-28 18:17:14 -04:00
if ( view == 'page' ) {
view = 'feed' ;
}
$ ( '.task_view_page' ) . addClass ( 'NB-exception-page' ) ;
} else {
$ ( '.task_view_page' ) . removeClass ( 'NB-exception-page' ) ;
}
this . story _view = view ;
} ,
2010-12-02 11:09:09 -05:00
// ===============
// = Feed Header =
// ===============
2011-11-11 12:45:32 -08:00
update _header _counts : function ( skip _sites , unread _view ) {
2010-12-02 11:09:09 -05:00
if ( ! skip _sites ) {
var feeds _count = _ . select ( this . model . feeds , function ( f ) {
return f . active ;
} ) . length ;
if ( feeds _count ) {
2010-12-04 23:06:35 -05:00
$ ( '.NB-feeds-header-right .NB-feeds-header-sites' ) . text ( feeds _count + Inflector . pluralize ( ' site' , feeds _count ) ) ;
2010-12-02 11:09:09 -05:00
}
}
var unread _counts = _ . reduce ( this . model . feeds , function ( m , v ) {
if ( v . active ) {
m [ 'positive' ] += v . ps ;
m [ 'neutral' ] += v . nt ;
m [ 'negative' ] += v . ng ;
}
return m ;
} , { 'positive' : 0 , 'negative' : 0 , 'neutral' : 0 } ) ;
_ ( [ 'positive' , 'neutral' , 'negative' ] ) . each ( function ( level ) {
2011-11-11 12:45:32 -08:00
// This is for .NB-feeds-header-count
2010-12-02 11:09:09 -05:00
var $count = $ ( '.NB-feeds-header-' + level ) ;
$count . text ( unread _counts [ level ] ) ;
$count . toggleClass ( 'NB-empty' , unread _counts [ level ] == 0 ) ;
} ) ;
2011-11-11 12:45:32 -08:00
if ( this . model . preference ( 'show_unread_counts_in_title' ) ) {
2011-11-17 22:33:00 -08:00
var title = '(' ;
2011-11-11 12:45:32 -08:00
var counts = [ ] ;
var unread _view = _ . isNumber ( unread _view ) && unread _view || this . model . preference ( 'unread_view' ) ;
if ( unread _view <= - 1 ) {
counts . push ( unread _counts [ 'negative' ] ) ;
}
if ( unread _view <= 0 ) {
counts . push ( unread _counts [ 'neutral' ] ) ;
}
if ( unread _view <= 1 ) {
counts . push ( unread _counts [ 'positive' ] ) ;
}
2011-11-17 22:33:00 -08:00
title += counts . join ( '/' ) + ') NewsBlur' ;
2011-11-11 12:45:32 -08:00
document . title = title ;
}
2010-12-02 11:09:09 -05:00
} ,
update _starred _count : function ( ) {
var starred _count = this . model . starred _count ;
2011-03-14 21:44:04 -04:00
var $starred _count = $ ( '.NB-feeds-header-count' , this . $s . $starred _header ) ;
var $starred _container = this . $s . $starred _header . closest ( '.NB-feeds-header-container' ) ;
2010-12-02 11:09:09 -05:00
if ( starred _count <= 0 ) {
this . $s . $starred _header . addClass ( 'NB-empty' ) ;
$starred _count . text ( '' ) ;
$starred _container . slideUp ( 350 ) ;
} else if ( starred _count > 0 ) {
$starred _count . text ( starred _count ) ;
this . $s . $starred _header . removeClass ( 'NB-empty' ) ;
$starred _container . slideDown ( 350 ) ;
2010-09-05 18:08:08 -07:00
}
} ,
2010-12-02 11:09:09 -05:00
open _starred _stories : function ( ) {
var $story _titles = this . $s . $story _titles ;
$story _titles . empty ( ) . scrollTop ( '0px' ) ;
this . reset _feed ( ) ;
this . hide _splash _page ( ) ;
2010-12-04 13:32:13 -05:00
this . active _feed = 'starred' ;
2011-03-14 21:44:04 -04:00
2011-04-21 10:44:50 -04:00
$story _titles . data ( 'page' , 1 ) ;
2010-12-02 11:09:09 -05:00
$story _titles . data ( 'feed_id' , null ) ;
this . iframe _scroll = null ;
this . mark _feed _as _selected ( null , null ) ;
2011-01-31 00:06:40 -05:00
this . show _correct _feed _in _feed _title _floater ( ) ;
2010-12-02 11:09:09 -05:00
this . $s . $starred _header . addClass ( 'NB-selected' ) ;
2010-12-12 22:52:15 -05:00
this . $s . $body . addClass ( 'NB-view-river' ) ;
2011-01-19 08:54:59 -05:00
this . flags . river _view = true ;
2010-12-04 21:53:39 -05:00
$ ( '.task_view_page' , this . $s . $taskbar ) . addClass ( 'NB-disabled' ) ;
2010-12-04 13:32:13 -05:00
var explicit _view _setting = NEWSBLUR . Preferences . view _settings [ this . active _feed ] ;
if ( ! explicit _view _setting ) {
explicit _view _setting = 'feed' ;
}
this . set _correct _story _view _for _feed ( this . active _feed , explicit _view _setting ) ;
2010-12-02 11:09:09 -05:00
// this.show_feed_title_in_stories(feed_id);
this . show _feedbar _loading ( ) ;
this . switch _taskbar _view ( this . story _view ) ;
this . setup _mousemove _on _views ( ) ;
2011-11-15 18:19:09 -08:00
this . model . fetch _starred _stories ( 1 , _ . bind ( this . post _open _starred _stories , this ) ,
_ . bind ( this . show _stories _error , this ) , true ) ;
2010-12-02 11:09:09 -05:00
} ,
2010-12-02 20:18:33 -05:00
post _open _starred _stories : function ( data , first _load ) {
2010-12-04 13:32:13 -05:00
if ( this . active _feed == 'starred' ) {
2010-12-12 23:22:53 -05:00
// NEWSBLUR.log(['post_open_starred_stories', data.stories.length, first_load]);
2010-12-02 20:18:33 -05:00
this . flags [ 'feed_view_positions_calculated' ] = false ;
this . story _titles _clear _loading _endbar ( ) ;
2010-12-10 15:26:50 -05:00
this . create _story _titles ( data . stories , { 'river_stories' : true } ) ;
this . make _story _feed _entries ( data . stories , first _load , { 'river_stories' : true } ) ;
2010-12-08 20:53:45 -05:00
this . show _story _titles _above _intelligence _level ( { 'animate' : false } ) ;
2010-12-02 20:18:33 -05:00
// $('.NB-feedbar-last-updated-date').text(data.last_update + ' ago');
this . flags [ 'story_titles_loaded' ] = true ;
2010-12-12 23:22:53 -05:00
this . prefetch _story _locations _in _feed _view ( ) ;
2011-12-14 21:56:27 -08:00
this . scroll _story _titles _to _show _selected _story _title ( ) ;
2011-01-11 19:33:55 -05:00
this . fill _out _story _titles ( ) ;
2010-09-14 20:49:28 -04:00
}
2010-12-02 11:09:09 -05:00
} ,
2010-12-10 15:26:50 -05:00
// =================
// = River of News =
// =================
2010-12-12 22:52:15 -05:00
open _river _stories : function ( $folder , folder _title ) {
2010-12-10 15:26:50 -05:00
var $story _titles = this . $s . $story _titles ;
2010-12-12 22:52:15 -05:00
$folder = $folder || this . $s . $feed _list ;
2010-09-14 20:49:28 -04:00
2010-12-10 15:26:50 -05:00
$story _titles . empty ( ) . scrollTop ( '0px' ) ;
this . reset _feed ( ) ;
this . hide _splash _page ( ) ;
2010-12-12 20:06:32 -05:00
if ( ! folder _title ) {
2010-12-12 22:52:15 -05:00
this . active _feed = 'river:' ;
2010-12-12 20:06:32 -05:00
this . $s . $river _header . addClass ( 'NB-selected' ) ;
} else {
this . active _feed = 'river:' + folder _title ;
2011-03-14 21:44:04 -04:00
$folder . addClass ( 'NB-selected' ) ;
2010-12-12 20:06:32 -05:00
}
2010-11-24 13:16:10 -05:00
2011-04-21 10:44:50 -04:00
$story _titles . data ( 'page' , 1 ) ;
2010-12-10 15:26:50 -05:00
$story _titles . data ( 'feed_id' , null ) ;
this . iframe _scroll = null ;
2011-02-01 00:23:44 -05:00
this . flags [ 'opening_feed' ] = true ;
2010-12-10 15:26:50 -05:00
this . mark _feed _as _selected ( null , null ) ;
2011-01-30 23:00:22 -05:00
this . show _correct _feed _in _feed _title _floater ( ) ;
2010-12-10 15:26:50 -05:00
this . $s . $body . addClass ( 'NB-view-river' ) ;
2011-01-19 08:54:59 -05:00
this . flags . river _view = true ;
2011-01-31 20:50:33 -05:00
2010-12-10 15:26:50 -05:00
$ ( '.task_view_page' , this . $s . $taskbar ) . addClass ( 'NB-disabled' ) ;
var explicit _view _setting = NEWSBLUR . Preferences . view _settings [ this . active _feed ] ;
if ( ! explicit _view _setting ) {
explicit _view _setting = 'feed' ;
}
this . set _correct _story _view _for _feed ( this . active _feed , explicit _view _setting ) ;
// this.show_feed_title_in_stories(feed_id);
this . show _feedbar _loading ( ) ;
this . switch _taskbar _view ( this . story _view ) ;
this . setup _mousemove _on _views ( ) ;
2011-01-31 20:08:07 -05:00
var feeds = this . list _feeds _with _unreads _in _folder ( $folder , false , true ) ;
2011-02-04 09:56:15 -05:00
this . cache [ 'river_feeds_with_unreads' ] = feeds ;
2011-01-31 20:53:30 -05:00
this . show _stories _progress _bar ( feeds . length ) ;
2011-06-12 23:22:58 -04:00
this . model . fetch _river _stories ( this . active _feed , feeds , 1 ,
2011-11-15 18:19:09 -08:00
_ . bind ( this . post _open _river _stories , this ) , _ . bind ( this . show _stories _error , this ) , true ) ;
2010-12-10 15:26:50 -05:00
} ,
post _open _river _stories : function ( data , first _load ) {
2011-02-04 09:56:15 -05:00
// NEWSBLUR.log(['post_open_river_stories', data, this.active_feed]);
2011-11-15 18:19:09 -08:00
if ( ! data ) {
return this . show _stories _error ( ) ;
}
2011-02-04 09:56:15 -05:00
if ( this . active _feed && this . active _feed . indexOf ( 'river:' ) != - 1 ) {
2011-02-13 14:49:13 -05:00
if ( ! NEWSBLUR . Globals . is _premium &&
2011-02-22 23:07:49 -05:00
NEWSBLUR . Globals . is _authenticated &&
2011-02-13 14:49:13 -05:00
this . flags [ 'river_view' ] &&
this . active _feed . indexOf ( 'river:' ) != - 1 ) {
this . flags [ 'non_premium_river_view' ] = true ;
}
2011-02-01 00:23:44 -05:00
this . flags [ 'opening_feed' ] = false ;
2010-12-10 15:26:50 -05:00
this . flags [ 'feed_view_positions_calculated' ] = false ;
this . story _titles _clear _loading _endbar ( ) ;
this . create _story _titles ( data . stories , { 'river_stories' : true } ) ;
this . make _story _feed _entries ( data . stories , first _load , { 'river_stories' : true } ) ;
this . show _story _titles _above _intelligence _level ( { 'animate' : false } ) ;
// $('.NB-feedbar-last-updated-date').text(data.last_update + ' ago');
this . flags [ 'story_titles_loaded' ] = true ;
2011-04-12 11:02:02 -04:00
if ( this . counts [ 'find_next_unread_on_page_of_feed_stories_load' ] ) {
2011-01-11 19:33:55 -05:00
this . show _next _unread _story ( true ) ;
2011-11-02 09:43:06 -07:00
} else if ( this . counts [ 'find_last_unread_on_page_of_feed_stories_load' ] ) {
this . show _last _unread _story ( true ) ;
2011-01-11 19:33:55 -05:00
}
2011-12-14 21:56:27 -08:00
this . scroll _story _titles _to _show _selected _story _title ( ) ;
2011-01-11 19:33:55 -05:00
this . fill _out _story _titles ( ) ;
2010-12-12 23:22:53 -05:00
this . prefetch _story _locations _in _feed _view ( ) ;
2011-01-31 20:50:33 -05:00
this . hide _stories _progress _bar ( ) ;
2010-12-10 15:26:50 -05:00
}
} ,
2011-01-31 20:08:07 -05:00
list _feeds _with _unreads _in _folder : function ( $folder , counts _only , visible _only ) {
2010-12-12 22:52:15 -05:00
var model = this . model ;
2011-01-10 09:49:26 -05:00
var unread _view = this . get _unread _view _name ( ) ;
2010-12-12 22:52:15 -05:00
$folder = $folder || this . $s . $feed _list ;
var $feeds = $ ( '.feed:not(.NB-empty)' , $folder ) ;
var feeds = _ . compact ( _ . map ( $ ( '.feed:not(.NB-empty)' , $folder ) , function ( o ) {
2011-03-30 09:30:45 -04:00
var feed _id = parseInt ( $ ( o ) . attr ( 'data-id' ) , 10 ) ;
2010-12-12 22:52:15 -05:00
var feed = model . get _feed ( feed _id ) ;
2011-06-12 23:16:59 -04:00
if ( ! feed ) {
return ;
} else if ( counts _only && ! visible _only ) {
2011-01-31 20:08:07 -05:00
return feed . ps + feed . nt + feed . ng ;
} else if ( counts _only && visible _only ) {
2011-01-10 09:49:26 -05:00
if ( unread _view == 'positive' ) return feed . ps ;
if ( unread _view == 'neutral' ) return feed . ps + feed . nt ;
if ( unread _view == 'negative' ) return feed . ps + feed . nt + feed . ng ;
2011-04-12 11:02:02 -04:00
} else if ( ! counts _only && visible _only ) {
if ( unread _view == 'positive' ) return feed . ps && feed _id ;
if ( unread _view == 'neutral' ) return ( feed . ps || feed . nt ) && feed _id ;
if ( unread _view == 'negative' ) return ( feed . ps || feed . nt || feed . ng ) && feed _id ;
2011-01-10 09:49:26 -05:00
} else {
return ( feed . ps || feed . nt || feed . ng ) && feed _id ;
}
2010-12-12 22:52:15 -05:00
} ) ) ;
2010-12-10 15:26:50 -05:00
2010-12-12 22:52:15 -05:00
return feeds ;
2010-09-14 20:49:28 -04:00
} ,
2011-01-31 20:53:30 -05:00
show _stories _progress _bar : function ( feeds _loading ) {
2011-11-15 18:19:09 -08:00
this . hide _stories _error ( ) ;
2011-01-31 19:51:39 -05:00
var $progress = $ . make ( 'div' , { className : 'NB-river-progress' } , [
$ . make ( 'div' , { className : 'NB-river-progress-text' } ) ,
$ . make ( 'div' , { className : 'NB-river-progress-bar' } )
2011-01-31 20:50:33 -05:00
] ) . css ( { 'opacity' : 0 } ) ;
this . $s . $story _taskbar . append ( $progress ) ;
2011-01-31 19:51:39 -05:00
2011-01-31 20:50:33 -05:00
$progress . animate ( { 'opacity' : 1 } , { 'duration' : 500 , 'queue' : false } ) ;
2011-01-31 19:51:39 -05:00
2011-01-31 20:08:07 -05:00
var $bar = $ ( '.NB-river-progress-bar' , $progress ) ;
2011-01-31 20:53:30 -05:00
var unreads ;
if ( feeds _loading ) unreads = feeds _loading ;
else unreads = this . get _unread _count ( false ) / 10 ;
this . animate _progress _bar ( $bar , unreads ) ;
2011-01-31 20:50:33 -05:00
$ ( '.NB-river-progress-text' , $progress ) . text ( 'Fetching stories' ) ;
// Center the progress bar
var i _width = $progress . width ( ) ;
var o _width = this . $s . $story _taskbar . width ( ) ;
var left = ( o _width / 2.0 ) - ( i _width / 2.0 ) ;
$progress . css ( { 'left' : left } ) ;
2011-01-31 19:51:39 -05:00
} ,
2011-01-31 20:50:33 -05:00
hide _stories _progress _bar : function ( ) {
var $progress = $ ( '.NB-river-progress' , this . $s . $story _taskbar ) ;
2011-03-15 23:42:27 -04:00
$progress . stop ( ) . animate ( { 'opacity' : 0 } , {
'duration' : 250 ,
'queue' : false ,
'complete' : function ( ) {
$progress . remove ( ) ;
}
} ) ;
2011-01-31 19:51:39 -05:00
} ,
2011-11-15 18:19:09 -08:00
show _stories _error : function ( ) {
2011-11-22 12:08:18 -05:00
console . log ( [ "show_stories_error" , arguments ] ) ;
2011-11-15 18:19:09 -08:00
this . hide _stories _progress _bar ( ) ;
var $error = $ . make ( 'div' , { className : 'NB-feed-error' } , [
$ . make ( 'div' , { className : 'NB-feed-error-icon' } ) ,
$ . make ( 'div' , { className : 'NB-feed-error-text' } , 'Oh no! There was an error!' )
] ) . css ( { 'opacity' : 0 } ) ;
this . $s . $story _taskbar . append ( $error ) ;
$error . animate ( { 'opacity' : 1 } , { 'duration' : 500 , 'queue' : false } ) ;
// Center the progress bar
var i _width = $error . width ( ) ;
var o _width = this . $s . $story _taskbar . width ( ) ;
var left = ( o _width / 2.0 ) - ( i _width / 2.0 ) ;
$error . css ( { 'left' : left } ) ;
this . story _titles _clear _loading _endbar ( ) ;
this . append _story _titles _endbar ( ) ;
} ,
hide _stories _error : function ( ) {
var $error = $ ( '.NB-feed-error' , this . $s . $story _taskbar ) ;
$error . animate ( { 'opacity' : 0 } , {
'duration' : 250 ,
'queue' : false ,
'complete' : function ( ) {
$error . remove ( ) ;
}
} ) ;
} ,
2010-06-14 13:17:38 -04:00
// ==========================
// = Story Pane - All Views =
// ==========================
2010-12-14 18:48:52 -05:00
open _story : function ( story , $story _title ) {
2010-06-14 13:17:38 -04:00
var self = this ;
var feed _position ;
var iframe _position ;
2011-07-13 09:50:02 -07:00
// NEWSBLUR.log(['open_story', this.story_view, story]);
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
if ( this . active _story != story ) {
this . active _story = story ;
2010-12-14 18:48:52 -05:00
this . mark _story _title _as _selected ( $story _title ) ;
2011-01-11 21:37:38 -05:00
this . mark _story _as _read _in _feed _view ( story , { 'animate' : true } ) ;
2011-09-30 18:02:48 -07:00
this . unload _story _iframe ( ) ;
2011-01-10 19:34:27 -05:00
2010-12-08 20:53:45 -05:00
// Used when auto-tracking the user as they move over the feed/page.
// No need to find the story, since they have already found it.
2010-12-14 18:48:52 -05:00
clearTimeout ( this . locks . scrolling ) ;
2011-02-23 19:41:05 -05:00
if ( _ . contains ( [ 'feed' , 'page' ] , this . story _view ) ) {
this . flags [ 'scrolling_by_selecting_story_title' ] = true ;
}
2010-12-14 18:48:52 -05:00
// User clicks on story, scroll them to it.
2011-11-15 18:37:42 -08:00
var $feed _story = this . find _story _in _feed _view ( story . id ) ;
2010-12-14 18:48:52 -05:00
if ( this . story _view == 'page' ) {
var $iframe _story = this . find _story _in _feed _iframe ( story ) ;
2010-06-14 13:17:38 -04:00
if ( ! $iframe _story || ! $iframe _story . length || ! this . flags [ 'story_titles_loaded' ] ) {
// If the iframe has not yet loaded, we can't touch it.
// So just assume story not found.
this . switch _to _correct _view ( false ) ;
feed _position = this . scroll _to _story _in _story _feed ( story , $feed _story ) ;
2011-11-04 18:12:28 -07:00
this . show _stories _preference _in _feed _view ( true ) ;
2010-06-14 13:17:38 -04:00
} else {
iframe _position = this . scroll _to _story _in _iframe ( story , $iframe _story ) ;
this . switch _to _correct _view ( iframe _position ) ;
}
2010-12-14 18:48:52 -05:00
} else if ( this . story _view == 'feed' ) {
this . switch _to _correct _view ( ) ;
feed _position = this . scroll _to _story _in _story _feed ( story , $feed _story ) ;
this . show _stories _preference _in _feed _view ( true ) ;
} else if ( this . story _view == 'story' ) {
this . open _story _in _story _view ( story ) ;
2010-06-14 13:17:38 -04:00
}
2011-01-10 19:34:27 -05:00
_ . defer ( _ . bind ( this . mark _story _as _read , this , story . id ) ) ;
2010-06-14 13:17:38 -04:00
}
2010-06-08 11:19:41 -04:00
} ,
2010-06-14 13:17:38 -04:00
switch _to _correct _view : function ( found _story _in _page ) {
2011-07-13 09:50:02 -07:00
// NEWSBLUR.log(['Found story', this.story_view, found_story_in_page, this.flags['page_view_showing_feed_view'], this.flags['feed_view_showing_story_view']]);
2010-06-14 13:17:38 -04:00
if ( found _story _in _page === false ) {
// Story not found, show in feed view with link to page view
if ( this . story _view == 'page' && ! this . flags [ 'page_view_showing_feed_view' ] ) {
2010-12-07 20:04:37 -05:00
// console.log(['turn on feed view', this.flags['page_view_showing_feed_view'], this.flags['feed_view_showing_story_view']]);
2010-06-14 13:17:38 -04:00
this . flags [ 'page_view_showing_feed_view' ] = true ;
2010-12-07 18:52:01 -05:00
this . flags [ 'feed_view_showing_story_view' ] = false ;
2010-12-06 10:41:24 -05:00
this . switch _taskbar _view ( 'feed' , 'page' ) ;
2010-12-08 20:53:45 -05:00
this . show _stories _preference _in _feed _view ( ) ;
2010-06-08 11:19:41 -04:00
}
2010-06-14 13:17:38 -04:00
} else {
2010-12-07 09:52:14 -05:00
if ( this . story _view == 'page' && this . flags [ 'page_view_showing_feed_view' ] ) {
2010-12-07 20:04:37 -05:00
// console.log(['turn off feed view', this.flags['page_view_showing_feed_view'], this.flags['feed_view_showing_story_view']]);
2010-12-07 09:52:14 -05:00
this . flags [ 'page_view_showing_feed_view' ] = false ;
2010-12-07 18:52:01 -05:00
this . flags [ 'feed_view_showing_story_view' ] = false ;
2010-12-07 09:52:14 -05:00
this . switch _taskbar _view ( 'page' ) ;
} else if ( this . flags [ 'feed_view_showing_story_view' ] ) {
2010-12-07 20:04:37 -05:00
// console.log(['turn off story view', this.flags['page_view_showing_feed_view'], this.flags['feed_view_showing_story_view']]);
2010-12-07 09:52:14 -05:00
this . flags [ 'page_view_showing_feed_view' ] = false ;
this . flags [ 'feed_view_showing_story_view' ] = false ;
2010-12-07 20:04:37 -05:00
this . switch _taskbar _view ( this . story _view , true ) ;
2010-12-07 09:52:14 -05:00
}
2010-06-08 11:19:41 -04:00
}
} ,
2010-06-14 13:17:38 -04:00
scroll _to _story _in _story _feed : function ( story , $story , skip _scroll ) {
var self = this ;
var $feed _view = this . $s . $feed _view ;
2011-01-24 23:50:38 -05:00
var $feed _stories = this . $s . $feed _stories ;
2010-06-14 13:17:38 -04:00
if ( ! story || ! $story || ! $story . length ) {
$story = $ ( '.story:first' , $feed _view ) ;
story = this . model . get _story ( $story . data ( 'story' ) ) ;
}
2010-06-28 13:25:02 -04:00
if ( ! story || ! $story || ! $story . length ) {
return ;
}
2011-06-07 12:57:34 -04:00
if ( ! this . model . preference ( 'animations' ) ) skip _scroll = true ;
2010-06-14 13:17:38 -04:00
if ( $story && $story . length ) {
2010-12-07 09:52:14 -05:00
if ( skip _scroll ||
2010-12-08 20:53:45 -05:00
( this . story _view == 'feed' &&
this . model . preference ( 'feed_view_single_story' ) ) ||
2010-12-07 09:52:14 -05:00
( this . story _view == 'page' &&
! this . flags [ 'page_view_showing_feed_view' ] ) ) {
2011-07-13 09:50:02 -07:00
this . locks . scrolling = setTimeout ( function ( ) {
self . flags . scrolling _by _selecting _story _title = false ;
} , 100 ) ;
$feed _stories . scrollTo ( $story , { duration : 0 , axis : 'y' , offset : 0 } ) ; // Do this at view switch instead.
2010-06-14 13:17:38 -04:00
} else if ( this . story _view == 'feed' || this . flags [ 'page_view_showing_feed_view' ] ) {
2011-01-24 23:50:38 -05:00
$feed _stories . scrollable ( ) . stop ( ) ;
2011-07-13 09:50:02 -07:00
$feed _stories . scrollTo ( $story , {
duration : 340 ,
2011-07-12 10:07:57 -07:00
axis : 'y' ,
easing : 'easeInOutQuint' ,
offset : 0 ,
queue : false ,
onAfter : function ( ) {
self . locks . scrolling = setTimeout ( function ( ) {
self . flags . scrolling _by _selecting _story _title = false ;
} , 100 ) ;
}
} ) ;
2010-06-14 13:17:38 -04:00
}
}
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
var parent _scroll = $story . parents ( '.NB-feed-story-view' ) . scrollTop ( ) ;
var story _offset = $story . offset ( ) . top ;
return story _offset + parent _scroll ;
} ,
scroll _to _story _in _iframe : function ( story , $story , skip _scroll ) {
2010-12-09 18:47:06 -05:00
var self = this ;
2010-12-06 10:41:24 -05:00
var $iframe = this . $s . $feed _iframe ;
2011-06-07 12:57:34 -04:00
if ( ! this . model . preference ( 'animations' ) ) skip _scroll = true ;
2011-07-13 09:50:02 -07:00
2010-06-14 13:17:38 -04:00
if ( $story && $story . length ) {
if ( skip _scroll
|| this . story _view == 'feed'
|| this . story _view == 'story'
|| this . flags [ 'page_view_showing_feed_view' ] ) {
2011-07-13 09:50:02 -07:00
$iframe . scrollTo ( $story , { duration : 0 , axis : 'y' , offset : - 24 } ) ; // Do this at story_view switch
2011-07-12 10:07:57 -07:00
self . locks . scrolling = setTimeout ( function ( ) {
self . flags . scrolling _by _selecting _story _title = false ;
} , 100 ) ;
2010-06-14 13:17:38 -04:00
} else if ( this . story _view == 'page' ) {
$iframe . scrollable ( ) . stop ( ) ;
2011-07-13 09:50:02 -07:00
$iframe . scrollTo ( $story , {
duration : 380 ,
2011-07-12 10:07:57 -07:00
axis : 'y' ,
easing : 'easeInOutQuint' ,
offset : - 24 ,
queue : false ,
onAfter : function ( ) {
self . locks . scrolling = setTimeout ( function ( ) {
self . flags . scrolling _by _selecting _story _title = false ;
} , 100 ) ;
}
} ) ;
2010-06-14 13:17:38 -04:00
}
var parent _scroll = $story . parents ( '.NB-feed-story-view' ) . scrollTop ( ) ;
var story _offset = $story . offset ( ) . top ;
2011-07-13 09:50:02 -07:00
2010-06-14 13:17:38 -04:00
return story _offset + parent _scroll ;
2010-06-08 11:19:41 -04:00
}
2010-06-14 13:17:38 -04:00
return false ;
2010-06-08 11:19:41 -04:00
} ,
2010-06-14 13:17:38 -04:00
prefetch _story _locations _in _story _frame : function ( ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-06-14 13:17:38 -04:00
var stories = this . model . stories ;
2010-12-06 10:41:24 -05:00
var $iframe = this . $s . $feed _iframe . contents ( ) ;
2010-11-08 19:39:27 -05:00
var prefetch _tries _left = 3 ;
2010-11-06 12:53:42 -04:00
this . cache [ 'prefetch_iteration' ] += 1 ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
// NEWSBLUR.log(['Prefetching', !this.flags['iframe_fetching_story_locations']]);
if ( ! this . flags [ 'iframe_fetching_story_locations' ]
&& ! this . flags [ 'iframe_story_locations_fetched' ] ) {
2010-12-06 10:41:24 -05:00
$iframe . unbind ( 'scroll' ) . scroll ( $ . rescope ( this . handle _scroll _feed _iframe , this ) ) ;
2010-06-15 18:29:13 -04:00
$iframe
. unbind ( 'mousemove.reader' )
. bind ( 'mousemove.reader' , $ . rescope ( this . handle _mousemove _iframe _view , this ) ) ;
2010-06-14 13:17:38 -04:00
2010-11-06 12:53:42 -04:00
var last _story _index = this . cache . iframe _story _positions _keys . length ;
var last _story _position = _ . last ( this . cache . iframe _story _positions _keys ) ;
var last _story = this . cache . iframe _story _positions [ last _story _position ] ;
var $last _story ;
if ( last _story ) {
2010-12-06 10:41:24 -05:00
$last _story = this . find _story _in _feed _iframe ( last _story , $iframe ) ;
2010-11-06 12:53:42 -04:00
}
// NEWSBLUR.log(['last_story', last_story_index, last_story_position, last_story, $last_story]);
var last _story _same _position ;
if ( $last _story && $last _story . length ) {
last _story _same _position = parseInt ( $last _story . offset ( ) . top , 10 ) == last _story _position ;
if ( ! last _story _same _position ) {
$ . extend ( this . cache , {
'iframe_stories' : { } ,
'iframe_story_positions' : { } ,
'iframe_story_positions_keys' : [ ]
} ) ;
}
}
2010-06-14 13:17:38 -04:00
for ( var s in stories ) {
2010-11-06 12:53:42 -04:00
if ( last _story _same _position && parseInt ( s , 10 ) < last _story _index ) continue ;
2010-06-14 13:17:38 -04:00
var story = stories [ s ] ;
2010-12-06 10:41:24 -05:00
var $story = this . find _story _in _feed _iframe ( story , $iframe ) ;
2010-11-06 12:53:42 -04:00
// NEWSBLUR.log(['Pre-fetching', parseInt(s, 10), last_story_index, last_story_same_position, $story, story.story_title]);
if ( ! $story ||
! $story . length ||
this . flags [ 'iframe_fetching_story_locations' ] ||
2010-11-08 19:39:27 -05:00
this . flags [ 'iframe_story_locations_fetched' ] ||
2011-06-09 20:51:48 -04:00
parseInt ( $story . offset ( ) . top , 10 ) > this . cache [ 'prefetch_iteration' ] * 2000 ) {
2010-11-06 12:53:42 -04:00
if ( $story && $story . length ) {
2011-02-04 00:22:58 -05:00
// NEWSBLUR.log(['Prefetch break on position too far', parseInt($story.offset().top, 10), this.cache['prefetch_iteration']*4000]);
2010-11-08 19:39:27 -05:00
break ;
}
if ( ! prefetch _tries _left ) {
break ;
} else {
prefetch _tries _left -= 1 ;
2010-11-06 12:53:42 -04:00
}
}
2010-06-08 11:19:41 -04:00
}
}
2010-06-14 13:17:38 -04:00
if ( ! this . flags [ 'iframe_fetching_story_locations' ]
&& ! this . flags [ 'iframe_story_locations_fetched' ] ) {
setTimeout ( function ( ) {
2010-11-08 19:39:27 -05:00
if ( ! self . flags [ 'iframe_fetching_story_locations' ]
&& ! self . flags [ 'iframe_story_locations_fetched' ] ) {
2010-06-14 13:17:38 -04:00
self . prefetch _story _locations _in _story _frame ( ) ;
}
2011-06-09 20:51:48 -04:00
} , 1000 ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2010-06-14 13:17:38 -04:00
fetch _story _locations _in _story _frame : function ( s , clear _cache , $iframe ) {
2010-06-08 11:19:41 -04:00
var self = this ;
var stories = this . model . stories ;
2010-06-14 13:17:38 -04:00
if ( ! s ) s = 0 ;
var story = stories [ s ] ;
2010-12-06 10:41:24 -05:00
if ( ! $iframe ) $iframe = this . $s . $feed _iframe . contents ( ) ;
2010-06-14 13:17:38 -04:00
this . flags [ 'iframe_fetching_story_locations' ] = true ;
2011-10-03 18:19:50 -07:00
this . flags [ 'iframe_story_locations_fetched' ] = false ;
2010-06-08 11:19:41 -04:00
if ( clear _cache ) {
$ . extend ( this . cache , {
2010-06-14 13:17:38 -04:00
'iframe_stories' : { } ,
'iframe_story_positions' : { } ,
'iframe_story_positions_keys' : [ ]
2010-06-08 11:19:41 -04:00
} ) ;
}
2010-06-14 13:17:38 -04:00
if ( story && story [ 'story_feed_id' ] == this . active _feed ) {
2010-12-06 10:41:24 -05:00
var $story = this . find _story _in _feed _iframe ( story , $iframe ) ;
2011-10-03 18:19:50 -07:00
// NEWSBLUR.log(['Fetching story', s, story.story_title, $story]);
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
setTimeout ( function ( ) {
if ( ( stories . length - 1 ) >= ( s + 1 )
&& ( s < 3
|| ( ( self . cache . iframe _stories [ stories [ s ] . id ]
&& self . cache . iframe _stories [ stories [ s ] . id ] . length )
|| ( self . cache . iframe _stories [ stories [ s - 1 ] . id ]
&& self . cache . iframe _stories [ stories [ s - 1 ] . id ] . length )
|| ( self . cache . iframe _stories [ stories [ s - 2 ] . id ]
&& self . cache . iframe _stories [ stories [ s - 2 ] . id ] . length ) ) ) ) {
self . fetch _story _locations _in _story _frame ( s + 1 , false , $iframe ) ;
2011-10-03 18:19:50 -07:00
self . flags [ 'iframe_story_locations_fetched' ] = false ;
2010-06-14 13:17:38 -04:00
} else {
NEWSBLUR . log ( [ 'iFrame view entirely loaded' , ( s - 2 ) + ' stories' , self . cache . iframe _stories ] ) ;
self . flags [ 'iframe_story_locations_fetched' ] = true ;
self . flags [ 'iframe_fetching_story_locations' ] = false ;
2010-07-24 18:22:23 -04:00
clearInterval ( self . flags [ 'iframe_scroll_snapback_check' ] ) ;
2010-06-14 13:17:38 -04:00
}
2010-11-06 13:27:52 -04:00
} , 20 ) ;
2010-06-14 13:17:38 -04:00
} else if ( story && story [ 'story_feed_id' ] != this . active _feed ) {
NEWSBLUR . log ( [ 'Switched off iframe early' ] ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2010-06-14 13:17:38 -04:00
open _story _link : function ( story , $st ) {
2010-11-15 22:43:01 -05:00
window . open ( story [ 'story_permalink' ] , '_blank' ) ;
2010-06-14 13:17:38 -04:00
window . focus ( ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-06-14 13:17:38 -04:00
mark _story _title _as _selected : function ( $story _title ) {
var $story _titles = this . $s . $story _titles ;
$ ( '.selected' , $story _titles ) . removeClass ( 'selected' ) ;
2011-01-10 19:34:27 -05:00
// $('.after_selected', $story_titles).removeClass('after_selected');
2010-06-14 13:17:38 -04:00
$story _title . addClass ( 'selected' ) ;
2011-01-10 19:34:27 -05:00
// $story_title.parent('.story').next('.story').children('a').addClass('after_selected');
2010-06-14 13:17:38 -04:00
} ,
2010-06-08 11:19:41 -04:00
2010-12-30 19:24:52 -05:00
mark _story _as _read : function ( story _id ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-12-30 19:24:52 -05:00
var $story _title = this . find _story _in _story _titles ( story _id ) ;
2010-12-14 19:23:16 -05:00
var feed _id = parseInt ( $story _title . data ( 'feed_id' ) , 10 ) || this . active _feed ;
2010-06-08 11:19:41 -04:00
2010-12-30 19:24:52 -05:00
this . model . mark _story _as _read ( story _id , feed _id , function ( read ) {
self . update _read _count ( story _id , feed _id , false , read ) ;
} ) ;
} ,
mark _story _as _unread : function ( story _id , feed _id ) {
var self = this ;
2011-01-10 09:49:26 -05:00
feed _id = feed _id || this . model . get _story ( story _id ) . story _feed _id ;
2010-09-05 18:08:08 -07:00
2010-12-30 19:24:52 -05:00
this . model . mark _story _as _unread ( story _id , feed _id , function ( ) {
self . update _read _count ( story _id , feed _id , true ) ;
} ) ;
} ,
update _read _count : function ( story _id , feed _id , unread , previously _read ) {
2011-03-09 20:04:50 -05:00
// NEWSBLUR.log(['update_read_count', feed_id, unread, previously_read]);
2010-12-30 19:24:52 -05:00
if ( previously _read ) return ;
var feed = this . model . get _feed ( feed _id ) ;
var $feed _list = this . $s . $feed _list ;
2011-06-07 16:08:59 -04:00
var $feed = this . find _feed _in _feed _list ( feed _id ) ;
2011-03-09 20:04:50 -05:00
var $feed _counts = this . cache . $feed _counts _in _feed _list [ feed _id ] || $ ( '.feed_counts_floater' , $feed ) ;
2010-12-30 19:24:52 -05:00
var $story _title = this . find _story _in _story _titles ( story _id ) ;
2011-11-15 18:37:42 -08:00
var $story = this . find _story _in _feed _view ( story _id ) ;
2010-12-30 19:24:52 -05:00
var $content _pane = this . $s . $content _pane ;
2011-04-12 18:23:04 -04:00
var $floater = $ ( '.feed_counts_floater' , $content _pane ) ;
var unread _view = this . get _unread _view _name ( ) ;
2011-03-02 17:58:12 -05:00
2011-03-09 20:04:50 -05:00
this . cache . $feed _counts _in _feed _list [ feed _id ] = $feed _counts ;
2010-06-08 11:19:41 -04:00
2010-12-30 19:24:52 -05:00
$story _title . toggleClass ( 'read' , ! unread ) ;
2011-11-15 18:37:42 -08:00
$story . toggleClass ( 'read' , ! unread ) ;
2011-04-12 18:23:04 -04:00
// NEWSBLUR.log(['marked read', feed.ps, feed.nt, feed.ng, $story_title.is('.NB-story-positive'), $story_title.is('.NB-story-neutral'), $story_title.is('.NB-story-negative')]);
2010-12-30 19:24:52 -05:00
if ( $story _title . is ( '.NB-story-positive' ) ) {
2011-04-12 18:23:04 -04:00
var count = Math . max ( feed . ps + ( unread ? 1 : - 1 ) , 0 ) ;
2010-12-30 19:24:52 -05:00
feed . ps = count ;
$ ( '.unread_count_positive' , $feed ) . text ( count ) ;
$ ( '.unread_count_positive' , $content _pane ) . text ( count ) ;
if ( count == 0 ) {
$feed . removeClass ( 'unread_positive' ) ;
$feed _counts . removeClass ( 'unread_positive' ) ;
} else {
$feed . addClass ( 'unread_positive' ) ;
$feed _counts . addClass ( 'unread_positive' ) ;
2010-09-05 18:08:08 -07:00
}
2010-12-30 19:24:52 -05:00
} else if ( $story _title . is ( '.NB-story-neutral' ) ) {
2011-04-12 18:23:04 -04:00
var count = Math . max ( feed . nt + ( unread ? 1 : - 1 ) , 0 ) ;
2010-12-30 19:24:52 -05:00
feed . nt = count ;
$ ( '.unread_count_neutral' , $feed ) . text ( count ) ;
$ ( '.unread_count_neutral' , $content _pane ) . text ( count ) ;
if ( count == 0 ) {
$feed . removeClass ( 'unread_neutral' ) ;
$feed _counts . removeClass ( 'unread_neutral' ) ;
} else {
$feed . addClass ( 'unread_neutral' ) ;
$feed _counts . addClass ( 'unread_neutral' ) ;
}
} else if ( $story _title . is ( '.NB-story-negative' ) ) {
2011-04-12 18:23:04 -04:00
var count = Math . max ( feed . ng + ( unread ? 1 : - 1 ) , 0 ) ;
2010-12-30 19:24:52 -05:00
feed . ng = count ;
$ ( '.unread_count_negative' , $feed ) . text ( count ) ;
$ ( '.unread_count_negative' , $content _pane ) . text ( count ) ;
if ( count == 0 ) {
$feed . removeClass ( 'unread_negative' ) ;
$feed _counts . removeClass ( 'unread_negative' ) ;
} else {
$feed . addClass ( 'unread_negative' ) ;
$feed _counts . addClass ( 'unread_negative' ) ;
2010-09-05 18:08:08 -07:00
}
2010-12-30 19:24:52 -05:00
}
2011-04-12 11:02:02 -04:00
_ . defer ( function ( ) {
2011-04-12 18:23:04 -04:00
$floater . animate ( { 'opacity' : 1 } , { 'duration' : 250 , 'queue' : false } ) ;
2011-04-12 11:02:02 -04:00
_ . delay ( function ( ) {
2011-04-12 18:23:04 -04:00
$floater . animate ( { 'opacity' : . 1 } , { 'duration' : 250 , 'queue' : false } ) ;
2011-04-12 11:02:02 -04:00
} , 400 ) ;
} ) ;
2010-06-08 11:19:41 -04:00
2011-11-23 16:45:36 -05:00
if ( this . model . preference ( 'folder_counts' ) || ! $feed . is ( ':visible' ) ) {
2011-10-31 19:44:36 -07:00
var $folder _title = $feed . closest ( 'li.folder:visible' ) . children ( '.folder_title' ) ;
var $children = $folder _title . closest ( 'li.folder' ) . children ( 'ul.folder, .feed' ) ;
2010-12-30 19:24:52 -05:00
this . show _collapsed _folder _count ( $folder _title , $children ) ;
}
2011-04-12 18:23:04 -04:00
if ( ( unread _view == 'positive' && feed . ps == 0 ) ||
( unread _view == 'neutral' && feed . ps == 0 && feed . nt == 0 ) ||
( unread _view == 'negative' && feed . ps == 0 && feed . nt == 0 && feed . ng == 0 ) ) {
2011-04-12 18:29:42 -04:00
_ . delay ( function ( ) {
$floater . animate ( {
'top' : $ ( '#story_taskbar' ) . height ( )
} , {
2011-04-12 19:43:30 -04:00
'duration' : 500 ,
'queue' : false ,
'easing' : 'easeOutQuint'
2011-04-12 18:29:42 -04:00
} ) ;
} , 500 ) ;
2011-04-12 18:23:04 -04:00
}
2010-11-22 10:44:52 -05:00
this . update _header _counts ( true ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-06-14 13:17:38 -04:00
mark _feed _as _read : function ( feed _id ) {
2010-07-24 00:04:14 -04:00
feed _id = feed _id || this . active _feed ;
2010-06-14 13:17:38 -04:00
2010-09-16 10:35:36 -04:00
this . mark _feed _as _read _update _counts ( feed _id ) ;
this . model . mark _feed _as _read ( [ feed _id ] ) ;
2010-11-25 09:26:21 -05:00
this . update _header _counts ( true ) ;
2011-10-31 19:44:36 -07:00
if ( this . model . preference ( 'folder_counts' ) ) {
var $feed = this . find _feed _in _feed _list ( feed _id ) ;
var $folder _title = $feed . closest ( 'li.folder:visible' ) . children ( '.folder_title' ) ;
var $children = $folder _title . closest ( 'li.folder' ) . children ( 'ul.folder, .feed' ) ;
this . show _collapsed _folder _count ( $folder _title , $children ) ;
}
2010-09-16 10:35:36 -04:00
} ,
mark _folder _as _read : function ( folder _name , $folder ) {
2011-10-31 18:40:07 -07:00
$folder = $folder || this . get _current _folder ( ) ;
folder _name = folder _name || $ ( '.folder_title_text' , $folder ) . eq ( 0 ) . text ( ) ;
2010-09-21 11:16:22 -04:00
var feeds = this . get _feed _ids _in _folder ( $folder ) ;
2011-11-23 16:45:36 -05:00
2010-09-16 10:35:36 -04:00
_ . each ( feeds , _ . bind ( function ( feed _id ) {
this . mark _feed _as _read _update _counts ( feed _id ) ;
} , this ) ) ;
this . mark _feed _as _read _update _counts ( null , $folder ) ;
this . model . mark _feed _as _read ( feeds ) ;
2010-11-25 09:26:21 -05:00
this . update _header _counts ( true ) ;
2011-10-31 18:40:07 -07:00
2011-10-31 18:50:39 -07:00
if ( _ . includes ( this . active _feed , folder _name ) ) {
$ ( '.story:not(.read)' , this . $s . $story _titles ) . addClass ( 'read' ) ;
_ . each ( this . model . stories , _ . bind ( function ( story ) {
this . mark _story _as _read _in _feed _view ( story ) ;
} , this ) ) ;
}
2010-09-16 10:35:36 -04:00
} ,
mark _feed _as _read _update _counts : function ( feed _id , $folder ) {
if ( feed _id ) {
var feed = this . model . get _feed ( feed _id ) ;
2011-10-31 18:50:39 -07:00
if ( ! feed ) return ;
2010-09-16 10:35:36 -04:00
var $feed = this . find _feed _in _feed _list ( feed _id ) ;
var $feed _counts = $ ( '.feed_counts_floater' , $feed ) ;
var $content _pane = this . $s . $content _pane ;
var $story _titles = this . $s . $story _titles ;
2010-06-14 13:17:38 -04:00
2010-09-16 10:35:36 -04:00
feed . ps = 0 ;
feed . nt = 0 ;
feed . ng = 0 ;
$ ( '.unread_count_neutral' , $feed ) . text ( 0 ) ;
$ ( '.unread_count_positive' , $feed ) . text ( 0 ) ;
$ ( '.unread_count_negative' , $feed ) . text ( 0 ) ;
if ( feed _id == this . active _feed ) {
$ ( '.unread_count_neutral' , $content _pane ) . text ( 0 ) ;
$ ( '.unread_count_positive' , $content _pane ) . text ( 0 ) ;
$ ( '.unread_count_negative' , $content _pane ) . text ( 0 ) ;
$ ( '.story:not(.read)' , $story _titles ) . addClass ( 'read' ) ;
}
$feed . removeClass ( 'unread_neutral' ) ;
$feed . removeClass ( 'unread_positive' ) ;
$feed . removeClass ( 'unread_negative' ) ;
$feed _counts . removeClass ( 'unread_neutral' ) ;
$feed _counts . removeClass ( 'unread_positive' ) ;
$feed _counts . removeClass ( 'unread_negative' ) ;
}
if ( $folder ) {
$ ( '.unread_count_neutral' , $folder ) . text ( 0 ) ;
$ ( '.unread_count_positive' , $folder ) . text ( 0 ) ;
$ ( '.unread_count_negative' , $folder ) . text ( 0 ) ;
$feed _counts = $ ( '.feed_counts_floater' , $folder ) ;
$feed _counts . removeClass ( 'unread_neutral' ) ;
$feed _counts . removeClass ( 'unread_positive' ) ;
$feed _counts . removeClass ( 'unread_negative' ) ;
}
2010-06-08 11:19:41 -04:00
} ,
2011-03-06 21:33:06 -05:00
open _story _trainer : function ( story _id , feed _id ) {
2011-10-30 22:15:04 -07:00
story _id = story _id || this . get _current _story _id ( ) ;
feed _id = feed _id || ( story _id && this . model . get _story ( story _id ) . story _feed _id ) ;
2010-06-14 13:17:38 -04:00
2011-10-30 22:15:04 -07:00
if ( story _id && feed _id ) {
NEWSBLUR . classifier = new NEWSBLUR . ReaderClassifierStory ( story _id , feed _id , {
'feed_loaded' : ! this . flags [ 'river_view' ]
} ) ;
}
2010-06-08 11:19:41 -04:00
} ,
2011-12-14 21:56:27 -08:00
mark _story _as _starred : function ( story _id ) {
2010-12-04 13:32:13 -05:00
var story = this . model . get _story ( story _id ) ;
2011-12-14 21:56:27 -08:00
var $story _title = this . find _story _in _story _titles ( story _id ) ;
var $feed _story = this . find _story _in _feed _view ( story _id ) ;
var $star = $ ( '.NB-storytitles-star' , $story _title ) ;
var $sideoption _title = $ ( '.NB-feed-story-save .NB-sideoption-title' , $feed _story ) ;
this . scroll _story _titles _to _show _selected _story _title ( $story _title ) ;
$feed _story . addClass ( 'NB-story-starred' ) ;
$story _title . addClass ( 'NB-story-starred' ) ;
$sideoption _title . text ( 'Saved' ) ;
2010-12-30 18:37:29 -05:00
$star . attr ( { 'title' : 'Saved!' } ) ;
$star . tipsy ( {
gravity : 'sw' ,
fade : true ,
trigger : 'manual' ,
2010-12-31 10:34:31 -05:00
offsetOpposite : - 1
2010-11-30 10:30:18 -05:00
} ) ;
2010-12-30 18:37:29 -05:00
$star . tipsy ( 'enable' ) ;
$star . tipsy ( 'show' ) ;
_ . delay ( function ( ) {
$star . tipsy ( 'hide' ) ;
$star . tipsy ( 'disable' ) ;
} , 850 ) ;
2011-12-14 21:56:27 -08:00
2010-12-30 18:37:29 -05:00
this . model . mark _story _as _starred ( story _id , story . story _feed _id , function ( ) { } ) ;
2010-12-02 11:09:09 -05:00
this . update _starred _count ( ) ;
2010-11-30 10:30:18 -05:00
} ,
2011-12-14 21:56:27 -08:00
mark _story _as _unstarred : function ( story _id ) {
var $story _title = this . find _story _in _story _titles ( story _id ) ;
var $feed _story = this . find _story _in _feed _view ( story _id ) ;
var $star = $ ( '.NB-storytitles-star' , $story _title ) ;
var $sideoption _title = $ ( '.NB-feed-story-save .NB-sideoption-title' , $feed _story ) ;
this . scroll _story _titles _to _show _selected _story _title ( $story _title ) ;
$story _title . one ( 'mouseout' , function ( ) {
$story _title . removeClass ( 'NB-unstarred' ) ;
2010-12-01 09:30:56 -05:00
} ) ;
2010-12-30 18:37:29 -05:00
$star . attr ( { 'title' : 'Removed' } ) ;
2011-12-14 21:56:27 -08:00
$sideoption _title . text ( 'Removed' ) ;
$sideoption _title . one ( 'mouseleave' , function ( ) {
_ . delay ( function ( ) {
if ( ! $feed _story . hasClass ( 'NB-story-starred' ) ) {
$sideoption _title . text ( 'Share this story' ) ;
}
} , 200 ) ;
} ) ;
2010-12-30 18:37:29 -05:00
$star . tipsy ( {
gravity : 'sw' ,
fade : true ,
trigger : 'manual' ,
2010-12-31 10:34:31 -05:00
offsetOpposite : - 1
2010-12-01 09:30:56 -05:00
} ) ;
2010-12-30 18:37:29 -05:00
$star . tipsy ( 'enable' ) ;
$star . tipsy ( 'show' ) ;
_ . delay ( function ( ) {
$star . tipsy ( 'hide' ) ;
$star . tipsy ( 'disable' ) ;
} , 850 ) ;
2011-12-14 21:56:27 -08:00
$story _title . removeClass ( 'NB-story-starred' ) ;
$feed _story . removeClass ( 'NB-story-starred' ) ;
2010-12-30 18:37:29 -05:00
this . model . mark _story _as _unstarred ( story _id , function ( ) { } ) ;
2010-12-02 11:09:09 -05:00
this . update _starred _count ( ) ;
2010-12-01 09:30:56 -05:00
} ,
2011-12-14 21:56:27 -08:00
toggle _feed _story _share _dialog : function ( story _id , feed _id ) {
2011-12-13 09:57:04 -08:00
var $feed _story = this . find _story _in _feed _view ( story _id ) ;
var $sideoption = $ ( '.NB-sideoption.NB-feed-story-share' , $feed _story ) ;
var $share = $ ( '.NB-sideoption-share-wrapper' , $feed _story ) ;
var $story _content = $ ( '.NB-feed-story-content' , $feed _story ) ;
2011-12-13 18:37:46 -08:00
var $comments = $ ( '.NB-sideoption-share-comments' , $share ) ;
2011-12-13 09:57:04 -08:00
if ( $sideoption . hasClass ( 'NB-active' ) ) {
$share . animate ( {
'height' : 0
} , {
'duration' : 300 ,
'easing' : 'easeInOutQuint' ,
'queue' : false
} ) ;
$sideoption . removeClass ( 'NB-active' ) ;
2011-12-13 18:37:46 -08:00
if ( $story _content . data ( 'original_height' ) ) {
$story _content . animate ( {
'height' : $story _content . data ( 'original_height' )
} , {
'duration' : 300 ,
'easing' : 'easeInOutQuint' ,
'queue' : false ,
'complete' : _ . bind ( this . fetch _story _locations _in _feed _view , this )
} ) ;
$story _content . removeData ( 'original_height' ) ;
}
2011-12-13 09:57:04 -08:00
return ;
}
$sideoption . addClass ( 'NB-active' ) ;
var $share _clone = $share . clone ( ) ;
var full _height = $share _clone . css ( {
'height' : 'auto' ,
'position' : 'absolute' ,
'visibility' : 'hidden'
} ) . appendTo ( $share . parent ( ) ) . height ( ) ;
$share _clone . remove ( ) ;
$share . animate ( {
'height' : full _height
} , {
'duration' : 350 ,
'easing' : 'easeInOutQuint' ,
2011-12-13 18:37:46 -08:00
'queue' : false ,
'complete' : function ( ) {
$comments . focus ( ) ;
}
2011-12-13 09:57:04 -08:00
} ) ;
2011-12-13 18:37:46 -08:00
var sideoptions _height = $ ( '.NB-feed-story-sideoptions-container' , $feed _story ) . innerHeight ( ) ;
if ( sideoptions _height + full _height > $story _content . innerHeight ( ) ) {
// console.log(["heights", $story_content.innerHeight(), full_height, sideoptions_height]);
// this.$s.$feed_stories.scrollTo(this.$s.$feed_stories.scrollTop() + sideoptions_height, {
// 'duration': 350,
// 'queue': false,
// 'easing': 'easeInOutQuint'
// });
var original _height = $story _content . height ( ) ;
2011-12-13 09:57:04 -08:00
$story _content . animate ( {
2011-12-13 18:37:46 -08:00
'height' : full _height + sideoptions _height
2011-12-13 09:57:04 -08:00
} , {
'duration' : 350 ,
'easing' : 'easeInOutQuint' ,
2011-12-13 18:37:46 -08:00
'queue' : false ,
'complete' : _ . bind ( this . fetch _story _locations _in _feed _view , this )
} ) . data ( 'original_height' , original _height ) ;
2011-12-13 09:57:04 -08:00
}
2011-12-13 18:37:46 -08:00
this . attach _handlers _to _share _comments ( $share ) ;
} ,
attach _handlers _to _share _comments : function ( $share ) {
var $comments = $ ( '.NB-sideoption-share-comments' , $share ) ;
var $share _button = $ ( '.NB-sideoption-share-save' , $share ) ;
$comments . bind ( 'keyup' , function ( ) {
if ( $comments . val ( ) . length ) {
$share _button . text ( 'Share with comment' ) ;
} else {
$share _button . text ( 'Share' ) ;
}
} ) ;
2011-12-13 09:57:04 -08:00
} ,
2011-12-14 21:56:27 -08:00
mark _story _as _shared : function ( story _id ) {
var story = this . model . get _story ( story _id ) ;
var $story _title = this . find _story _in _story _titles ( story _id ) ;
var $feed _story = this . find _story _in _feed _view ( story _id ) ;
2011-12-14 09:51:47 -08:00
var $share _button = $ ( '.NB-sideoption-share-save' , $story ) ;
var $share _sideoption = $ ( '.NB-feed-story-share .NB-sideoption-title' , $story ) ;
2011-12-14 21:56:27 -08:00
var comments = $ ( '.NB-sideoption-share-comments' , $story ) . val ( ) ;
2011-12-14 09:51:47 -08:00
$share _button . addClass ( 'NB-saving' ) . text ( 'Sharing...' ) ;
2011-12-14 21:56:27 -08:00
this . model . mark _story _as _shared ( story _id , story . story _feed _id , comments , _ . bind ( function ( ) {
this . toggle _feed _story _share _dialog ( story _id , story . story _feed _id ) ;
2011-12-14 09:51:47 -08:00
$share _button . removeClass ( 'NB-saving' ) . text ( 'Share' ) ;
2011-12-14 21:56:27 -08:00
$share _sideoption . text ( 'Shared' ) . closest ( '.NB-sideoption' ) ;
$feed _story . addClass ( 'NB-story-shared' ) ;
2011-12-14 09:51:47 -08:00
} , this ) ) ;
} ,
2010-12-31 10:34:31 -05:00
send _story _to _instapaper : function ( story _id ) {
var story = this . model . get _story ( story _id ) ;
2011-01-07 16:36:46 -05:00
var url = 'http://www.instapaper.com/edit' ;
var instapaper _url = [
url ,
'?url=' ,
encodeURIComponent ( story . story _permalink ) ,
'&title=' ,
encodeURIComponent ( story . story _title )
] . join ( '' ) ;
window . open ( instapaper _url , '_blank' ) ;
this . mark _story _as _read ( story _id ) ;
2010-06-08 11:19:41 -04:00
} ,
2011-02-15 21:31:33 -05:00
send _story _to _readitlater : function ( story _id ) {
var story = this . model . get _story ( story _id ) ;
var url = 'https://readitlaterlist.com/save' ;
var readitlater _url = [
url ,
'?url=' ,
encodeURIComponent ( story . story _permalink ) ,
'&title=' ,
encodeURIComponent ( story . story _title )
] . join ( '' ) ;
window . open ( readitlater _url , '_blank' ) ;
this . mark _story _as _read ( story _id ) ;
} ,
2011-02-16 20:45:37 -05:00
send _story _to _readability : function ( story _id ) {
var story = this . model . get _story ( story _id ) ;
var url = 'https://readability.com/save' ;
var readability _url = [
url ,
'?url=' ,
encodeURIComponent ( story . story _permalink ) ,
'&title=' ,
encodeURIComponent ( story . story _title )
] . join ( '' ) ;
window . open ( readability _url , '_blank' ) ;
this . mark _story _as _read ( story _id ) ;
} ,
2011-02-04 00:22:58 -05:00
send _story _to _twitter : function ( story _id ) {
var story = this . model . get _story ( story _id ) ;
var url = 'http://twitter.com/' ;
var twitter _url = [
url ,
'?status=' ,
encodeURIComponent ( story . story _title ) ,
': ' ,
encodeURIComponent ( story . story _permalink )
] . join ( '' ) ;
window . open ( twitter _url , '_blank' ) ;
this . mark _story _as _read ( story _id ) ;
} ,
send _story _to _facebook : function ( story _id ) {
var story = this . model . get _story ( story _id ) ;
2011-02-04 00:30:33 -05:00
var url = 'http://www.facebook.com/sharer.php?src=newsblur&v=3.14159265&i=1.61803399' ;
2011-02-04 00:22:58 -05:00
var facebook _url = [
url ,
'&u=' ,
encodeURIComponent ( story . story _permalink ) ,
'&t=' ,
encodeURIComponent ( story . story _title )
] . join ( '' ) ;
window . open ( facebook _url , '_blank' ) ;
this . mark _story _as _read ( story _id ) ;
} ,
2011-11-07 18:21:38 -08:00
send _story _to _pinboard : function ( story _id ) {
var story = this . model . get _story ( story _id ) ;
var url = 'http://pinboard.in/add/?' ;
var pinboard _url = [
url ,
'url=' ,
encodeURIComponent ( story . story _permalink ) ,
'&title=' ,
encodeURIComponent ( story . story _title ) ,
'&tags=' ,
encodeURIComponent ( story . story _tags . join ( ', ' ) )
] . join ( '' ) ;
window . open ( pinboard _url , '_blank' ) ;
this . mark _story _as _read ( story _id ) ;
} ,
send _story _to _googleplus : function ( story _id ) {
var story = this . model . get _story ( story _id ) ;
var url = 'https://plusone.google.com/_/+1/confirm' ; //?hl=en&url=${url}
var googleplus _url = [
url ,
'?hl=en&url=' ,
encodeURIComponent ( story . story _permalink ) ,
'&title=' ,
encodeURIComponent ( story . story _title ) ,
'&tags=' ,
encodeURIComponent ( story . story _tags . join ( ', ' ) )
] . join ( '' ) ;
window . open ( googleplus _url , '_blank' ) ;
this . mark _story _as _read ( story _id ) ;
} ,
2011-05-03 11:40:38 -04:00
send _story _to _email : function ( story _id ) {
2011-05-03 20:59:07 -04:00
NEWSBLUR . reader _send _email = new NEWSBLUR . ReaderSendEmail ( story _id ) ;
2011-05-03 11:40:38 -04:00
this . mark _story _as _read ( story _id ) ;
} ,
2010-06-14 13:17:38 -04:00
// =====================
// = Story Titles Pane =
// =====================
2010-06-08 11:19:41 -04:00
2011-02-01 00:23:44 -05:00
hide _content _pane _feed _counter : function ( ) {
var $content _pane = this . $s . $content _pane ;
2011-03-17 22:11:03 -04:00
$ ( '.feed_counts_floater' , $content _pane ) . remove ( ) ;
2011-02-01 00:23:44 -05:00
} ,
2010-06-14 13:17:38 -04:00
make _content _pane _feed _counter : function ( feed _id ) {
2010-06-15 18:29:13 -04:00
var $content _pane = this . $s . $content _pane ;
2011-03-17 22:08:21 -04:00
feed _id = feed _id || this . active _feed ;
2010-06-14 13:17:38 -04:00
var feed = this . model . get _feed ( feed _id ) ;
2011-03-17 22:08:21 -04:00
var $counter = this . make _feed _counts _floater ( feed . ps , feed . nt , feed . ng ) ;
2011-02-01 00:23:44 -05:00
$counter . css ( { 'opacity' : 0 } ) ;
2010-06-08 11:19:41 -04:00
2011-03-17 22:08:21 -04:00
$ ( '.feed_counts_floater' , $content _pane ) . remove ( ) ;
2011-01-31 20:50:33 -05:00
this . $s . $story _taskbar . append ( $counter ) ;
2011-02-01 00:23:44 -05:00
_ . delay ( function ( ) {
$counter . animate ( { 'opacity' : . 1 } , { 'duration' : 1000 , 'queue' : false } ) ;
} , 500 ) ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
$ ( '.unread_count' , $content _pane ) . corner ( '4px' ) ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
// Center the counter
2011-03-17 22:08:21 -04:00
var i _width = $ ( '.feed_counts_floater' , $content _pane ) . width ( ) ;
2010-06-14 13:17:38 -04:00
var o _width = $content _pane . width ( ) ;
var left = ( o _width / 2.0 ) - ( i _width / 2.0 ) ;
2011-03-17 22:08:21 -04:00
$ ( '.feed_counts_floater' , $content _pane ) . css ( { 'left' : left } ) ;
2010-06-14 13:17:38 -04:00
} ,
2010-12-04 16:42:51 -05:00
create _story _titles : function ( stories , options ) {
2010-06-14 13:17:38 -04:00
var $story _titles = this . $s . $story _titles ;
2010-12-04 16:42:51 -05:00
options = options || { } ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
for ( s in stories ) {
2011-04-24 20:48:16 -04:00
if ( this . flags [ 'non_premium_river_view' ] && $story _titles . children ( ':visible' ) . length >= this . constants . RIVER _STORIES _FOR _STANDARD _ACCOUNT ) {
2011-02-13 14:49:13 -05:00
this . append _story _titles _endbar ( ) ;
break ;
}
2010-06-14 13:17:38 -04:00
var story = stories [ s ] ;
2010-12-04 16:42:51 -05:00
var $story _title = this . make _story _title ( story , options ) ;
2010-06-14 13:17:38 -04:00
$story _titles . append ( $story _title ) ;
}
if ( ! stories || stories . length == 0 ) {
2011-02-13 14:49:13 -05:00
this . append _story _titles _endbar ( ) ;
2011-09-27 22:16:09 -07:00
}
this . hover _story _titles ( ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-12-04 16:42:51 -05:00
make _story _title : function ( story , options ) {
2010-06-14 13:17:38 -04:00
var unread _view = this . model . preference ( 'unread_view' ) ;
var read = story . read _status
2010-11-30 10:30:18 -05:00
? ' read '
2010-06-14 13:17:38 -04:00
: '' ;
2011-11-28 12:13:09 -05:00
var score = this . compute _story _score ( story ) ;
2010-06-14 13:17:38 -04:00
var score _color = 'neutral' ;
2010-11-30 10:30:18 -05:00
var starred = story . starred ? ' NB-story-starred ' : '' ;
2010-12-12 22:52:15 -05:00
if ( options . river _stories ) {
2010-12-04 16:42:51 -05:00
var feed = this . model . get _feed ( story . story _feed _id ) ;
}
2010-06-14 13:17:38 -04:00
if ( score > 0 ) score _color = 'positive' ;
if ( score < 0 ) score _color = 'negative' ;
var $story _tags = $ . make ( 'span' , { className : 'NB-storytitles-tags' } ) ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
for ( var t in story . story _tags ) {
var tag = story . story _tags [ t ] ;
var $tag = $ . make ( 'span' , { className : 'NB-storytitles-tag' } , tag ) . corner ( '4px' ) ;
$story _tags . append ( $tag ) ;
break ;
2010-06-08 11:19:41 -04:00
}
2010-12-02 20:18:33 -05:00
var $story _title = $ . make ( 'div' , { className : 'story ' + read + starred + 'NB-story-' + score _color } , [
2010-12-30 18:37:29 -05:00
$ . make ( 'div' , { className : 'NB-storytitles-sentiment' } ) ,
2010-11-15 22:43:01 -05:00
$ . make ( 'a' , { href : story . story _permalink , className : 'story_title' } , [
2011-01-12 10:32:59 -05:00
( options [ 'river_stories' ] && feed &&
$ . make ( 'div' , { className : 'NB-story-feed' } , [
2011-02-17 10:32:47 -05:00
$ . make ( 'img' , { className : 'feed_favicon' , src : $ . favicon ( feed . favicon ) } ) ,
2011-01-12 10:32:59 -05:00
$ . make ( 'span' , { className : 'feed_title' } , feed . feed _title )
] ) ) ,
2011-01-14 10:07:30 -05:00
$ . make ( 'div' , { className : 'NB-storytitles-star' } ) ,
2010-06-14 13:17:38 -04:00
$ . make ( 'span' , { className : 'NB-storytitles-title' } , story . story _title ) ,
$ . make ( 'span' , { className : 'NB-storytitles-author' } , story . story _authors ) ,
$story _tags
] ) ,
$ . make ( 'span' , { className : 'story_date' } , story . short _parsed _date ) ,
$ . make ( 'span' , { className : 'story_id' } , '' + story . id ) ,
2010-12-30 18:37:29 -05:00
$ . make ( 'div' , { className : 'NB-story-manage-icon' } )
2010-12-04 16:42:51 -05:00
] ) . data ( 'story_id' , story . id ) . data ( 'feed_id' , story . story _feed _id ) ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
if ( unread _view > score ) {
$story _title . css ( { 'display' : 'none' } ) ;
2010-06-08 11:19:41 -04:00
}
2010-11-26 19:03:31 -05:00
2011-05-01 20:22:54 -04:00
if ( this . model . preference ( 'show_tooltips' ) ) {
$ ( '.NB-story-sentiment' , $story _title ) . tipsy ( {
delayIn : 375 ,
gravity : 's'
} ) ;
}
2010-06-14 13:17:38 -04:00
return $story _title ;
2010-06-08 11:19:41 -04:00
} ,
2011-09-27 22:16:09 -07:00
hover _story _titles : function ( ) {
2011-09-27 23:06:49 -07:00
var $story _titles = $ ( '#story_titles .story,.NB-feedbar .feed' ) ;
2011-09-27 22:16:09 -07:00
$story _titles . unbind ( 'mouseenter' ) . unbind ( 'mouseleave' ) ;
$story _titles . hover ( function ( ) {
var $this = $ ( this ) ;
2011-11-11 12:09:20 -08:00
var menu _height = $this . hasClass ( 'story' ) ? 190 : 270 ;
2011-09-29 09:53:55 -07:00
2011-09-27 23:06:49 -07:00
if ( $this . offset ( ) . top > $ ( window ) . height ( ) - menu _height ) {
2011-09-27 22:16:09 -07:00
$this . addClass ( 'NB-hover-inverse' ) ;
}
} , function ( ) {
$ ( this ) . removeClass ( 'NB-hover-inverse' ) ;
} ) ;
} ,
2010-06-14 13:17:38 -04:00
story _titles _clear _loading _endbar : function ( ) {
var $story _titles = this . $s . $story _titles ;
var $endbar = $ ( '.NB-story-titles-end-stories-line' , $story _titles ) ;
if ( $endbar . length ) {
$endbar . remove ( ) ;
clearInterval ( this . feed _stories _loading ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2011-02-27 19:42:22 -05:00
recalculate _story _scores : function ( feed _id ) {
feed _id = feed _id || this . active _feed ;
this . model . recalculate _story _scores ( feed _id ) ;
2011-02-27 16:13:22 -05:00
var replace _stories = _ . bind ( function ( $story , story _id ) {
var story = this . model . get _story ( story _id ) ;
2011-02-27 19:42:22 -05:00
if ( story . story _feed _id != feed _id ) return ;
2011-11-28 12:13:09 -05:00
var score = this . compute _story _score ( story ) ;
2011-02-27 16:13:22 -05:00
$story . removeClass ( 'NB-story-positive' )
. removeClass ( 'NB-story-neutral' )
. removeClass ( 'NB-story-negative' ) ;
if ( score > 0 ) {
$story . addClass ( 'NB-story-positive' ) ;
} else if ( score == 0 ) {
$story . addClass ( 'NB-story-neutral' ) ;
} else if ( score < 0 ) {
$story . addClass ( 'NB-story-negative' ) ;
}
2011-03-17 18:33:59 -04:00
NEWSBLUR . log ( [ 'story recalculation' , story , story . read _status , $story ] ) ;
2011-03-16 11:54:20 -04:00
// $story.toggleClass('read', !story.read_status);
2011-03-02 19:59:31 -05:00
$ ( '.NB-feed-story-tags' , $story ) . replaceWith ( this . make _story _feed _tags ( story ) ) ;
2011-03-04 19:25:15 -05:00
$ ( '.NB-feed-story-author' , $story ) . replaceWith ( this . make _story _feed _author ( story ) ) ;
$ ( '.NB-feed-story-title' , $story ) . replaceWith ( this . make _story _feed _title ( story ) ) ;
2011-04-13 18:22:56 -04:00
if ( this . model . preference ( 'new_window' ) == 1 ) {
$ ( 'a' , $story ) . attr ( 'target' , '_blank' ) ;
}
2011-02-27 16:13:22 -05:00
} , this ) ;
_ . each ( this . cache . feed _view _stories , _ . bind ( function ( $story , story _id ) {
replace _stories ( $story , story _id ) ;
} ) ) ;
$ ( '.story' , this . $s . $story _titles ) . each ( function ( ) {
var $story = $ ( this ) ;
var story _id = $story . data ( 'story_id' ) ;
replace _stories ( $story , story _id ) ;
} ) ;
} ,
2010-06-14 13:17:38 -04:00
// =================================
// = Story Pane - iFrame/Page View =
// =================================
2010-06-08 11:19:41 -04:00
2010-12-06 10:41:24 -05:00
unload _feed _iframe : function ( ) {
var $feed _iframe = this . $s . $feed _iframe ;
2010-11-24 13:16:10 -05:00
var $taskbar _view _page = $ ( '.NB-taskbar .task_view_page' ) ;
$taskbar _view _page . removeClass ( 'NB-disabled' ) ;
2011-02-02 14:10:24 -05:00
$taskbar _view _page . removeClass ( 'NB-task-return' ) ;
2010-07-06 18:43:06 -04:00
2010-07-06 18:30:16 -04:00
this . flags [ 'iframe_view_loaded' ] = false ;
this . flags [ 'iframe_story_locations_fetched' ] = false ;
this . flags [ 'iframe_prevented_from_loading' ] = false ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
$ . extend ( this . cache , {
'iframe_stories' : { } ,
'iframe_story_positions' : { } ,
'iframe_story_positions_keys' : [ ]
} ) ;
2010-06-08 11:19:41 -04:00
2010-12-06 10:41:24 -05:00
$feed _iframe . removeAttr ( 'src' ) ;
2011-09-30 18:02:48 -07:00
$feed _iframe . empty ( ) ;
this . $s . $story _iframe . attr ( 'src' , '' ) ;
this . $s . $story _iframe . empty ( ) ;
2010-07-06 18:43:06 -04:00
} ,
2010-12-06 10:41:24 -05:00
load _feed _iframe : function ( feed _id ) {
2010-11-06 13:27:52 -04:00
feed _id = feed _id || this . active _feed ;
2010-07-06 18:43:06 -04:00
var self = this ;
var $feed _view = this . $s . $story _pane ;
2010-12-06 10:41:24 -05:00
var $feed _iframe = this . $s . $feed _iframe ;
2010-07-06 18:43:06 -04:00
2010-12-06 10:41:24 -05:00
this . unload _feed _iframe ( ) ;
2010-07-06 18:43:06 -04:00
2010-06-14 13:17:38 -04:00
if ( ! feed _id ) {
2010-12-06 10:41:24 -05:00
feed _id = $feed _iframe . data ( 'feed_id' ) ;
2010-06-14 13:17:38 -04:00
} else {
2010-12-06 10:41:24 -05:00
$feed _iframe . data ( 'feed_id' , feed _id ) ;
2010-06-08 11:19:41 -04:00
}
2010-06-14 13:17:38 -04:00
this . flags . iframe _scroll _snap _back _prepared = true ;
this . iframe _link _attacher _num _links = 0 ;
2010-06-08 11:19:41 -04:00
2011-04-21 22:36:26 -04:00
$feed _iframe . removeAttr ( 'src' ) . attr ( { src : '/reader/page/' + feed _id } ) ;
2010-06-14 13:17:38 -04:00
2010-11-06 13:27:52 -04:00
if ( this . flags [ 'iframe_view_loaded' ] ) {
// NEWSBLUR.log(['Titles loaded, iframe loaded']);
2010-12-06 10:41:24 -05:00
var $iframe = this . $s . $feed _iframe . contents ( ) ;
2010-11-06 13:27:52 -04:00
this . fetch _story _locations _in _story _frame ( 0 , true , $iframe ) ;
} else {
// NEWSBLUR.log(['Titles loaded, iframe NOT loaded -- prefetching now']);
2010-11-08 19:39:27 -05:00
_ . delay ( _ . bind ( function ( ) {
this . prefetch _story _locations _in _story _frame ( ) ;
} , this ) , 500 ) ;
2010-11-06 13:27:52 -04:00
}
2010-12-06 10:41:24 -05:00
$feed _iframe . ready ( function ( ) {
2010-06-14 13:17:38 -04:00
setTimeout ( function ( ) {
2010-12-06 10:41:24 -05:00
$feed _iframe . load ( function ( ) {
2010-07-24 18:22:23 -04:00
self . return _to _snapback _position ( true ) ;
2010-06-14 13:17:38 -04:00
} ) ;
} , 50 ) ;
2010-07-24 18:22:23 -04:00
self . flags [ 'iframe_scroll_snapback_check' ] = setInterval ( function ( ) {
2010-07-25 15:34:50 -04:00
// NEWSBLUR.log(['Checking scroll', self.iframe_scroll, self.flags.iframe_scroll_snap_back_prepared]);
2010-07-24 18:22:23 -04:00
if ( self . iframe _scroll && self . flags . iframe _scroll _snap _back _prepared ) {
self . return _to _snapback _position ( ) ;
} else {
clearInterval ( self . flags [ 'iframe_scroll_snapback_check' ] ) ;
}
} , 500 ) ;
2010-06-14 13:17:38 -04:00
2011-04-20 09:35:59 -04:00
// NEWSBLUR.log(['iFrame domain', $feed_iframe.attr('src').indexOf('/reader/page?feed_id='+feed_id), $feed_iframe.attr('src')]);
2011-04-21 22:36:26 -04:00
if ( $feed _iframe . attr ( 'src' ) . indexOf ( '/reader/page/' + feed _id ) != - 1 ) {
2010-06-14 13:17:38 -04:00
var iframe _link _attacher = function ( ) {
2010-12-06 10:41:24 -05:00
var num _links = $feed _iframe . contents ( ) . find ( 'a' ) . length ;
2010-06-14 13:17:38 -04:00
// NEWSBLUR.log(['Finding links', self.iframe_link_attacher_num_links, num_links]);
if ( self . iframe _link _attacher _num _links != num _links ) {
// NEWSBLUR.log(['Found new links', num_links, self.iframe_link_attacher_num_links]);
self . iframe _link _attacher _num _links = num _links ;
2010-12-06 10:41:24 -05:00
$feed _iframe . contents ( ) . find ( 'a' )
2010-06-14 13:17:38 -04:00
. unbind ( 'click.NB-taskbar' )
. bind ( 'click.NB-taskbar' , function ( ) {
self . taskbar _show _return _to _page ( ) ;
} ) ;
}
} ;
clearInterval ( self . iframe _link _attacher ) ;
self . iframe _link _attacher = setInterval ( iframe _link _attacher , 2000 ) ;
iframe _link _attacher ( ) ;
2010-12-06 10:41:24 -05:00
$feed _iframe . load ( function ( ) {
2010-06-14 13:17:38 -04:00
clearInterval ( self . iframe _link _attacher ) ;
} ) ;
}
} ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-07-24 18:22:23 -04:00
return _to _snapback _position : function ( iframe _loaded ) {
2010-12-06 10:41:24 -05:00
var $feed _iframe = this . $s . $feed _iframe ;
2010-07-24 18:22:23 -04:00
if ( this . iframe _scroll
&& this . flags . iframe _scroll _snap _back _prepared
2010-12-06 10:41:24 -05:00
&& $feed _iframe . contents ( ) . scrollTop ( ) == 0 ) {
2010-07-25 15:34:50 -04:00
// NEWSBLUR.log(['Snap back, loaded, scroll', this.iframe_scroll]);
2010-12-06 10:41:24 -05:00
$feed _iframe . contents ( ) . scrollTop ( this . iframe _scroll ) ;
2010-07-24 18:22:23 -04:00
if ( iframe _loaded ) {
this . flags . iframe _scroll _snap _back _prepared = false ;
clearInterval ( self . flags [ 'iframe_scroll_snapback_check' ] ) ;
}
}
} ,
2010-06-14 13:17:38 -04:00
setup _feed _page _iframe _load : function ( ) {
var self = this ;
var $story _pane = this . $s . $story _pane ;
2010-12-06 10:41:24 -05:00
var $feed _iframe = this . $s . $feed _iframe ;
2010-06-14 13:17:38 -04:00
2010-12-06 10:41:24 -05:00
$feed _iframe . removeAttr ( 'src' ) . load ( function ( ) {
2010-06-14 13:17:38 -04:00
self . flags . iframe _view _loaded = true ;
try {
2010-12-06 10:41:24 -05:00
var $iframe _contents = $feed _iframe . contents ( ) ;
2010-06-14 13:17:38 -04:00
$iframe _contents . find ( 'a' )
. unbind ( 'click.NB-taskbar' )
. bind ( 'click.NB-taskbar' , function ( e ) {
var href = $ ( this ) . attr ( 'href' ) ;
if ( href . indexOf ( '#' ) == 0 ) {
e . preventDefault ( ) ;
var $footnote = $ ( 'a[name=' + href . substr ( 1 ) + '], [id=' + href . substr ( 1 ) + ']' ,
$iframe _contents ) ;
// NEWSBLUR.log(['Footnote', $footnote, href, href.substr(1)]);
2011-07-13 09:50:02 -07:00
$iframe _contents . scrollTo ( $footnote , {
duration : 600 ,
2010-06-14 13:17:38 -04:00
axis : 'y' ,
easing : 'easeInOutQuint' ,
offset : 0 ,
queue : false
} ) ;
return false ;
}
self . taskbar _show _return _to _page ( ) ;
} ) ;
$iframe _contents
. unbind ( 'scroll' )
2010-12-06 10:41:24 -05:00
. scroll ( $ . rescope ( self . handle _scroll _feed _iframe , self ) ) ;
2010-06-14 13:17:38 -04:00
$iframe _contents
2010-06-15 18:29:13 -04:00
. unbind ( 'mousemove.reader' )
. bind ( 'mousemove.reader' , $ . rescope ( self . handle _mousemove _iframe _view , self ) ) ;
2010-06-14 13:17:38 -04:00
if ( self . flags [ 'story_titles_loaded' ] ) {
// NEWSBLUR.log(['iframe loaded, titles loaded']);
self . fetch _story _locations _in _story _frame ( 0 , true , $iframe _contents ) ;
}
} catch ( e ) {
// Not on local domain. Ignore.
2010-06-08 11:19:41 -04:00
}
2010-06-14 13:17:38 -04:00
} ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-06-14 13:17:38 -04:00
taskbar _show _return _to _page : function ( ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-12-06 10:41:24 -05:00
var $feed _iframe = $ ( '.NB-feed-frame' ) ;
2010-06-08 11:19:41 -04:00
2011-02-13 14:49:13 -05:00
_ . delay ( function ( ) {
2010-12-06 10:41:24 -05:00
var $feed _iframe = $ ( '.NB-feed-frame' ) ;
2010-06-14 13:17:38 -04:00
var $taskbar _view _page = $ ( '.NB-taskbar .task_view_page' ) ;
try {
2011-02-02 14:10:24 -05:00
NEWSBLUR . log ( [ 'return' , $feed _iframe . contents ( ) . find ( 'body' ) ] ) ;
2010-12-06 10:41:24 -05:00
var length = $feed _iframe . contents ( ) . find ( 'body' ) . length ;
2010-06-14 13:17:38 -04:00
if ( length ) {
return false ;
}
} catch ( e ) {
2011-02-02 14:10:24 -05:00
$taskbar _view _page . addClass ( 'NB-task-return' ) ;
2010-06-14 13:17:38 -04:00
} finally {
2011-02-02 14:10:24 -05:00
$taskbar _view _page . addClass ( 'NB-task-return' ) ;
2010-06-14 13:17:38 -04:00
}
2011-02-02 14:10:24 -05:00
} , 1000 ) ;
2010-06-14 13:17:38 -04:00
} ,
2011-04-03 11:48:42 -04:00
load _page _of _feed _stories : function ( hide _loading ) {
2010-06-14 13:17:38 -04:00
var $story _titles = this . $s . $story _titles ;
var feed _id = $story _titles . data ( 'feed_id' ) ;
var page = $story _titles . data ( 'page' ) ;
2010-12-12 22:52:15 -05:00
2010-06-14 13:17:38 -04:00
if ( ! this . flags [ 'opening_feed' ] ) {
2011-04-03 11:48:42 -04:00
if ( ! hide _loading ) this . show _feedbar _loading ( ) ;
2010-06-14 13:17:38 -04:00
$story _titles . data ( 'page' , page + 1 ) ;
2010-12-04 13:32:13 -05:00
if ( this . active _feed == 'starred' ) {
2011-11-15 18:19:09 -08:00
this . model . fetch _starred _stories ( page + 1 , _ . bind ( this . post _open _starred _stories , this ) ,
_ . bind ( this . show _stories _error , this ) , false ) ;
2011-02-04 09:56:15 -05:00
} else if ( this . flags [ 'river_view' ] ) {
this . model . fetch _river _stories ( this . active _feed , this . cache [ 'river_feeds_with_unreads' ] ,
2011-11-15 18:19:09 -08:00
page + 1 , _ . bind ( this . post _open _river _stories , this ) ,
_ . bind ( this . show _stories _error , this ) , false ) ;
2010-12-03 09:49:38 -05:00
} else {
this . model . load _feed ( feed _id , page + 1 , false ,
2011-11-15 18:19:09 -08:00
$ . rescope ( this . post _open _feed , this ) , _ . bind ( this . show _stories _error , this ) ) ;
2010-12-03 09:49:38 -05:00
}
2010-06-11 20:55:38 -04:00
}
2010-06-14 13:17:38 -04:00
} ,
2011-01-11 19:33:55 -05:00
fill _out _story _titles : function ( ) {
var $last = $ ( '.story:visible:last' , this . $s . $story _titles ) ;
var container _height = this . $s . $story _titles . height ( ) ;
var $feedbar = $ ( '.NB-story-titles-end-stories-line' ) ;
2011-04-12 18:23:04 -04:00
// console.log(['fill_out_story_titles', $last.length, $last, $('#story_titles').scrollTop(), this.constants.FILL_OUT_PAGES, this.counts['page_fill_outs'], $last.length && $last.position().top, $last.length && $last.height(), container_height]);
2011-01-11 19:33:55 -05:00
if ( ! $feedbar . length &&
( $last . length == 0 ||
( $ ( '#story_titles' ) . scrollTop ( ) == 0 &&
2011-04-12 18:23:04 -04:00
$last . position ( ) . top + $last . height ( ) - 13 < container _height ) ) ) {
2011-04-12 11:02:02 -04:00
if ( this . counts [ 'page_fill_outs' ] < this . constants . FILL _OUT _PAGES ) {
2011-03-09 09:48:24 -05:00
this . counts [ 'page_fill_outs' ] += 1 ;
2011-04-03 11:48:42 -04:00
_ . delay ( _ . bind ( this . load _page _of _feed _stories , this , true ) , 250 ) ;
2011-03-09 09:48:24 -05:00
} else {
this . append _story _titles _endbar ( ) ;
}
2011-01-11 19:33:55 -05:00
}
} ,
2010-06-14 13:17:38 -04:00
show _feedbar _loading : function ( ) {
var $story _titles = this . $s . $story _titles ;
var $feedbar = $ ( '.NB-story-titles-end-stories-line' ) ;
if ( ! $feedbar . length ) {
$feedbar = $ . make ( 'div' , { className : 'NB-story-titles-end-stories-line' } ) ;
2010-06-08 11:19:41 -04:00
}
2010-06-14 13:17:38 -04:00
$feedbar . css ( { 'background' : '#E1EBFF' } ) ;
$story _titles . append ( $feedbar ) ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
$feedbar . animate ( { 'backgroundColor' : '#5C89C9' } , { 'duration' : 750 } )
. animate ( { 'backgroundColor' : '#E1EBFF' } , 750 ) ;
this . feed _stories _loading = setInterval ( function ( ) {
$feedbar . animate ( { 'backgroundColor' : '#5C89C9' } , { 'duration' : 750 } )
. animate ( { 'backgroundColor' : '#E1EBFF' } , 750 ) ;
} , 1500 ) ;
2011-12-06 19:12:45 -08:00
$story _titles . scrollTo ( $feedbar , {
duration : 0 ,
axis : 'y' ,
easing : 'easeInOutQuint' ,
offset : 0 ,
queue : false
} ) ;
2010-06-14 13:17:38 -04:00
} ,
2010-11-01 18:20:26 -04:00
show _feed _title _in _stories : function ( feed _id ) {
var $story _titles = this . $s . $story _titles ;
2010-06-14 13:17:38 -04:00
var feed = this . model . get _feed ( feed _id ) ;
2011-01-11 19:33:55 -05:00
if ( ! feed ) return ;
2010-06-14 13:17:38 -04:00
var $feedbar = $ . make ( 'div' , { className : 'NB-feedbar' } , [
2011-03-30 09:30:45 -04:00
$ ( this . make _feed _title _template ( feed , 'story' ) ) ,
2010-11-26 19:03:31 -05:00
// $.make('div', { className: 'NB-feedbar-intelligence' }, [
// $.make('div', { className: 'NB-feed-sentiment NB-feed-like', title: 'What I like about this site...' }),
// $.make('div', { className: 'NB-feed-sentiment NB-feed-dislike', title: 'What I dislike about this site...' })
// ]),
2010-06-14 13:17:38 -04:00
$ . make ( 'span' , { className : 'feed_id' } , '' + feed . id )
] ) . hover ( function ( ) {
$ ( this ) . addClass ( 'NB-feedbar-hover' ) ;
} , function ( ) {
$ ( this ) . removeClass ( 'NB-feedbar-hover' ) ;
} ) ;
2010-06-08 11:19:41 -04:00
2011-05-01 20:22:54 -04:00
if ( this . model . preference ( 'show_tooltips' ) ) {
$ ( '.NB-feedbar-train-feed, .NB-feedbar-statistics' , $feedbar ) . tipsy ( {
gravity : 's' ,
delayIn : 375
} ) ;
}
2011-03-30 09:30:45 -04:00
2010-06-14 13:17:38 -04:00
$story _titles . prepend ( $feedbar ) ;
$ ( '.unread_count' , $feedbar ) . corner ( '4px' ) ;
2010-06-08 11:19:41 -04:00
} ,
2011-01-04 19:27:00 -05:00
show _feed _hidden _story _title _indicator : function ( is _feed _load ) {
if ( is _feed _load && this . flags [ 'unread_threshold_temporarily' ] ) return ;
2011-01-04 19:39:57 -05:00
else this . flags [ 'unread_threshold_temporarily' ] = null ;
2011-01-04 19:27:00 -05:00
2010-11-01 18:20:26 -04:00
var $story _titles = this . $s . $story _titles ;
var feed _id = this . active _feed ;
var feed = this . model . get _feed ( feed _id ) ;
var unread _view _name = this . get _unread _view _name ( ) ;
2011-01-04 08:40:15 -05:00
var $indicator = $ ( '.NB-story-title-indicator' , $story _titles ) ;
2011-01-04 08:21:47 -05:00
var hidden _stories = _ . any ( this . model . stories , _ . bind ( function ( story ) {
2011-11-28 12:13:09 -05:00
var score = this . compute _story _score ( story ) ;
2011-01-04 08:21:47 -05:00
if ( unread _view _name == 'positive' ) return score <= 0 ;
else if ( unread _view _name == 'neutral' ) return score < 0 ;
} , this ) ) ;
2010-11-01 18:20:26 -04:00
2011-01-04 08:21:47 -05:00
if ( hidden _stories ) {
2011-01-04 08:40:15 -05:00
if ( $indicator . length ) {
var $counts = this . make _feed _counts _floater ( feed . ps , feed . nt , feed . ng ) ;
$ ( '.feed_counts_floater' , $indicator ) . replaceWith ( $counts ) ;
2011-06-07 16:08:59 -04:00
this . cache . $feed _counts _in _feed _list [ feed _id ] = null ;
2011-01-04 10:10:23 -05:00
$indicator . css ( { 'opacity' : 1 } ) ;
2011-01-07 19:20:34 -05:00
} else if ( feed ) {
2011-01-04 08:40:15 -05:00
$indicator = $ . make ( 'div' , { className : 'NB-story-title-indicator' } , [
this . make _feed _counts _floater ( feed . ps , feed . nt , feed . ng ) ,
$ . make ( 'span' , { className : 'NB-story-title-indicator-text' } , 'show hidden stories' )
] ) . css ( {
'opacity' : 0
} ) ;
2011-01-04 10:10:23 -05:00
$ ( '.NB-feedbar .feed .feed_title' , this . $story _titles ) . prepend ( $indicator ) ;
2011-01-04 08:40:15 -05:00
_ . delay ( function ( ) {
$indicator . animate ( { 'opacity' : 1 } , { 'duration' : 1000 , 'easing' : 'easeOutCubic' } ) ;
} , 500 ) ;
}
2010-11-01 18:20:26 -04:00
$indicator . removeClass ( 'unread_threshold_positive' )
. removeClass ( 'unread_threshold_neutral' )
. removeClass ( 'unread_threshold_negative' )
2011-01-04 08:40:15 -05:00
. addClass ( 'unread_threshold_' + unread _view _name ) ;
2010-11-01 18:20:26 -04:00
}
} ,
2011-09-27 22:16:09 -07:00
check _story _titles _last _story : function ( ) {
var $story _titles = this . $s . $story _titles ;
if ( ! ( $ ( '.NB-story-titles-end-stories-line' , $story _titles ) . length ) ) {
var $last _story = $ ( '#story_titles .story' ) . last ( ) ;
var container _offset = $story _titles . position ( ) . top ;
var full _height = ( $last _story . offset ( ) && $last _story . offset ( ) . top ) + $last _story . height ( ) - container _offset ;
var visible _height = $ ( '#story_titles' ) . height ( ) ;
var scroll _y = $ ( '#story_titles' ) . scrollTop ( ) ;
// NEWSBLUR.log(['Story_titles Scroll', full_height, container_offset, visible_height, scroll_y]);
// Fudge factor is simply because it looks better at 13 pixels off.
if ( ( visible _height + 13 ) >= full _height ) {
this . load _page _of _feed _stories ( ) ;
}
}
} ,
2010-11-01 18:20:26 -04:00
show _hidden _story _titles : function ( ) {
var feed _id = this . active _feed ;
var feed = this . model . get _feed ( feed _id ) ;
var $indicator = $ ( '.NB-story-title-indicator' , this . $s . $story _titles ) ;
2011-01-04 08:21:47 -05:00
var unread _view _name = $indicator . hasClass ( 'unread_threshold_positive' ) ?
'positive' :
'neutral' ;
var hidden _stories _at _threshold = _ . any ( this . model . stories , _ . bind ( function ( story ) {
2011-11-28 12:13:09 -05:00
var score = this . compute _story _score ( story ) ;
2011-01-04 08:21:47 -05:00
if ( unread _view _name == 'positive' ) return score == 0 ;
else if ( unread _view _name == 'neutral' ) return score < 0 ;
} , this ) ) ;
var hidden _stories _below _threshold = unread _view _name == 'positive' &&
_ . any ( this . model . stories , _ . bind ( function ( story ) {
2011-11-28 12:13:09 -05:00
var score = this . compute _story _score ( story ) ;
2011-01-04 08:21:47 -05:00
return score < 0 ;
} , this ) ) ;
2010-11-01 18:20:26 -04:00
2011-01-04 19:44:00 -05:00
// NEWSBLUR.log(['show_hidden_story_titles', hidden_stories_at_threshold, hidden_stories_below_threshold, unread_view_name]);
2011-01-04 19:39:57 -05:00
2010-11-01 18:20:26 -04:00
// First click, open neutral. Second click, open negative.
2011-01-04 08:21:47 -05:00
if ( unread _view _name == 'positive' && hidden _stories _at _threshold && hidden _stories _below _threshold ) {
2011-01-04 19:39:57 -05:00
this . flags [ 'unread_threshold_temporarily' ] = 'neutral' ;
2011-01-03 19:18:27 -05:00
this . show _story _titles _above _intelligence _level ( {
2010-11-01 18:20:26 -04:00
'unread_view_name' : 'neutral' ,
'animate' : true ,
2011-02-01 18:29:22 -05:00
'follow' : true ,
'temporary' : true
2010-11-01 18:20:26 -04:00
} ) ;
$indicator . removeClass ( 'unread_threshold_positive' ) . addClass ( 'unread_threshold_neutral' ) ;
2011-01-04 08:21:47 -05:00
} else {
2011-01-04 19:39:57 -05:00
this . flags [ 'unread_threshold_temporarily' ] = 'negative' ;
2011-01-03 19:18:27 -05:00
this . show _story _titles _above _intelligence _level ( {
2011-01-04 08:21:47 -05:00
'unread_view_name' : 'negative' ,
2010-11-01 18:20:26 -04:00
'animate' : true ,
2011-02-01 18:29:22 -05:00
'follow' : true ,
'temporary' : true
2010-11-01 18:20:26 -04:00
} ) ;
$indicator . removeClass ( 'unread_threshold_positive' )
. removeClass ( 'unread_threshold_neutral' )
. addClass ( 'unread_threshold_negative' ) ;
2011-01-04 08:21:47 -05:00
$indicator . animate ( { 'opacity' : 0 } , { 'duration' : 500 } ) ;
2010-11-01 18:20:26 -04:00
}
} ,
2010-06-14 13:17:38 -04:00
open _feed _link : function ( feed _id , $fd ) {
2010-10-12 20:13:33 -04:00
if ( ! feed _id ) feed _id = this . active _feed ;
2010-06-14 13:17:38 -04:00
this . mark _feed _as _read ( feed _id ) ;
var feed = this . model . get _feed ( feed _id ) ;
window . open ( feed [ 'feed_link' ] , '_blank' ) ;
2011-10-31 18:04:25 -07:00
// window.focus();
2010-06-14 13:17:38 -04:00
} ,
2011-02-23 11:40:25 -05:00
open _story _in _new _tab : function ( story _id , $t ) {
2011-10-31 18:04:25 -07:00
story _id = story _id || this . get _current _story _id ( ) ;
if ( story _id ) {
var story = this . model . get _story ( story _id ) ;
window . open ( story [ 'story_permalink' ] , '_blank' ) ;
window . focus ( ) ;
}
2010-12-14 17:08:52 -05:00
} ,
open _unread _stories _in _tabs : function ( feed _id ) {
feed _id = feed _id || this . active _feed ;
if ( this . active _feed == feed _id ) {
this . flags [ 'open_unread_stories_in_tabs' ] = false ;
_ . each ( this . model . stories , function ( story ) {
2010-12-14 23:10:13 -05:00
NEWSBLUR . log ( [ 'story' , story , ! story . read _status ] ) ;
2010-12-14 17:08:52 -05:00
if ( ! story . read _status ) {
2010-12-14 23:10:13 -05:00
window . open ( story [ 'story_permalink' ] , '_blank' ) ;
window . focus ( ) ;
2010-12-14 17:08:52 -05:00
}
} ) ;
this . mark _feed _as _read ( feed _id ) ;
} else {
this . flags [ 'open_unread_stories_in_tabs' ] = true ;
var $feed = this . find _feed _in _feed _list ( feed _id ) ;
this . open _feed ( feed _id , false , $feed ) ;
}
} ,
2010-06-14 13:17:38 -04:00
mark _feed _as _selected : function ( feed _id , $feed _link ) {
2010-11-22 10:44:52 -05:00
if ( $feed _link === undefined ) {
2010-10-11 12:07:32 -04:00
$feed _link = $ ( '.feed.selected' , this . $feed _list ) . eq ( 0 ) ;
}
2010-06-14 13:17:38 -04:00
$ ( '#feed_list .selected' ) . removeClass ( 'selected' ) ;
$ ( '#feed_list .after_selected' ) . removeClass ( 'after_selected' ) ;
2010-09-05 18:08:08 -07:00
if ( $feed _link ) {
$feed _link . addClass ( 'selected' ) ;
$feed _link . parent ( '.feed' ) . next ( '.feed' ) . children ( 'a' ) . addClass ( 'after_selected' ) ;
}
2010-06-14 13:17:38 -04:00
} ,
2010-09-17 12:40:42 -04:00
open _feed _intelligence _modal : function ( score , feed _id , feed _loaded ) {
2010-09-12 13:50:27 -04:00
feed _id = feed _id || this . active _feed ;
2011-10-30 22:17:16 -07:00
if ( feed _id ) {
NEWSBLUR . classifier = new NEWSBLUR . ReaderClassifierFeed ( feed _id , {
'score' : score ,
'feed_loaded' : feed _loaded
} ) ;
}
2010-08-01 23:47:40 -04:00
} ,
open _trainer _modal : function ( score ) {
var feed _id = this . active _feed ;
2010-08-01 19:12:42 -04:00
// NEWSBLUR.classifier = new NEWSBLUR.ReaderClassifierFeed(feed_id, {'score': score});
NEWSBLUR . classifier = new NEWSBLUR . ReaderClassifierTrainer ( { 'score' : score } ) ;
2011-12-21 18:23:53 -08:00
} ,
open _friends _modal : function ( score ) {
2011-12-23 18:28:16 -08:00
NEWSBLUR . reader _friends = new NEWSBLUR . ReaderFriends ( ) ;
2010-06-08 11:19:41 -04:00
} ,
2011-03-28 10:08:10 -04:00
open _recommend _modal : function ( feed _id ) {
2011-04-07 10:30:05 -04:00
NEWSBLUR . recommend _feed = new NEWSBLUR . ReaderRecommendFeed ( feed _id ) ;
2011-03-28 10:08:10 -04:00
} ,
2011-05-10 18:30:35 -04:00
open _tutorial _modal : function ( ) {
NEWSBLUR . tutorial = new NEWSBLUR . ReaderTutorial ( ) ;
} ,
2011-05-13 10:15:56 -04:00
hide _tutorial : function ( ) {
var $tutorial = $ ( '.NB-module-tutorial' ) ;
this . model . preference ( 'tutorial_finished' , true ) ;
$tutorial . animate ( {
'opacity' : 0
} , {
'duration' : 500 ,
'complete' : function ( ) {
$tutorial . slideUp ( 350 ) ;
}
} ) ;
} ,
2011-08-07 21:38:09 -07:00
hide _mobile : function ( ) {
var $mobile = $ ( '.NB-module-mobile' ) ;
this . model . preference ( 'hide_mobile' , true ) ;
$mobile . animate ( {
'opacity' : 0
} , {
'duration' : 500 ,
'complete' : function ( ) {
$mobile . slideUp ( 350 ) ;
}
} ) ;
} ,
2010-06-14 13:17:38 -04:00
// ==========================
// = Story Pane - Feed View =
// ==========================
2010-12-04 13:32:13 -05:00
make _story _feed _entries : function ( stories , first _load , options ) {
2010-06-14 13:17:38 -04:00
var $feed _view = this . $s . $feed _view ;
2011-01-24 23:50:38 -05:00
var $stories = this . $s . $feed _stories ;
2010-06-08 11:19:41 -04:00
var self = this ;
2010-06-14 13:17:38 -04:00
var unread _view = this . model . preference ( 'unread_view' ) ;
2011-01-25 22:59:38 -05:00
var river _same _feed ;
2011-01-29 19:16:40 -05:00
var feed = this . model . get _feed ( this . active _feed ) ;
2010-06-08 11:19:41 -04:00
2010-12-04 13:32:13 -05:00
options = options || { } ;
2011-01-26 20:51:29 -05:00
if ( first _load && ! options . refresh _load ) {
$ ( '.NB-feed-story-endbar' , $feed _view ) . remove ( ) ;
2010-06-08 11:19:41 -04:00
}
2010-06-14 13:17:38 -04:00
for ( var s in stories ) {
2011-04-24 20:48:16 -04:00
if ( this . flags [ 'non_premium_river_view' ] && $stories . children ( ':visible' ) . length >= this . constants . RIVER _STORIES _FOR _STANDARD _ACCOUNT ) {
2011-02-13 14:49:13 -05:00
this . append _story _titles _endbar ( ) ;
2011-02-22 19:45:29 -05:00
this . append _river _premium _only _notification ( ) ;
2011-02-13 14:49:13 -05:00
break ;
}
2010-06-14 13:17:38 -04:00
var story = stories [ s ] ;
2011-04-11 23:25:44 -04:00
var story _has _modifications = false ;
2011-12-14 21:56:27 -08:00
var starred = story . starred ? ' NB-story-starred ' : '' ;
2011-12-15 09:10:37 -08:00
var shared = story . shared ? ' NB-story-shared ' : '' ;
2011-01-29 19:16:40 -05:00
if ( options . river _stories ) feed = this . model . get _feed ( story . story _feed _id ) ;
2010-06-14 13:17:38 -04:00
var read = story . read _status
2010-12-04 13:32:13 -05:00
? ' read '
2010-06-14 13:17:38 -04:00
: '' ;
2011-11-28 12:13:09 -05:00
var score = this . compute _story _score ( story ) ;
2010-06-14 13:17:38 -04:00
var score _color = 'neutral' ;
2010-12-10 15:26:50 -05:00
var river _stories = options [ 'river_stories' ]
? ' NB-river-story '
2010-12-04 13:32:13 -05:00
: '' ;
2010-06-14 13:17:38 -04:00
if ( score > 0 ) score _color = 'positive' ;
if ( score < 0 ) score _color = 'negative' ;
2011-04-11 23:26:47 -04:00
if ( story . story _content . indexOf ( '<ins' ) != - 1 ) story _has _modifications = true ;
2011-04-13 23:31:00 -04:00
if ( ! story _has _modifications && this . model . preference ( 'hide_story_changes' ) ) {
if ( story . story _content . indexOf ( '<del' ) != - 1 ) story _has _modifications = true ;
}
2011-01-25 22:59:38 -05:00
2011-10-19 23:04:45 -07:00
river _same _feed = "" ;
2011-01-25 22:59:38 -05:00
if ( this . cache . last _feed _view _story _feed _id == story . story _feed _id ) {
2011-10-19 23:04:45 -07:00
river _same _feed = 'NB-feed-story-river-same-feed' ;
2011-01-25 22:59:38 -05:00
}
2011-12-15 09:10:37 -08:00
var $story = $ . make ( 'li' , { className : 'NB-feed-story ' + read + starred + shared + river _stories + ' NB-story-' + score _color } , [
2010-06-14 13:17:38 -04:00
$ . make ( 'div' , { className : 'NB-feed-story-header' } , [
2011-10-19 23:04:45 -07:00
$ . make ( 'div' , { className : 'NB-feed-story-header-feed' } , [
2011-01-26 19:36:28 -05:00
( options . river _stories && feed && // !river_same_feed
2011-01-14 00:59:51 -05:00
$ . make ( 'div' , { className : 'NB-feed-story-feed' } , [
2011-02-17 10:32:47 -05:00
$ . make ( 'img' , { className : 'feed_favicon' , src : $ . favicon ( feed . favicon ) } ) ,
2011-01-14 00:59:51 -05:00
$ . make ( 'span' , { className : 'feed_title' } , feed . feed _title )
] )
)
2011-06-16 23:45:41 -04:00
] ) . css ( 'background-image' , NEWSBLUR . utils . generate _gradient ( feed , 'webkit' ) )
. css ( 'background-image' , NEWSBLUR . utils . generate _gradient ( feed , 'moz' ) )
. css ( 'borderBottom' , NEWSBLUR . utils . generate _gradient ( feed , 'border' ) )
. css ( 'borderTop' , NEWSBLUR . utils . generate _gradient ( feed , 'border' ) )
. toggleClass ( 'NB-inverse' , NEWSBLUR . utils . is _feed _floater _gradient _light ( feed ) ) ,
2011-01-14 00:59:51 -05:00
$ . make ( 'div' , { className : 'NB-feed-story-header-info' } , [
( story . story _authors &&
2011-03-04 19:25:15 -05:00
this . make _story _feed _author ( story ) ) ,
2011-03-02 19:59:31 -05:00
( story . story _tags && story . story _tags . length && this . make _story _feed _tags ( story ) ) ,
2011-01-14 00:59:51 -05:00
$ . make ( 'div' , { className : 'NB-feed-story-title-container' } , [
$ . make ( 'div' , { className : 'NB-feed-story-sentiment' } ) ,
$ . make ( 'div' , { className : 'NB-feed-story-manage-icon' } ) ,
// $.make('div', { className: 'NB-feed-story-sentiment NB-feed-story-sentiment-animate' }),
2011-03-04 19:25:15 -05:00
this . make _story _feed _title ( story )
2011-01-14 00:59:51 -05:00
] ) ,
( story . long _parsed _date &&
2011-04-11 23:25:44 -04:00
$ . make ( 'span' , { className : 'NB-feed-story-date' } , [
2011-04-13 23:06:16 -04:00
( story _has _modifications && $ . make ( 'div' , {
className : 'NB-feed-story-hide-changes' ,
title : ( this . model . preference ( 'hide_story_changes' ) ?
'Show' : 'Hide' ) + ' story modifications'
} ) ) ,
2011-04-11 23:25:44 -04:00
story . long _parsed _date
] ) ) ,
2011-01-14 00:59:51 -05:00
( story . starred _date &&
$ . make ( 'span' , { className : 'NB-feed-story-starred-date' } , story . starred _date ) )
] )
] ) ,
2011-12-12 20:06:30 -08:00
$ . make ( 'div' , { className : 'NB-feed-story-content' } , this . make _story _content ( story . story _content ) ) ,
2011-12-17 13:05:11 -08:00
$ . make ( 'div' , { className : 'NB-feed-story-comments' } , this . make _story _share _comments ( story ) ) ,
2011-12-12 20:06:30 -08:00
$ . make ( 'div' , { className : 'NB-feed-story-sideoptions-container' } , [
$ . make ( 'div' , { className : 'NB-sideoption NB-feed-story-train' } , [
$ . make ( 'div' , { className : 'NB-sideoption-icon' } , ' ' ) ,
$ . make ( 'div' , { className : 'NB-sideoption-title' } , 'Train this story' )
] ) ,
2011-12-14 21:56:27 -08:00
$ . make ( 'div' , { className : 'NB-sideoption NB-feed-story-save' } , [
$ . make ( 'div' , { className : 'NB-sideoption-icon' } , ' ' ) ,
$ . make ( 'div' , { className : 'NB-sideoption-title' } , story . starred _date ? 'Saved' : 'Save this story' )
] ) ,
2011-12-12 20:06:30 -08:00
$ . make ( 'div' , { className : 'NB-sideoption NB-feed-story-share' } , [
$ . make ( 'div' , { className : 'NB-sideoption-icon' } , ' ' ) ,
2011-12-15 09:10:37 -08:00
$ . make ( 'div' , { className : 'NB-sideoption-title' } , story . shared _date ? 'Shared' : 'Share this story' )
2011-12-13 09:57:04 -08:00
] ) ,
$ . make ( 'div' , { className : 'NB-sideoption-share-wrapper' } , [
$ . make ( 'div' , { className : 'NB-sideoption-share' } , [
$ . make ( 'div' , { className : 'NB-sideoption-share-optional' } , 'Optional' ) ,
$ . make ( 'div' , { className : 'NB-sideoption-share-title' } , 'Comments:' ) ,
2011-12-15 09:10:37 -08:00
$ . make ( 'textarea' , { className : 'NB-sideoption-share-comments' } , story . shared _comments ) ,
2011-12-14 09:51:47 -08:00
$ . make ( 'div' , { className : 'NB-sideoption-share-save NB-modal-submit-button' } , 'Share' )
2011-12-13 09:57:04 -08:00
] )
2011-12-12 20:06:30 -08:00
] )
] )
2011-01-14 00:59:51 -05:00
] ) . data ( 'story' , story . id ) . data ( 'story_id' , story . id ) . data ( 'feed_id' , story . story _feed _id ) ;
2010-10-31 16:03:50 -04:00
2011-05-01 20:22:54 -04:00
if ( story _has _modifications && this . model . preference ( 'show_tooltips' ) ) {
2011-04-11 23:32:58 -04:00
$ ( '.NB-feed-story-hide-changes' , $story ) . tipsy ( {
delayIn : 375
} ) ;
}
2011-04-13 23:06:16 -04:00
if ( story _has _modifications && this . model . preference ( 'hide_story_changes' ) ) {
$ ( 'ins' , $story ) . css ( { 'text-decoration' : 'none' } ) ;
$ ( 'del' , $story ) . css ( { 'display' : 'none' } ) ;
}
2011-04-13 18:22:56 -04:00
if ( this . model . preference ( 'new_window' ) == 1 ) {
2010-10-31 16:03:50 -04:00
$ ( 'a' , $story ) . attr ( 'target' , '_blank' ) ;
}
2010-12-04 13:32:13 -05:00
if ( options . refresh _load ) {
2010-06-14 13:17:38 -04:00
$stories . prepend ( $story ) ;
} else {
$stories . append ( $story ) ;
}
2011-01-25 22:59:38 -05:00
this . cache . last _feed _view _story _feed _id = story . story _feed _id ;
2010-06-14 13:17:38 -04:00
this . cache . feed _view _stories [ story . id ] = $story ;
var image _count = $ ( 'img' , $story ) . length ;
if ( ! image _count ) {
this . flags . feed _view _images _loaded [ story . id ] = true ;
} else {
// Progressively load the images in each story, so that when one story
// loads, the position is calculated and the next story can calculate
// its position (atfer its own images are loaded).
2010-11-04 21:49:13 -04:00
this . flags . feed _view _images _loaded [ story . id ] = false ;
2010-06-14 13:17:38 -04:00
( function ( $story , story , image _count ) {
$ ( 'img' , $story ) . load ( function ( ) {
// NEWSBLUR.log(['Loaded image', $story, story, image_count]);
if ( image _count == 1 ) {
self . flags . feed _view _images _loaded [ story . id ] = true ;
} else {
image _count -- ;
}
2010-11-15 22:43:01 -05:00
return true ;
2010-06-14 13:17:38 -04:00
} ) ;
} ) ( $story , story , image _count ) ;
}
2010-06-08 11:19:41 -04:00
}
2010-12-08 20:53:45 -05:00
2011-01-10 09:49:26 -05:00
if ( ! stories || ! stories . length ) {
2010-12-15 16:10:54 -05:00
this . fetch _story _locations _in _feed _view ( ) ;
}
2011-02-13 14:49:13 -05:00
this . append _feed _view _story _endbar ( ) ;
2011-09-27 23:06:49 -07:00
this . hover _story _feed _titles ( ) ;
2011-05-03 12:19:53 -04:00
if ( first _load ) this . show _stories _preference _in _feed _view ( true ) ;
2010-06-08 11:19:41 -04:00
} ,
2011-11-06 14:25:49 -08:00
make _story _content : function ( story _content ) {
var $story _content = $ ( '<div>' ) . html ( story _content ) . autolink ( ) ;
return $story _content ;
} ,
2011-12-17 13:05:11 -08:00
make _story _share _comments : function ( story ) {
var $comments = $ ( [ ] ) ;
var $share = $ . make ( 'div' , { className : 'NB-story-comments-sharers' } , 'Shared by: ' ) ;
var $comment = this . make _story _share _comment ( { 'content' : 'Pour some sugar on this comment form. It\'s done.' } ) ;
var $comment2 = this . make _story _share _comment ( { 'content' : 'These are all AWESOME changes and things we wished we\'d had when we were doing our campaign! Good job, guys. Go go gadget team!' } ) ;
var $comment3 = this . make _story _share _comment ( { 'content' : 'So cool to get a glimpse of the NewsBlur team and offices! (Love the farm table and tin wainscotting). Thanks for sharing the love with my baby girl! And never apologize for delicious sandwiches. ;)' } ) ;
var $public _teaser = $ . make ( 'div' , { className : 'NB-story-comments-public-teaser-wrapper' } , [
$ . make ( 'div' , { className : 'NB-story-comments-public-teaser' } , [
'There are ' ,
$ . make ( 'b' , { style : 'padding: 0 1px' } , '3' ) ,
' public comments'
] )
] ) ;
Math . random ( ) < . 35 && $comments . push ( $comment ) ;
Math . random ( ) < . 45 && $comments . push ( $comment2 ) ;
Math . random ( ) < . 35 && $comments . push ( $comment3 ) ;
Math . random ( ) < . 45 && $comments . push ( $public _teaser ) ;
return $comments ;
} ,
make _story _share _comment : function ( comment ) {
var $comment = $ . make ( 'div' , { className : 'NB-story-comment' } , [
$ . make ( 'div' , { className : 'NB-user-avatar' } , [
$ . make ( 'img' , { src : '/media/img/reader/account_standard_3.jpg' } )
] ) ,
$ . make ( 'div' , { className : 'NB-story-comment-author-container' } , [
$ . make ( 'div' , { className : 'NB-story-comment-username' } , 'samuelclay' ) ,
$ . make ( 'div' , { className : 'NB-story-comment-date' } , '2 hours ago' )
] ) ,
$ . make ( 'div' , { className : 'NB-story-comment-content' } , comment . content )
] ) ;
return $comment ;
} ,
2011-03-04 19:25:15 -05:00
make _story _feed _title : function ( story ) {
var title = story . story _title ;
2011-10-25 00:01:35 -07:00
var feed _titles = this . model . classifiers [ story . story _feed _id ] &&
this . model . classifiers [ story . story _feed _id ] . titles ||
[ ] ;
2011-10-24 08:55:28 -07:00
_ . each ( feed _titles , function ( score , title _classifier ) {
2011-03-04 19:25:15 -05:00
if ( title . indexOf ( title _classifier ) != - 1 ) {
title = title . replace ( title _classifier , '<span class="NB-score-' + score + '">' + title _classifier + '</span>' ) ;
}
} ) ;
return $ . make ( 'a' , { className : 'NB-feed-story-title' , href : story . story _permalink } , title ) ;
} ,
make _story _feed _author : function ( story ) {
2011-10-25 00:01:35 -07:00
var score = this . model . classifiers [ story . story _feed _id ] &&
this . model . classifiers [ story . story _feed _id ] . authors [ story . story _authors ] ;
2011-03-04 19:25:15 -05:00
return $ . make ( 'div' , {
2011-03-17 18:33:59 -04:00
className : 'NB-feed-story-author ' + ( ! ! score && 'NB-score-' + score || '' )
} , story . story _authors ) . data ( 'author' , story . story _authors ) ;
2011-03-04 19:25:15 -05:00
} ,
2011-03-02 19:59:31 -05:00
make _story _feed _tags : function ( story ) {
2011-10-25 00:01:35 -07:00
var feed _tags = this . model . classifiers [ story . story _feed _id ] &&
this . model . classifiers [ story . story _feed _id ] . tags ||
{ } ;
2011-03-04 19:25:15 -05:00
return $ . make ( 'div' , { className : 'NB-feed-story-tags' } ,
_ . map ( story . story _tags , function ( tag ) {
var score = feed _tags [ tag ] ;
return $ . make ( 'div' , {
2011-03-09 09:48:24 -05:00
className : 'NB-feed-story-tag ' + ( ! ! score && 'NB-score-' + score || '' )
} , tag ) . data ( 'tag' , tag ) ;
2011-03-04 19:25:15 -05:00
} ) ) ;
2011-03-02 19:59:31 -05:00
} ,
2011-09-27 23:06:49 -07:00
hover _story _feed _titles : function ( ) {
var $story _titles = $ ( '.NB-feed-story-header-info' ) ;
$story _titles . unbind ( 'mouseenter' ) . unbind ( 'mouseleave' ) ;
$story _titles . hover ( function ( ) {
var $this = $ ( this ) ;
var menu _height = $this . hasClass ( 'story' ) ? 150 : 270 ;
if ( $this . offset ( ) . top > $ ( window ) . height ( ) - menu _height ) {
$this . closest ( '.NB-feed-story' ) . addClass ( 'NB-hover-inverse' ) ;
}
} , function ( ) {
$ ( this ) . closest ( '.NB-feed-story' ) . removeClass ( 'NB-hover-inverse' ) ;
} ) ;
} ,
2011-03-17 18:33:59 -04:00
preserve _classifier _color : function ( $story , classifier _type , value , score ) {
2011-03-09 09:48:24 -05:00
var $t ;
2011-03-17 18:33:59 -04:00
$ ( '.NB-feed-story-' + classifier _type , $story ) . each ( function ( ) {
if ( $ ( this ) . data ( classifier _type ) == value ) {
2011-03-09 09:48:24 -05:00
$t = $ ( this ) ;
return false ;
}
} ) ;
$t . removeClass ( 'NB-score-now-1' )
. removeClass ( 'NB-score-now--1' )
. removeClass ( 'NB-score-now-0' )
. addClass ( 'NB-score-now-' + score )
. one ( 'mouseleave' , function ( ) {
$t . removeClass ( 'NB-score-now-' + score ) ;
} ) ;
_ . defer ( function ( ) {
$t . one ( 'mouseenter' , function ( ) {
$t . removeClass ( 'NB-score-now-' + score ) ;
} ) ;
} ) ;
} ,
2011-03-17 18:33:59 -04:00
save _classifier : function ( type , value , score , feed _id , callback ) {
2011-03-09 09:48:24 -05:00
var data = {
'feed_id' : feed _id
} ;
if ( score == 0 ) {
data [ 'remove_like_' + type ] = value ;
} else if ( score == 1 ) {
data [ 'like_' + type ] = value ;
} else if ( score == - 1 ) {
data [ 'dislike_' + type ] = value ;
}
2011-10-24 08:55:28 -07:00
this . model . classifiers [ feed _id ] [ type + 's' ] [ value ] = score ;
2011-04-24 01:52:44 -04:00
this . model . save _classifier ( data , _ . bind ( function ( resp ) {
2011-03-17 20:06:38 -04:00
this . force _feeds _refresh ( callback , true , feed _id ) ;
2011-03-09 09:48:24 -05:00
} , this ) ) ;
this . recalculate _story _scores ( feed _id ) ;
2011-03-02 19:59:31 -05:00
} ,
2011-01-19 08:54:59 -05:00
show _correct _feed _in _feed _title _floater : function ( story ) {
2011-01-25 22:59:38 -05:00
var $story , $header ;
2011-01-30 23:00:22 -05:00
if ( story && this . cache . feed _title _floater _feed _id != story . story _feed _id ) {
2011-01-25 22:59:38 -05:00
var $feed _floater = this . $s . $feed _floater ;
2011-11-15 18:37:42 -08:00
$story = this . find _story _in _feed _view ( story . id ) ;
2011-01-25 22:59:38 -05:00
$header = $ ( '.NB-feed-story-header-feed' , $story ) ;
var $new _header = $header . clone ( ) ;
if ( ! $new _header . find ( '.NB-feed-story-feed' ) . length ) {
var feed = this . model . get _feed ( story . story _feed _id ) ;
feed && $new _header . append ( $ . make ( 'div' , { className : 'NB-feed-story-feed' } , [
2011-02-17 10:32:47 -05:00
$ . make ( 'img' , { className : 'feed_favicon' , src : $ . favicon ( feed . favicon ) } ) ,
2011-01-25 22:59:38 -05:00
$ . make ( 'span' , { className : 'feed_title' } , feed . feed _title )
] ) ) ;
}
$feed _floater . empty ( ) . append ( $new _header ) ;
this . cache . feed _title _floater _feed _id = story . story _feed _id ;
2011-01-26 20:51:29 -05:00
$feed _floater . width ( $header . outerWidth ( ) ) ;
2011-01-30 23:00:22 -05:00
} else if ( ! story ) {
this . $s . $feed _floater . empty ( ) ;
this . cache . feed _title _floater _feed _id = null ;
2011-01-25 22:59:38 -05:00
}
2011-01-30 23:00:22 -05:00
if ( story && this . cache . feed _title _floater _story _id != story . id ) {
2011-11-15 18:37:42 -08:00
$story = $story || this . find _story _in _feed _view ( story . id ) ;
2011-01-25 22:59:38 -05:00
$header = $header || $ ( '.NB-feed-story-header-feed' , $story ) ;
$ ( '.NB-floater' ) . removeClass ( 'NB-floater' ) ;
$header . addClass ( 'NB-floater' ) ;
this . cache . feed _title _floater _story _id = story . id ;
2011-01-30 23:00:22 -05:00
} else if ( ! story ) {
this . cache . feed _title _floater _story _id = null ;
2011-01-25 22:59:38 -05:00
}
2011-01-19 08:54:59 -05:00
} ,
2010-11-25 15:34:06 -05:00
apply _story _styling : function ( reset _stories ) {
var $body = this . $s . $body ;
$body . removeClass ( 'NB-theme-sans-serif' ) ;
$body . removeClass ( 'NB-theme-serif' ) ;
if ( NEWSBLUR . Preferences [ 'story_styling' ] == 'sans-serif' ) {
$body . addClass ( 'NB-theme-sans-serif' ) ;
} else if ( NEWSBLUR . Preferences [ 'story_styling' ] == 'serif' ) {
$body . addClass ( 'NB-theme-serif' ) ;
}
if ( reset _stories ) {
2010-12-08 20:53:45 -05:00
this . show _story _titles _above _intelligence _level ( { 'animate' : true , 'follow' : true } ) ;
2010-11-25 15:34:06 -05:00
}
2010-06-08 11:19:41 -04:00
} ,
2011-04-11 23:25:44 -04:00
hide _story _changes : function ( $story ) {
2011-04-12 09:09:29 -04:00
var $button = $ ( '.NB-feed-story-hide-changes' , $story ) ;
2011-04-13 23:06:16 -04:00
if ( this . model . preference ( 'hide_story_changes' ) ) {
$ ( 'ins' , $story ) . css ( { 'text-decoration' : 'underline' } ) ;
$ ( 'del' , $story ) . css ( { 'display' : 'inline' } ) ;
} else {
$ ( 'ins' , $story ) . css ( { 'text-decoration' : 'none' } ) ;
$ ( 'del' , $story ) . css ( { 'display' : 'none' } ) ;
}
2011-04-12 09:09:29 -04:00
$button . css ( 'opacity' , 1 ) . fadeOut ( 400 ) ;
$button . tipsy ( 'hide' ) . tipsy ( 'disable' ) ;
2011-04-11 23:25:44 -04:00
} ,
2010-11-04 21:49:13 -04:00
prefetch _story _locations _in _feed _view : function ( ) {
2010-06-08 11:19:41 -04:00
var self = this ;
var stories = this . model . stories ;
2010-12-08 20:53:45 -05:00
// NEWSBLUR.log(['Prefetching', this.flags['feed_view_positions_calculated'], this.flags.feed_view_images_loaded, (_.keys(this.flags.feed_view_images_loaded).length > 0 || this.cache.feed_view_story_positions_keys.length > 0)]);
2010-11-04 21:49:13 -04:00
if ( ! this . flags [ 'feed_view_positions_calculated' ] ) {
2010-06-08 11:19:41 -04:00
$ . extend ( this . cache , {
2010-06-14 13:17:38 -04:00
'feed_view_story_positions' : { } ,
'feed_view_story_positions_keys' : [ ]
2010-06-08 11:19:41 -04:00
} ) ;
2010-11-04 21:49:13 -04:00
for ( var s in stories ) {
var story = stories [ s ] ;
var $story = self . cache . feed _view _stories [ story . id ] ;
this . determine _feed _view _story _position ( $story , story ) ;
// NEWSBLUR.log(['Pre-fetching', $story, story.story_title, this.flags.feed_view_images_loaded[story.id]]);
if ( ! $story || ! $story . length || this . flags [ 'feed_view_positions_calculated' ] ) break ;
2010-06-14 13:17:38 -04:00
}
2010-06-08 11:19:41 -04:00
}
2010-11-15 22:43:01 -05:00
if ( _ . all ( this . flags . feed _view _images _loaded ) &&
2010-12-08 20:53:45 -05:00
( _ . keys ( this . flags . feed _view _images _loaded ) . length > 0 ||
this . cache . feed _view _story _positions _keys . length > 0 ) ) {
2010-11-04 21:49:13 -04:00
this . fetch _story _locations _in _feed _view ( ) ;
2010-12-12 23:22:53 -05:00
} else {
// NEWSBLUR.log(['Still loading feed view...', _.keys(this.flags.feed_view_images_loaded).length, this.cache.feed_view_story_positions_keys.length, this.flags.feed_view_images_loaded]);
2010-11-04 21:49:13 -04:00
}
if ( ! this . flags [ 'feed_view_positions_calculated' ] ) {
setTimeout ( function ( ) {
if ( ! self . flags [ 'feed_view_positions_calculated' ] ) {
self . prefetch _story _locations _in _feed _view ( ) ;
}
} , 2000 ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2010-11-04 21:49:13 -04:00
fetch _story _locations _in _feed _view : function ( ) {
2011-01-29 19:16:40 -05:00
var stories = this . model . stories ;
if ( ! stories || ! stories . length ) return ;
2011-07-24 23:00:05 -07:00
$ . extend ( this . cache , {
'feed_view_story_positions' : { } ,
'feed_view_story_positions_keys' : [ ]
} ) ;
2011-01-29 19:16:40 -05:00
for ( var s in stories ) {
var story = stories [ s ] ;
var $story = this . cache . feed _view _stories [ story . id ] ;
this . determine _feed _view _story _position ( $story , story ) ;
}
this . flags [ 'feed_view_positions_calculated' ] = true ;
NEWSBLUR . log ( [ 'Feed view entirely loaded' , this . model . stories . length + " stories" ] ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-06-14 13:17:38 -04:00
determine _feed _view _story _position : function ( $story , story ) {
2010-08-30 22:42:44 -04:00
if ( $story && $story . is ( ':visible' ) ) {
2011-10-19 23:04:45 -07:00
var position _original = parseInt ( $story . position ( ) . top , 10 ) ;
2010-06-14 13:17:38 -04:00
var position _offset = parseInt ( $story . offsetParent ( ) . scrollTop ( ) , 10 ) ;
var position = position _original + position _offset ;
this . cache . feed _view _story _positions [ position ] = story ;
this . cache . feed _view _story _positions _keys . push ( position ) ;
2010-11-04 21:49:13 -04:00
this . cache . feed _view _story _positions _keys . sort ( function ( a , b ) { return a - b ; } ) ;
2010-06-14 13:17:38 -04:00
// NEWSBLUR.log(['Positioning story', position, $story, story, this.cache.feed_view_story_positions_keys]);
}
} ,
2011-02-13 14:49:13 -05:00
append _feed _view _story _endbar : function ( ) {
2011-01-30 23:00:22 -05:00
var $feed _view = this . $s . $feed _view ;
var $stories = this . $s . $feed _stories ;
var $endbar = $ . make ( 'div' , { className : 'NB-feed-story-endbar' } ) ;
$stories . find ( '.NB-feed-story-endbar' ) . remove ( ) ;
$stories . append ( $endbar ) ;
} ,
2011-02-13 14:49:13 -05:00
append _story _titles _endbar : function ( ) {
var $story _titles = this . $s . $story _titles ;
var $end _stories _line = $ . make ( 'div' , {
className : 'NB-story-titles-end-stories-line'
} ) ;
if ( ! ( $ ( '.NB-story-titles-end-stories-line' , $story _titles ) . length ) ) {
$story _titles . append ( $end _stories _line ) ;
}
} ,
2011-02-22 19:45:29 -05:00
append _river _premium _only _notification : function ( ) {
var $story _titles = this . $s . $story _titles ;
var $notice = $ . make ( 'div' , { className : 'NB-feed-story-premium-only' } , [
$ . make ( 'div' , { className : 'NB-feed-story-premium-only-divider' } ) ,
$ . make ( 'div' , { className : 'NB-feed-story-premium-only-text' } , [
'The full River of News is a ' ,
2011-03-13 16:24:49 -04:00
$ . make ( 'a' , { href : '#' , className : 'NB-splash-link' } , 'premium feature' ) ,
2011-02-22 19:45:29 -05:00
'.'
] )
] ) ;
2011-02-22 22:00:32 -05:00
$ ( '.NB-feed-story-premium-only' , $story _titles ) . remove ( ) ;
2011-02-22 19:45:29 -05:00
$story _titles . append ( $notice ) ;
} ,
2010-06-14 13:17:38 -04:00
// ===================
// = Taskbar - Story =
// ===================
2010-12-06 10:41:24 -05:00
switch _taskbar _view : function ( view , skip _save _type ) {
2011-02-04 00:22:58 -05:00
// NEWSBLUR.log(['switch_taskbar_view', view]);
2010-06-14 13:17:38 -04:00
var self = this ;
var $story _pane = this . $s . $story _pane ;
2010-10-28 18:17:14 -04:00
var feed = this . model . get _feed ( this . active _feed ) ;
2010-06-08 11:19:41 -04:00
2010-12-04 21:53:39 -05:00
if ( view == 'page' && feed && feed . has _exception && feed . exception _type == 'page' ) {
2010-10-28 18:17:14 -04:00
this . open _feed _exception _modal ( this . active _feed ) ;
return ;
2011-04-30 23:33:36 -04:00
} else if ( $ ( '.task_button_view.task_view_' + view ) . hasClass ( 'NB-disabled' ) ) {
2010-12-04 21:53:39 -05:00
return ;
}
2010-12-06 10:41:24 -05:00
// NEWSBLUR.log(['$button', $button, this.flags['page_view_showing_feed_view'], $button.hasClass('NB-active'), skip_save_type]);
2010-06-14 13:17:38 -04:00
var $taskbar _buttons = $ ( '.NB-taskbar .task_button_view' ) ;
var $feed _view = this . $s . $feed _view ;
2010-12-06 10:41:24 -05:00
var $feed _iframe = this . $s . $feed _iframe ;
2010-06-14 13:17:38 -04:00
var $page _to _feed _arrow = $ ( '.NB-taskbar .NB-task-view-page-to-feed-arrow' ) ;
2010-12-06 10:41:24 -05:00
var $feed _to _story _arrow = $ ( '.NB-taskbar .NB-task-view-feed-to-story-arrow' ) ;
2010-06-08 11:19:41 -04:00
2010-12-06 10:41:24 -05:00
if ( ! skip _save _type && this . story _view != view ) {
2010-07-06 14:57:32 -04:00
this . model . view _setting ( this . active _feed , view ) ;
}
2010-12-06 10:41:24 -05:00
$page _to _feed _arrow . hide ( ) ;
$feed _to _story _arrow . hide ( ) ;
this . flags [ 'page_view_showing_feed_view' ] = false ;
if ( skip _save _type == 'page' ) {
2010-06-14 13:17:38 -04:00
$page _to _feed _arrow . show ( ) ;
this . flags [ 'page_view_showing_feed_view' ] = true ;
2010-12-06 10:41:24 -05:00
} else if ( skip _save _type == 'story' ) {
$feed _to _story _arrow . show ( ) ;
2010-12-07 09:52:14 -05:00
this . flags [ 'feed_view_showing_story_view' ] = true ;
2010-06-14 13:17:38 -04:00
} else {
$taskbar _buttons . removeClass ( 'NB-active' ) ;
$ ( '.task_button_view.task_view_' + view ) . addClass ( 'NB-active' ) ;
this . story _view = view ;
2010-06-08 11:19:41 -04:00
}
2010-12-14 18:48:52 -05:00
// this.flags.scrolling_by_selecting_story_title = true;
// clearInterval(this.locks.scrolling);
2010-12-13 21:53:22 -05:00
// this.locks.scrolling = setTimeout(function() {
2010-12-14 18:48:52 -05:00
// self.flags.scrolling_by_selecting_story_title = false;
// }, 1000);
2010-06-14 13:17:38 -04:00
if ( view == 'page' ) {
2010-07-06 18:30:16 -04:00
if ( this . flags [ 'iframe_prevented_from_loading' ] ) {
2010-12-06 10:41:24 -05:00
this . load _feed _iframe ( this . active _feed ) ;
2010-07-06 18:30:16 -04:00
}
2010-12-06 10:41:24 -05:00
var $iframe _story = this . find _story _in _feed _iframe ( this . active _story ) ;
2010-06-14 13:17:38 -04:00
this . scroll _to _story _in _iframe ( this . active _story , $iframe _story , true ) ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
$story _pane . animate ( {
'left' : 0
} , {
'easing' : 'easeInOutQuint' ,
2011-06-07 12:57:34 -04:00
'duration' : this . model . preference ( 'animations' ) ? 550 : 0 ,
2010-06-14 13:17:38 -04:00
'queue' : false
} ) ;
} else if ( view == 'feed' ) {
if ( this . active _story ) {
2011-11-15 18:37:42 -08:00
var $feed _story = this . find _story _in _feed _view ( this . active _story . id ) ;
2010-06-14 13:17:38 -04:00
this . scroll _to _story _in _story _feed ( this . active _story , $feed _story , true ) ;
2010-06-08 11:19:41 -04:00
}
2010-06-14 13:17:38 -04:00
$story _pane . animate ( {
2010-12-06 10:41:24 -05:00
'left' : - 1 * $feed _iframe . width ( )
2010-06-14 13:17:38 -04:00
} , {
'easing' : 'easeInOutQuint' ,
2011-06-07 12:57:34 -04:00
'duration' : this . model . preference ( 'animations' ) ? 550 : 0 ,
2010-06-14 13:17:38 -04:00
'queue' : false
} ) ;
this . flags [ 'switching_to_feed_view' ] = true ;
setTimeout ( function ( ) {
self . flags [ 'switching_to_feed_view' ] = false ;
} , 100 ) ;
2010-12-08 20:53:45 -05:00
this . show _stories _preference _in _feed _view ( ) ;
if ( ! this . flags [ 'feed_view_positions_calculated' ] ) {
this . prefetch _story _locations _in _feed _view ( ) ;
2010-06-08 11:19:41 -04:00
}
2010-06-14 13:17:38 -04:00
} else if ( view == 'story' ) {
$story _pane . animate ( {
2010-12-07 09:52:14 -05:00
'left' : - 2 * $feed _iframe . width ( )
2010-06-14 13:17:38 -04:00
} , {
'easing' : 'easeInOutQuint' ,
2011-06-07 12:57:34 -04:00
'duration' : this . model . preference ( 'animations' ) ? 550 : 0 ,
2010-06-14 13:17:38 -04:00
'queue' : false
2010-06-08 11:19:41 -04:00
} ) ;
2010-12-08 20:53:45 -05:00
this . load _story _iframe ( ) ;
2011-02-09 19:24:35 -05:00
if ( ! this . active _story ) {
this . show _next _story ( 1 ) ;
}
2010-06-08 11:19:41 -04:00
}
2010-07-06 14:57:32 -04:00
2010-06-14 13:17:38 -04:00
} ,
switch _taskbar _view _direction : function ( direction ) {
var $active = $ ( '.taskbar_nav_view .NB-active' ) ;
var view ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
if ( direction == - 1 ) {
if ( $active . hasClass ( 'task_view_page' ) ) {
// view = 'page';
} else if ( $active . hasClass ( 'task_view_feed' ) ) {
view = 'page' ;
} else if ( $active . hasClass ( 'task_view_story' ) ) {
view = 'feed' ;
}
} else if ( direction == 1 ) {
if ( $active . hasClass ( 'task_view_page' ) ) {
view = 'feed' ;
} else if ( $active . hasClass ( 'task_view_feed' ) ) {
view = 'story' ;
} else if ( $active . hasClass ( 'task_view_story' ) ) {
// view = 'story';
}
2010-06-08 11:19:41 -04:00
}
2010-06-14 13:17:38 -04:00
if ( view ) {
this . switch _taskbar _view ( view ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2010-12-08 20:53:45 -05:00
show _stories _preference _in _feed _view : function ( is _creating ) {
2010-06-14 13:17:38 -04:00
var $feed _view = this . $s . $feed _view ;
var $feed _view _stories = $ ( ".NB-feed-story" , $feed _view ) ;
2011-01-24 23:50:38 -05:00
var $stories = this . $s . $feed _stories ;
2010-06-14 13:17:38 -04:00
var story = this . active _story ;
2010-06-08 11:19:41 -04:00
2010-12-08 20:53:45 -05:00
if ( story && this . model . preference ( 'feed_view_single_story' ) ) {
2010-12-09 09:59:45 -05:00
// NEWSBLUR.log(['show_stories_preference_in_feed_view', is_creating, this.model.preference('feed_view_single_story'), $feed_view_stories.length + " stories"]);
2010-06-14 13:17:38 -04:00
$stories . removeClass ( 'NB-feed-view-feed' ) . addClass ( 'NB-feed-view-story' ) ;
$feed _view _stories . css ( { 'display' : 'none' } ) ;
2011-05-03 12:19:53 -04:00
if ( is _creating ) this . $s . $feed _stories . scrollTop ( '0px' ) ;
2010-12-08 20:53:45 -05:00
var $current _story = this . get _current _story _from _story _titles ( $feed _view _stories ) ;
2010-06-14 13:17:38 -04:00
if ( $current _story && $current _story . length ) {
$current _story . css ( { 'display' : 'block' } ) ;
2010-06-08 11:19:41 -04:00
}
2010-12-08 20:53:45 -05:00
this . flags [ 'feed_view_positions_calculated' ] = false ;
} else {
$stories . removeClass ( 'NB-feed-view-story' ) . addClass ( 'NB-feed-view-feed' ) ;
if ( ! is _creating ) {
this . show _story _titles _above _intelligence _level ( { 'animate' : false } ) ;
2010-06-08 11:19:41 -04:00
}
}
2011-10-19 18:42:49 -07:00
this . cache . story _pane _position = null ;
2010-06-08 11:19:41 -04:00
} ,
2010-12-06 10:41:24 -05:00
// ==============
// = Story View =
// ==============
2010-12-07 09:52:14 -05:00
open _story _in _story _view : function ( story , is _temporary ) {
2010-12-07 20:04:37 -05:00
if ( ! story ) story = this . active _story ;
2010-12-07 09:52:14 -05:00
this . switch _taskbar _view ( 'story' , is _temporary ? 'story' : false ) ;
this . load _story _iframe ( story , story . story _feed _id ) ;
2010-12-06 10:41:24 -05:00
} ,
load _story _iframe : function ( story , feed _id ) {
2010-12-08 20:53:45 -05:00
story = story || this . active _story ;
if ( ! story ) return ;
2010-12-06 10:41:24 -05:00
feed _id = feed _id || this . active _feed ;
var self = this ;
var $story _iframe = this . $s . $story _iframe ;
2010-12-08 20:53:45 -05:00
if ( $story _iframe . attr ( 'src' ) != story . story _permalink ) {
// NEWSBLUR.log(['load_story_iframe', story.story_permalink, $story_iframe.attr('src')]);
this . unload _story _iframe ( ) ;
2010-12-06 10:41:24 -05:00
2010-12-08 20:53:45 -05:00
if ( ! feed _id ) {
feed _id = $story _iframe . data ( 'feed_id' ) ;
} else {
$story _iframe . data ( 'feed_id' , feed _id ) ;
}
2010-12-06 10:41:24 -05:00
2010-12-08 20:53:45 -05:00
this . flags . iframe _scroll _snap _back _prepared = true ;
this . iframe _link _attacher _num _links = 0 ;
$story _iframe . removeAttr ( 'src' ) . attr ( { src : story . story _permalink } ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2010-12-07 09:52:14 -05:00
unload _story _iframe : function ( ) {
var $story _iframe = this . $s . $story _iframe ;
2011-09-30 18:02:48 -07:00
$story _iframe . empty ( ) ;
2010-12-08 20:53:45 -05:00
$story _iframe . removeAttr ( 'src' ) . attr ( { src : 'about:blank' } ) ;
2010-12-07 09:52:14 -05:00
} ,
2010-06-14 13:17:38 -04:00
// ===================
// = Taskbar - Feeds =
// ===================
2011-02-01 03:35:11 +01:00
open _add _feed _modal : function ( options ) {
2010-06-14 13:17:38 -04:00
clearInterval ( this . flags [ 'bouncing_callout' ] ) ;
2010-08-30 19:57:27 -04:00
$ . modal . close ( ) ;
2010-06-08 11:19:41 -04:00
2011-02-01 03:35:11 +01:00
NEWSBLUR . add _feed = new NEWSBLUR . ReaderAddFeed ( options ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-09-12 13:50:27 -04:00
open _manage _feed _modal : function ( feed _id ) {
feed _id = feed _id || this . active _feed ;
2010-06-08 11:19:41 -04:00
2010-07-25 23:13:27 -04:00
NEWSBLUR . manage _feed = new NEWSBLUR . ReaderManageFeed ( feed _id ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-10-10 23:36:09 -04:00
2010-06-14 13:17:38 -04:00
open _mark _read _modal : function ( ) {
NEWSBLUR . mark _read = new NEWSBLUR . ReaderMarkRead ( ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-10-10 23:36:09 -04:00
open _keyboard _shortcuts _modal : function ( ) {
NEWSBLUR . keyboard = new NEWSBLUR . ReaderKeyboard ( ) ;
} ,
2010-08-18 20:35:45 -04:00
2011-01-20 09:57:23 -05:00
open _goodies _modal : function ( ) {
NEWSBLUR . goodies = new NEWSBLUR . ReaderGoodies ( ) ;
} ,
2010-06-14 13:17:38 -04:00
open _preferences _modal : function ( ) {
2010-07-25 23:13:27 -04:00
NEWSBLUR . preferences = new NEWSBLUR . ReaderPreferences ( ) ;
} ,
2011-07-27 09:33:34 -07:00
2011-09-21 17:49:26 -07:00
open _account _modal : function ( options ) {
NEWSBLUR . account = new NEWSBLUR . ReaderAccount ( options ) ;
2011-07-27 09:33:34 -07:00
} ,
2010-07-25 23:13:27 -04:00
2010-09-24 01:08:03 -04:00
open _feedchooser _modal : function ( ) {
NEWSBLUR . feedchooser = new NEWSBLUR . ReaderFeedchooser ( ) ;
} ,
2010-08-18 20:35:45 -04:00
open _feed _exception _modal : function ( feed _id ) {
NEWSBLUR . feed _exception = new NEWSBLUR . ReaderFeedException ( feed _id ) ;
} ,
2010-09-12 13:50:27 -04:00
open _feed _statistics _modal : function ( feed _id ) {
feed _id = feed _id || this . active _feed ;
2010-06-08 11:19:41 -04:00
2010-07-25 23:13:27 -04:00
NEWSBLUR . statistics = new NEWSBLUR . ReaderStatistics ( feed _id ) ;
2010-06-08 11:19:41 -04:00
} ,
2011-02-22 19:11:29 -05:00
close _sidebar : function ( ) {
this . $s . $body . layout ( ) . close ( 'west' ) ;
this . resize _window ( ) ;
2011-02-23 18:09:09 -05:00
this . flags [ 'sidebar_closed' ] = true ;
2011-02-22 19:11:29 -05:00
$ ( '.NB-taskbar-sidebar-toggle-open' ) . stop ( ) . animate ( {
'left' : - 1
} , {
'duration' : 1000 ,
'easing' : 'easeOutQuint' ,
'queue' : false
} ) ;
} ,
open _sidebar : function ( ) {
this . $s . $body . layout ( ) . open ( 'west' ) ;
this . resize _window ( ) ;
2011-02-23 18:09:09 -05:00
this . flags [ 'sidebar_closed' ] = false ;
2011-02-22 19:11:29 -05:00
$ ( '.NB-taskbar-sidebar-toggle-open' ) . stop ( ) . css ( {
'left' : - 24
} ) ;
} ,
2010-12-11 17:16:12 -05:00
// =======================
// = Sidebar Manage Menu =
// =======================
2010-10-10 20:14:31 -04:00
2010-12-30 18:37:29 -05:00
make _manage _menu : function ( type , feed _id , story _id , inverse , $item ) {
2010-09-12 13:50:27 -04:00
var $manage _menu ;
2010-07-24 00:04:14 -04:00
2010-09-12 13:50:27 -04:00
if ( type == 'site' ) {
2010-10-05 19:05:01 -04:00
var show _chooser = ! NEWSBLUR . Globals . is _premium && NEWSBLUR . Globals . is _authenticated ;
2010-09-12 13:50:27 -04:00
$manage _menu = $ . make ( 'ul' , { className : 'NB-menu-manage' } , [
$ . make ( 'li' , { className : 'NB-menu-manage-site-info' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
2010-09-22 10:12:38 -04:00
$ . make ( 'span' , { className : 'NB-menu-manage-title' } , "Manage NewsBlur" )
2010-09-12 13:50:27 -04:00
] ) . corner ( 'tl tr 8px' ) ,
2010-10-10 23:36:09 -04:00
$ . make ( 'li' , { className : 'NB-menu-separator' } ) ,
2011-07-27 09:33:34 -07:00
$ . make ( 'li' , { className : 'NB-menu-manage-account' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'My Account' )
] ) ,
2011-07-27 22:17:34 -07:00
$ . make ( 'li' , { className : 'NB-menu-manage-preferences' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Preferences' )
] ) ,
$ . make ( 'li' , { className : 'NB-menu-separator' } ) ,
2010-10-10 23:36:09 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-keyboard' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Keyboard shortcuts' )
] ) ,
2011-05-09 20:59:52 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-tutorial' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Tutorial' )
] ) ,
2010-10-10 23:36:09 -04:00
$ . make ( 'li' , { className : 'NB-menu-separator' } ) ,
2010-09-14 20:49:28 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-mark-read NB-menu-manage-site-mark-read' } , [
2010-07-30 23:50:49 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
2010-09-13 00:38:25 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Mark everything as read' ) ,
2010-09-12 13:50:27 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-subtitle' } , 'Choose how many days back.' )
] ) ,
$ . make ( 'li' , { className : 'NB-menu-manage-trainer' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Intelligence Trainer' ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-subtitle' } , 'Accurate filters are happy filters.' )
] ) ,
2011-01-20 09:57:23 -05:00
$ . make ( 'li' , { className : 'NB-menu-manage-goodies' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Goodies' ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-subtitle' } , 'Extensions and extras.' )
] ) ,
2011-12-22 13:36:03 -08:00
$ . make ( 'li' , { className : 'NB-menu-manage-friends' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Friends' ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-subtitle' } , 'Find friends to follow.' )
] ) ,
2010-09-24 01:08:03 -04:00
( show _chooser && $ . make ( 'li' , { className : 'NB-menu-manage-feedchooser' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
2011-12-22 13:36:03 -08:00
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Choose Your 64 sites' ) ,
2010-09-24 01:08:03 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-subtitle' } , 'Enable the sites you want.' )
] ) )
2010-09-12 13:50:27 -04:00
] ) ;
$manage _menu . addClass ( 'NB-menu-manage-notop' ) ;
} else if ( type == 'feed' ) {
2010-09-13 00:38:25 -04:00
var feed = this . model . get _feed ( feed _id ) ;
2010-12-31 14:35:00 -05:00
if ( ! feed ) return ;
2011-01-31 20:08:07 -05:00
var unread _count = this . get _unread _count ( true , feed _id ) ;
var tab _unread _count = Math . min ( 25 , unread _count ) ;
2010-09-12 13:50:27 -04:00
$manage _menu = $ . make ( 'ul' , { className : 'NB-menu-manage' } , [
2010-09-13 00:38:25 -04:00
$ . make ( 'li' , { className : 'NB-menu-separator-inverse' } ) ,
( feed . has _exception && $ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-feed-exception' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Fix this misbehaving site' )
] ) ) ,
( feed . has _exception && $ . make ( 'li' , { className : 'NB-menu-separator-inverse' } ) ) ,
2010-10-28 18:17:14 -04:00
( feed . exception _type != 'feed' && $ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-mark-read NB-menu-manage-feed-mark-read' } , [
2010-09-12 13:50:27 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Mark as read' )
2010-09-13 00:38:25 -04:00
] ) ) ,
2010-10-10 20:14:31 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-feed-reload' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Insta-fetch stories' )
] ) ,
2010-09-12 13:50:27 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-feed-stats' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Statistics' )
2010-07-30 23:50:49 -04:00
] ) ,
2011-09-26 09:22:46 -07:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-feed-settings' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
2011-11-12 18:19:57 -08:00
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Site settings' )
2011-09-26 09:22:46 -07:00
] ) ,
2010-09-12 13:50:27 -04:00
$ . make ( 'li' , { className : 'NB-menu-separator' } ) ,
2010-07-24 00:04:14 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-feed-train' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
2010-12-30 18:37:29 -05:00
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Intelligence trainer' ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-subtitle' } , 'What you like and dislike.' )
2010-07-24 00:04:14 -04:00
] ) ,
2011-03-28 10:08:10 -04:00
$ . make ( 'li' , { className : 'NB-menu-separator' } ) ,
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-feed-recommend' } , [
2010-12-31 10:34:31 -05:00
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
2011-03-28 10:08:10 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Recommend this site' )
] ) ,
2010-09-12 13:50:27 -04:00
$ . make ( 'li' , { className : 'NB-menu-separator' } ) ,
2011-09-04 15:42:13 -07:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-move NB-menu-manage-feed-move' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Move to folder' )
] ) ,
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-confirm NB-menu-manage-feed-move-confirm NB-modal-submit' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-confirm-position' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-move-save NB-menu-manage-feed-move-save NB-modal-submit-green NB-modal-submit-button' } , 'Save' ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-add-folders' } , NEWSBLUR . utils . make _folders ( this . model ) )
] )
] ) ,
2010-12-11 11:26:21 -05:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-rename NB-menu-manage-feed-rename' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Rename this site' )
] ) ,
2011-09-04 15:42:13 -07:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-confirm NB-menu-manage-feed-rename-confirm NB-modal-submit' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-confirm-position' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-rename-save NB-menu-manage-feed-rename-save NB-modal-submit-green NB-modal-submit-button' } , 'Save' ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'input' , { name : 'new_title' , className : 'NB-menu-manage-title' , value : feed . feed _title } )
] )
2010-12-11 11:26:21 -05:00
] ) ,
2010-09-14 20:49:28 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-delete NB-menu-manage-feed-delete' } , [
2010-07-21 23:22:27 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
2010-09-12 13:50:27 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Delete this site' )
2010-07-21 23:22:27 -04:00
] ) ,
2010-09-14 20:49:28 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-delete-confirm NB-menu-manage-feed-delete-confirm' } , [
2010-07-24 00:04:14 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
2010-09-12 13:50:27 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Really delete?' )
2010-07-21 23:22:27 -04:00
] )
2010-09-12 13:50:27 -04:00
] ) ;
$manage _menu . data ( 'feed_id' , feed _id ) ;
2010-09-14 20:49:28 -04:00
$manage _menu . data ( '$feed' , $item ) ;
2011-01-31 20:08:07 -05:00
if ( feed _id && unread _count == 0 ) {
2010-09-12 13:50:27 -04:00
$ ( '.NB-menu-manage-feed-mark-read' , $manage _menu ) . addClass ( 'NB-disabled' ) ;
2010-12-14 17:08:52 -05:00
$ ( '.NB-menu-manage-feed-unreadtabs' , $manage _menu ) . addClass ( 'NB-disabled' ) ;
2010-06-14 13:17:38 -04:00
}
2010-09-12 13:50:27 -04:00
} else if ( type == 'folder' ) {
$manage _menu = $ . make ( 'ul' , { className : 'NB-menu-manage' } , [
2010-09-13 17:32:41 -04:00
$ . make ( 'li' , { className : 'NB-menu-separator-inverse' } ) ,
2010-09-14 20:49:28 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-mark-read NB-menu-manage-folder-mark-read' } , [
2010-09-12 13:50:27 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Mark folder as read' )
] ) ,
2010-09-22 10:12:38 -04:00
$ . make ( 'li' , { className : 'NB-menu-separator' } ) ,
2011-09-04 15:42:13 -07:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-move NB-menu-manage-folder-move' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Move to folder' )
] ) ,
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-confirm NB-menu-manage-folder-move-confirm NB-modal-submit' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-confirm-position' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-move-save NB-menu-manage-folder-move-save NB-modal-submit-green NB-modal-submit-button' } , 'Save' ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-add-folders' } , NEWSBLUR . utils . make _folders ( this . model ) )
] )
] ) ,
2010-12-11 12:41:24 -05:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-rename NB-menu-manage-folder-rename' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Rename this folder' )
] ) ,
2011-09-04 15:42:13 -07:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-confirm NB-menu-manage-folder-rename-confirm NB-modal-submit' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-confirm-position' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-rename-save NB-menu-manage-folder-rename-save NB-modal-submit-green NB-modal-submit-button' } , 'Save' ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'input' , { name : 'new_title' , className : 'NB-menu-manage-title' , value : feed _id } )
] )
2010-12-11 12:41:24 -05:00
] ) ,
2010-09-22 10:12:38 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-delete NB-menu-manage-folder-delete' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Delete this folder' )
] ) ,
2010-09-14 20:49:28 -04:00
$ . make ( 'li' , { className : 'NB-menu-manage-feed NB-menu-manage-delete-confirm NB-menu-manage-folder-delete-confirm' } , [
2010-09-12 13:50:27 -04:00
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Really delete?' )
2010-09-13 17:32:41 -04:00
] )
2010-09-12 13:50:27 -04:00
] ) ;
2010-09-14 20:49:28 -04:00
$manage _menu . data ( 'folder_name' , feed _id ) ;
$manage _menu . data ( '$folder' , $item ) ;
2010-12-30 18:37:29 -05:00
} else if ( type == 'story' ) {
var feed = this . model . get _feed ( feed _id ) ;
var story = this . model . get _story ( story _id ) ;
var starred _class = story . starred ? 'NB-story-starred' : '' ;
var starred _title = story . starred ? 'Remove bookmark' : 'Save This Story' ;
$manage _menu = $ . make ( 'ul' , { className : 'NB-menu-manage NB-menu-manage-story ' + starred _class } , [
2011-02-23 11:40:25 -05:00
$ . make ( 'li' , { className : 'NB-menu-separator' } ) ,
$ . make ( 'li' , { className : 'NB-menu-manage-story-open' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Open' )
] ) ,
2010-12-31 10:34:31 -05:00
$ . make ( 'li' , { className : 'NB-menu-separator' } ) ,
2010-12-30 18:37:29 -05:00
$ . make ( 'li' , { className : 'NB-menu-manage-story-star' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , starred _title )
] ) ,
2011-11-08 13:48:54 -08:00
( story . read _status && $ . make ( 'li' , { className : 'NB-menu-manage-story-unread' } , [
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Mark as unread' )
] ) ) ,
2011-02-04 00:22:58 -05:00
$ . make ( 'li' , { className : 'NB-menu-manage-story-thirdparty' } , [
2011-02-16 20:45:37 -05:00
( NEWSBLUR . Preferences [ 'story_share_facebook' ] && $ . make ( 'div' , { className : 'NB-menu-manage-thirdparty-icon NB-menu-manage-thirdparty-facebook' } ) . bind ( 'mouseenter' , _ . bind ( function ( e ) {
2011-11-09 18:38:00 -08:00
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Facebook' ) . parent ( ) . addClass ( 'NB-menu-manage-highlight-facebook' ) ;
2011-02-04 00:22:58 -05:00
} , this ) ) . bind ( 'mouseleave' , _ . bind ( function ( e ) {
2011-11-09 18:38:00 -08:00
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Email story' ) . parent ( ) . removeClass ( 'NB-menu-manage-highlight-facebook' ) ;
2011-02-16 20:45:37 -05:00
} , this ) ) ) ,
( NEWSBLUR . Preferences [ 'story_share_twitter' ] && $ . make ( 'div' , { className : 'NB-menu-manage-thirdparty-icon NB-menu-manage-thirdparty-twitter' } ) . bind ( 'mouseenter' , _ . bind ( function ( e ) {
2011-11-09 18:38:00 -08:00
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Twitter' ) . parent ( ) . addClass ( 'NB-menu-manage-highlight-twitter' ) ;
2011-02-04 00:22:58 -05:00
} , this ) ) . bind ( 'mouseleave' , _ . bind ( function ( e ) {
2011-11-09 18:38:00 -08:00
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Email story' ) . parent ( ) . removeClass ( 'NB-menu-manage-highlight-twitter' ) ;
2011-02-16 20:45:37 -05:00
} , this ) ) ) ,
( NEWSBLUR . Preferences [ 'story_share_readitlater' ] && $ . make ( 'div' , { className : 'NB-menu-manage-thirdparty-icon NB-menu-manage-thirdparty-readitlater' } ) . bind ( 'mouseenter' , _ . bind ( function ( e ) {
2011-02-15 21:31:33 -05:00
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Read It Later' ) . parent ( ) . addClass ( 'NB-menu-manage-highlight-readitlater' ) ;
} , this ) ) . bind ( 'mouseleave' , _ . bind ( function ( e ) {
2011-11-09 18:38:00 -08:00
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Email story' ) . parent ( ) . removeClass ( 'NB-menu-manage-highlight-readitlater' ) ;
2011-02-16 20:45:37 -05:00
} , this ) ) ) ,
2011-11-07 18:21:38 -08:00
( NEWSBLUR . Preferences [ 'story_share_pinboard' ] && $ . make ( 'div' , { className : 'NB-menu-manage-thirdparty-icon NB-menu-manage-thirdparty-pinboard' } ) . bind ( 'mouseenter' , _ . bind ( function ( e ) {
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Pinboard' ) . parent ( ) . addClass ( 'NB-menu-manage-highlight-pinboard' ) ;
} , this ) ) . bind ( 'mouseleave' , _ . bind ( function ( e ) {
2011-11-09 18:38:00 -08:00
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Email story' ) . parent ( ) . removeClass ( 'NB-menu-manage-highlight-pinboard' ) ;
2011-11-07 18:21:38 -08:00
} , this ) ) ) ,
( NEWSBLUR . Preferences [ 'story_share_googleplus' ] && $ . make ( 'div' , { className : 'NB-menu-manage-thirdparty-icon NB-menu-manage-thirdparty-googleplus' } ) . bind ( 'mouseenter' , _ . bind ( function ( e ) {
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Google+' ) . parent ( ) . addClass ( 'NB-menu-manage-highlight-googleplus' ) ;
} , this ) ) . bind ( 'mouseleave' , _ . bind ( function ( e ) {
2011-11-09 18:38:00 -08:00
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Email story' ) . parent ( ) . removeClass ( 'NB-menu-manage-highlight-googleplus' ) ;
2011-11-07 18:21:38 -08:00
} , this ) ) ) ,
2011-11-09 18:38:00 -08:00
( NEWSBLUR . Preferences [ 'story_share_instapaper' ] && $ . make ( 'div' , { className : 'NB-menu-manage-thirdparty-icon NB-menu-manage-thirdparty-instapaper' } ) . bind ( 'mouseenter' , _ . bind ( function ( e ) {
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Instapaper' ) . parent ( ) . addClass ( 'NB-menu-manage-highlight-instapaper' ) ;
2011-05-03 11:40:38 -04:00
} , this ) ) . bind ( 'mouseleave' , _ . bind ( function ( e ) {
2011-11-09 18:38:00 -08:00
$ ( e . target ) . siblings ( '.NB-menu-manage-title' ) . text ( 'Email story' ) . parent ( ) . removeClass ( 'NB-menu-manage-highlight-instapaper' ) ;
2011-05-03 11:40:38 -04:00
} , this ) ) ) ,
2011-02-23 11:40:25 -05:00
// (NEWSBLUR.Preferences['story_share_readability'] && $.make('div', { className: 'NB-menu-manage-thirdparty-icon NB-menu-manage-thirdparty-readability'}).bind('mouseenter', _.bind(function(e) {
2011-11-09 18:38:00 -08:00
// $(e.target).siblings('.NB-menu-manage-title').text('Readability').parent().addClass('NB-menu-manage-highlight-readability');
2011-02-23 11:40:25 -05:00
// }, this)).bind('mouseleave', _.bind(function(e) {
2011-11-09 18:38:00 -08:00
// $(e.target).siblings('.NB-menu-manage-title').text('Email story').parent().removeClass('NB-menu-manage-highlight-readability');
2011-02-23 11:40:25 -05:00
// }, this))),
2011-01-07 16:36:46 -05:00
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
2011-11-09 18:38:00 -08:00
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Email story' )
2011-01-07 16:36:46 -05:00
] ) . bind ( 'click' , _ . bind ( function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2011-02-04 00:22:58 -05:00
var $target = $ ( e . target ) ;
if ( $target . hasClass ( 'NB-menu-manage-thirdparty-facebook' ) ) {
this . send _story _to _facebook ( story . id ) ;
} else if ( $target . hasClass ( 'NB-menu-manage-thirdparty-twitter' ) ) {
this . send _story _to _twitter ( story . id ) ;
2011-02-15 21:31:33 -05:00
} else if ( $target . hasClass ( 'NB-menu-manage-thirdparty-readitlater' ) ) {
this . send _story _to _readitlater ( story . id ) ;
2011-02-16 20:45:37 -05:00
} else if ( $target . hasClass ( 'NB-menu-manage-thirdparty-readability' ) ) {
this . send _story _to _readability ( story . id ) ;
2011-11-07 18:21:38 -08:00
} else if ( $target . hasClass ( 'NB-menu-manage-thirdparty-pinboard' ) ) {
this . send _story _to _pinboard ( story . id ) ;
} else if ( $target . hasClass ( 'NB-menu-manage-thirdparty-googleplus' ) ) {
this . send _story _to _googleplus ( story . id ) ;
2011-11-09 18:38:00 -08:00
} else if ( $target . hasClass ( 'NB-menu-manage-thirdparty-instapaper' ) ) {
2011-02-04 00:22:58 -05:00
this . send _story _to _instapaper ( story . id ) ;
2011-11-09 18:38:00 -08:00
} else {
this . send _story _to _email ( story . id ) ;
2011-02-04 00:22:58 -05:00
}
2011-01-07 16:36:46 -05:00
} , this ) ) ,
2010-12-31 10:34:31 -05:00
$ . make ( 'li' , { className : 'NB-menu-separator' } ) ,
$ . make ( 'li' , { className : 'NB-menu-manage-story-train' } , [
2010-12-30 18:37:29 -05:00
$ . make ( 'div' , { className : 'NB-menu-manage-image' } ) ,
2010-12-31 10:34:31 -05:00
$ . make ( 'div' , { className : 'NB-menu-manage-title' } , 'Intelligence trainer' ) ,
$ . make ( 'div' , { className : 'NB-menu-manage-subtitle' } , 'What you like and dislike.' )
2010-12-31 14:35:00 -05:00
] )
2010-12-30 18:37:29 -05:00
] ) ;
$manage _menu . data ( 'feed_id' , feed _id ) ;
$manage _menu . data ( 'story_id' , story _id ) ;
$manage _menu . data ( '$story' , $item ) ;
2010-06-14 13:17:38 -04:00
}
2010-09-13 00:38:25 -04:00
if ( inverse ) $manage _menu . addClass ( 'NB-inverse' ) ;
2010-06-14 13:17:38 -04:00
return $manage _menu ;
2010-06-08 11:19:41 -04:00
} ,
2011-04-03 10:52:34 -04:00
show _manage _menu : function ( type , $item , options ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2011-04-03 10:52:34 -04:00
var options = _ . extend ( {
'toplevel' : false ,
'inverse' : false
} , options ) ;
2010-06-14 13:17:38 -04:00
var $manage _menu _container = $ ( '.NB-menu-manage-container' ) ;
2010-09-12 13:50:27 -04:00
// NEWSBLUR.log(['show_manage_menu', type, $item, $manage_menu_container.data('item'), $item && $item[0] == $manage_menu_container.data('item')]);
2010-06-14 13:17:38 -04:00
clearTimeout ( this . flags . closed _manage _menu ) ;
2010-06-08 11:19:41 -04:00
2010-09-12 13:50:27 -04:00
// If another menu is open, hide it first.
// If this menu is already open, then hide it instead.
if ( ( $item && $item [ 0 ] == $manage _menu _container . data ( 'item' ) ) &&
parseInt ( $manage _menu _container . css ( 'opacity' ) , 10 ) == 1 ) {
2011-02-08 22:07:59 -05:00
this . hide _manage _menu ( type , $item ) ;
2010-09-12 13:50:27 -04:00
return ;
} else {
2011-02-08 22:07:59 -05:00
this . hide _manage _menu ( type , $item ) ;
2010-06-14 13:17:38 -04:00
}
2011-02-02 08:05:31 -05:00
if ( $item . hasClass ( 'NB-empty' ) ) return ;
2011-02-01 22:58:00 -05:00
2011-02-08 22:07:59 -05:00
$item . addClass ( 'NB-showing-menu' ) ;
2010-09-12 13:50:27 -04:00
// Create menu, size and position it, then attach to the right place.
2010-12-30 18:37:29 -05:00
var feed _id , inverse , story _id ;
2010-09-14 20:49:28 -04:00
if ( type == 'folder' ) {
feed _id = $ ( '.folder_title_text' , $item ) . eq ( 0 ) . text ( ) ;
2011-04-03 10:52:34 -04:00
inverse = options . inverse || $ ( '.folder_title' , $item ) . hasClass ( "NB-hover-inverse" ) ;
2010-12-30 18:37:29 -05:00
} else if ( type == 'feed' ) {
2011-03-30 09:30:45 -04:00
feed _id = $item && parseInt ( $item . attr ( 'data-id' ) , 10 ) ;
2011-04-03 10:52:34 -04:00
inverse = options . inverse || $item . hasClass ( "NB-hover-inverse" ) ;
2010-12-30 18:37:29 -05:00
} else if ( type == 'story' ) {
2011-09-27 23:06:49 -07:00
story _id = $item . data ( 'story_id' ) ;
2011-09-27 22:16:09 -07:00
if ( $item . hasClass ( 'NB-hover-inverse' ) ) inverse = true ;
2010-12-30 18:37:29 -05:00
} else if ( type == 'site' ) {
2011-02-22 19:11:29 -05:00
$ ( '.NB-task-manage' ) . tipsy ( 'hide' ) ;
2011-02-22 19:45:29 -05:00
$ ( '.NB-task-manage' ) . tipsy ( 'disable' ) ;
2010-09-14 20:49:28 -04:00
}
2011-04-03 10:52:34 -04:00
var toplevel = options . toplevel || $item . hasClass ( "NB-toplevel" ) ||
2010-12-30 18:37:29 -05:00
$item . children ( '.folder_title' ) . hasClass ( "NB-toplevel" ) ;
var $manage _menu = this . make _manage _menu ( type , feed _id , story _id , inverse , $item ) ;
2010-06-14 13:17:38 -04:00
$manage _menu _container . empty ( ) . append ( $manage _menu ) ;
2010-09-12 13:50:27 -04:00
$manage _menu _container . data ( 'item' , $item && $item [ 0 ] ) ;
2010-06-14 13:17:38 -04:00
$ ( '.NB-task-manage' ) . parents ( '.NB-taskbar' ) . css ( 'z-index' , 2 ) ;
2010-09-12 13:50:27 -04:00
if ( type == 'site' ) {
$manage _menu _container . align ( $ ( '.NB-task-manage' ) , '-bottom -left' , {
'top' : - 32 ,
'left' : - 2
} ) ;
$ ( '.NB-task-manage' ) . addClass ( 'NB-hover' ) ;
$manage _menu _container . corner ( 'tl tr 8px' ) ;
2010-12-30 18:37:29 -05:00
} else if ( type == 'feed' || type == 'folder' || type == 'story' ) {
2010-12-12 20:06:32 -05:00
var left , top ;
// NEWSBLUR.log(['menu open', $item, inverse, toplevel, type]);
2010-09-13 00:38:25 -04:00
if ( inverse ) {
2011-09-27 23:06:49 -07:00
var $align = $item ;
2010-12-12 20:06:32 -05:00
if ( type == 'feed' ) {
left = toplevel ? 0 : - 20 ;
2010-12-31 10:34:31 -05:00
top = toplevel ? 21 : 21 ;
2010-12-12 20:06:32 -05:00
} else if ( type == 'folder' ) {
left = toplevel ? 0 : - 20 ;
2010-12-31 10:34:31 -05:00
top = toplevel ? 24 : 24 ;
2011-09-27 23:06:49 -07:00
$align = $ ( '.folder_title' , $item ) ;
2010-12-30 18:37:29 -05:00
} else if ( type == 'story' ) {
left = 4 ;
2011-09-27 22:16:09 -07:00
top = 24 ;
2011-09-27 23:06:49 -07:00
$align = $ ( '.NB-story-manage-icon,.NB-feed-story-manage-icon' , $item ) ;
2010-12-12 20:06:32 -05:00
}
2010-09-13 00:38:25 -04:00
$manage _menu _container . align ( $align , '-bottom -left' , {
'top' : - 1 * top ,
'left' : left
} ) ;
$manage _menu _container . corner ( 'br 8px' ) ;
$ ( 'li' , $manage _menu _container ) . each ( function ( ) {
$ ( this ) . prependTo ( $ ( this ) . parent ( ) ) ;
} ) ;
} else {
2011-09-27 23:06:49 -07:00
var $align = $item ;
2010-12-12 20:06:32 -05:00
if ( type == 'feed' ) {
2011-09-27 23:06:49 -07:00
left = toplevel ? 2 : - 18 ;
2010-12-12 20:06:32 -05:00
top = toplevel ? 21 : 21 ;
2011-09-27 23:06:49 -07:00
$align = $ ( '.NB-feedlist-manage-icon' , $item ) ;
2010-12-12 20:06:32 -05:00
} else if ( type == 'folder' ) {
left = toplevel ? 2 : - 20 ;
top = toplevel ? 22 : 21 ;
2011-01-12 22:45:52 -05:00
} else if ( type == 'story' ) {
left = 4 ;
2011-01-14 00:59:51 -05:00
top = 18 ;
2011-09-27 23:06:49 -07:00
$align = $ ( '.NB-story-manage-icon,.NB-feed-story-manage-icon' , $item ) ;
2010-12-12 20:06:32 -05:00
}
2011-09-27 23:06:49 -07:00
$manage _menu _container . align ( $align , '-top -left' , {
2010-09-13 00:38:25 -04:00
'top' : top ,
'left' : left
} ) ;
$manage _menu _container . corner ( 'tr 8px' ) ;
}
2010-09-12 13:50:27 -04:00
}
$manage _menu _container . stop ( ) . css ( { 'display' : 'block' , 'opacity' : 1 } ) ;
// Create and position the arrow tab
2010-12-30 18:37:29 -05:00
if ( type == 'feed' || type == 'folder' || type == 'story' ) {
2010-09-13 00:38:25 -04:00
var $arrow = $ . make ( 'div' , { className : 'NB-menu-manage-arrow' } ) ;
if ( inverse ) {
$arrow . corner ( 'bl br 5px' ) ;
$manage _menu _container . append ( $arrow ) ;
$arrow . addClass ( 'NB-inverse' ) ;
} else {
$arrow . corner ( 'tl tr 5px' ) ;
$manage _menu _container . prepend ( $arrow ) ;
}
2010-09-12 13:50:27 -04:00
}
// Hide menu on click outside menu.
_ . defer ( function ( ) {
$ ( document ) . bind ( 'click.menu' , function ( e ) {
2010-12-31 14:35:00 -05:00
if ( e . button == 2 ) return ; // Ignore right-clicks
2010-09-12 13:50:27 -04:00
self . hide _manage _menu ( type , $item , false ) ;
} ) ;
2010-06-08 11:19:41 -04:00
} ) ;
2010-06-14 13:17:38 -04:00
2010-09-12 13:50:27 -04:00
// Hide menu on mouseout (on a delay).
2010-06-14 13:17:38 -04:00
$manage _menu _container . hover ( function ( ) {
clearTimeout ( self . flags . closed _manage _menu ) ;
} , function ( ) {
clearTimeout ( self . flags . closed _manage _menu ) ;
self . flags . closed _manage _menu = setTimeout ( function ( ) {
2010-07-24 00:04:14 -04:00
if ( self . flags . closed _manage _menu ) {
2010-09-12 13:50:27 -04:00
self . hide _manage _menu ( type , $item , true ) ;
2010-07-24 00:04:14 -04:00
}
2010-06-14 13:17:38 -04:00
} , 1000 ) ;
2010-06-08 11:19:41 -04:00
} ) ;
2010-09-12 13:50:27 -04:00
// Hide menu on scroll.
2010-12-30 18:37:29 -05:00
var $scroll ;
2010-09-12 13:50:27 -04:00
this . flags [ 'feed_list_showing_manage_menu' ] = true ;
2010-12-30 18:37:29 -05:00
if ( type == 'feed' ) {
$scroll = this . $s . $feed _list . parent ( ) ;
} else if ( type == 'story' ) {
2011-05-16 11:34:05 -04:00
$scroll = this . $s . $story _titles . add ( this . $s . $feed _stories ) ;
2010-12-30 18:37:29 -05:00
}
$scroll && $scroll . unbind ( 'scroll.manage_menu' ) . bind ( 'scroll.manage_menu' , function ( e ) {
2010-09-12 13:50:27 -04:00
if ( self . flags [ 'feed_list_showing_manage_menu' ] ) {
self . hide _manage _menu ( type , $item , true ) ;
} else {
2011-01-12 22:45:52 -05:00
$scroll . unbind ( 'scroll.manage_menu' ) ;
2010-09-12 13:50:27 -04:00
}
} ) ;
2010-06-14 13:17:38 -04:00
} ,
2010-09-12 13:50:27 -04:00
hide _manage _menu : function ( type , $item , animate ) {
2010-06-14 13:17:38 -04:00
var $manage _menu _container = $ ( '.NB-menu-manage-container' ) ;
var height = $manage _menu _container . outerHeight ( ) ;
2011-09-04 15:42:13 -07:00
if ( this . flags [ 'showing_confirm_input_on_manage_menu' ] && animate ) return ;
2010-09-12 13:50:27 -04:00
// NEWSBLUR.log(['hide_manage_menu', type, $item, animate, $manage_menu_container.css('opacity')]);
2010-06-14 13:17:38 -04:00
clearTimeout ( this . flags . closed _manage _menu ) ;
2010-09-12 13:50:27 -04:00
this . flags [ 'feed_list_showing_manage_menu' ] = false ;
2010-06-14 13:17:38 -04:00
$ ( document ) . unbind ( 'click.menu' ) ;
2010-09-13 00:38:25 -04:00
$manage _menu _container . uncorner ( ) ;
2011-05-01 20:22:54 -04:00
if ( this . model . preference ( 'show_tooltips' ) ) {
$ ( '.NB-task-manage' ) . tipsy ( 'enable' ) ;
}
2011-02-08 22:07:59 -05:00
2011-11-07 20:50:46 -08:00
if ( $item ) $item . removeClass ( 'NB-showing-menu' ) ;
2011-02-08 22:07:59 -05:00
2010-09-12 13:50:27 -04:00
if ( animate ) {
$manage _menu _container . stop ( ) . animate ( {
'opacity' : 0
} , {
'duration' : 250 ,
'queue' : false ,
'complete' : function ( ) {
$manage _menu _container . css ( { 'display' : 'none' , 'opacity' : 0 } ) ;
}
} ) ;
} else {
$manage _menu _container . css ( { 'display' : 'none' , 'opacity' : 0 } ) ;
}
2010-06-14 13:17:38 -04:00
$ ( '.NB-task-manage' ) . removeClass ( 'NB-hover' ) ;
} ,
2010-12-11 17:16:12 -05:00
// ========================
// = Manage menu - Delete =
// ========================
2010-07-01 00:29:26 -04:00
show _confirm _delete _menu _item : function ( ) {
2010-09-14 20:49:28 -04:00
var $delete = $ ( '.NB-menu-manage-feed-delete,.NB-menu-manage-folder-delete' ) ;
var $confirm = $ ( '.NB-menu-manage-feed-delete-confirm,.NB-menu-manage-folder-delete-confirm' ) ;
2010-07-01 00:29:26 -04:00
$delete . addClass ( 'NB-menu-manage-feed-delete-cancel' ) ;
2010-07-21 23:22:27 -04:00
$ ( '.NB-menu-manage-title' , $delete ) . text ( 'Cancel delete' ) ;
2010-07-01 00:29:26 -04:00
$confirm . slideDown ( 500 ) ;
} ,
hide _confirm _delete _menu _item : function ( ) {
2010-09-14 20:49:28 -04:00
var $delete = $ ( '.NB-menu-manage-feed-delete,.NB-menu-manage-folder-delete' ) ;
var $confirm = $ ( '.NB-menu-manage-feed-delete-confirm,.NB-menu-manage-folder-delete-confirm' ) ;
2010-07-01 00:29:26 -04:00
$delete . removeClass ( 'NB-menu-manage-feed-delete-cancel' ) ;
2010-12-11 11:26:21 -05:00
var text = $delete . hasClass ( 'NB-menu-manage-folder-delete' ) ?
'Delete this folder' :
'Delete this site' ;
2010-09-14 20:49:28 -04:00
$ ( '.NB-menu-manage-title' , $delete ) . text ( text ) ;
2010-07-01 00:29:26 -04:00
$confirm . slideUp ( 500 ) ;
} ,
2010-09-14 20:49:28 -04:00
manage _menu _delete _feed : function ( feed , $feed ) {
2010-07-01 00:29:26 -04:00
var self = this ;
var feed _id = feed || this . active _feed ;
2010-10-23 10:29:35 -04:00
$feed = $feed || this . find _feed _in _feed _list ( feed _id ) ;
2010-09-14 20:49:28 -04:00
var in _folder = $feed . parents ( 'li.folder' ) . eq ( 0 ) . find ( '.folder_title_text' ) . eq ( 0 ) . text ( ) ;
2011-01-23 14:08:49 -05:00
var duplicate _feed = this . find _feed _in _feed _list ( feed _id ) . length > 1 ;
2011-09-26 09:22:46 -07:00
this . delete _feed ( feed _id , $feed ) ;
2010-09-14 20:49:28 -04:00
this . model . delete _feed ( feed _id , in _folder , function ( ) {
self . delete _feed ( feed _id , $feed ) ;
2011-01-23 14:08:49 -05:00
} , duplicate _feed ) ;
2010-09-14 20:49:28 -04:00
} ,
manage _menu _delete _folder : function ( folder , $folder ) {
var self = this ;
2010-09-16 10:35:36 -04:00
var in _folder = '' ;
var $parent = $folder . parents ( 'li.folder' ) ;
2010-09-22 10:12:38 -04:00
var feeds = this . get _feed _ids _in _folder ( $folder ) ;
2010-09-16 10:35:36 -04:00
if ( $parent . length ) {
in _folder = $parent . eq ( 0 ) . find ( '.folder_title_text' ) . eq ( 0 ) . text ( ) ;
}
2010-07-01 00:29:26 -04:00
2010-09-22 10:12:38 -04:00
this . model . delete _folder ( folder , in _folder , feeds , function ( ) {
2010-09-14 20:49:28 -04:00
self . delete _folder ( folder , $folder ) ;
2010-07-01 00:29:26 -04:00
} ) ;
} ,
2010-12-11 14:02:37 -05:00
delete _feed : function ( feed _id , $feed ) {
var self = this ;
$feed = $feed || this . find _feed _in _feed _list ( feed _id ) ;
$feed . slideUp ( 500 ) ;
2011-03-30 09:30:45 -04:00
if ( this . active _feed == parseInt ( $feed . attr ( 'data-id' ) , 10 ) ) {
2010-12-11 14:02:37 -05:00
this . reset _feed ( ) ;
this . show _splash _page ( ) ;
}
this . update _header _counts ( ) ;
} ,
delete _folder : function ( folder _name , $folder ) {
var self = this ;
var feeds = this . get _feed _ids _in _folder ( $folder ) ;
if ( $folder . length ) {
$folder . slideUp ( 500 ) ;
}
// If the active feed is under this folder, deselect it.
var feed _active = false ;
_ . each ( feeds , _ . bind ( function ( feed _id ) {
if ( self . active _feed == feed _id ) {
this . reset _feed ( ) ;
this . show _splash _page ( ) ;
return false ;
}
} , this ) ) ;
this . update _header _counts ( ) ;
} ,
2011-09-04 15:42:13 -07:00
// ========================
// = Manage menu - Move =
// ========================
show _confirm _move _menu _item : function ( feed _id , $feed ) {
var self = this ;
var $move = $ ( '.NB-menu-manage-feed-move,.NB-menu-manage-folder-move' ) ;
var $confirm = $ ( '.NB-menu-manage-feed-move-confirm,.NB-menu-manage-folder-move-confirm' ) ;
var $position = $ ( '.NB-menu-manage-confirm-position' , $confirm ) ;
var $select = $ ( 'select' , $confirm ) ;
var $parent = $feed . closest ( 'li.folder' ) ;
var in _folder = '' ;
if ( $parent . length ) {
in _folder = $feed . eq ( 0 ) . closest ( 'li.folder' ) . find ( '.folder_title_text' ) . eq ( 0 ) . text ( ) ;
}
$move . addClass ( 'NB-menu-manage-feed-move-cancel' ) ;
$ ( '.NB-menu-manage-title' , $move ) . text ( 'Cancel move' ) ;
$position . css ( 'position' , 'relative' ) ;
var height = $confirm . height ( ) ;
$position . css ( 'position' , 'absolute' ) ;
$confirm . css ( { 'height' : 0 , 'display' : 'block' } ) . animate ( { 'height' : height } , {
'duration' : 500 ,
'easing' : 'easeOutQuart'
} ) ;
$ ( 'select' , $confirm ) . focus ( ) . select ( ) ;
this . flags [ 'showing_confirm_input_on_manage_menu' ] = true ;
console . log ( [ "$select" , $select , $ ( 'option' , $select ) ] ) ;
$ ( 'option' , $select ) . each ( function ( ) {
console . log ( [ "show_confirm_move_menu_item" , in _folder , $ ( this ) . attr ( 'value' ) ] ) ;
if ( $ ( this ) . attr ( 'value' ) == in _folder ) {
$ ( this ) . attr ( 'selected' , 'selected' ) ;
return false ;
}
} ) ;
} ,
hide _confirm _move _menu _item : function ( moved ) {
var $move = $ ( '.NB-menu-manage-feed-move,.NB-menu-manage-folder-move' ) ;
var $confirm = $ ( '.NB-menu-manage-feed-move-confirm,.NB-menu-manage-folder-move-confirm' ) ;
$move . removeClass ( 'NB-menu-manage-feed-move-cancel' ) ;
var text = 'Move to folder' ;
if ( moved ) {
text = 'Moved' ;
$move . addClass ( 'NB-active' ) ;
} else {
$move . removeClass ( 'NB-active' ) ;
}
$ ( '.NB-menu-manage-title' , $move ) . text ( text ) ;
$confirm . slideUp ( 500 ) ;
this . flags [ 'showing_confirm_input_on_manage_menu' ] = false ;
} ,
manage _menu _move _feed : function ( feed , $feed ) {
var self = this ;
var feed _id = feed || this . active _feed ;
$feed = $feed || this . find _feed _in _feed _list ( feed _id ) ;
var $parent = $feed . closest ( 'li.folder' ) ;
var in _folder = '' ;
2011-11-07 20:50:46 -08:00
var to _folder = $ ( '.NB-menu-manage-feed-move-confirm select' ) . val ( ) ;
2011-09-04 15:42:13 -07:00
if ( $parent . length ) {
in _folder = $feed . eq ( 0 ) . closest ( 'li.folder' ) . find ( '.folder_title_text' ) . eq ( 0 ) . text ( ) ;
}
2011-11-07 20:50:46 -08:00
if ( to _folder == in _folder ) return this . hide _confirm _move _menu _item ( ) ;
2011-09-04 15:42:13 -07:00
2011-11-07 20:50:46 -08:00
this . model . move _feed _to _folder ( feed _id , in _folder , to _folder , _ . bind ( function ( ) {
_ . delay ( _ . bind ( function ( ) {
this . $s . $feed _list . css ( 'opacity' , 1 ) . animate ( { 'opacity' : 0 } , {
'duration' : 100 ,
'complete' : _ . bind ( function ( ) {
this . make _feeds ( ) ;
} , this )
} ) ;
} , this ) , 250 ) ;
this . hide _manage _menu ( 'feed' , $feed , true ) ;
} , this ) ) ;
2011-09-04 15:42:13 -07:00
this . hide _confirm _move _menu _item ( true ) ;
} ,
manage _menu _move _folder : function ( folder , $folder ) {
var self = this ;
var in _folder = '' ;
2011-11-08 09:20:10 -08:00
var $parent = $folder . parents ( 'li.folder' ) . eq ( 0 ) ;
var to _folder = $ ( '.NB-menu-manage-folder-move-confirm select' ) . val ( ) ;
var folder _name = $folder . find ( '.folder_title_text' ) . eq ( 0 ) . text ( ) ;
var child _folders = $folder . find ( '.folder_title_text' ) . map ( function ( ) {
return $ ( this ) . text ( ) ;
} ) . get ( ) ;
2011-09-04 15:42:13 -07:00
if ( $parent . length ) {
in _folder = $parent . find ( '.folder_title_text' ) . eq ( 0 ) . text ( ) ;
}
2011-11-08 09:20:10 -08:00
if ( to _folder == in _folder ||
to _folder == folder _name ||
_ . contains ( child _folders , to _folder ) ) {
return this . hide _confirm _move _menu _item ( ) ;
}
2011-11-07 20:50:46 -08:00
2011-11-08 09:20:10 -08:00
this . model . move _folder _to _folder ( folder , in _folder , to _folder , _ . bind ( function ( ) {
2011-11-07 20:50:46 -08:00
_ . delay ( _ . bind ( function ( ) {
this . $s . $feed _list . css ( 'opacity' , 1 ) . animate ( { 'opacity' : 0 } , {
'duration' : 100 ,
'complete' : _ . bind ( function ( ) {
this . make _feeds ( ) ;
} , this )
} ) ;
} , this ) , 250 ) ;
2011-11-08 09:20:10 -08:00
this . hide _manage _menu ( 'folder' , $parent , true ) ;
} , this ) ) ;
2011-09-04 15:42:13 -07:00
this . hide _confirm _move _menu _item ( true ) ;
} ,
2010-12-11 17:16:12 -05:00
// ========================
// = Manage menu - Rename =
// ========================
2010-12-11 11:26:21 -05:00
show _confirm _rename _menu _item : function ( ) {
2010-12-11 14:02:37 -05:00
var self = this ;
2010-12-11 11:26:21 -05:00
var $rename = $ ( '.NB-menu-manage-feed-rename,.NB-menu-manage-folder-rename' ) ;
var $confirm = $ ( '.NB-menu-manage-feed-rename-confirm,.NB-menu-manage-folder-rename-confirm' ) ;
2011-09-04 15:42:13 -07:00
var $position = $ ( '.NB-menu-manage-confirm-position' , $confirm ) ;
2010-12-11 11:26:21 -05:00
$rename . addClass ( 'NB-menu-manage-feed-rename-cancel' ) ;
$ ( '.NB-menu-manage-title' , $rename ) . text ( 'Cancel rename' ) ;
2011-09-04 15:42:13 -07:00
$position . css ( 'position' , 'relative' ) ;
2010-12-11 11:26:21 -05:00
var height = $confirm . height ( ) ;
2011-09-04 15:42:13 -07:00
$position . css ( 'position' , 'absolute' ) ;
$confirm . css ( { 'height' : 0 , 'display' : 'block' } ) . animate ( { 'height' : height } , {
'duration' : 500 ,
'easing' : 'easeOutQuart'
} ) ;
2010-12-11 12:41:24 -05:00
$ ( 'input' , $confirm ) . focus ( ) . select ( ) ;
2011-09-04 15:42:13 -07:00
this . flags [ 'showing_confirm_input_on_manage_menu' ] = true ;
2010-12-11 14:02:37 -05:00
$ ( '.NB-menu-manage-feed-rename-confirm input.NB-menu-manage-title' ) . bind ( 'keyup' , 'return' , function ( e ) {
var $t = $ ( e . target ) ;
var feed _id = $t . closest ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
var $feed = $t . closest ( '.NB-menu-manage' ) . data ( '$feed' ) ;
self . manage _menu _rename _feed ( feed _id , $feed ) ;
} ) ;
$ ( '.NB-menu-manage-folder-rename-confirm input.NB-menu-manage-title' ) . bind ( 'keyup' , 'return' , function ( e ) {
var $t = $ ( e . target ) ;
var folder _name = $t . parents ( '.NB-menu-manage' ) . data ( 'folder_name' ) ;
var $folder = $t . parents ( '.NB-menu-manage' ) . data ( '$folder' ) ;
self . manage _menu _rename _folder ( folder _name , $folder ) ;
} ) ;
2010-12-11 11:26:21 -05:00
} ,
2010-12-11 14:02:37 -05:00
hide _confirm _rename _menu _item : function ( renamed ) {
2010-12-11 11:26:21 -05:00
var $rename = $ ( '.NB-menu-manage-feed-rename,.NB-menu-manage-folder-rename' ) ;
var $confirm = $ ( '.NB-menu-manage-feed-rename-confirm,.NB-menu-manage-folder-rename-confirm' ) ;
$rename . removeClass ( 'NB-menu-manage-feed-rename-cancel' ) ;
var text = $rename . hasClass ( 'NB-menu-manage-folder-rename' ) ?
'Rename this folder' :
'Rename this site' ;
2010-12-11 14:02:37 -05:00
if ( renamed ) {
text = 'Renamed' ;
$rename . addClass ( 'NB-active' ) ;
} else {
$rename . removeClass ( 'NB-active' ) ;
}
2010-12-11 11:26:21 -05:00
$ ( '.NB-menu-manage-title' , $rename ) . text ( text ) ;
$confirm . slideUp ( 500 ) ;
2011-09-04 15:42:13 -07:00
this . flags [ 'showing_confirm_input_on_manage_menu' ] = false ;
2010-12-11 11:26:21 -05:00
} ,
manage _menu _rename _feed : function ( feed , $feed ) {
2010-12-11 14:02:37 -05:00
var self = this ;
var feed _id = feed || this . active _feed ;
$feed = $feed || this . find _feed _in _feed _list ( feed _id ) ;
var new _title = $ ( '.NB-menu-manage-feed-rename-confirm .NB-menu-manage-title' ) . val ( ) ;
2010-12-11 11:26:21 -05:00
2010-12-11 17:16:12 -05:00
if ( new _title . length <= 0 ) return this . hide _confirm _rename _menu _item ( ) ;
2010-12-11 15:26:45 -05:00
this . model . rename _feed ( feed _id , new _title , function ( ) {
2010-12-11 11:26:21 -05:00
} ) ;
2010-12-11 15:26:45 -05:00
2011-11-28 12:20:02 -05:00
$ ( '.feed_title' , $feed ) . eq ( 0 ) . text ( new _title ) ;
2010-12-11 14:02:37 -05:00
if ( feed _id == this . active _feed ) {
2011-11-28 12:20:02 -05:00
$ ( '.feed_title' , this . $s . $story _titles ) . eq ( 0 ) . text ( new _title ) ;
2010-12-11 14:02:37 -05:00
}
this . hide _confirm _rename _menu _item ( true ) ;
2010-12-11 11:26:21 -05:00
} ,
manage _menu _rename _folder : function ( folder , $folder ) {
2010-12-11 14:02:37 -05:00
var self = this ;
2010-12-11 11:26:21 -05:00
var in _folder = '' ;
2010-12-11 14:02:37 -05:00
var $parent = $folder . parents ( 'li.folder' ) ;
var new _folder _name = $ ( '.NB-menu-manage-folder-rename-confirm .NB-menu-manage-title' ) . val ( ) ;
2010-12-11 17:16:12 -05:00
if ( new _folder _name . length <= 0 ) return this . hide _confirm _rename _menu _item ( ) ;
2010-12-11 11:26:21 -05:00
if ( $parent . length ) {
in _folder = $parent . eq ( 0 ) . find ( '.folder_title_text' ) . eq ( 0 ) . text ( ) ;
}
2010-12-11 14:02:37 -05:00
this . model . rename _folder ( folder , new _folder _name , in _folder , function ( ) {
2010-12-11 11:26:21 -05:00
} ) ;
2011-11-28 12:20:02 -05:00
$ ( '.folder_title_text' , $folder ) . eq ( 0 ) . text ( new _folder _name ) ;
2010-12-11 14:02:37 -05:00
this . hide _confirm _rename _menu _item ( true ) ;
2010-12-11 17:16:12 -05:00
$ ( '.NB-menu-manage-folder-rename' ) . parents ( '.NB-menu-manage' ) . data ( 'folder_name' , new _folder _name ) ;
2010-12-11 11:26:21 -05:00
} ,
2010-06-14 13:17:38 -04:00
// ==========================
// = Taskbar - Intelligence =
// ==========================
load _intelligence _slider : function ( ) {
var self = this ;
var $slider = this . $s . $intelligence _slider ;
var unread _view = this . model . preference ( 'unread_view' ) ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
this . switch _feed _view _unread _view ( unread _view ) ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
$slider . slider ( {
range : 'max' ,
min : - 1 ,
max : 1 ,
step : 1 ,
value : unread _view ,
slide : function ( e , ui ) {
self . switch _feed _view _unread _view ( ui . value ) ;
} ,
stop : function ( e , ui ) {
2011-07-29 09:41:49 -07:00
self . slide _intelligence _slider ( ui . value ) ;
2010-06-14 13:17:38 -04:00
}
2010-06-08 11:19:41 -04:00
} ) ;
2010-06-14 13:17:38 -04:00
} ,
2011-07-29 09:41:49 -07:00
slide _intelligence _slider : function ( value ) {
if ( this . model . preference ( 'unread_view' ) != value ) {
this . model . preference ( 'unread_view' , value ) ;
}
this . flags [ 'feed_view_positions_calculated' ] = false ;
this . switch _feed _view _unread _view ( value ) ;
this . show _feed _hidden _story _title _indicator ( ) ;
this . show _story _titles _above _intelligence _level ( { 'animate' : true , 'follow' : true } ) ;
2011-11-11 12:45:32 -08:00
this . update _header _counts ( true ) ;
2011-07-29 09:41:49 -07:00
} ,
move _intelligence _slider : function ( direction ) {
var $slider = this . $s . $intelligence _slider ;
var value = this . model . preference ( 'unread_view' ) + direction ;
$slider . slider ( { value : value } ) ;
this . slide _intelligence _slider ( value ) ;
} ,
2010-06-14 13:17:38 -04:00
switch _feed _view _unread _view : function ( unread _view ) {
2011-01-04 10:10:23 -05:00
if ( ! _ . isNumber ( unread _view ) ) unread _view = this . model . preference ( 'unread_view' ) ;
2011-01-04 19:39:57 -05:00
var $feed _list = this . $s . $feed _list ;
var unread _view _name = this . get _unread _view _name ( unread _view ) ;
var $next _story _button = $ ( '.task_story_next_unread' ) ;
2010-11-01 18:20:26 -04:00
var $story _title _indicator = $ ( '.NB-story-title-indicator' , this . $story _titles ) ;
2011-01-04 19:39:57 -05:00
var $hidereadfeeds _button = $ ( '.NB-feeds-header-sites' ) ;
2011-01-04 08:21:47 -05:00
2010-06-14 13:17:38 -04:00
$feed _list . removeClass ( 'unread_view_positive' )
. removeClass ( 'unread_view_neutral' )
. removeClass ( 'unread_view_negative' )
. addClass ( 'unread_view_' + unread _view _name ) ;
2010-11-05 10:35:52 -04:00
if ( NEWSBLUR . Preferences [ 'hide_read_feeds' ] == 1 ) {
2010-12-04 23:06:35 -05:00
$hidereadfeeds _button . attr ( 'title' , 'Show all sites' ) ;
2011-03-13 16:24:49 -04:00
this . $s . $body . addClass ( 'NB-feedlist-hide-read-feeds' ) ;
2010-11-05 10:35:52 -04:00
} else {
2010-12-04 23:06:35 -05:00
$hidereadfeeds _button . attr ( 'title' , 'Show only unread stories' ) ;
2011-03-13 16:24:49 -04:00
this . $s . $body . removeClass ( 'NB-feedlist-hide-read-feeds' ) ;
2010-11-05 10:35:52 -04:00
}
2011-05-01 20:22:54 -04:00
if ( this . model . preference ( 'show_tooltips' ) ) {
$hidereadfeeds _button . tipsy ( {
gravity : 'n' ,
delayIn : 375
} ) ;
}
2010-12-04 23:06:35 -05:00
2010-06-14 13:17:38 -04:00
$next _story _button . removeClass ( 'task_story_next_positive' )
. removeClass ( 'task_story_next_neutral' )
. removeClass ( 'task_story_next_negative' )
. addClass ( 'task_story_next_' + unread _view _name ) ;
2010-11-01 18:20:26 -04:00
$story _title _indicator . removeClass ( 'unread_threshold_positive' )
. removeClass ( 'unread_threshold_neutral' )
. removeClass ( 'unread_threshold_negative' )
. addClass ( 'unread_threshold_' + unread _view _name ) ;
2011-11-11 12:45:32 -08:00
this . update _header _counts ( true , unread _view ) ;
2010-06-14 13:17:38 -04:00
} ,
get _unread _view _name : function ( unread _view ) {
2010-07-21 00:47:55 -04:00
if ( typeof unread _view == 'undefined' ) {
unread _view = this . model . preference ( 'unread_view' ) ;
}
2011-01-11 22:12:33 -05:00
2010-06-14 13:17:38 -04:00
return ( unread _view > 0
? 'positive'
: unread _view < 0
? 'negative'
: 'neutral' ) ;
} ,
2010-09-12 13:50:27 -04:00
get _unread _count : function ( visible _only , feed _id ) {
2010-06-14 13:17:38 -04:00
var total = 0 ;
2011-01-10 09:49:26 -05:00
var $folder ;
2010-09-12 13:50:27 -04:00
feed _id = feed _id || this . active _feed ;
2010-06-08 11:19:41 -04:00
2011-02-04 09:56:15 -05:00
if ( feed _id == 'starred' ) {
// Umm, no. Not yet.
} else if ( this . flags [ 'river_view' ] ) {
2011-01-10 09:49:26 -05:00
if ( feed _id == 'river:' ) {
$folder = this . $s . $feed _list ;
} else {
$folder = $ ( 'li.folder.NB-selected' ) ;
}
2011-01-31 20:08:07 -05:00
var counts = this . list _feeds _with _unreads _in _folder ( $folder , true , visible _only ) ;
2011-01-10 09:49:26 -05:00
return _ . reduce ( counts , function ( m , c ) { return m + c ; } , 0 ) ;
2010-06-14 13:17:38 -04:00
} else {
2011-01-10 09:49:26 -05:00
var feed = this . model . get _feed ( feed _id ) ;
if ( ! visible _only ) {
total = feed . ng + feed . nt + feed . ps ;
} else {
var unread _view _name = this . get _unread _view _name ( ) ;
if ( unread _view _name == 'positive' ) {
total = feed . ps ;
} else if ( unread _view _name == 'neutral' ) {
total = feed . ps + feed . nt ;
} else if ( unread _view _name == 'negative' ) {
total = feed . ps + feed . nt + feed . ng ;
}
2010-06-14 13:17:38 -04:00
}
2011-01-10 09:49:26 -05:00
return total ;
2010-06-14 13:17:38 -04:00
}
} ,
2011-01-03 19:18:27 -05:00
show _story _titles _above _intelligence _level : function ( opts ) {
2010-11-01 18:20:26 -04:00
var defaults = {
'unread_view_name' : null ,
'animate' : true ,
2011-02-01 18:29:22 -05:00
'follow' : true ,
'temporary' : false
2010-11-01 18:20:26 -04:00
} ;
var options = $ . extend ( { } , defaults , opts ) ;
2010-06-14 13:17:38 -04:00
var self = this ;
var $story _titles = this . $s . $story _titles ;
2010-11-01 18:20:26 -04:00
var unread _view _name = options [ 'unread_view_name' ] || this . get _unread _view _name ( ) ;
2010-06-14 13:17:38 -04:00
var $stories _show , $stories _hide ;
2011-01-04 19:27:00 -05:00
2011-12-20 11:55:48 -08:00
if ( this . model . stories . length > 100 ) {
options [ 'animate' ] = false ;
}
2011-01-04 19:27:00 -05:00
if ( this . flags [ 'unread_threshold_temporarily' ] ) {
unread _view _name = this . flags [ 'unread_threshold_temporarily' ] ;
2011-02-28 09:44:06 -05:00
options [ 'temporary' ] = true ;
2011-01-04 19:27:00 -05:00
}
2010-12-02 20:18:33 -05:00
2010-06-14 13:17:38 -04:00
if ( unread _view _name == 'positive' ) {
$stories _show = $ ( '.story,.NB-feed-story' ) . filter ( '.NB-story-positive' ) ;
$stories _hide = $ ( '.story,.NB-feed-story' )
. filter ( '.NB-story-neutral,.NB-story-negative' ) ;
} else if ( unread _view _name == 'neutral' ) {
$stories _show = $ ( '.story,.NB-feed-story' )
. filter ( '.NB-story-positive,.NB-story-neutral' ) ;
$stories _hide = $ ( '.story,.NB-feed-story' ) . filter ( '.NB-story-negative' ) ;
2011-02-01 18:29:22 -05:00
if ( options [ 'temporary' ] ) {
$stories _show . filter ( '.NB-story-neutral' ) . addClass ( 'NB-story-hidden-visible' ) ;
} else {
$stories _show . filter ( '.NB-story-hidden-visible' ) . removeClass ( 'NB-story-hidden-visible' ) ;
}
2010-06-14 13:17:38 -04:00
} else if ( unread _view _name == 'negative' ) {
$stories _show = $ ( '.story,.NB-feed-story' )
. filter ( '.NB-story-positive,.NB-story-neutral,.NB-story-negative' ) ;
$stories _hide = $ ( ) ;
2011-02-01 18:29:22 -05:00
if ( options [ 'temporary' ] ) {
$stories _show . filter ( '.NB-story-negative,.NB-story-neutral:not(:visible)' )
. addClass ( 'NB-story-hidden-visible' ) ;
} else {
$stories _show . filter ( '.NB-story-hidden-visible' ) . removeClass ( 'NB-story-hidden-visible' ) ;
}
2010-06-14 13:17:38 -04:00
}
2010-06-08 11:19:41 -04:00
2011-11-04 18:12:28 -07:00
if ( ( this . story _view == 'feed' || this . flags . page _view _showing _feed _view ) &&
this . model . preference ( 'feed_view_single_story' ) ) {
2010-12-09 09:59:45 -05:00
// No need to show/hide feed view stories under single_story preference.
// If the user switches to feed/page, then no animation is happening
// and this will work anyway.
2011-05-03 12:19:53 -04:00
var active _story = this . active _story ;
var $active _story = active _story && $ ( '.NB-feed-story' ) . filter ( function ( ) {
return $ ( this ) . data ( 'story_id' ) == active _story . id ;
} ) ;
if ( $active _story && $active _story . length ) {
$stories _show = $stories _show . not ( '.NB-feed-story' ) . add ( $active _story ) ;
$stories _hide = $stories _hide . add ( '.NB-feed-story' ) . not ( $stories _show ) ;
}
2010-06-14 13:17:38 -04:00
}
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
if ( ! options [ 'animate' ] ) {
$stories _hide . css ( { 'display' : 'none' } ) ;
$stories _show . css ( { 'display' : 'block' } ) ;
2011-09-27 22:16:09 -07:00
this . check _story _titles _last _story ( ) ;
2010-06-14 13:17:38 -04:00
}
2010-06-08 11:19:41 -04:00
2010-12-08 20:53:45 -05:00
if ( this . story _view == 'feed' && ! this . model . preference ( 'feed_view_single_story' ) ) {
if ( $stories _show . filter ( ':visible' ) . length != $stories _show . length
2010-06-14 13:17:38 -04:00
|| $stories _hide . filter ( ':visible' ) . length != 0 ) {
2011-01-04 19:27:00 -05:00
// NEWSBLUR.log(['Show/Hide stories', $stories_show.filter(':visible').length, $stories_show.length, $stories_hide.filter(':visible').length, $stories_hide.length]);
2010-06-14 13:17:38 -04:00
setTimeout ( function ( ) {
2010-12-08 20:53:45 -05:00
self . flags [ 'feed_view_positions_calculated' ] = false ;
self . prefetch _story _locations _in _feed _view ( ) ;
2010-11-04 21:49:13 -04:00
} , 500 ) ;
2010-06-13 18:57:20 -04:00
}
2010-06-14 13:17:38 -04:00
}
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
// NEWSBLUR.log(['Showing correct stories', this.story_view, this.flags['feed_view_positions_calculated'], unread_view_name, $stories_show.length, $stories_hide.length]);
if ( options [ 'animate' ] && options [ 'follow' ] ) {
2011-06-07 12:57:34 -04:00
if ( this . model . preference ( 'animations' ) ) {
2011-09-28 09:31:30 -07:00
$stories _hide . slideUp ( 500 , function ( ) {
self . check _story _titles _last _story ( ) ;
} ) ;
2011-06-07 12:57:34 -04:00
$stories _show . slideDown ( 500 ) ;
} else {
$stories _hide . css ( { 'display' : 'none' } ) ;
$stories _show . css ( { 'display' : 'block' } ) ;
2011-09-28 09:31:30 -07:00
this . check _story _titles _last _story ( ) ;
2011-06-07 12:57:34 -04:00
}
2010-06-14 13:17:38 -04:00
setTimeout ( function ( ) {
2011-01-03 19:18:27 -05:00
if ( ! self . active _story ) return ;
2010-12-30 18:37:29 -05:00
var $story = self . find _story _in _story _titles ( self . active _story . id ) ;
2010-06-14 13:17:38 -04:00
// NEWSBLUR.log(['$story', $story]);
if ( $story && $story . length && $story . is ( ':visible' ) ) {
var story = self . active _story ;
self . active _story = null ; // Set is in open_story(), which allows it to scroll.
self . open _story ( story , $story ) ;
self . scroll _story _titles _to _show _selected _story _title ( $story ) ;
}
2011-06-07 12:57:34 -04:00
} , this . model . preference ( 'animations' ) ? 550 : 0 ) ;
2010-06-14 13:17:38 -04:00
}
2010-06-08 11:19:41 -04:00
} ,
2010-06-14 13:17:38 -04:00
// ===================
// = Feed Refreshing =
// ===================
2010-12-24 11:00:30 -05:00
force _instafetch _stories : function ( feed _id ) {
var self = this ;
feed _id = feed _id || this . active _feed ;
var $feed = this . find _feed _in _feed _list ( feed _id ) ;
$feed . addClass ( 'NB-feed-unfetched' ) . removeClass ( 'NB-feed-exception' ) ;
2011-04-23 18:22:52 -04:00
2010-12-24 11:00:30 -05:00
this . model . save _exception _retry ( feed _id , _ . bind ( this . force _feed _refresh , this , feed _id , $feed ) ) ;
} ,
2011-11-07 08:27:59 -08:00
setup _socket _realtime _unread _counts : function ( force ) {
if ( force && ! this . socket ) {
2011-11-06 12:21:27 -08:00
this . socket = this . socket || io . connect ( 'http://' + window . location . hostname + ':8888' ) ;
// this.socket.refresh_feeds = _.debounce(_.bind(this.force_feeds_refresh, this), 1000*10);
this . socket . on ( 'connect' , _ . bind ( function ( ) {
2011-11-28 18:01:39 -08:00
var active _feeds = _ . compact ( _ . map ( this . model . feeds , function ( feed ) { return feed . active && feed . id ; } ) ) ;
console . log ( [ "Connecting to pubsub" , this . socket , active _feeds . length ] ) ;
this . socket . emit ( 'subscribe:feeds' , active _feeds ) ;
2011-11-06 12:21:27 -08:00
this . socket . on ( 'feed:update' , _ . bind ( function ( feed _id , message ) {
console . log ( [ 'Feed update' , feed _id , message ] ) ;
this . force _feeds _refresh ( false , false , parseInt ( feed _id , 10 ) ) ;
} , this ) ) ;
this . flags . feed _refreshing _in _realtime = true ;
this . setup _feed _refresh ( ) ;
} , this ) ) ;
}
} ,
2011-01-30 21:48:17 -05:00
setup _feed _refresh : function ( new _feeds ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2011-04-12 11:02:02 -04:00
var refresh _interval = this . constants . FEED _REFRESH _INTERVAL ;
2011-11-01 15:31:25 -07:00
var feed _count = _ . size ( this . model . feeds ) ;
2011-01-30 21:48:17 -05:00
2011-02-08 22:07:59 -05:00
if ( ! NEWSBLUR . Globals . is _premium ) {
2011-04-12 18:23:04 -04:00
refresh _interval *= 2 ;
}
2011-11-01 15:31:25 -07:00
if ( feed _count > 250 ) {
2011-04-12 18:23:04 -04:00
refresh _interval *= 4 ;
2011-02-08 22:07:59 -05:00
}
2011-11-01 15:31:25 -07:00
if ( feed _count > 500 ) {
refresh _interval *= 1.5 ;
}
2011-11-06 12:21:27 -08:00
if ( this . flags . feed _refreshing _in _realtime ) {
refresh _interval *= 20 ;
}
2011-11-01 00:20:06 -07:00
2011-11-01 15:31:25 -07:00
if ( new _feeds && feed _count < 250 ) {
2011-07-17 21:50:37 -07:00
refresh _interval = ( 1000 * 60 ) * 1 / 10 ;
2011-11-01 15:31:25 -07:00
} else if ( new _feeds && feed _count < 500 ) {
refresh _interval = ( 1000 * 60 ) * 1 / 4 ;
2011-01-30 21:48:17 -05:00
}
2010-06-08 11:19:41 -04:00
2010-08-17 20:59:47 -04:00
clearInterval ( this . flags . feed _refresh ) ;
2010-06-14 13:17:38 -04:00
this . flags . feed _refresh = setInterval ( function ( ) {
2010-08-30 22:42:44 -04:00
if ( ! self . flags [ 'pause_feed_refreshing' ] ) {
2011-11-28 18:01:39 -08:00
console . log ( [ "setup feed refresh" , self . flags [ 'has_unfetched_feeds' ] ] ) ;
2010-08-30 22:42:44 -04:00
self . model . refresh _feeds ( _ . bind ( function ( updated _feeds ) {
self . post _feed _refresh ( updated _feeds ) ;
} , self ) , self . flags [ 'has_unfetched_feeds' ] ) ;
}
2011-02-06 15:04:21 -05:00
} , refresh _interval ) ;
2010-06-08 11:19:41 -04:00
} ,
2011-11-29 09:43:16 -08:00
force _feed _refresh : function ( feed _id , $feed , new _feed _id ) {
2011-03-17 18:33:59 -04:00
var self = this ;
feed _id = feed _id || this . active _feed ;
$feed = $feed || this . find _feed _in _feed _list ( feed _id ) ;
2011-11-29 09:43:16 -08:00
new _feed _id = new _feed _id || feed _id ;
2011-04-23 18:22:52 -04:00
2011-03-17 18:33:59 -04:00
this . force _feeds _refresh ( function ( feeds ) {
2011-11-29 09:43:16 -08:00
var $new _feed = $ ( self . make _feed _title _template ( feeds [ new _feed _id ] , 'feed' ) ) ;
2011-03-17 18:33:59 -04:00
if ( $feed . hasClass ( 'NB-toplevel' ) ) $new _feed . addClass ( 'NB-toplevel' ) ;
$feed . replaceWith ( $new _feed ) ;
2011-06-07 16:08:59 -04:00
self . cache . $feed _in _feed _list [ feed _id ] = null ;
2011-11-29 09:43:16 -08:00
self . cache . $feed _in _feed _list [ new _feed _id ] = null ;
2011-03-17 18:33:59 -04:00
self . hover _over _feed _titles ( $new _feed ) ;
2011-11-29 09:43:16 -08:00
if ( self . active _feed == feed _id || self . active _feed == new _feed _id ) {
self . open _feed ( new _feed _id , true , $new _feed ) ;
2011-03-17 18:33:59 -04:00
}
2011-11-29 09:43:16 -08:00
} , true , new _feed _id ) ;
2011-03-17 18:33:59 -04:00
} ,
2011-03-10 18:39:58 -05:00
force _feeds _refresh : function ( callback , replace _active _feed , feed _id ) {
2010-06-14 13:17:38 -04:00
if ( callback ) {
this . cache . refresh _callback = callback ;
} else {
delete this . cache . refresh _callback ;
2010-06-08 11:19:41 -04:00
}
2010-08-30 22:42:44 -04:00
this . flags [ 'pause_feed_refreshing' ] = true ;
2010-12-31 14:35:00 -05:00
2010-08-30 22:42:44 -04:00
this . model . refresh _feeds ( _ . bind ( function ( updated _feeds ) {
2011-03-17 22:08:21 -04:00
this . post _feed _refresh ( updated _feeds , replace _active _feed , feed _id ) ;
2011-03-09 09:48:24 -05:00
} , this ) , this . flags [ 'has_unfetched_feeds' ] , feed _id ) ;
2010-06-08 11:19:41 -04:00
} ,
2011-03-17 22:08:21 -04:00
post _feed _refresh : function ( updated _feeds , replace _active _feed , single _feed _id ) {
2010-06-14 13:17:38 -04:00
var feeds = this . model . feeds ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
if ( this . cache . refresh _callback && $ . isFunction ( this . cache . refresh _callback ) ) {
2010-10-10 23:36:09 -04:00
this . cache . refresh _callback ( feeds ) ;
2010-06-14 13:17:38 -04:00
delete this . cache . refresh _callback ;
2010-06-08 11:19:41 -04:00
}
2010-08-11 11:43:48 -04:00
2010-06-14 13:17:38 -04:00
for ( var f in updated _feeds ) {
var feed _id = updated _feeds [ f ] ;
var feed = this . model . get _feed ( feed _id ) ;
2010-08-16 16:30:04 -04:00
if ( ! feed ) continue ;
2011-03-30 09:30:45 -04:00
var $feed = $ ( this . make _feed _title _template ( feed , 'feed' ) ) ;
2011-06-07 16:08:59 -04:00
var $feed _on _page = this . find _feed _in _feed _list ( feed _id ) ;
2010-08-11 11:43:48 -04:00
2011-03-10 18:39:58 -05:00
if ( feed _id == this . active _feed ) {
2011-03-16 11:54:20 -04:00
NEWSBLUR . log ( [ 'UPDATING INLINE' , feed . feed _title , $feed , $feed _on _page , replace _active _feed ] ) ;
2011-03-10 18:39:58 -05:00
if ( ! replace _active _feed ) {
2011-04-21 10:44:50 -04:00
// this.model.refresh_feed(feed_id, $.rescope(this.post_refresh_active_feed, this));
2011-03-10 18:39:58 -05:00
// Set the unread counts to what the client thinks they are, so when
// the counts can be updated, they will force a refresh of the feed.
this . model . feeds [ feed _id ] . ps = parseInt ( $ ( '.unread_count_positive' , $feed _on _page ) . text ( ) , 10 ) ;
this . model . feeds [ feed _id ] . nt = parseInt ( $ ( '.unread_count_neutral' , $feed _on _page ) . text ( ) , 10 ) ;
this . model . feeds [ feed _id ] . ng = parseInt ( $ ( '.unread_count_negative' , $feed _on _page ) . text ( ) , 10 ) ;
} else {
2011-03-16 11:54:20 -04:00
if ( $feed _on _page . hasClass ( 'NB-toplevel' ) ) $feed . addClass ( 'NB-toplevel' ) ;
2011-03-10 18:39:58 -05:00
$feed _on _page . replaceWith ( $feed ) ;
2011-06-07 16:08:59 -04:00
this . cache . $feed _in _feed _list [ feed _id ] = null ;
2011-03-10 18:39:58 -05:00
this . mark _feed _as _selected ( this . active _feed , $feed ) ;
2011-03-17 22:08:21 -04:00
if ( ! single _feed _id ) this . recalculate _story _scores ( feed _id ) ;
this . show _feed _hidden _story _title _indicator ( ) ;
this . make _content _pane _feed _counter ( ) ;
2011-03-10 18:39:58 -05:00
}
2010-06-14 13:17:38 -04:00
} else {
2010-08-11 22:02:47 -04:00
if ( ! this . flags [ 'has_unfetched_feeds' ] ) {
NEWSBLUR . log ( [ 'UPDATING' , feed . feed _title , $feed , $feed _on _page ] ) ;
}
2011-02-06 15:04:21 -05:00
if ( $feed _on _page . hasClass ( 'NB-toplevel' ) ) $feed . addClass ( 'NB-toplevel' ) ;
2010-06-14 13:17:38 -04:00
$feed _on _page . replaceWith ( $feed ) ;
2011-06-07 16:08:59 -04:00
this . cache . $feed _in _feed _list [ feed _id ] = null ;
2011-04-12 18:23:04 -04:00
( function ( $feed ) {
$feed . css ( { 'backgroundColor' : '#D7DDE6' } ) ;
$feed . animate ( {
'backgroundColor' : '#F0F076'
} , {
'duration' : 800 ,
'queue' : false ,
'complete' : function ( ) {
$feed . animate ( { 'backgroundColor' : '#D7DDE6' } , { 'duration' : 1000 , 'queue' : false } ) ;
}
} ) ;
} ) ( $feed ) ;
2010-06-08 11:19:41 -04:00
}
2010-10-06 22:22:32 -04:00
this . hover _over _feed _titles ( $feed ) ;
2010-06-08 11:19:41 -04:00
}
2010-08-11 11:43:48 -04:00
2010-08-11 22:02:47 -04:00
this . check _feed _fetch _progress ( ) ;
2010-11-22 10:44:52 -05:00
this . update _header _counts ( ) ;
2011-11-01 00:20:06 -07:00
this . count _collapsed _unread _stories ( ) ;
2010-08-30 22:42:44 -04:00
this . flags [ 'pause_feed_refreshing' ] = false ;
2010-06-08 11:19:41 -04:00
} ,
2010-06-14 13:17:38 -04:00
post _refresh _active _feed : function ( e , data , first _load ) {
var stories = data . stories ;
var tags = data . tags ;
var feed _id = this . active _feed ;
var new _stories = [ ] ;
var $first _story = $ ( '.story:first' , this . $s . $story _titles ) ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
for ( var s in stories ) {
feed _id = stories [ s ] . story _feed _id ;
break ;
}
if ( this . active _feed == feed _id ) {
for ( var s in this . model . stories ) {
var story = this . model . stories [ s ] ;
2010-12-30 18:37:29 -05:00
var $story = this . find _story _in _story _titles ( story . id ) ;
2011-11-15 18:37:42 -08:00
var $feed _story = this . find _story _in _feed _view ( story . id ) ;
2010-06-14 13:17:38 -04:00
if ( $story && $story . length ) {
// Just update intelligence
2011-11-28 12:13:09 -05:00
var score = this . compute _story _score ( story ) ;
2010-06-14 13:17:38 -04:00
$story . removeClass ( 'NB-story-neutral' )
. removeClass ( 'NB-story-negative' )
. removeClass ( 'NB-story-positive' ) ;
$feed _story . removeClass ( 'NB-story-neutral' )
. removeClass ( 'NB-story-negative' )
. removeClass ( 'NB-story-positive' ) ;
if ( score < 0 ) {
$story . addClass ( 'NB-story-negative' ) ;
$feed _story . addClass ( 'NB-story-negative' ) ;
} else if ( score > 0 ) {
$story . addClass ( 'NB-story-positive' ) ;
$feed _story . addClass ( 'NB-story-positive' ) ;
} else if ( score == 0 ) {
$story . addClass ( 'NB-story-neutral' ) ;
$feed _story . addClass ( 'NB-story-neutral' ) ;
}
} else {
// New story! Prepend.
new _stories . unshift ( story ) ;
$new _story = this . make _story _title ( story ) ;
$new _story . css ( { 'display' : 'none' } ) ;
$first _story . before ( $new _story ) ;
NEWSBLUR . log ( [ 'New story' , $new _story , $first _story ] ) ;
}
}
if ( new _stories . length ) {
2010-12-04 13:32:13 -05:00
this . make _story _feed _entries ( new _stories , false , { 'refresh_load' : true } ) ;
2010-06-14 13:17:38 -04:00
this . flags [ 'feed_view_positions_calculated' ] = false ;
}
2010-12-08 20:53:45 -05:00
this . show _story _titles _above _intelligence _level ( { 'animate' : true , 'follow' : false } ) ;
2010-06-08 11:19:41 -04:00
}
2010-11-22 10:44:52 -05:00
this . update _header _counts ( ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-06-14 13:17:38 -04:00
// ===================
// = Mouse Indicator =
// ===================
2010-12-09 09:59:45 -05:00
hide _mouse _indicator : function ( ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-06-11 20:55:38 -04:00
2010-12-09 09:59:45 -05:00
if ( ! this . flags [ 'mouse_indicator_hidden' ] ) {
this . flags [ 'mouse_indicator_hidden' ] = true ;
this . $s . $mouse _indicator . animate ( { 'opacity' : 0 , 'left' : - 10 } , {
'duration' : 200 ,
'queue' : false ,
'complete' : function ( ) {
self . flags [ 'mouse_indicator_hidden' ] = true ;
}
} ) ;
2010-06-08 11:19:41 -04:00
}
2010-12-09 09:59:45 -05:00
} ,
show _mouse _indicator : function ( ) {
var self = this ;
2010-06-08 11:19:41 -04:00
2010-12-09 09:59:45 -05:00
if ( this . flags [ 'mouse_indicator_hidden' ] ) {
this . flags [ 'mouse_indicator_hidden' ] = false ;
this . $s . $mouse _indicator . animate ( { 'opacity' : 1 , 'left' : 0 } , {
'duration' : 200 ,
'queue' : false ,
'complete' : function ( ) {
self . flags [ 'mouse_indicator_hidden' ] = false ;
}
} ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2010-06-11 16:55:07 -04:00
handle _mouse _indicator _hover : function ( ) {
var self = this ;
var $callout = $ ( '.NB-callout-mouse-indicator' ) ;
$ ( '.NB-callout-text' , $callout ) . text ( 'Lock' ) ;
$callout . corner ( '5px' ) ;
2010-06-14 13:17:38 -04:00
this . $s . $mouse _indicator . hover ( function ( ) {
2010-06-11 20:55:38 -04:00
if ( parseInt ( self . model . preference ( 'lock_mouse_indicator' ) , 10 ) ) {
$ ( '.NB-callout-text' , $callout ) . text ( 'Unlock' ) ;
} else {
$ ( '.NB-callout-text' , $callout ) . text ( 'Lock' ) ;
}
2010-06-11 16:55:07 -04:00
self . flags [ 'still_hovering_on_mouse_indicator' ] = true ;
setTimeout ( function ( ) {
if ( self . flags [ 'still_hovering_on_mouse_indicator' ] ) {
$callout . css ( {
'display' : 'block'
} ) . animate ( {
'opacity' : 1 ,
'left' : '20px'
} , { 'duration' : 200 , 'queue' : false } ) ;
}
} , 50 ) ;
} , function ( ) {
self . flags [ 'still_hovering_on_mouse_indicator' ] = false ;
$callout . animate ( { 'opacity' : 0 , 'left' : '-100px' } , { 'duration' : 200 , 'queue' : false } ) ;
} ) ;
} ,
2010-06-11 20:55:38 -04:00
lock _mouse _indicator : function ( ) {
var self = this ;
var $callout = $ ( '.NB-callout-mouse-indicator' ) ;
if ( parseInt ( self . model . preference ( 'lock_mouse_indicator' ) , 10 ) ) {
self . model . preference ( 'lock_mouse_indicator' , 0 ) ;
$ ( '.NB-callout-text' , $callout ) . text ( 'Unlocked' ) ;
} else {
self . model . preference ( 'lock_mouse_indicator' , this . cache . mouse _position _y ) ;
$ ( '.NB-callout-text' , $callout ) . text ( 'Locked' ) ;
}
setTimeout ( function ( ) {
self . flags [ 'still_hovering_on_mouse_indicator' ] = true ;
$callout . fadeOut ( 200 ) ;
} , 500 ) ;
} ,
position _mouse _indicator : function ( ) {
var position = parseInt ( this . model . preference ( 'lock_mouse_indicator' ) , 10 ) ;
if ( position == 0 ) {
position = 50 ; // Start with a 50 offset
} else {
position = position - 8 ; // Compensate for mouse indicator height.
}
2010-06-14 13:17:38 -04:00
this . $s . $mouse _indicator . css ( 'top' , position ) ;
2010-06-11 20:55:38 -04:00
} ,
2010-07-05 16:05:54 -04:00
// ==========================
// = Login and Signup Forms =
// ==========================
handle _login _and _signup _forms : function ( ) {
var self = this ;
var $hidden _inputs = $ ( '.NB-signup-hidden' ) ;
2011-09-14 20:08:40 -07:00
var $signup _username = $ ( 'input[name=signup-username]' ) ;
2010-07-05 16:05:54 -04:00
$signup _username . bind ( 'focus' , function ( ) {
$hidden _inputs . slideDown ( 300 ) ;
} ) . bind ( 'blur' , function ( ) {
2011-04-02 19:41:22 -04:00
if ( $signup _username . val ( ) . length < 1 ) {
2010-07-05 16:05:54 -04:00
$hidden _inputs . slideUp ( 300 ) ;
}
} ) ;
} ,
2010-06-30 12:17:22 -04:00
// ==================
// = Features Board =
// ==================
load _feature _page : function ( direction ) {
var self = this ;
2011-03-04 12:45:31 -05:00
var $module = $ ( '.NB-module-features' ) ;
2010-07-07 16:22:26 -04:00
var $next = $ ( '.NB-module-features .NB-module-next-page' ) ;
var $previous = $ ( '.NB-module-features .NB-module-previous-page' ) ;
2011-03-04 12:45:31 -05:00
2011-03-13 16:24:49 -04:00
$module . addClass ( 'NB-loading' ) ;
2010-06-30 12:17:22 -04:00
2010-08-11 11:43:48 -04:00
if ( direction == - 1 && ! this . counts [ 'feature_page' ] ) {
2011-03-13 16:24:49 -04:00
$module . removeClass ( 'NB-loading' ) ;
2010-06-30 12:17:22 -04:00
return ;
}
2010-06-30 21:57:24 -04:00
if ( direction == 1 && this . flags [ 'features_last_page' ] ) {
2011-03-13 16:24:49 -04:00
$module . removeClass ( 'NB-loading' ) ;
2010-06-30 16:18:55 -04:00
return ;
}
2010-08-11 11:43:48 -04:00
this . model . get _features _page ( this . counts [ 'feature_page' ] + direction , function ( features ) {
2011-03-13 16:24:49 -04:00
$module . removeClass ( 'NB-loading' ) ;
2010-08-11 11:43:48 -04:00
self . counts [ 'feature_page' ] += direction ;
2010-06-30 16:18:55 -04:00
2011-05-07 12:06:51 -04:00
var $table = $ . make ( 'table' , { className : 'NB-features' , cellSpacing : 0 , cellPadding : 0 } ) ;
2010-06-30 16:18:55 -04:00
for ( var f in features ) {
2010-06-30 22:13:24 -04:00
if ( f == 3 ) break ;
2010-06-30 16:18:55 -04:00
var feature = features [ f ] ;
var $tr = $ . make ( 'tr' , { className : 'NB-module-feature' } , [
2010-07-31 00:13:27 -04:00
$ . make ( 'td' , { className : 'NB-module-feature-date' } , feature . date ) ,
2010-06-30 16:18:55 -04:00
$ . make ( 'td' , { className : 'NB-module-feature-description' } , feature . description )
] ) ;
$table . append ( $tr ) ;
}
2010-06-30 12:17:22 -04:00
2011-05-07 12:06:51 -04:00
$ ( '.NB-module-features .NB-features' ) . replaceWith ( $table ) ;
2010-06-30 21:57:24 -04:00
var features _count = features . length ;
if ( features _count < 4 ) {
$next . addClass ( 'NB-disabled' ) ;
self . flags [ 'features_last_page' ] = true ;
} else {
$next . removeClass ( 'NB-disabled' ) ;
self . flags [ 'features_last_page' ] = false ;
}
2010-08-11 11:43:48 -04:00
if ( self . counts [ 'feature_page' ] > 0 ) {
2010-06-30 21:57:24 -04:00
$previous . removeClass ( 'NB-disabled' ) ;
} else {
$previous . addClass ( 'NB-disabled' ) ;
}
2010-06-30 12:17:22 -04:00
} ) ;
} ,
2011-03-29 21:56:15 -04:00
setup _howitworks _hovers : function ( ) {
var $page _indicators = $ ( '.NB-module-howitworks .NB-module-page-indicator' ) ;
$page _indicators . bind ( 'mouseenter' , _ . bind ( function ( e ) {
var page = $ ( e . target ) . prevAll ( '.NB-module-page-indicator' ) . length ;
this . load _howitworks _page ( page ) ;
} , this ) ) ;
} ,
2010-07-07 16:22:26 -04:00
load _howitworks _page : function ( page ) {
var self = this ;
var $next = $ ( '.NB-module-howitworks .NB-module-next-page' ) ;
var $previous = $ ( '.NB-module-howitworks .NB-module-previous-page' ) ;
var $pages = $ ( '.NB-howitworks-page' ) ;
var $page _indicators = $ ( '.NB-module-howitworks .NB-module-page-indicator' ) ;
var pages _count = $pages . length ;
if ( page == - 1 ) {
return ;
}
if ( page >= pages _count ) {
return ;
}
$pages . removeClass ( "NB-active" ) ;
$page _indicators . removeClass ( "NB-active" ) ;
$pages . eq ( page ) . addClass ( "NB-active" ) ;
$page _indicators . eq ( page ) . addClass ( "NB-active" ) ;
if ( page >= pages _count - 1 ) {
$next . addClass ( 'NB-disabled' ) ;
} else {
$next . removeClass ( 'NB-disabled' ) ;
}
if ( page <= 0 ) {
$previous . addClass ( 'NB-disabled' ) ;
} else {
$previous . removeClass ( 'NB-disabled' ) ;
}
} ,
2010-06-14 13:17:38 -04:00
// ========
// = FTUX =
// ========
2010-06-13 00:54:32 -04:00
2010-06-14 13:17:38 -04:00
setup _ftux _add _feed _callout : function ( ) {
2010-06-13 00:54:32 -04:00
var self = this ;
2010-06-14 13:17:38 -04:00
$ ( '.NB-callout-ftux .NB-callout-text' ) . text ( 'First things first...' ) ;
$ ( '.NB-callout-ftux' ) . corner ( '5px' ) ;
$ ( '.NB-callout-ftux' ) . css ( {
'opacity' : 0 ,
'display' : 'block'
} ) . animate ( {
'opacity' : 1 ,
2010-10-02 17:05:55 -04:00
'bottom' : 6
2010-06-13 00:54:32 -04:00
} , {
2010-06-14 13:17:38 -04:00
'duration' : 750 ,
'easing' : 'easeInOutQuint'
} ) . each ( function ( ) {
var $this = $ ( this ) ;
self . flags [ 'bouncing_callout' ] = setInterval ( function ( ) {
$this . animate ( { 'bottom' : '+=2px' } , { 'duration' : 200 , 'easing' : 'easeInOutQuint' } )
. animate ( { 'bottom' : '+=0px' } , { 'duration' : 50 } )
. animate ( { 'bottom' : '-=2px' } , { 'duration' : 200 , 'easing' : 'easeInOutQuint' } ) ;
2010-06-13 18:57:20 -04:00
} , 1000 ) ;
} ) ;
2010-06-13 00:54:32 -04:00
} ,
2010-06-14 13:17:38 -04:00
setup _ftux _signup _callout : function ( ) {
var self = this ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
if ( ! self . flags [ 'bouncing_callout' ] ) {
$ ( '.NB-callout-ftux-signup .NB-callout-text' ) . text ( 'Signup' ) ;
$ ( '.NB-callout-ftux-signup' ) . corner ( '5px' ) ;
$ ( '.NB-callout-ftux-signup' ) . css ( {
'opacity' : 0 ,
'display' : 'block'
} ) . animate ( {
'opacity' : 1 ,
'bottom' : 36
} , {
'duration' : 750 ,
'easing' : 'easeInOutQuint'
} ) . each ( function ( ) {
var $this = $ ( this ) ;
self . flags [ 'bouncing_callout' ] = setInterval ( function ( ) {
$this . animate ( { 'bottom' : '+=2px' } , { 'duration' : 200 , 'easing' : 'easeInOutQuint' } )
. animate ( { 'bottom' : '+=0px' } , { 'duration' : 50 } )
. animate ( { 'bottom' : '-=2px' } , { 'duration' : 200 , 'easing' : 'easeInOutQuint' } ) ;
} , 10000 ) ;
} ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2010-08-17 20:59:47 -04:00
// =============================
// = Import from Google Reader =
// =============================
2010-08-17 23:40:03 -04:00
2010-08-17 20:59:47 -04:00
start _import _from _google _reader : function ( ) {
2010-08-17 23:40:03 -04:00
var self = this ;
var $progress = this . $s . $feeds _progress ;
var $bar = $ ( '.NB-progress-bar' , $progress ) ;
var percentage = 0 ;
2011-02-01 00:23:44 -05:00
this . flags [ 'import_from_google_reader_working' ] = true ;
2010-08-17 23:40:03 -04:00
$ ( '.NB-progress-title' , $progress ) . text ( 'Importing from Google Reader' ) ;
$ ( '.NB-progress-counts' , $progress ) . hide ( ) ;
$ ( '.NB-progress-percentage' , $progress ) . hide ( ) ;
$bar . progressbar ( {
value : percentage
} ) ;
2011-01-31 19:51:39 -05:00
this . animate _progress _bar ( $bar , 4 ) ;
2010-08-17 23:40:03 -04:00
this . model . start _import _from _google _reader ( $ . rescope ( this . finish _import _from _google _reader , this ) ) ;
2010-11-24 15:01:35 -05:00
this . show _progress _bar ( ) ;
2010-08-17 20:59:47 -04:00
} ,
2010-08-17 23:40:03 -04:00
2010-08-17 20:59:47 -04:00
finish _import _from _google _reader : function ( e , data ) {
2010-08-17 23:40:03 -04:00
var $progress = this . $s . $feeds _progress ;
var $bar = $ ( '.NB-progress-bar' , $progress ) ;
2011-02-01 00:23:44 -05:00
this . flags [ 'import_from_google_reader_working' ] = false ;
clearTimeout ( this . locks [ 'animate_progress_bar' ] ) ;
2010-08-17 23:40:03 -04:00
if ( data . code >= 1 ) {
$bar . progressbar ( { value : 100 } ) ;
this . load _feeds ( ) ;
} else {
NEWSBLUR . log ( [ 'Import Error!' , data ] ) ;
this . $s . $feed _link _loader . fadeOut ( 250 ) ;
$progress . addClass ( 'NB-progress-error' ) ;
$ ( '.NB-progress-title' , $progress ) . text ( 'Error importing Google Reader' ) ;
$ ( '.NB-progress-link' , $progress ) . html ( $ . make ( 'a' , { href : NEWSBLUR . URLs [ 'google-reader-authorize' ] , className : 'NB-splash-link' } , 'Try importing again' ) ) ;
2011-11-01 09:25:59 -07:00
$ ( '.left-center-footer' ) . css ( 'height' , 'auto' ) ;
2010-08-17 23:40:03 -04:00
}
2010-08-17 20:59:47 -04:00
} ,
2010-08-17 23:40:03 -04:00
2010-08-17 20:59:47 -04:00
start _count _unreads _after _import : function ( ) {
2010-08-17 23:40:03 -04:00
var self = this ;
var $progress = this . $s . $feeds _progress ;
var $bar = $ ( '.NB-progress-bar' , $progress ) ;
var percentage = 0 ;
2011-01-31 19:51:39 -05:00
var feeds _count = _ . keys ( this . model . feeds ) . length ;
2010-08-17 23:40:03 -04:00
2010-12-31 14:35:00 -05:00
if ( ! this . flags [ 'pause_feed_refreshing' ] ) return ;
2011-02-01 00:23:44 -05:00
this . flags [ 'count_unreads_after_import_working' ] = true ;
2010-08-18 08:10:24 -04:00
2010-08-17 23:40:03 -04:00
$ ( '.NB-progress-title' , $progress ) . text ( 'Counting is difficult' ) ;
$ ( '.NB-progress-counts' , $progress ) . hide ( ) ;
$ ( '.NB-progress-percentage' , $progress ) . hide ( ) ;
$bar . progressbar ( {
value : percentage
} ) ;
setTimeout ( function ( ) {
2011-02-01 00:23:44 -05:00
if ( self . flags [ 'count_unreads_after_import_working' ] ) {
2011-02-06 15:04:21 -05:00
self . animate _progress _bar ( $bar , feeds _count / 10 ) ;
2010-08-17 23:40:03 -04:00
self . show _progress _bar ( ) ;
}
} , 500 ) ;
2010-08-17 20:59:47 -04:00
} ,
2010-08-17 23:40:03 -04:00
2010-08-17 20:59:47 -04:00
finish _count _unreads _after _import : function ( e , data ) {
2010-08-17 23:40:03 -04:00
$ ( '.NB-progress-bar' , this . $s . $feeds _progress ) . progressbar ( {
value : 100
} ) ;
2011-02-01 00:23:44 -05:00
this . flags [ 'count_unreads_after_import_working' ] = false ;
clearTimeout ( this . locks [ 'animate_progress_bar' ] ) ;
2010-08-17 23:40:03 -04:00
this . $s . $feed _link _loader . fadeOut ( 250 ) ;
this . setup _feed _refresh ( ) ;
if ( ! this . flags [ 'has_unfetched_feeds' ] ) {
this . hide _progress _bar ( ) ;
}
2010-08-17 20:59:47 -04:00
} ,
2010-09-04 17:02:26 -04:00
2011-03-02 12:05:58 -05:00
// =====================
// = Recommended Feeds =
// =====================
load _recommended _feeds : function ( ) {
2011-03-14 21:44:04 -04:00
// Reload recommended feeds every 10 minutes.
2011-04-12 11:02:02 -04:00
clearInterval ( this . locks . load _recommended _feed ) ;
this . locks . load _recommended _feed = setInterval ( _ . bind ( function ( ) {
2011-04-09 11:13:02 -04:00
this . load _recommended _feed ( 0 , true ) ;
2011-03-14 21:44:04 -04:00
} , this ) , 10 * 60 * 1000 ) ;
2011-03-02 12:05:58 -05:00
} ,
2011-05-18 22:33:42 -04:00
load _feed _in _tryfeed _view : function ( feed _id , feed ) {
feed = feed || { } ;
2011-03-15 23:42:27 -04:00
var $recommended _feeds = $ ( '.NB-module-recommended' ) ;
var $tryfeed _container = this . $s . $tryfeed _header . closest ( '.NB-feeds-header-container' ) ;
2011-03-15 10:21:47 -04:00
var feed = {
2011-03-15 23:42:27 -04:00
feed _id : feed _id ,
2011-05-18 22:33:42 -04:00
feed _title : feed . feed _title || $ ( '.NB-recommended-title' , $recommended _feeds ) . text ( ) ,
2011-05-20 17:34:39 -04:00
favicon : feed . favicon ? $ . favicon ( feed . favicon ) : $ ( '.NB-recommended-favicon' , $recommended _feeds ) . attr ( 'src' ) ,
feed _address : feed . feed _address
2011-03-15 10:21:47 -04:00
} ;
2011-03-15 23:42:27 -04:00
this . reset _feed ( ) ;
this . model . set _feed ( feed _id , feed ) ;
$ ( '.NB-feeds-header-title' , this . $s . $tryfeed _header ) . text ( feed . feed _title ) ;
$ ( '.NB-feeds-header-icon' , this . $s . $tryfeed _header ) . attr ( 'src' , feed . favicon ) ;
$tryfeed _container . slideDown ( 350 , _ . bind ( function ( ) {
this . open _feed ( feed _id ) ;
this . flags [ 'showing_feed_in_tryfeed_view' ] = true ;
this . $s . $tryfeed _header . addClass ( 'NB-selected' ) ;
} , this ) ) ;
} ,
hide _tryfeed _view : function ( ) {
var $tryfeed _container = this . $s . $tryfeed _header . closest ( '.NB-feeds-header-container' ) ;
$tryfeed _container . slideUp ( 350 ) ;
this . $s . $story _taskbar . find ( '.NB-tryfeed-add' ) . remove ( ) ;
this . flags [ 'showing_feed_in_tryfeed_view' ] = false ;
} ,
show _tryfeed _add _button : function ( ) {
2011-03-16 19:20:38 -04:00
if ( this . $s . $story _taskbar . find ( '.NB-tryfeed-add:visible' ) . length ) return ;
2011-03-15 23:42:27 -04:00
var $add = $ . make ( 'div' , { className : 'NB-modal-submit' } , [
$ . make ( 'div' , { className : 'NB-tryfeed-add NB-modal-submit-green NB-modal-submit-button' } , 'Add' )
] ) . css ( { 'opacity' : 0 } ) ;
this . $s . $story _taskbar . find ( '.NB-taskbar' ) . append ( $add ) ;
$add . animate ( { 'opacity' : 1 } , { 'duration' : 600 } ) ;
2011-03-11 20:05:41 -05:00
} ,
add _recommended _feed : function ( feed _id ) {
2011-03-15 23:42:27 -04:00
var feed _address = this . model . get _feed ( feed _id ? feed _id : this . active _feed ) . feed _address ;
this . open _add _feed _modal ( { url : feed _address } ) ;
2011-03-11 20:05:41 -05:00
} ,
2011-07-11 18:22:28 -07:00
approve _feed _in _moderation _queue : function ( feed _id ) {
2011-03-13 16:24:49 -04:00
var self = this ;
2011-07-11 18:22:28 -07:00
var $module = $ ( '.NB-module-recommended.NB-recommended-unmoderated' ) ;
$module . addClass ( 'NB-loading' ) ;
2011-07-11 18:44:47 -07:00
var date = $ ( '.NB-recommended-moderation-date' ) . val ( ) ;
2011-07-11 18:22:28 -07:00
2011-07-11 18:44:47 -07:00
this . model . approve _feed _in _moderation _queue ( feed _id , date , function ( resp ) {
2011-07-11 18:22:28 -07:00
if ( ! resp ) return ;
$module . removeClass ( 'NB-loading' ) ;
$module . replaceWith ( resp ) ;
self . load _javascript _elements _on _page ( ) ;
} ) ;
} ,
decline _feed _in _moderation _queue : function ( feed _id ) {
var self = this ;
var $module = $ ( '.NB-module-recommended.NB-recommended-unmoderated' ) ;
$module . addClass ( 'NB-loading' ) ;
this . model . decline _feed _in _moderation _queue ( feed _id , function ( resp ) {
if ( ! resp ) return ;
$module . removeClass ( 'NB-loading' ) ;
$module . replaceWith ( resp ) ;
self . load _javascript _elements _on _page ( ) ;
} ) ;
} ,
load _recommended _feed : function ( direction , refresh , unmoderated ) {
2011-03-13 16:24:49 -04:00
var self = this ;
2011-07-11 18:22:28 -07:00
var $module = unmoderated ?
$ ( '.NB-module-recommended.NB-recommended-unmoderated' ) :
$ ( '.NB-module-recommended:not(.NB-recommended-unmoderated)' ) ;
2011-03-13 16:24:49 -04:00
$module . addClass ( 'NB-loading' ) ;
direction = direction || 0 ;
2011-03-11 20:05:41 -05:00
2011-07-11 18:22:28 -07:00
this . model . load _recommended _feed ( this . counts [ 'recommended_feed_page' ] + direction ,
! ! refresh , unmoderated , function ( resp ) {
2011-03-20 20:12:21 -04:00
if ( ! resp ) return ;
2011-03-13 16:24:49 -04:00
self . counts [ 'recommended_feed_page' ] += direction ;
$module . removeClass ( 'NB-loading' ) ;
$module . replaceWith ( resp ) ;
self . load _javascript _elements _on _page ( ) ;
2011-04-09 13:07:12 -04:00
} , $ . noop ) ;
2011-03-11 20:05:41 -05:00
} ,
2011-04-24 22:47:20 -04:00
// ====================
// = Dashboard Graphs =
// ====================
setup _dashboard _graphs : function ( ) {
// Reload dashboard graphs every 10 minutes.
clearInterval ( this . locks . load _dashboard _graphs ) ;
this . locks . load _dashboard _graphs = setInterval ( _ . bind ( function ( ) {
this . load _dashboard _graphs ( ) ;
2011-12-18 18:03:40 -08:00
} , this ) , NEWSBLUR . Globals . is _staff ? 60 * 1000 : 10 * 60 * 1000 ) ;
2011-04-24 22:47:20 -04:00
} ,
2011-12-18 18:03:40 -08:00
load _dashboard _graphs : function ( ) {
2011-04-24 22:47:20 -04:00
var self = this ;
2011-12-20 08:55:55 -08:00
var $module = $ ( '.NB-module-site-stats' ) ;
2011-04-24 22:47:20 -04:00
$module . addClass ( 'NB-loading' ) ;
this . model . load _dashboard _graphs ( function ( resp ) {
if ( ! resp ) return ;
$module . removeClass ( 'NB-loading' ) ;
$module . replaceWith ( resp ) ;
self . load _javascript _elements _on _page ( ) ;
} , $ . noop ) ;
} ,
2011-12-18 18:03:40 -08:00
setup _feedback _table : function ( ) {
// Reload feedback module every 10 minutes.
clearInterval ( this . locks . load _feedback _table ) ;
this . locks . load _feedback _table = setInterval ( _ . bind ( function ( ) {
this . load _feedback _table ( ) ;
} , this ) , NEWSBLUR . Globals . is _staff ? 60 * 1000 : 10 * 60 * 1000 ) ;
} ,
load _feedback _table : function ( ) {
var self = this ;
var $module = $ ( '.NB-feedback-table' ) ;
$module . addClass ( 'NB-loading' ) ;
this . model . load _feedback _table ( function ( resp ) {
if ( ! resp ) return ;
$module . removeClass ( 'NB-loading' ) ;
2011-04-24 22:47:20 -04:00
$module . replaceWith ( resp ) ;
self . load _javascript _elements _on _page ( ) ;
} , $ . noop ) ;
} ,
2010-06-14 13:17:38 -04:00
// ==========
// = Events =
// ==========
2010-08-17 23:40:03 -04:00
2010-06-14 13:17:38 -04:00
handle _clicks : function ( elem , e ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-09-12 13:50:27 -04:00
var stopPropagation = false ;
2010-07-07 16:22:26 -04:00
// var start = (new Date().getMilliseconds());
2011-01-12 22:45:52 -05:00
// NEWSBLUR.log(['click', e, e.button]);
2010-09-12 13:50:27 -04:00
// Feeds ==========================================================
2010-06-08 11:19:41 -04:00
2010-09-11 17:15:08 -04:00
$ . targetIs ( e , { tagSelector : '#feed_list .NB-feedlist-manage-icon' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! self . flags [ 'sorting_feed' ] ) {
stopPropagation = true ;
if ( $t . parent ( ) . hasClass ( 'feed' ) ) {
2011-02-08 22:07:59 -05:00
self . show _manage _menu ( 'feed' , $t . closest ( '.feed' ) ) ;
2010-09-11 17:15:08 -04:00
} else {
2011-02-08 22:07:59 -05:00
var $folder = $t . closest ( '.folder' ) ;
self . show _manage _menu ( 'folder' , $folder ) ;
$folder . addClass ( 'NB-hover' ) ;
2010-09-11 17:15:08 -04:00
}
}
} ) ;
if ( stopPropagation ) return ;
2010-08-18 20:35:45 -04:00
$ . targetIs ( e , { tagSelector : '#feed_list .feed.NB-feed-exception' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! self . flags [ 'sorting_feed' ] ) {
2011-03-30 09:30:45 -04:00
var feed _id = parseInt ( $t . attr ( 'data-id' ) , 10 ) ;
2010-09-12 13:50:27 -04:00
stopPropagation = true ;
2010-08-18 20:35:45 -04:00
self . open _feed _exception _modal ( feed _id , $t ) ;
}
} ) ;
2010-09-11 17:15:08 -04:00
if ( stopPropagation ) return ;
2010-08-18 20:35:45 -04:00
2010-11-25 15:46:54 -05:00
$ . targetIs ( e , { tagSelector : '#feed_list .feed:not(.NB-empty)' } , function ( $t , $p ) {
2010-06-14 13:17:38 -04:00
e . preventDefault ( ) ;
2010-07-10 17:59:17 -04:00
if ( ! self . flags [ 'sorting_feed' ] ) {
2011-03-30 09:30:45 -04:00
var feed _id = parseInt ( $t . attr ( 'data-id' ) , 10 ) ;
2011-01-04 19:47:02 -05:00
if ( NEWSBLUR . hotkeys . command ) {
self . open _unread _stories _in _tabs ( feed _id ) ;
} else {
self . open _feed ( feed _id , false , $t ) ;
}
2010-07-10 17:59:17 -04:00
}
2010-06-14 13:17:38 -04:00
} ) ;
2011-10-31 18:04:25 -07:00
$ . targetIs ( e , { tagSelector : '#feed_list .folder_title .NB-feedlist-collapse-icon' } , function ( $t , $p ) {
2010-12-12 20:06:32 -05:00
e . preventDefault ( ) ;
stopPropagation = true ;
2011-10-31 18:04:25 -07:00
var $folder = $t . closest ( '.folder_title' ) ;
2010-09-05 18:08:08 -07:00
if ( ! self . flags [ 'sorting_feed' ] ) {
self . collapse _folder ( $folder ) ;
}
} ) ;
2011-10-31 18:04:25 -07:00
if ( stopPropagation ) return ;
$ . targetIs ( e , { tagSelector : '#feed_list .folder_title' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var $folder = $t . closest ( 'li.folder' ) ;
var folder _title = $t . find ( '.folder_title_text' ) . text ( ) ;
self . open _river _stories ( $folder , folder _title ) ;
} ) ;
2011-04-03 10:52:34 -04:00
// ============
// = Feed Bar =
// ============
$ . targetIs ( e , { tagSelector : '.NB-feedbar .NB-feedlist-manage-icon' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2011-09-27 23:06:49 -07:00
self . show _manage _menu ( 'feed' , $t . closest ( '.feed' ) , { toplevel : true } ) ;
2011-04-03 10:52:34 -04:00
} ) ;
2010-06-14 13:17:38 -04:00
$ . targetIs ( e , { tagSelector : '.NB-feedbar-mark-feed-read' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2011-03-30 09:30:45 -04:00
var feed _id = parseInt ( $t . closest ( '.feed' ) . attr ( 'data-id' ) , 10 ) ;
2010-06-14 13:17:38 -04:00
self . mark _feed _as _read ( feed _id , $t ) ;
$t . fadeOut ( 400 ) ;
} ) ;
2010-08-13 18:18:46 -04:00
$ . targetIs ( e , { tagSelector : '.NB-feedbar-statistics' } , function ( $t , $p ) {
self . open _feed _statistics _modal ( ) ;
} ) ;
2010-10-21 23:32:07 -04:00
$ . targetIs ( e , { tagSelector : '.NB-feedbar-train-feed' } , function ( $t , $p ) {
2010-06-14 13:17:38 -04:00
e . preventDefault ( ) ;
if ( ! $ ( '.NB-task-manage' ) . hasClass ( 'NB-disabled' ) ) {
2010-10-21 23:32:07 -04:00
self . open _feed _intelligence _modal ( 1 , this . active _feed , true ) ;
2010-06-14 13:17:38 -04:00
}
} ) ;
2010-11-01 18:20:26 -04:00
$ . targetIs ( e , { tagSelector : '.NB-story-title-indicator' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . show _hidden _story _titles ( ) ;
} ) ;
2010-06-08 11:19:41 -04:00
2010-12-02 11:09:09 -05:00
// = Feed Header ==================================================
$ . targetIs ( e , { tagSelector : '.NB-feeds-header-starred' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . open _starred _stories ( ) ;
} ) ;
2010-12-10 15:26:50 -05:00
$ . targetIs ( e , { tagSelector : '.NB-feeds-header-river' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2010-12-12 22:52:15 -05:00
self . open _river _stories ( ) ;
2010-12-10 15:26:50 -05:00
} ) ;
2010-12-02 11:09:09 -05:00
2010-09-12 13:50:27 -04:00
// = Feed Bar =====================================================
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
$ . targetIs ( e , { tagSelector : '.NB-feed-like' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . open _feed _intelligence _modal ( 1 ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-feed-dislike' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . open _feed _intelligence _modal ( - 1 ) ;
} ) ;
2010-06-08 11:19:41 -04:00
2010-09-12 13:50:27 -04:00
// = Stories ======================================================
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
var story _prevent _bubbling = false ;
2010-12-30 18:37:29 -05:00
$ . targetIs ( e , { tagSelector : '.NB-story-manage-icon' } , function ( $t , $p ) {
e . preventDefault ( ) ;
story _prevent _bubbling = true ;
self . show _manage _menu ( 'story' , $t . closest ( '.story' ) ) ;
} ) ;
2011-01-12 22:45:52 -05:00
$ . targetIs ( e , { tagSelector : '.NB-feed-story-manage-icon' } , function ( $t , $p ) {
e . preventDefault ( ) ;
story _prevent _bubbling = true ;
2011-09-27 23:06:49 -07:00
self . show _manage _menu ( 'story' , $t . closest ( '.NB-feed-story' ) ) ;
2011-01-12 22:45:52 -05:00
} ) ;
2011-02-23 11:40:25 -05:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-story-open' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var story _id = $t . closest ( '.NB-menu-manage-story' ) . data ( 'story_id' ) ;
self . open _story _in _new _tab ( story _id ) ;
story _prevent _bubbling = true ;
} ) ;
2010-12-30 18:37:29 -05:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-story-star' } , function ( $t , $p ) {
2010-06-14 13:17:38 -04:00
e . preventDefault ( ) ;
2010-12-30 18:37:29 -05:00
var story _id = $t . closest ( '.NB-menu-manage-story' ) . data ( 'story_id' ) ;
var $story = self . find _story _in _story _titles ( story _id ) ;
if ( $story . hasClass ( 'NB-story-starred' ) ) {
2011-12-14 21:56:27 -08:00
self . mark _story _as _unstarred ( story _id ) ;
2010-12-01 09:30:56 -05:00
} else {
2011-12-14 21:56:27 -08:00
self . mark _story _as _starred ( story _id ) ;
2010-12-01 09:30:56 -05:00
}
2010-06-14 13:17:38 -04:00
story _prevent _bubbling = true ;
} ) ;
2011-12-14 09:51:47 -08:00
$ . targetIs ( e , { tagSelector : '.NB-sideoption-share-save' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2011-12-14 21:56:27 -08:00
var story _id = $t . closest ( '.NB-feed-story' ) . data ( 'story_id' ) ;
self . mark _story _as _shared ( story _id ) ;
2011-12-14 09:51:47 -08:00
} ) ;
2011-04-11 23:25:44 -04:00
$ . targetIs ( e , { tagSelector : '.NB-feed-story-hide-changes' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var $story = $t . closest ( '.NB-feed-story' ) ;
self . hide _story _changes ( $story ) ;
story _prevent _bubbling = true ;
} ) ;
2010-06-08 11:19:41 -04:00
2010-06-14 13:17:38 -04:00
if ( story _prevent _bubbling ) return false ;
2010-06-08 11:19:41 -04:00
2011-03-09 09:48:24 -05:00
$ . targetIs ( e , { tagSelector : '.NB-feed-story-tag' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var $story = $t . closest ( '.NB-feed-story' ) ;
var feed _id = $story . data ( 'feed_id' ) ;
2011-03-17 18:33:59 -04:00
var classifier _type = 'tag' ;
var tag = $t . data ( classifier _type ) ;
var score = $t . hasClass ( 'NB-score-1' ) ? - 1 : $t . hasClass ( 'NB-score--1' ) ? 0 : 1 ;
self . save _classifier ( classifier _type , tag , score , feed _id ) ;
self . preserve _classifier _color ( $story , classifier _type , tag , score ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-feed-story-author' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var $story = $t . closest ( '.NB-feed-story' ) ;
var feed _id = $story . data ( 'feed_id' ) ;
var classifier _type = 'author' ;
var author = $t . data ( classifier _type ) ;
2011-03-09 09:48:24 -05:00
var score = $t . hasClass ( 'NB-score-1' ) ? - 1 : $t . hasClass ( 'NB-score--1' ) ? 0 : 1 ;
2011-03-17 18:33:59 -04:00
self . save _classifier ( classifier _type , author , score , feed _id ) ;
2011-03-17 20:06:38 -04:00
self . preserve _classifier _color ( $story , classifier _type , author , score ) ;
2011-03-09 09:48:24 -05:00
} ) ;
2011-12-12 20:06:30 -08:00
$ . targetIs ( e , { tagSelector : '.NB-feed-story-train' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var $story = $t . closest ( '.NB-feed-story' ) ;
var feed _id = $story . data ( 'feed_id' ) ;
var story _id = $story . data ( 'story_id' ) ;
self . open _story _trainer ( story _id , feed _id ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-feed-story-save' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2011-12-14 21:56:27 -08:00
var story _id = $t . closest ( '.NB-feed-story' ) . data ( 'story_id' ) ;
2011-12-12 20:06:30 -08:00
var $story = self . find _story _in _story _titles ( story _id ) ;
if ( $story . hasClass ( 'NB-story-starred' ) ) {
2011-12-14 21:56:27 -08:00
self . mark _story _as _unstarred ( story _id ) ;
2011-12-12 20:06:30 -08:00
} else {
2011-12-14 21:56:27 -08:00
self . mark _story _as _starred ( story _id ) ;
2011-12-12 20:06:30 -08:00
}
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-feed-story-share' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var $story = $t . closest ( '.NB-feed-story' ) ;
var feed _id = $story . data ( 'feed_id' ) ;
var story _id = $story . data ( 'story_id' ) ;
2011-12-14 21:56:27 -08:00
self . toggle _feed _story _share _dialog ( story _id , feed _id ) ;
2011-12-12 20:06:30 -08:00
} ) ;
2011-03-09 09:48:24 -05:00
2010-06-14 13:17:38 -04:00
$ . targetIs ( e , { tagSelector : '.story' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var story _id = $ ( '.story_id' , $t ) . text ( ) ;
self . push _current _story _on _history ( ) ;
2010-12-14 17:08:52 -05:00
if ( NEWSBLUR . hotkeys . command ) {
2011-02-23 11:40:25 -05:00
self . open _story _in _new _tab ( story _id , $t ) ;
2010-12-14 17:08:52 -05:00
} else {
2011-02-23 11:40:25 -05:00
var story = self . model . get _story ( story _id ) ;
2010-12-14 17:08:52 -05:00
self . open _story ( story , $t ) ;
}
2010-06-14 13:17:38 -04:00
} ) ;
$ . targetIs ( e , { tagSelector : 'a.mark_story_as_read' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var story _id = $t . attr ( 'href' ) . slice ( 1 ) . split ( '/' ) ;
2010-12-30 19:24:52 -05:00
self . mark _story _as _read ( story _id ) ;
2010-06-14 13:17:38 -04:00
} ) ;
2011-02-22 22:00:32 -05:00
$ . targetIs ( e , { tagSelector : '.NB-feed-story-premium-only a' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . open _feedchooser _modal ( ) ;
} ) ;
2010-06-08 11:19:41 -04:00
2010-09-12 13:50:27 -04:00
// = Taskbar ======================================================
2010-06-14 13:17:38 -04:00
$ . targetIs ( e , { tagSelector : '.NB-task-add' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . open _add _feed _modal ( ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-task-manage' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
2010-09-12 13:50:27 -04:00
self . show _manage _menu ( 'site' , $t ) ;
2010-06-14 13:17:38 -04:00
}
} ) ;
2011-02-22 19:11:29 -05:00
$ . targetIs ( e , { tagSelector : '.NB-taskbar-sidebar-toggle-close' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . close _sidebar ( ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-taskbar-sidebar-toggle-open' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . open _sidebar ( ) ;
} ) ;
2010-07-24 00:04:14 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-train' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
2010-09-12 13:50:27 -04:00
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
2010-09-17 12:40:42 -04:00
self . open _feed _intelligence _modal ( 1 , feed _id , false ) ;
2010-07-24 00:04:14 -04:00
}
} ) ;
2011-03-28 10:08:10 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-recommend' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
self . open _recommend _modal ( feed _id ) ;
} ) ;
2010-12-30 19:24:52 -05:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-story-train' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
var feed _id = $t . closest ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
var story _id = $t . closest ( '.NB-menu-manage' ) . data ( 'story_id' ) ;
2011-03-06 21:33:06 -05:00
self . open _story _trainer ( story _id , feed _id ) ;
2010-12-30 19:24:52 -05:00
}
} ) ;
2010-08-01 23:47:40 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-trainer' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _trainer _modal ( ) ;
}
} ) ;
2011-05-10 18:30:35 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-tutorial' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _tutorial _modal ( ) ;
}
} ) ;
2010-07-24 00:04:14 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-stats' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
2010-09-12 13:50:27 -04:00
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
NEWSBLUR . log ( [ 'statistics feed_id' , feed _id ] ) ;
self . open _feed _statistics _modal ( feed _id ) ;
2010-06-14 13:17:38 -04:00
}
} ) ;
2011-09-26 09:22:46 -07:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-settings' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
self . open _feed _exception _modal ( feed _id , $t ) ;
}
} ) ;
2010-10-10 20:14:31 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-reload' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
2010-12-24 11:00:30 -05:00
self . force _instafetch _stories ( feed _id ) ;
2010-10-10 20:14:31 -04:00
}
} ) ;
2010-09-14 20:49:28 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-delete' } , function ( $t , $p ) {
2010-07-01 00:29:26 -04:00
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2010-09-14 20:49:28 -04:00
if ( $t . hasClass ( 'NB-menu-manage-feed-delete-cancel' ) ||
$t . hasClass ( 'NB-menu-manage-folder-delete-cancel' ) ) {
2010-07-01 00:29:26 -04:00
self . hide _confirm _delete _menu _item ( ) ;
} else {
self . show _confirm _delete _menu _item ( ) ;
}
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-delete-confirm' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2010-09-12 13:50:27 -04:00
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
2010-09-14 20:49:28 -04:00
var $feed = $t . parents ( '.NB-menu-manage' ) . data ( '$feed' ) ;
self . manage _menu _delete _feed ( feed _id , $feed ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-folder-delete-confirm' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var folder _name = $t . parents ( '.NB-menu-manage' ) . data ( 'folder_name' ) ;
var $folder = $t . parents ( '.NB-menu-manage' ) . data ( '$folder' ) ;
self . manage _menu _delete _folder ( folder _name , $folder ) ;
2010-07-01 00:29:26 -04:00
} ) ;
2011-09-04 15:42:13 -07:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-move' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
var $feed = $t . parents ( '.NB-menu-manage' ) . data ( '$feed' ) ;
var folder _name = $t . parents ( '.NB-menu-manage' ) . data ( 'folder_name' ) ;
var $folder = $t . parents ( '.NB-menu-manage' ) . data ( '$folder' ) ;
if ( $t . hasClass ( 'NB-menu-manage-feed-move-cancel' ) ||
$t . hasClass ( 'NB-menu-manage-folder-move-cancel' ) ) {
self . hide _confirm _move _menu _item ( ) ;
} else {
self . show _confirm _move _menu _item ( feed _id || folder _name , $feed || $folder ) ;
}
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-folder-move-save' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var folder _name = $t . parents ( '.NB-menu-manage' ) . data ( 'folder_name' ) ;
var $folder = $t . parents ( '.NB-menu-manage' ) . data ( '$folder' ) ;
2011-11-07 20:50:46 -08:00
self . manage _menu _move _folder ( folder _name , $folder ) ;
2011-09-04 15:42:13 -07:00
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-move-save' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
var $feed = $t . parents ( '.NB-menu-manage' ) . data ( '$feed' ) ;
self . manage _menu _move _feed ( feed _id , $feed ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-move-confirm' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-folder-move-confirm' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
} ) ;
2010-12-11 11:26:21 -05:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-rename' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
if ( $t . hasClass ( 'NB-menu-manage-feed-rename-cancel' ) ||
$t . hasClass ( 'NB-menu-manage-folder-rename-cancel' ) ) {
self . hide _confirm _rename _menu _item ( ) ;
} else {
self . show _confirm _rename _menu _item ( ) ;
}
} ) ;
2010-12-11 12:41:24 -05:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-folder-rename-save' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var folder _name = $t . parents ( '.NB-menu-manage' ) . data ( 'folder_name' ) ;
var $folder = $t . parents ( '.NB-menu-manage' ) . data ( '$folder' ) ;
self . manage _menu _rename _folder ( folder _name , $folder ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-rename-save' } , function ( $t , $p ) {
2010-12-11 11:26:21 -05:00
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
var $feed = $t . parents ( '.NB-menu-manage' ) . data ( '$feed' ) ;
self . manage _menu _rename _feed ( feed _id , $feed ) ;
} ) ;
2010-12-11 12:41:24 -05:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-rename-confirm' } , function ( $t , $p ) {
2010-12-11 11:26:21 -05:00
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
} ) ;
2010-12-11 12:41:24 -05:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-folder-rename-confirm' } , function ( $t , $p ) {
2010-12-11 11:26:21 -05:00
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
} ) ;
2010-07-24 00:04:14 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-mark-read' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2010-09-12 13:50:27 -04:00
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
self . mark _feed _as _read ( feed _id ) ;
2010-07-24 00:04:14 -04:00
} ) ;
2010-09-16 10:35:36 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-folder-mark-read' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var folder _name = $t . parents ( '.NB-menu-manage' ) . data ( 'folder_name' ) ;
var $folder = $t . parents ( '.NB-menu-manage' ) . data ( '$folder' ) ;
self . mark _folder _as _read ( folder _name , $folder ) ;
} ) ;
2010-09-14 20:49:28 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-site-mark-read' } , function ( $t , $p ) {
2010-06-14 13:17:38 -04:00
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _mark _read _modal ( ) ;
}
} ) ;
2010-10-10 23:36:09 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-keyboard' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _keyboard _shortcuts _modal ( ) ;
}
} ) ;
2010-09-13 00:38:25 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feed-exception' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var feed _id = $t . parents ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
self . open _feed _exception _modal ( feed _id , $t ) ;
} ) ;
2011-01-20 09:57:23 -05:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-goodies' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _goodies _modal ( ) ;
}
} ) ;
2011-12-22 13:36:03 -08:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-friends' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _friends _modal ( ) ;
}
} ) ;
2010-06-14 13:17:38 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-preferences' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _preferences _modal ( ) ;
2010-06-08 11:19:41 -04:00
}
2010-06-14 13:17:38 -04:00
} ) ;
2011-07-27 09:33:34 -07:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-account' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _account _modal ( ) ;
}
} ) ;
2010-09-24 01:08:03 -04:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-feedchooser' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _feedchooser _modal ( ) ;
}
} ) ;
2010-10-17 17:25:10 -04:00
$ . targetIs ( e , { tagSelector : '.NB-module-account-upgrade' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _feedchooser _modal ( ) ;
}
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-module-account-train' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _trainer _modal ( ) ;
}
} ) ;
2011-12-21 18:23:53 -08:00
$ . targetIs ( e , { tagSelector : '.NB-module-friends-button' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _friends _modal ( ) ;
}
} ) ;
2011-05-10 18:30:35 -04:00
$ . targetIs ( e , { tagSelector : '.NB-module-launch-tutorial' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . open _tutorial _modal ( ) ;
}
} ) ;
2011-05-13 10:15:56 -04:00
$ . targetIs ( e , { tagSelector : '.NB-module-tutorial-hide' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . hide _tutorial ( ) ;
}
} ) ;
2011-08-07 21:38:09 -07:00
$ . targetIs ( e , { tagSelector : '.NB-module-mobile-hide' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
self . hide _mobile ( ) ;
}
} ) ;
2010-12-30 19:24:52 -05:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-story-unread' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var feed _id = $t . closest ( '.NB-menu-manage' ) . data ( 'feed_id' ) ;
var story _id = $t . closest ( '.NB-menu-manage' ) . data ( 'story_id' ) ;
self . mark _story _as _unread ( story _id , feed _id ) ;
} ) ;
2011-02-02 14:10:24 -05:00
$ . targetIs ( e , { tagSelector : '.task_view_page:not(.NB-task-return)' } , function ( $t , $p ) {
2010-06-14 13:17:38 -04:00
e . preventDefault ( ) ;
2011-02-02 14:10:24 -05:00
self . switch _taskbar _view ( 'page' ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.task_view_feed' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . switch _taskbar _view ( 'feed' ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.task_view_story' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . switch _taskbar _view ( 'story' ) ;
2010-06-08 11:19:41 -04:00
} ) ;
2011-02-02 14:10:24 -05:00
$ . targetIs ( e , { tagSelector : '.NB-task-return' } , function ( $t , $p ) {
2010-06-14 13:17:38 -04:00
e . preventDefault ( ) ;
2010-12-06 10:41:24 -05:00
self . load _feed _iframe ( ) ;
2010-06-14 13:17:38 -04:00
} ) ;
$ . targetIs ( e , { tagSelector : '.task_button_story.task_story_next_unread' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2011-04-30 22:09:43 -04:00
self . open _next _unread _story _across _feeds ( ) ;
2010-06-14 13:17:38 -04:00
} ) ;
$ . targetIs ( e , { tagSelector : '.task_button_story.task_story_next' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . show _next _story ( 1 ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.task_button_story.task_story_previous' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . show _previous _story ( ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.task_button_signup' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . show _splash _page ( ) ;
} ) ;
2010-12-04 23:18:07 -05:00
$ . targetIs ( e , { tagSelector : '.NB-feeds-header-sites' } , function ( $t , $p ) {
2010-12-04 23:06:35 -05:00
e . preventDefault ( ) ;
stopPropagation = true ;
self . switch _preferences _hide _read _feeds ( ) ;
} ) ;
if ( stopPropagation ) return ;
2011-03-14 21:44:04 -04:00
$ . targetIs ( e , { tagSelector : '.NB-feeds-header-dashboard' } , function ( $t , $p ) {
2010-11-22 10:44:52 -05:00
e . preventDefault ( ) ;
self . show _splash _page ( ) ;
} ) ;
2010-06-08 11:19:41 -04:00
2011-03-04 12:27:31 -05:00
// =====================
// = Recommended Feeds =
// =====================
$ . targetIs ( e , { tagSelector : '.NB-recommended-statistics' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var feed _id = $t . closest ( '.NB-recommended' ) . attr ( 'data-feed-id' ) ;
2011-03-04 12:45:31 -05:00
$ ( '.NB-module-recommended' ) . addClass ( 'NB-loading' ) ;
2011-03-04 12:27:31 -05:00
self . model . load _canonical _feed ( feed _id , function ( ) {
2011-03-04 12:45:31 -05:00
$ ( '.NB-module-recommended' ) . removeClass ( 'NB-loading' ) ;
2011-03-04 12:27:31 -05:00
self . open _feed _statistics _modal ( feed _id ) ;
} ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-recommended-intelligence' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var feed _id = $t . closest ( '.NB-recommended' ) . attr ( 'data-feed-id' ) ;
2011-03-04 12:45:31 -05:00
$ ( '.NB-module-recommended' ) . addClass ( 'NB-loading' ) ;
2011-03-04 12:27:31 -05:00
self . model . load _canonical _feed ( feed _id , function ( ) {
2011-03-04 12:45:31 -05:00
$ ( '.NB-module-recommended' ) . removeClass ( 'NB-loading' ) ;
2011-03-04 12:27:31 -05:00
self . open _feed _intelligence _modal ( 1 , feed _id ) ;
} ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-recommended-try' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var feed _id = $t . closest ( '.NB-recommended' ) . attr ( 'data-feed-id' ) ;
2011-03-15 10:21:47 -04:00
self . load _feed _in _tryfeed _view ( feed _id ) ;
2011-03-04 12:27:31 -05:00
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-recommended-add' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var feed _id = $t . closest ( '.NB-recommended' ) . attr ( 'data-feed-id' ) ;
2011-03-11 20:05:41 -05:00
$ ( '.NB-module-recommended' ) . addClass ( 'NB-loading' ) ;
self . model . load _canonical _feed ( feed _id , function ( ) {
$ ( '.NB-module-recommended' ) . removeClass ( 'NB-loading' ) ;
self . add _recommended _feed ( feed _id ) ;
} ) ;
2011-03-04 12:27:31 -05:00
} ) ;
2011-07-11 18:22:28 -07:00
$ . targetIs ( e , { tagSelector : '.NB-recommended-decline' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var feed _id = $t . closest ( '.NB-recommended' ) . attr ( 'data-feed-id' ) ;
self . decline _feed _in _moderation _queue ( feed _id ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-recommended-approve' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var feed _id = $t . closest ( '.NB-recommended' ) . attr ( 'data-feed-id' ) ;
self . approve _feed _in _moderation _queue ( feed _id ) ;
} ) ;
2011-03-04 12:27:31 -05:00
$ . targetIs ( e , { tagSelector : '.NB-module-recommended .NB-module-next-page' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2011-03-13 16:24:49 -04:00
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
2011-07-11 18:22:28 -07:00
console . log ( [ 'parent' , $t . closest ( '.NB-module-recommended' ) , $t . closest ( '.NB-module-recommended' ) . hasClass ( 'NB-recommended-unmoderated' ) ] ) ;
var unmoderated = $t . closest ( '.NB-module-recommended' ) . hasClass ( 'NB-recommended-unmoderated' ) ;
self . load _recommended _feed ( 1 , false , unmoderated ) ;
2011-03-13 16:24:49 -04:00
}
2011-03-04 12:27:31 -05:00
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-module-recommended .NB-module-previous-page' } , function ( $t , $p ) {
e . preventDefault ( ) ;
if ( ! $t . hasClass ( 'NB-disabled' ) ) {
2011-07-11 18:22:28 -07:00
var unmoderated = $t . closest ( '.NB-module-recommended' ) . hasClass ( 'NB-recommended-unmoderated' ) ;
console . log ( [ 'parent' , $t . closest ( '.NB-module-recommended' ) ] ) ;
self . load _recommended _feed ( - 1 , false , unmoderated ) ;
2011-03-04 12:27:31 -05:00
}
} ) ;
2011-03-15 23:42:27 -04:00
$ . targetIs ( e , { tagSelector : '.NB-tryfeed-add' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var feed _id = self . active _feed ;
self . add _recommended _feed ( feed _id ) ;
} ) ;
2010-09-12 13:50:27 -04:00
// = One-offs =====================================================
2010-07-07 16:22:26 -04:00
var clicked = false ;
2010-06-14 13:17:38 -04:00
$ . targetIs ( e , { tagSelector : '#mouse-indicator' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . lock _mouse _indicator ( ) ;
} ) ;
2010-08-17 23:40:03 -04:00
$ . targetIs ( e , { tagSelector : '.NB-progress-close' } , function ( $t , $p ) {
2010-08-11 22:02:47 -04:00
e . preventDefault ( ) ;
self . hide _unfetched _feed _progress ( true ) ;
} ) ;
2010-07-07 16:22:26 -04:00
$ . targetIs ( e , { tagSelector : '.NB-module-next-page' , childOf : '.NB-module-features' } , function ( $t , $p ) {
2010-06-30 12:17:22 -04:00
e . preventDefault ( ) ;
self . load _feature _page ( 1 ) ;
} ) ;
2010-07-07 16:22:26 -04:00
$ . targetIs ( e , { tagSelector : '.NB-module-previous-page' , childOf : '.NB-module-features' } , function ( $t , $p ) {
2010-06-30 12:17:22 -04:00
e . preventDefault ( ) ;
self . load _feature _page ( - 1 ) ;
} ) ;
2010-07-07 16:22:26 -04:00
$ . targetIs ( e , { tagSelector : '.NB-module-next-page' , childOf : '.NB-module-howitworks' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var page = $ ( '.NB-howitworks-page.NB-active' ) . prevAll ( '.NB-howitworks-page' ) . length ;
self . load _howitworks _page ( page + 1 ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-module-previous-page' , childOf : '.NB-module-howitworks' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var page = $ ( '.NB-howitworks-page.NB-active' ) . prevAll ( '.NB-howitworks-page' ) . length ;
self . load _howitworks _page ( page - 1 ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-module-page-indicator' , childOf : '.NB-module-howitworks' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var page = $t . prevAll ( '.NB-module-page-indicator' ) . length ;
self . load _howitworks _page ( page ) ;
} ) ;
2010-09-02 20:41:53 -04:00
$ . targetIs ( e , { tagSelector : '.NB-splash-meta-about' } , function ( $t , $p ) {
e . preventDefault ( ) ;
NEWSBLUR . about = new NEWSBLUR . About ( ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-splash-meta-faq' } , function ( $t , $p ) {
e . preventDefault ( ) ;
NEWSBLUR . faq = new NEWSBLUR . Faq ( ) ;
} ) ;
2010-07-07 16:22:26 -04:00
// NEWSBLUR.log(['End', (new Date().getMilliseconds()) - start]);
2010-06-08 11:19:41 -04:00
} ,
2010-06-14 13:17:38 -04:00
handle _dblclicks : function ( elem , e ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-09-12 13:50:27 -04:00
var stopPropagation = false ;
$ . targetIs ( e , { tagSelector : '#feed_list .NB-feedlist-manage-icon' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
stopPropagation = true ;
} ) ;
if ( stopPropagation ) return ;
$ . targetIs ( e , { tagSelector : '#feed_list .feed.NB-feed-exception' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
exception = true ;
} ) ;
if ( stopPropagation ) return ;
2010-06-14 13:17:38 -04:00
$ . targetIs ( e , { tagSelector : '#story_titles .story' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
// NEWSBLUR.log(['Story dblclick', $t]);
var story _id = $ ( '.story_id' , $t ) . text ( ) ;
var story = self . model . get _story ( story _id ) ;
2010-12-07 09:52:14 -05:00
self . open _story _in _story _view ( story , true ) ;
2010-06-14 13:17:38 -04:00
} ) ;
$ . targetIs ( e , { tagSelector : '#feed_list .feed' } , function ( $t , $p ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
// NEWSBLUR.log(['Feed dblclick', $('.feed_id', $t), $t]);
2011-03-30 09:30:45 -04:00
var feed _id = parseInt ( $t . attr ( 'data-id' ) , 10 ) ;
2010-06-14 13:17:38 -04:00
self . open _feed _link ( feed _id , $t ) ;
} ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-12-31 14:35:00 -05:00
handle _rightclicks : function ( elem , e ) {
var self = this ;
2011-02-01 00:51:19 -05:00
// NEWSBLUR.log(['right click', e.button, e, e.target, e.currentTarget]);
2010-12-31 14:35:00 -05:00
2011-02-01 22:58:00 -05:00
$ . targetIs ( e , { tagSelector : '.feed' , childOf : '#feed_list' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . show _manage _menu ( 'feed' , $t ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.folder_title' , childOf : '#feed_list' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . show _manage _menu ( 'folder' , $t . closest ( 'li.folder' ) ) ;
} ) ;
2010-12-31 14:35:00 -05:00
$ . targetIs ( e , { tagSelector : '.story' , childOf : '#story_titles' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . show _manage _menu ( 'story' , $t ) ;
} ) ;
2011-01-12 22:45:52 -05:00
$ . targetIs ( e , { tagSelector : '.NB-feed-story-header' , childOf : '#story_pane' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2011-09-27 23:06:49 -07:00
self . show _manage _menu ( 'story' , $t . closest ( '.NB-feed-story' ) ) ;
2011-01-12 22:45:52 -05:00
} ) ;
2010-12-31 14:35:00 -05:00
$ . targetIs ( e , { tagSelector : '.NB-menu-manage' } , function ( $t , $p ) {
e . preventDefault ( ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-menu-manage-arrow' } , function ( $t , $p ) {
e . preventDefault ( ) ;
} ) ;
} ,
2010-06-14 13:17:38 -04:00
handle _scroll _story _titles : function ( elem , e ) {
var self = this ;
2011-09-27 22:16:09 -07:00
this . check _story _titles _last _story ( ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-12-06 10:41:24 -05:00
handle _scroll _feed _iframe : function ( elem , e ) {
2010-06-14 13:17:38 -04:00
var self = this ;
if ( this . story _view == 'page'
&& ! this . flags [ 'page_view_showing_feed_view' ]
&& ! this . flags [ 'scrolling_by_selecting_story_title' ] ) {
2010-12-06 10:41:24 -05:00
var from _top = this . cache . mouse _position _y + this . $s . $feed _iframe . contents ( ) . scrollTop ( ) ;
2010-06-14 13:17:38 -04:00
var positions = this . cache . iframe _story _positions _keys ;
var closest = $ . closest ( from _top , positions ) ;
var story = this . cache . iframe _story _positions [ positions [ closest ] ] ;
// NEWSBLUR.log(['Scroll iframe', from_top, closest, positions[closest], this.cache.iframe_story_positions[positions[closest]]]);
this . navigate _story _titles _to _story ( story ) ;
2010-07-24 18:22:23 -04:00
if ( ! this . flags . iframe _scroll _snap _back _prepared ) {
this . iframe _scroll = from _top - this . cache . mouse _position _y ;
}
2010-06-14 13:17:38 -04:00
this . flags . iframe _scroll _snap _back _prepared = false ;
// NEWSBLUR.log(['Setting snap back', this.iframe_scroll]);
}
2010-06-08 11:19:41 -04:00
} ,
2010-06-15 18:29:13 -04:00
handle _mousemove _iframe _view : function ( elem , e ) {
var self = this ;
this . show _mouse _indicator ( ) ;
2010-06-14 13:17:38 -04:00
if ( parseInt ( this . model . preference ( 'lock_mouse_indicator' ) , 10 ) ) {
return ;
}
2010-12-06 10:41:24 -05:00
var scroll _top = this . $s . $feed _iframe . contents ( ) . scrollTop ( ) ;
2010-06-14 13:17:38 -04:00
this . cache . mouse _position _y = e . pageY - scroll _top ;
this . $s . $mouse _indicator . css ( 'top' , this . cache . mouse _position _y - 8 ) ;
setTimeout ( function ( ) {
self . flags [ 'mousemove_timeout' ] = false ;
} , 40 ) ;
if ( ! this . flags [ 'mousemove_timeout' ]
&& ! this . flags . scrolling _by _selecting _story _title ) {
var from _top = this . cache . mouse _position _y + scroll _top ;
var positions = this . cache . iframe _story _positions _keys ;
var closest = $ . closest ( from _top , positions ) ;
var story = this . cache . iframe _story _positions [ positions [ closest ] ] ;
this . flags [ 'mousemove_timeout' ] = true ;
this . navigate _story _titles _to _story ( story ) ;
// NEWSBLUR.log(['Setting snap back', this.iframe_scroll]);
}
2010-06-08 11:19:41 -04:00
} ,
2010-12-09 09:59:45 -05:00
handle _mousemove _feed _view : function ( elem , e ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-12-09 09:59:45 -05:00
if ( this . model . preference ( 'feed_view_single_story' ) ) {
return this . hide _mouse _indicator ( ) ;
} else {
this . show _mouse _indicator ( ) ;
}
if ( parseInt ( this . model . preference ( 'lock_mouse_indicator' ) , 10 ) ) {
return ;
}
this . cache . mouse _position _y = e . pageY ;
2011-10-19 18:42:49 -07:00
if ( this . cache . story _pane _position == null ) {
2011-10-19 23:04:45 -07:00
this . cache . story _pane _position = this . $s . $feed _stories . offsetParent ( ) . offset ( ) . top ;
2011-10-19 18:42:49 -07:00
}
this . $s . $mouse _indicator . css ( 'top' , this . cache . mouse _position _y - this . cache . story _pane _position - 8 ) ;
2010-12-09 09:59:45 -05:00
if ( this . flags [ 'mousemove_timeout' ] ) {
return ;
}
setTimeout ( function ( ) {
self . flags [ 'mousemove_timeout' ] = false ;
} , 40 ) ;
if ( ! this . flags [ 'mousemove_timeout' ]
2010-06-14 13:17:38 -04:00
&& ! this . flags [ 'switching_to_feed_view' ]
&& ! this . flags . scrolling _by _selecting _story _title
&& this . story _view != 'story' ) {
2011-01-24 23:50:38 -05:00
var from _top = this . cache . mouse _position _y + this . $s . $feed _stories . scrollTop ( ) ;
2011-10-19 23:04:45 -07:00
var offset = this . cache . story _pane _position ;
var position = from _top - offset ;
2010-06-14 13:17:38 -04:00
var positions = this . cache . feed _view _story _positions _keys ;
2011-10-19 23:04:45 -07:00
var closest = $ . closest ( position , positions ) ;
2010-06-14 13:17:38 -04:00
var story = this . cache . feed _view _story _positions [ positions [ closest ] ] ;
2010-12-09 09:59:45 -05:00
this . flags [ 'mousemove_timeout' ] = true ;
2011-01-11 21:37:38 -05:00
if ( story == this . active _story ) return ;
2010-12-09 09:59:45 -05:00
// NEWSBLUR.log(['Mousemove feed view', from_top, closest, positions[closest]]);
this . navigate _story _titles _to _story ( story ) ;
}
} ,
2010-06-14 13:17:38 -04:00
handle _scroll _feed _view : function ( elem , e ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2011-02-23 19:41:05 -05:00
// NEWSBLUR.log(['handle_scroll_feed_view', this.story_view, this.flags['switching_to_feed_view'], this.flags['scrolling_by_selecting_story_title']]);
2010-12-08 20:53:45 -05:00
if ( ( this . story _view == 'feed' ||
( this . story _view == 'page' && this . flags [ 'page_view_showing_feed_view' ] ) ) &&
! this . flags [ 'switching_to_feed_view' ] &&
! this . flags [ 'scrolling_by_selecting_story_title' ] &&
! this . model . preference ( 'feed_view_single_story' ) ) {
2011-01-24 23:50:38 -05:00
var from _top = this . cache . mouse _position _y + this . $s . $feed _stories . scrollTop ( ) ;
2011-10-19 23:04:45 -07:00
var offset = this . cache . story _pane _position ;
var position = from _top - offset ;
2010-06-14 13:17:38 -04:00
var positions = this . cache . feed _view _story _positions _keys ;
2011-10-19 23:04:45 -07:00
var closest = $ . closest ( position , positions ) ;
2010-06-14 13:17:38 -04:00
var story = this . cache . feed _view _story _positions [ positions [ closest ] ] ;
// NEWSBLUR.log(['Scroll feed view', from_top, e, closest, positions[closest], this.cache.feed_view_story_positions_keys, positions, self.cache]);
this . navigate _story _titles _to _story ( story ) ;
2010-06-13 20:10:48 -04:00
}
2011-01-24 23:50:38 -05:00
if ( this . flags . river _view &&
! this . model . preference ( 'feed_view_single_story' ) ) {
2011-01-26 19:36:28 -05:00
var story ;
if ( this . flags . scrolling _by _selecting _story _title ) {
story = this . active _story ;
} else {
var from _top = Math . max ( 1 , this . $s . $feed _stories . scrollTop ( ) ) ;
var positions = this . cache . feed _view _story _positions _keys ;
var closest = $ . closest ( from _top , positions ) ;
story = this . cache . feed _view _story _positions [ positions [ closest ] ] ;
}
2011-01-30 23:00:22 -05:00
2011-01-24 23:50:38 -05:00
this . show _correct _feed _in _feed _title _floater ( story ) ;
}
2010-06-14 14:00:46 -04:00
} ,
handle _keystrokes : function ( ) {
var self = this ;
var $document = $ ( document ) ;
2010-12-14 17:08:52 -05:00
NEWSBLUR . hotkeys . initialize ( ) ;
2010-10-12 20:22:18 -04:00
$document . bind ( 'keydown' , '?' , function ( e ) {
e . preventDefault ( ) ;
self . open _keyboard _shortcuts _modal ( ) ;
} ) ;
2010-10-12 20:23:03 -04:00
$document . bind ( 'keydown' , 'shift+/' , function ( e ) {
e . preventDefault ( ) ;
self . open _keyboard _shortcuts _modal ( ) ;
} ) ;
2010-06-14 14:00:46 -04:00
$document . bind ( 'keydown' , 'down' , function ( e ) {
e . preventDefault ( ) ;
self . show _next _story ( 1 ) ;
} ) ;
$document . bind ( 'keydown' , 'up' , function ( e ) {
e . preventDefault ( ) ;
self . show _next _story ( - 1 ) ;
} ) ;
$document . bind ( 'keydown' , 'j' , function ( e ) {
e . preventDefault ( ) ;
2010-08-13 10:43:48 -04:00
self . show _next _story ( 1 ) ;
2010-06-14 14:00:46 -04:00
} ) ;
$document . bind ( 'keydown' , 'k' , function ( e ) {
e . preventDefault ( ) ;
2010-08-13 10:43:48 -04:00
self . show _next _story ( - 1 ) ;
2010-10-21 18:52:25 -04:00
} ) ;
$document . bind ( 'keydown' , 'shift+j' , function ( e ) {
e . preventDefault ( ) ;
self . show _next _feed ( 1 ) ;
} ) ;
$document . bind ( 'keydown' , 'shift+k' , function ( e ) {
e . preventDefault ( ) ;
self . show _next _feed ( - 1 ) ;
2010-10-21 19:36:03 -04:00
} ) ;
$document . bind ( 'keydown' , 'shift+down' , function ( e ) {
e . preventDefault ( ) ;
self . show _next _feed ( 1 ) ;
} ) ;
$document . bind ( 'keydown' , 'shift+up' , function ( e ) {
e . preventDefault ( ) ;
self . show _next _feed ( - 1 ) ;
2010-06-14 14:00:46 -04:00
} ) ;
$document . bind ( 'keydown' , 'left' , function ( e ) {
e . preventDefault ( ) ;
self . switch _taskbar _view _direction ( - 1 ) ;
} ) ;
$document . bind ( 'keydown' , 'right' , function ( e ) {
e . preventDefault ( ) ;
self . switch _taskbar _view _direction ( 1 ) ;
} ) ;
2010-10-25 20:20:59 -04:00
$document . bind ( 'keydown' , 'h' , function ( e ) {
e . preventDefault ( ) ;
self . switch _taskbar _view _direction ( - 1 ) ;
} ) ;
$document . bind ( 'keydown' , 'l' , function ( e ) {
e . preventDefault ( ) ;
self . switch _taskbar _view _direction ( 1 ) ;
} ) ;
2011-05-02 14:15:24 -07:00
$document . bind ( 'keydown' , 'r' , function ( e ) {
e . preventDefault ( ) ;
self . open _river _stories ( ) ;
} ) ;
2010-10-12 20:13:33 -04:00
$document . bind ( 'keydown' , 'enter' , function ( e ) {
e . preventDefault ( ) ;
2010-12-07 20:04:37 -05:00
self . open _story _in _story _view ( null , true ) ;
2010-10-12 20:13:33 -04:00
} ) ;
$document . bind ( 'keydown' , 'return' , function ( e ) {
e . preventDefault ( ) ;
2010-12-07 20:04:37 -05:00
self . open _story _in _story _view ( null , true ) ;
2010-10-12 20:13:33 -04:00
} ) ;
2010-06-14 14:00:46 -04:00
$document . bind ( 'keydown' , 'space' , function ( e ) {
e . preventDefault ( ) ;
2011-11-06 14:38:19 -08:00
self . page _in _story ( 0.4 , 1 ) ;
2010-06-14 14:00:46 -04:00
} ) ;
$document . bind ( 'keydown' , 'shift+space' , function ( e ) {
e . preventDefault ( ) ;
2011-11-25 11:06:07 -05:00
self . page _in _story ( 0.65 , - 1 ) ;
2010-06-14 14:00:46 -04:00
} ) ;
2011-02-23 18:09:09 -05:00
$document . bind ( 'keydown' , 'u' , function ( e ) {
e . preventDefault ( ) ;
if ( self . flags [ 'sidebar_closed' ] ) {
self . open _sidebar ( ) ;
} else {
self . close _sidebar ( ) ;
}
} ) ;
2011-04-12 11:02:02 -04:00
$document . bind ( 'keydown' , 'n' , function ( e ) {
e . preventDefault ( ) ;
self . open _next _unread _story _across _feeds ( ) ;
} ) ;
2011-11-02 09:43:06 -07:00
$document . bind ( 'keydown' , 'm' , function ( e ) {
e . preventDefault ( ) ;
self . show _last _unread _story ( ) ;
} ) ;
2011-05-01 00:03:13 -04:00
$document . bind ( 'keydown' , 'b' , function ( e ) {
e . preventDefault ( ) ;
self . show _previous _story ( ) ;
} ) ;
2011-07-29 09:41:49 -07:00
$document . bind ( 'keydown' , 's' , function ( e ) {
e . preventDefault ( ) ;
if ( self . active _story ) {
var story _id = self . active _story . id ;
var $story = self . find _story _in _story _titles ( story _id ) ;
if ( $story . hasClass ( 'NB-story-starred' ) ) {
2011-12-14 21:56:27 -08:00
self . mark _story _as _unstarred ( story _id ) ;
2011-07-29 09:41:49 -07:00
} else {
2011-12-14 21:56:27 -08:00
self . mark _story _as _starred ( story _id ) ;
2011-07-29 09:41:49 -07:00
}
}
} ) ;
$document . bind ( 'keypress' , '+' , function ( e ) {
e . preventDefault ( ) ;
self . move _intelligence _slider ( 1 ) ;
} ) ;
$document . bind ( 'keypress' , '-' , function ( e ) {
e . preventDefault ( ) ;
self . move _intelligence _slider ( - 1 ) ;
} ) ;
2011-07-29 09:58:25 -07:00
$document . bind ( 'keypress' , 'd' , function ( e ) {
e . preventDefault ( ) ;
self . show _splash _page ( ) ;
} ) ;
2011-10-30 22:15:04 -07:00
$document . bind ( 'keypress' , 't' , function ( e ) {
e . preventDefault ( ) ;
self . open _story _trainer ( ) ;
} ) ;
2011-10-30 22:17:16 -07:00
$document . bind ( 'keypress' , 'f' , function ( e ) {
e . preventDefault ( ) ;
self . open _feed _intelligence _modal ( 1 ) ;
} ) ;
2011-10-31 18:04:25 -07:00
$document . bind ( 'keypress' , 'o' , function ( e ) {
e . preventDefault ( ) ;
self . open _story _in _new _tab ( ) ;
} ) ;
2011-10-31 18:40:07 -07:00
$document . bind ( 'keydown' , 'shift+a' , function ( e ) {
e . preventDefault ( ) ;
if ( self . flags . river _view ) {
self . mark _folder _as _read ( ) ;
} else {
self . mark _feed _as _read ( ) ;
}
} ) ;
2011-11-06 14:44:20 -08:00
$document . bind ( 'keydown' , 'shift+e' , function ( e ) {
e . preventDefault ( ) ;
self . open _river _stories ( ) ;
} ) ;
2010-06-08 11:19:41 -04:00
}
} ;
2010-10-19 19:09:08 -04:00
} ) ( jQuery ) ;