2014-07-29 17:34:10 +00:00
var Metamaps = { } ; // this variable declaration defines a Javascript object that will contain all the variables and functions used by us, broken down into 'sub-modules' that look something like this
/ *
* unless you are on a page with the Javascript InfoVis Toolkit ( Topic or Map ) the only section in the metamaps
2014-07-30 03:18:43 +00:00
* object will be these
2014-07-29 17:34:10 +00:00
GlobalUI
2014-07-30 03:18:43 +00:00
Active
Maps
Mappers
Backbone
2014-07-29 17:34:10 +00:00
* all these get added when you are on a page with the Javascript Infovis Toolkit
Settings
Touch
Mouse
Selected
Metacodes
Topics
Synapses
Mappings
Create
TopicCard
SynapseCard
Visualize
Util
Realtime
Control
Filter
Listeners
Organize
Map
Mapper
2014-07-30 03:18:43 +00:00
Topic
Synapse
2014-07-29 17:34:10 +00:00
JIT
* /
2014-07-30 03:18:43 +00:00
Metamaps . Active = {
Map : null ,
Topic : null ,
Mapper : null
} ;
2014-08-10 17:06:58 +00:00
Metamaps . Maps = { } ;
2014-07-29 17:34:10 +00:00
$ ( document ) . ready ( function ( ) {
for ( var prop in Metamaps ) {
2014-07-30 03:18:43 +00:00
2014-07-29 17:34:10 +00:00
// this runs the init function within each sub-object on the Metamaps one
if ( Metamaps . hasOwnProperty ( prop ) &&
Metamaps [ prop ] . hasOwnProperty ( 'init' ) &&
typeof ( Metamaps [ prop ] . init ) == 'function'
) {
Metamaps [ prop ] . init ( ) ;
}
}
2014-10-24 15:30:26 +00:00
// initialize the famous ui
var callFamous = function ( ) {
if ( Metamaps . Famous ) {
Metamaps . Famous . build ( ) ;
}
else {
setTimeout ( callFamous , 100 ) ;
}
}
callFamous ( ) ;
2014-07-29 17:34:10 +00:00
} ) ;
Metamaps . GlobalUI = {
notifyTimeout : null ,
2014-07-30 03:18:43 +00:00
lightbox : null ,
2014-07-29 17:34:10 +00:00
init : function ( ) {
var self = Metamaps . GlobalUI ;
self . Search . init ( ) ;
self . CreateMap . init ( ) ;
self . Account . init ( ) ;
//bind lightbox clicks
$ ( '.openLightbox' ) . click ( function ( event ) {
self . openLightbox ( $ ( this ) . attr ( 'data-open' ) ) ;
event . preventDefault ( ) ;
return false ;
} ) ;
2014-07-30 05:02:47 +00:00
$ ( '#lightbox_screen, #lightbox_close' ) . click ( self . closeLightbox ) ;
2014-07-31 01:10:10 +00:00
// initialize global backbone models and collections
2014-08-06 14:09:01 +00:00
if ( Metamaps . Active . Mapper ) Metamaps . Active . Mapper = new Metamaps . Backbone . Mapper ( Metamaps . Active . Mapper ) ;
2014-08-10 17:06:58 +00:00
var myCollection = Metamaps . Maps . Mine ? Metamaps . Maps . Mine : [ ] ;
2014-11-25 20:06:30 +00:00
var mapperCollection = [ ] ;
2014-11-29 06:37:06 +00:00
var mapperOptionsObj = { id : 'mapper' , sortBy : 'updated_at' } ;
2014-11-25 20:06:30 +00:00
if ( Metamaps . Maps . Mapper ) {
mapperCollection = Metamaps . Maps . Mapper . models ;
mapperOptionsObj . mapperId = Metamaps . Maps . Mapper . id ;
}
2014-08-10 17:06:58 +00:00
var featuredCollection = Metamaps . Maps . Featured ? Metamaps . Maps . Featured : [ ] ;
var activeCollection = Metamaps . Maps . Active ? Metamaps . Maps . Active : [ ] ;
2014-11-29 06:37:06 +00:00
Metamaps . Maps . Mine = new Metamaps . Backbone . MapsCollection ( myCollection , { id : 'mine' , sortBy : 'updated_at' } ) ;
2014-11-25 20:06:30 +00:00
// 'Mapper' refers to another mapper
Metamaps . Maps . Mapper = new Metamaps . Backbone . MapsCollection ( mapperCollection , mapperOptionsObj ) ;
2014-11-29 06:37:06 +00:00
Metamaps . Maps . Featured = new Metamaps . Backbone . MapsCollection ( featuredCollection , { id : 'featured' , sortBy : 'updated_at' } ) ;
2014-08-20 19:37:18 +00:00
Metamaps . Maps . Active = new Metamaps . Backbone . MapsCollection ( activeCollection , { id : 'active' , sortBy : 'updated_at' } ) ;
2014-07-29 17:34:10 +00:00
} ,
openLightbox : function ( which ) {
2014-07-30 03:18:43 +00:00
var self = Metamaps . GlobalUI ;
2014-07-29 17:34:10 +00:00
$ ( '.lightboxContent' ) . hide ( ) ;
$ ( '#' + which ) . show ( ) ;
2014-07-30 03:18:43 +00:00
self . lightbox = which ;
2014-07-29 17:34:10 +00:00
$ ( '#lightbox_overlay' ) . show ( ) ;
2014-07-31 01:10:10 +00:00
var heightOfContent = '-' + ( $ ( '#lightbox_main' ) . height ( ) / 2 ) + 'px' ;
// animate the content in from the bottom
$ ( '#lightbox_main' ) . animate ( {
'top' : '50%' ,
'margin-top' : heightOfContent
} , 200 , 'easeOutCubic' ) ;
// fade the black overlay in
$ ( '#lightbox_screen' ) . animate ( {
'opacity' : '0.42'
} , 200 ) ;
2014-09-21 05:02:21 +00:00
2014-07-29 17:34:10 +00:00
if ( which == "switchMetacodes" ) {
Metamaps . Create . isSwitchingSet = true ;
}
} ,
2014-07-30 05:02:47 +00:00
closeLightbox : function ( event ) {
2014-07-30 03:18:43 +00:00
var self = Metamaps . GlobalUI ;
2014-07-30 05:02:47 +00:00
if ( event ) event . preventDefault ( ) ;
2014-07-31 01:10:10 +00:00
// animate the lightbox content offscreen
$ ( '#lightbox_main' ) . animate ( {
'top' : '100%' ,
'margin-top' : '0'
} , 200 , 'easeInCubic' ) ;
// fade the black overlay out
$ ( '#lightbox_screen' ) . animate ( {
'opacity' : '0.0'
} , 200 , function ( ) {
$ ( '#lightbox_overlay' ) . hide ( ) ;
} ) ;
2014-07-30 03:18:43 +00:00
if ( self . lightbox === 'forkmap' ) Metamaps . GlobalUI . CreateMap . reset ( 'fork_map' ) ;
if ( self . lightbox === 'newmap' ) Metamaps . GlobalUI . CreateMap . reset ( 'new_map' ) ;
2014-07-29 17:34:10 +00:00
if ( Metamaps . Create && Metamaps . Create . isSwitchingSet ) {
Metamaps . Create . cancelMetacodeSetSwitch ( ) ;
}
2014-07-30 03:18:43 +00:00
self . lightbox = null ;
2014-07-29 17:34:10 +00:00
} ,
2014-08-10 17:06:58 +00:00
notifyUser : function ( message , leaveOpen ) {
2014-07-29 17:34:10 +00:00
var self = Metamaps . GlobalUI ;
2014-07-30 03:18:43 +00:00
2014-08-10 17:06:58 +00:00
Metamaps . Famous . toast . surf . setContent ( message ) ;
Metamaps . Famous . toast . show ( ) ;
clearTimeout ( self . notifyTimeOut ) ;
if ( ! leaveOpen ) {
self . notifyTimeOut = setTimeout ( function ( ) {
Metamaps . Famous . toast . hide ( ) ;
} , 8000 ) ;
2014-07-29 17:34:10 +00:00
}
2014-08-10 17:06:58 +00:00
} ,
clearNotify : function ( ) {
var self = Metamaps . GlobalUI ;
2014-07-29 17:34:10 +00:00
clearTimeout ( self . notifyTimeOut ) ;
2014-08-10 17:06:58 +00:00
Metamaps . Famous . toast . hide ( ) ;
2014-11-20 03:42:14 +00:00
} ,
shareInvite : function ( inviteLink ) {
window . prompt ( "To copy the invite link, press: Ctrl+C, Enter" , inviteLink ) ;
2014-07-29 17:34:10 +00:00
}
} ;
Metamaps . GlobalUI . CreateMap = {
2014-07-30 03:18:43 +00:00
newMap : null ,
emptyMapForm : "" ,
emptyForkMapForm : "" ,
topicsToMap : [ ] ,
synapsesToMap : [ ] ,
2014-07-29 17:34:10 +00:00
init : function ( ) {
2014-07-30 03:18:43 +00:00
var self = Metamaps . GlobalUI . CreateMap ;
self . newMap = new Metamaps . Backbone . Map ( { permission : 'commons' } ) ;
self . bindFormEvents ( ) ;
self . emptyMapForm = $ ( '#new_map' ) . html ( ) ;
} ,
bindFormEvents : function ( ) {
var self = Metamaps . GlobalUI . CreateMap ;
2014-07-29 17:34:10 +00:00
2014-07-30 03:18:43 +00:00
$ ( '.new_map button.cancel' ) . unbind ( ) . bind ( 'click' , function ( event ) {
event . preventDefault ( ) ;
Metamaps . GlobalUI . closeLightbox ( ) ;
2014-07-29 17:34:10 +00:00
} ) ;
2014-07-30 03:18:43 +00:00
$ ( '.new_map button.submitMap' ) . unbind ( ) . bind ( 'click' , self . submit ) ;
2014-07-29 17:34:10 +00:00
2014-07-30 03:18:43 +00:00
// bind permission changer events on the createMap form
$ ( '.permIcon' ) . unbind ( ) . bind ( 'click' , self . switchPermission ) ;
2014-07-29 17:34:10 +00:00
} ,
2014-10-12 02:49:44 +00:00
closeSuccess : function ( ) {
$ ( '#mapCreatedSuccess' ) . fadeOut ( 300 , function ( ) {
$ ( this ) . remove ( ) ;
} ) ;
} ,
2014-07-30 03:18:43 +00:00
generateSuccessMessage : function ( id ) {
2014-10-12 02:49:44 +00:00
var stringStart = "<div id='mapCreatedSuccess'><h6>SUCCESS!</h6>Your map has been created. Do you want to: <a id='mapGo' href='/maps/" ;
2014-07-30 03:18:43 +00:00
stringStart += id ;
2014-10-12 02:49:44 +00:00
stringStart += "' onclick='Metamaps.GlobalUI.CreateMap.closeSuccess();'>Go to your new map</a>" ;
stringStart += "<span>OR</span><a id='mapStay' href='#' onclick='Metamaps.GlobalUI.CreateMap.closeSuccess(); return false;'>Stay on this " ;
2014-07-30 03:18:43 +00:00
var page = Metamaps . Active . Map ? 'map' : 'page' ;
2014-10-12 02:49:44 +00:00
var stringEnd = "</a></div>" ;
2014-07-30 03:18:43 +00:00
return stringStart + page + stringEnd ;
} ,
switchPermission : function ( ) {
var self = Metamaps . GlobalUI . CreateMap ;
self . newMap . set ( 'permission' , $ ( this ) . attr ( 'data-permission' ) ) ;
$ ( this ) . siblings ( '.permIcon' ) . find ( '.mapPermIcon' ) . removeClass ( 'selected' ) ;
$ ( this ) . find ( '.mapPermIcon' ) . addClass ( 'selected' ) ;
2014-09-09 19:13:53 +00:00
var permText = $ ( this ) . find ( '.tip' ) . html ( ) ;
$ ( this ) . parents ( '.new_map' ) . find ( '.permText' ) . html ( permText ) ;
2014-07-30 03:18:43 +00:00
} ,
submit : function ( event ) {
2014-11-02 21:04:53 +00:00
if ( event ) event . preventDefault ( ) ;
2014-07-30 03:18:43 +00:00
var self = Metamaps . GlobalUI . CreateMap ;
2014-07-29 17:34:10 +00:00
2014-07-30 03:18:43 +00:00
if ( Metamaps . GlobalUI . lightbox === 'forkmap' ) {
self . newMap . set ( 'topicsToMap' , self . topicsToMap ) ;
self . newMap . set ( 'synapsesToMap' , self . synapsesToMap ) ;
}
var formId = Metamaps . GlobalUI . lightbox === 'forkmap' ? '#fork_map' : '#new_map' ;
2014-11-02 21:04:53 +00:00
var $form = $ ( formId ) ;
2014-07-29 17:34:10 +00:00
2014-11-02 21:04:53 +00:00
self . newMap . set ( 'name' , $form . find ( '#map_name' ) . val ( ) ) ;
self . newMap . set ( 'desc' , $form . find ( '#map_desc' ) . val ( ) ) ;
2014-07-29 17:34:10 +00:00
2014-08-10 20:52:49 +00:00
if ( self . newMap . get ( 'name' ) . length === 0 ) {
2014-11-02 21:04:53 +00:00
self . throwMapNameError ( ) ;
2014-08-10 20:52:49 +00:00
return ;
}
2014-07-30 03:18:43 +00:00
self . newMap . save ( null , {
success : self . success
// TODO add error message
} ) ;
2014-10-12 02:49:44 +00:00
Metamaps . GlobalUI . closeLightbox ( ) ;
Metamaps . GlobalUI . notifyUser ( 'Working...' ) ;
2014-07-30 03:18:43 +00:00
} ,
2014-11-02 21:04:53 +00:00
throwMapNameError : function ( ) {
var self = Metamaps . GlobalUI . CreateMap ;
var formId = Metamaps . GlobalUI . lightbox === 'forkmap' ? '#fork_map' : '#new_map' ;
var $form = $ ( formId ) ;
var message = $ ( "<div class='feedback_message'>Please enter a map name...</div>" ) ;
$form . find ( '#map_name' ) . after ( message ) ;
setTimeout ( function ( ) {
message . fadeOut ( 'fast' , function ( ) {
message . remove ( ) ;
} ) ;
} , 5000 ) ;
} ,
2014-07-30 03:18:43 +00:00
success : function ( model ) {
var self = Metamaps . GlobalUI . CreateMap ;
2014-10-15 03:20:40 +00:00
//push the new map onto the collection of 'my maps'
Metamaps . Maps . Mine . add ( model ) ;
2014-07-30 03:18:43 +00:00
var formId = Metamaps . GlobalUI . lightbox === 'forkmap' ? '#fork_map' : '#new_map' ;
var form = $ ( formId ) ;
2014-10-12 02:49:44 +00:00
Metamaps . GlobalUI . clearNotify ( ) ;
$ ( '#wrapper' ) . append ( self . generateSuccessMessage ( model . id ) ) ;
2014-07-30 03:18:43 +00:00
} ,
reset : function ( id ) {
var self = Metamaps . GlobalUI . CreateMap ;
2014-07-29 17:34:10 +00:00
2014-07-30 03:18:43 +00:00
var form = $ ( '#' + id ) ;
if ( id === "fork_map" ) {
self . topicsToMap = [ ] ;
self . synapsesToMap = [ ] ;
form . html ( self . emptyForkMapForm ) ;
}
else {
form . html ( self . emptyMapForm ) ;
}
self . bindFormEvents ( ) ;
self . newMap = new Metamaps . Backbone . Map ( { permission : 'commons' } ) ;
2014-07-29 17:34:10 +00:00
return false ;
} ,
} ;
Metamaps . GlobalUI . Account = {
isOpen : false ,
changing : false ,
init : function ( ) {
var self = Metamaps . GlobalUI . Account ;
2014-08-15 22:04:22 +00:00
$ ( '.sidebarAccountIcon' ) . click ( self . toggleBox ) ;
$ ( '.sidebarAccountBox' ) . click ( function ( event ) {
event . stopPropagation ( ) ;
} ) ;
$ ( 'body' ) . click ( self . close ) ;
} ,
toggleBox : function ( event ) {
var self = Metamaps . GlobalUI . Account ;
if ( self . isOpen ) self . close ( ) ;
else self . open ( ) ;
event . stopPropagation ( ) ;
2014-07-29 17:34:10 +00:00
} ,
open : function ( ) {
var self = Metamaps . GlobalUI . Account ;
2014-08-15 22:04:22 +00:00
Metamaps . Realtime . close ( ) ;
Metamaps . Filter . close ( ) ;
2014-11-15 01:54:51 +00:00
$ ( '.sidebarAccountIcon .tooltipsUnder' ) . addClass ( 'hide' ) ;
2014-11-12 18:31:15 +00:00
2014-08-10 17:06:58 +00:00
2014-07-29 17:34:10 +00:00
if ( ! self . isOpen && ! self . changing ) {
self . changing = true ;
$ ( '.sidebarAccountBox' ) . fadeIn ( 200 , function ( ) {
self . changing = false ;
self . isOpen = true ;
2014-08-27 02:51:50 +00:00
$ ( '.sidebarAccountBox #user_email' ) . focus ( ) ;
2014-07-29 17:34:10 +00:00
} ) ;
}
} ,
2014-08-15 22:04:22 +00:00
close : function ( ) {
2014-07-29 17:34:10 +00:00
var self = Metamaps . GlobalUI . Account ;
2014-11-15 01:54:51 +00:00
$ ( '.sidebarAccountIcon .tooltipsUnder' ) . removeClass ( 'hide' ) ;
2014-08-15 22:04:22 +00:00
if ( ! self . changing ) {
self . changing = true ;
2014-08-27 02:51:50 +00:00
$ ( '.sidebarAccountBox #user_email' ) . blur ( ) ;
2014-08-15 22:04:22 +00:00
$ ( '.sidebarAccountBox' ) . fadeOut ( 200 , function ( ) {
self . changing = false ;
self . isOpen = false ;
} ) ;
}
2014-07-29 17:34:10 +00:00
}
} ;
Metamaps . GlobalUI . Search = {
2014-08-10 17:06:58 +00:00
locked : false ,
2014-07-29 17:34:10 +00:00
isOpen : false ,
timeOut : null ,
changing : false ,
optionsInitialized : false ,
init : function ( ) {
var self = Metamaps . GlobalUI . Search ;
2014-10-01 17:18:24 +00:00
var loader = new CanvasLoader ( 'searchLoading' ) ;
loader . setColor ( '#4fb5c0' ) ; // default is '#000000'
loader . setDiameter ( 24 ) ; // default is 40
loader . setDensity ( 41 ) ; // default is 40
loader . setRange ( 0.9 ) ; // default is 1.3
loader . show ( ) ; // Hidden by default
2014-07-29 17:34:10 +00:00
// bind the hover events
$ ( ".sidebarSearch" ) . hover ( function ( ) {
self . open ( )
} , function ( ) {
self . close ( 800 , false )
} ) ;
$ ( '.sidebarSearchIcon' ) . click ( function ( e ) {
$ ( '.sidebarSearchField' ) . focus ( ) ;
} ) ;
$ ( '.sidebarSearch' ) . click ( function ( e ) {
e . stopPropagation ( ) ;
} ) ;
$ ( 'body' ) . click ( function ( e ) {
self . close ( 0 , false ) ;
} ) ;
// open if the search is closed and user hits ctrl+/
// close if they hit ESC
2014-10-17 03:54:26 +00:00
$ ( 'body' ) . bind ( 'keyup' , function ( e ) {
2014-07-29 17:34:10 +00:00
switch ( e . which ) {
case 191 :
2014-08-10 17:06:58 +00:00
if ( ( e . ctrlKey && ! self . isOpen ) || ( e . ctrlKey && self . locked ) ) {
2014-10-17 03:54:26 +00:00
self . open ( true ) ; // true for focus
2014-07-29 17:34:10 +00:00
}
break ;
case 27 :
if ( self . isOpen ) {
self . close ( 0 , true ) ;
}
break ;
2014-10-05 05:03:54 +00:00
2014-07-29 17:34:10 +00:00
default :
break ; //console.log(e.which);
}
} ) ;
2014-07-30 03:18:43 +00:00
2014-07-29 17:34:10 +00:00
self . startTypeahead ( ) ;
} ,
2014-08-10 17:06:58 +00:00
lock : function ( ) {
var self = Metamaps . GlobalUI . Search ;
self . locked = true ;
} ,
unlock : function ( ) {
var self = Metamaps . GlobalUI . Search ;
self . locked = false ;
} ,
2014-10-17 03:54:26 +00:00
open : function ( focus ) {
2014-07-29 17:34:10 +00:00
var self = Metamaps . GlobalUI . Search ;
clearTimeout ( self . timeOut ) ;
2014-08-10 17:06:58 +00:00
if ( ! self . isOpen && ! self . changing && ! self . locked ) {
2014-07-29 17:34:10 +00:00
self . changing = true ;
$ ( '.sidebarSearch .twitter-typeahead, .sidebarSearch .tt-hint, .sidebarSearchField' ) . animate ( {
2014-08-10 17:06:58 +00:00
width : '400px'
} , 300 , function ( ) {
2014-10-17 03:54:26 +00:00
if ( focus ) $ ( '.sidebarSearchField' ) . focus ( ) ;
2014-07-29 17:34:10 +00:00
$ ( '.sidebarSearchField, .sidebarSearch .tt-hint' ) . css ( {
2014-08-27 02:51:50 +00:00
padding : '7px 10px 3px 10px' ,
2014-08-10 17:06:58 +00:00
width : '380px'
2014-07-29 17:34:10 +00:00
} ) ;
self . changing = false ;
self . isOpen = true ;
} ) ;
}
} ,
close : function ( closeAfter , bypass ) {
var self = Metamaps . GlobalUI . Search ;
self . timeOut = setTimeout ( function ( ) {
2014-08-10 17:06:58 +00:00
if ( ! self . locked && ! self . changing && self . isOpen && ( bypass || $ ( '.sidebarSearchField' ) . val ( ) == '' ) ) {
2014-07-29 17:34:10 +00:00
self . changing = true ;
$ ( '.sidebarSearchField, .sidebarSearch .tt-hint' ) . css ( {
2014-08-27 02:51:50 +00:00
padding : '7px 0 3px 0' ,
2014-08-10 17:06:58 +00:00
width : '400px'
2014-07-29 17:34:10 +00:00
} ) ;
$ ( '.sidebarSearch .twitter-typeahead, .sidebarSearch .tt-hint, .sidebarSearchField' ) . animate ( {
width : '0'
2014-08-10 17:06:58 +00:00
} , 300 , function ( ) {
2014-07-29 17:34:10 +00:00
$ ( '.sidebarSearchField' ) . typeahead ( 'setQuery' , '' ) ;
$ ( '.sidebarSearchField' ) . blur ( ) ;
self . changing = false ;
self . isOpen = false ;
} ) ;
}
} , closeAfter ) ;
} ,
startTypeahead : function ( ) {
var self = Metamaps . GlobalUI . Search ;
2014-10-01 17:18:24 +00:00
var mapheader = Metamaps . Active . Mapper ? '<div class="searchMapsHeader searchHeader"><h3 class="search-heading">Maps</h3><input type="checkbox" class="limitToMe" id="limitMapsToMe"></input><label for="limitMapsToMe" class="limitToMeLabel">added by me</label><div class="minimizeResults minimizeMapResults"></div><div class="clearfloat"></div></div>' : '<div class="searchMapsHeader searchHeader"><h3 class="search-heading">Maps</h3><div class="minimizeResults minimizeMapResults"></div><div class="clearfloat"></div></div>' ;
var topicheader = Metamaps . Active . Mapper ? '<div class="searchTopicsHeader searchHeader"><h3 class="search-heading">Topics</h3><input type="checkbox" class="limitToMe" id="limitTopicsToMe"></input><label for="limitTopicsToMe" class="limitToMeLabel">added by me</label><div class="minimizeResults minimizeTopicResults"></div><div class="clearfloat"></div></div>' : '<div class="searchTopicsHeader searchHeader"><h3 class="search-heading">Topics</h3><div class="minimizeResults minimizeTopicResults"></div><div class="clearfloat"></div></div>' ;
2014-09-03 23:05:25 +00:00
var mapperheader = '<div class="searchMappersHeader searchHeader"><h3 class="search-heading">Mappers</h3><div class="minimizeResults minimizeMapperResults"></div><div class="clearfloat"></div></div>' ;
2014-07-29 17:34:10 +00:00
var topics = {
name : 'topics' ,
limit : 9999 ,
dupChecker : function ( datum1 , datum2 ) {
return false ;
} ,
template : $ ( '#topicSearchTemplate' ) . html ( ) ,
remote : {
url : '/search/topics?term=%QUERY' ,
replace : function ( ) {
var q = '/search/topics?term=' + $ ( '.sidebarSearchField' ) . val ( ) ;
2014-07-31 01:10:10 +00:00
if ( Metamaps . Active . Mapper && $ ( "#limitTopicsToMe" ) . is ( ':checked' ) ) {
q += "&user=" + Metamaps . Active . Mapper . id . toString ( ) ;
2014-07-29 17:34:10 +00:00
}
return q ;
} ,
filter : function ( dataset ) {
if ( dataset . length == 0 ) {
dataset . push ( {
value : "No results" ,
label : "No results" ,
typeImageURL : "/assets/icons/wildcard.png" ,
rtype : "noresult"
} ) ;
}
return dataset ;
}
} ,
engine : Hogan ,
header : topicheader
} ;
var maps = {
name : 'maps' ,
limit : 9999 ,
dupChecker : function ( datum1 , datum2 ) {
return false ;
} ,
template : $ ( '#mapSearchTemplate' ) . html ( ) ,
remote : {
url : '/search/maps?term=%QUERY' ,
replace : function ( ) {
var q = '/search/maps?term=' + $ ( '.sidebarSearchField' ) . val ( ) ;
2014-07-31 01:10:10 +00:00
if ( Metamaps . Active . Mapper && $ ( "#limitMapsToMe" ) . is ( ':checked' ) ) {
q += "&user=" + Metamaps . Active . Mapper . id . toString ( ) ;
2014-07-29 17:34:10 +00:00
}
return q ;
} ,
filter : function ( dataset ) {
if ( dataset . length == 0 ) {
dataset . push ( {
value : "No results" ,
label : "No results" ,
rtype : "noresult"
} ) ;
}
return dataset ;
}
} ,
engine : Hogan ,
header : mapheader
} ;
var mappers = {
name : 'mappers' ,
limit : 9999 ,
dupChecker : function ( datum1 , datum2 ) {
return false ;
} ,
template : $ ( '#mapperSearchTemplate' ) . html ( ) ,
remote : {
url : '/search/mappers?term=%QUERY' ,
filter : function ( dataset ) {
if ( dataset . length == 0 ) {
dataset . push ( {
2014-09-03 23:05:25 +00:00
profile : "/assets/user.png" ,
2014-10-01 13:54:56 +00:00
2014-07-29 17:34:10 +00:00
value : "No results" ,
label : "No results" ,
rtype : "noresult"
} ) ;
}
return dataset ;
}
} ,
engine : Hogan ,
header : mapperheader
} ;
$ ( '.sidebarSearchField' ) . typeahead ( [ topics , maps , mappers ] ) ;
//Set max height of the search results box to prevent it from covering bottom left footer
2014-10-01 17:18:24 +00:00
$ ( '.sidebarSearchField' ) . bind ( 'typeahead:suggestionsRendered' , function ( event ) {
self . initSearchOptions ( ) ;
self . hideLoader ( ) ;
2014-07-29 17:34:10 +00:00
var h = $ ( window ) . height ( ) ;
$ ( ".tt-dropdown-menu" ) . css ( 'max-height' , h - 100 ) ;
} ) ;
$ ( window ) . resize ( function ( ) {
var h = $ ( window ) . height ( ) ;
$ ( ".tt-dropdown-menu" ) . css ( 'max-height' , h - 100 ) ;
} ) ;
// tell the autocomplete to launch a new tab with the topic, map, or mapper you clicked on
$ ( '.sidebarSearchField' ) . bind ( 'typeahead:selected' , self . handleResultClick ) ;
2014-10-01 17:18:24 +00:00
2014-07-29 17:34:10 +00:00
// don't do it, if they clicked on a 'addToMap' button
$ ( '.sidebarSearch button.addToMap' ) . click ( function ( event ) {
event . stopPropagation ( ) ;
} ) ;
// make sure that when you click on 'limit to me' or 'toggle section' it works
2014-10-01 17:18:24 +00:00
$ ( '.sidebarSearchField' ) . bind ( 'typeahead:queryChanged' , function ( ) {
if ( $ ( this ) . val ( ) === "" ) {
self . hideLoader ( ) ;
}
else {
self . showLoader ( ) ;
}
} ) ;
2014-07-29 17:34:10 +00:00
} ,
handleResultClick : function ( event , datum , dataset ) {
var self = Metamaps . GlobalUI . Search ;
2014-10-17 03:54:26 +00:00
self . hideLoader ( ) ;
2014-07-29 17:34:10 +00:00
if ( datum . rtype != "noresult" ) {
self . close ( 0 , true ) ;
var win ;
if ( dataset == "topics" ) {
2014-08-11 22:57:34 +00:00
Metamaps . Router . topics ( datum . id ) ;
2014-07-29 17:34:10 +00:00
} else if ( dataset == "maps" ) {
2014-08-11 16:04:06 +00:00
Metamaps . Router . maps ( datum . id ) ;
2014-07-29 17:34:10 +00:00
} else if ( dataset == "mappers" ) {
2014-11-25 20:06:30 +00:00
Metamaps . Router . explore ( "mapper" , datum . id ) ;
2014-07-29 17:34:10 +00:00
}
}
} ,
initSearchOptions : function ( ) {
var self = Metamaps . GlobalUI . Search ;
function toggleResultSet ( set ) {
var s = $ ( '.tt-dataset-' + set + ' .tt-suggestions' ) ;
if ( s . css ( 'height' ) == '0px' ) {
s . css ( {
'height' : 'auto' ,
'overflow' : 'visible'
} ) ;
$ ( this ) . removeClass ( 'maximizeResults' ) . addClass ( 'minimizeResults' ) ;
} else {
s . css ( {
'height' : '0' ,
'overflow' : 'hidden'
} ) ;
$ ( this ) . removeClass ( 'minimizeResults' ) . addClass ( 'maximizeResults' ) ;
}
}
2014-10-02 00:00:03 +00:00
$ ( '.limitToMe' ) . unbind ( ) . bind ( "change" , function ( e ) {
// set the value of the search equal to itself to retrigger the autocomplete event
self . isOpen = false ;
$ ( '.sidebarSearchField' ) . typeahead ( 'setQuery' , $ ( '.sidebarSearchField' ) . val ( ) ) ;
setTimeout ( function ( ) {
self . isOpen = true ;
} , 2000 ) ;
} ) ;
2014-07-29 17:34:10 +00:00
2014-10-02 00:00:03 +00:00
// when the user clicks minimize section, hide the results for that section
$ ( '.minimizeMapperResults' ) . unbind ( ) . click ( function ( e ) {
toggleResultSet . call ( this , 'mappers' ) ;
} ) ;
$ ( '.minimizeTopicResults' ) . unbind ( ) . click ( function ( e ) {
toggleResultSet . call ( this , 'topics' ) ;
} ) ;
$ ( '.minimizeMapResults' ) . unbind ( ) . click ( function ( e ) {
toggleResultSet . call ( this , 'maps' ) ;
} ) ;
2014-10-01 17:18:24 +00:00
} ,
hideLoader : function ( ) {
$ ( '#searchLoading' ) . hide ( ) ;
} ,
showLoader : function ( ) {
$ ( '#searchLoading' ) . show ( ) ;
2014-07-29 17:34:10 +00:00
}
} ;