diff options
author | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-07-31 12:53:34 -0400 |
---|---|---|
committer | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-07-31 12:53:34 -0400 |
commit | 17058c946717e7487302e87c118223227ddb9987 (patch) | |
tree | 0503c8f0d8b1f15f789216d6da4510ebeba3e81f | |
parent | 0d3ebbfefdc65a90c78fa49c28eccbd1e0dfb563 (diff) | |
parent | b93b066a425fae11d304ee59f8d745e1251005a9 (diff) | |
download | nextcloud-server-17058c946717e7487302e87c118223227ddb9987.tar.gz nextcloud-server-17058c946717e7487302e87c118223227ddb9987.zip |
Merge branch 'master' into sharing
-rw-r--r-- | apps/files_imageviewer/appinfo/app.php | 6 | ||||
-rw-r--r-- | apps/files_imageviewer/js/lightbox.js | 56 | ||||
-rw-r--r-- | core/js/js.js | 49 | ||||
-rw-r--r-- | core/templates/part.searchbox.php | 2 | ||||
-rw-r--r-- | lib/base.php | 15 | ||||
-rw-r--r-- | lib/filesystem.php | 9 | ||||
-rw-r--r-- | lib/search/provider/file.php | 12 | ||||
-rw-r--r-- | search/css/results.css | 1 | ||||
-rw-r--r-- | search/js/result.js | 17 |
9 files changed, 122 insertions, 45 deletions
diff --git a/apps/files_imageviewer/appinfo/app.php b/apps/files_imageviewer/appinfo/app.php index 6d32e2d628e..3dfbb76ceb0 100644 --- a/apps/files_imageviewer/appinfo/app.php +++ b/apps/files_imageviewer/appinfo/app.php @@ -1,8 +1,6 @@ <?php -if(OC_App::getCurrentApp()=='files'){ - OC_Util::addScript( 'files_imageviewer', 'lightbox' ); - OC_Util::addStyle( 'files_imageviewer', 'lightbox' ); -} +OC_Util::addScript( 'files_imageviewer', 'lightbox' ); +OC_Util::addStyle( 'files_imageviewer', 'lightbox' ); ?> diff --git a/apps/files_imageviewer/js/lightbox.js b/apps/files_imageviewer/js/lightbox.js index 318c764458e..847954d2f15 100644 --- a/apps/files_imageviewer/js/lightbox.js +++ b/apps/files_imageviewer/js/lightbox.js @@ -1,31 +1,48 @@ var lightBoxShown=false; $(document).ready(function() { + images={};//image cache + var overlay=$('<div id="lightbox_overlay"/>'); + $( 'body' ).append(overlay); + var container=$('<div id="lightbox"/>'); + $( 'body' ).append(container); + $( 'body' ).click(hideLightbox); if(typeof FileActions!=='undefined'){ - images={};//image cache - var overlay=$('<div id="lightbox_overlay"/>'); - $( 'body' ).append(overlay); - var container=$('<div id="lightbox"/>'); - $( 'body' ).append(container); FileActions.register('image','View','',function(filename){ - var location='ajax/download.php?files='+filename+'&dir='+$('#dir').val(); - overlay.show(); - if(!images[location]){ - var img = new Image(); - img.onload = function(){ - images[location]=img; - showLightbox(container,img); - } - img.src = location; - }else{ - showLightbox(container,images[location]); - } + viewImage($('#dir').val(),filename); }); - $( 'body' ).click(hideLightbox); FileActions.setDefault('image','View'); } + OC.search.customResults.Images=function(row,item){ + var image=item.link.substr(item.link.indexOf('file=')+5); + var a=row.find('a'); + var container=$('<div id="lightbox"/>'); + a.attr('href','#'); + a.click(function(){ + var file=image.split('/').pop(); + var dir=image.substr(0,image.length-file.length-1); + viewImage(dir,file); + }); + } }); +function viewImage(dir,file){ + var location=OC.filePath('files','ajax','download.php')+'?files='+file+'&dir='+dir; + var overlay=$('#lightbox_overlay'); + var container=$('#lightbox'); + overlay.show(); + if(!images[location]){ + var img = new Image(); + img.onload = function(){ + images[location]=img; + showLightbox(container,img); + } + img.src = location; + }else{ + showLightbox(container,images[location]); + } +} + function showLightbox(container,img){ var maxWidth = $( window ).width() - 50; var maxHeight = $( window ).height() - 50; @@ -49,8 +66,9 @@ function showLightbox(container,img){ },100); } -function hideLightbox(){ +function hideLightbox(event){ if(lightBoxShown){ + event.stopPropagation(); $('#lightbox_overlay').hide(); $('#lightbox').hide(); lightBoxShown=false; diff --git a/core/js/js.js b/core/js/js.js index 99372c5f241..a83d6abb6a5 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -70,14 +70,18 @@ OC={ }, search:function(query){ if(query){ - OC.addScript('search','result',function(){ - OC.addStyle('search','results'); - $.getJSON(OC.filePath('search','ajax','search.php')+'?query='+encodeURIComponent(query), OC.search.showResults); + OC.addStyle('search','results'); + $.getJSON(OC.filePath('search','ajax','search.php')+'?query='+encodeURIComponent(query), function(results){ + OC.search.lastResults=results; + OC.search.showResults(results); }); } } } OC.search.customResults={}; +OC.search.currentResult=-1; +OC.search.lastQuery=''; +OC.search.lastResults={}; OC.addStyle.loaded=[]; OC.addScript.loaded=[]; @@ -133,15 +137,40 @@ $(document).ready(function(){ element.attr('src',src.substr(0,src.length-3)+'png'); }); }; - $('#searchbox').keyup(function(){ - var query=$('#searchbox').val(); - if(query.length>2){ - OC.search(query); + $('form.searchbox').submit(function(event){ + event.preventDefault(); + }) + $('#searchbox').keyup(function(event){ + if(event.keyCode==13){//enter + if(OC.search.currentResult>-1){ + var result=$('#searchresults tr.result a')[OC.search.currentResult]; + $(result).click(); + } + }else if(event.keyCode==38){//up + if(OC.search.currentResult>0){ + OC.search.currentResult--; + OC.search.renderCurrent(); + } + }else if(event.keyCode==40){//down + if(OC.search.lastResults.length>OC.search.currentResult+1){ + OC.search.currentResult++; + OC.search.renderCurrent(); + } + }else if(event.keyCode==27){//esc + OC.search.hide(); }else{ - if(OC.search.hide){ - OC.search.hide(); + var query=$('#searchbox').val(); + if(OC.search.lastQuery!=query){ + OC.search.lastQuery=query; + OC.search.currentResult=-1; + if(query.length>2){ + OC.search(query); + }else{ + if(OC.search.hide){ + OC.search.hide(); + } + } } } }); - $('#searchbox').click(function(){$('#searchbox').trigger('keyup')}); }); diff --git a/core/templates/part.searchbox.php b/core/templates/part.searchbox.php index ddf184ed5b6..49b44c718ec 100644 --- a/core/templates/part.searchbox.php +++ b/core/templates/part.searchbox.php @@ -1,3 +1,3 @@ -<form class="searchbox" action="<?php echo $_['searchurl']?>" method="post"> +<form class="searchbox" action="#" method="post"> <input id='searchbox' type="search" name="query" value="<?php if(isset($_POST['query'])){echo $_POST['query'];};?>" class="prettybutton" /> </form> diff --git a/lib/base.php b/lib/base.php index bbd89e4fdb3..5a5381a890e 100644 --- a/lib/base.php +++ b/lib/base.php @@ -91,6 +91,14 @@ if( !OC_Config::getValue( "installed", false )){ OC_User::useBackend( OC_Config::getValue( "userbackend", "database" )); OC_Group::setBackend( OC_Config::getValue( "groupbackend", "database" )); +// Add the stuff we need always +OC_Util::addScript( "jquery-1.6.2.min" ); +OC_Util::addScript( "jquery-ui-1.8.14.custom.min" ); +OC_Util::addScript( "js" ); +OC_Util::addScript('search','result'); +OC_Util::addStyle( "jquery-ui-1.8.14.custom" ); +OC_Util::addStyle( "styles" ); + // Load Apps // This includes plugins for users and filesystems as well if(!$error and !$RUNTIME_NOAPPS ){ @@ -107,13 +115,6 @@ if(!$error and !$RUNTIME_NOSETUPFS ){ OC_Util::setupFS(); } -// Add the stuff we need always -OC_Util::addScript( "jquery-1.6.2.min" ); -OC_Util::addScript( "jquery-ui-1.8.14.custom.min" ); -OC_Util::addScript( "js" ); -OC_Util::addStyle( "jquery-ui-1.8.14.custom" ); -OC_Util::addStyle( "styles" ); - // FROM Connect.php function OC_CONNECT_TEST($path,$user,$password){ diff --git a/lib/filesystem.php b/lib/filesystem.php index c2153520650..829482c7fa5 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -574,14 +574,17 @@ class OC_Filesystem{ static public function search($query){ $files=array(); - $fakeRootLength=strlen(self::$fakeRoot); + $fakeRoot=self::$fakeRoot; + $fakeRootLength=strlen($fakeRoot); foreach(self::$storages as $mountpoint=>$storage){ $results=$storage->search($query); if(is_array($results)){ foreach($results as $result){ $file=str_replace('//','/',$mountpoint.$result); - $file=substr($file,$fakeRootLength); - $files[]=$file; + if(substr($file,0,$fakeRootLength)==$fakeRoot){ + $file=substr($file,$fakeRootLength); + $files[]=$file; + } } } } diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php index f84d098dd69..f3d235abdce 100644 --- a/lib/search/provider/file.php +++ b/lib/search/provider/file.php @@ -8,7 +8,17 @@ class OC_Search_Provider_File extends OC_Search_Provider{ if(OC_Filesystem::is_dir($file)){ $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'index.php?dir='.$file ),'Files'); }else{ - $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Files'); + $mime=OC_Filesystem::getMimeType($file); + $mimeBase=substr($mime,0,strpos($mime,'/')); + switch($mimeBase){ + case 'audio': + break; + case 'image': + $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Images'); + break; + default: + $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Files'); + } } } return $results; diff --git a/search/css/results.css b/search/css/results.css index 61b7cf541c5..e61bf419b35 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -6,3 +6,4 @@ #searchresults td.result{width:30em;} #searchresults td.result *{cursor:pointer} #searchresults td.type{width:7em;text-align:right; border-right:1px solid #aaa;border-bottom:none} +#searchresults tr.current{background-color:#ddd} diff --git a/search/js/result.js b/search/js/result.js index cb5ec31cd31..1087f9684b2 100644 --- a/search/js/result.js +++ b/search/js/result.js @@ -16,6 +16,9 @@ OC.search.hide=function(){ }; } OC.search.showResults=function(results){ + if(results.length==0){ + return; + } if(!OC.search.showResults.loaded){ var parent=$('<div/>'); $('body').append(parent); @@ -27,12 +30,14 @@ OC.search.showResults=function(results){ $(window).click(function(event){ OC.search.hide(); }); + OC.search.lastResults=results; OC.search.showResults(results); }); }else{ var types=OC.search.catagorizeResults(results); $('#searchresults').show(); $('#searchresults tr.result').remove(); + var index=0; for(var name in types){ var type=types[name]; if(type.length>0){ @@ -43,6 +48,8 @@ OC.search.showResults=function(results){ row.find('td.result a').attr('href',type[0].link); row.find('td.result div.name').text(type[0].name); row.find('td.result div.text').text(type[0].text); + row.data('index',index); + index++; if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here OC.search.customResults[name](row,type[0]); } @@ -54,6 +61,8 @@ OC.search.showResults=function(results){ row.find('td.result a').attr('href',type[i].link); row.find('td.result div.name').text(type[i].name); row.find('td.result div.text').text(type[i].text); + row.data('index',index); + index++; if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here OC.search.customResults[name](row,type[i]); } @@ -64,3 +73,11 @@ OC.search.showResults=function(results){ } } OC.search.showResults.loaded=false; + +OC.search.renderCurrent=function(){ + if($('#searchresults tr.result')[OC.search.currentResult]){ + var result=$('#searchresults tr.result')[OC.search.currentResult]; + $('#searchresults tr.result').removeClass('current'); + $(result).addClass('current'); + } +} |