1
0
mirror of https://github.com/misterunknown/ifm.git synced 2025-08-10 18:14:00 +02:00

added folder links functionality

This commit is contained in:
Marco Dickert
2017-02-16 14:04:55 +01:00
parent efb41453c3
commit d14512b62d
3 changed files with 42 additions and 12 deletions

27
ifm.php
View File

@@ -130,7 +130,7 @@ class IFMZip {
*/ */
class IFM { class IFM {
const VERSION = '2.3.0'; const VERSION = '2.3.1';
public function __construct() { public function __construct() {
session_start(); session_start();
@@ -561,19 +561,21 @@ function IFM() {
// todo: bootstrap-fancybox for images // todo: bootstrap-fancybox for images
}; };
this.changeDirectory = function( newdir ) { this.changeDirectory = function( newdir, options={ absolute: false, pushState: true } ) {
if( ! options.absolute ) newdir = self.pathCombine( self.currentDir, newdir );
$.ajax({ $.ajax({
url: self.IFM_SCFN, url: self.IFM_SCFN,
type: "POST", type: "POST",
data: ({ data: ({
api: "getRealpath", api: "getRealpath",
dir: self.pathCombine( ifm.currentDir, newdir ) dir: newdir
}), }),
dataType: "json", dataType: "json",
success: function( data ){ success: function( data ) {
self.currentDir = data.realpath; self.currentDir = data.realpath;
self.refreshFileTable(); self.refreshFileTable();
$( "#currentDir" ).val( self.currentDir ); $( "#currentDir" ).val( self.currentDir );
if( options.pushState ) history.pushState( { dir: self.currentDir }, self.currentDir, "#"+self.currentDir );
}, },
error: function() { self.showMessage( "General error occured: No or broken response", "e" ); } error: function() { self.showMessage( "General error occured: No or broken response", "e" ); }
}); });
@@ -1058,10 +1060,13 @@ function IFM() {
this.JSEncode = function(s) { this.JSEncode = function(s) {
return s.replace(/'/g, '\\x27').replace(/"/g, '\\x22'); return s.replace(/'/g, '\\x27').replace(/"/g, '\\x22');
}; };
this.historyPopstateHandler = function(event) {
var dir = "";
if( event.state && event.state.dir ) dir = event.state.dir;
self.changeDirectory( dir, { pushState: false, absolute: true } );
};
// static button bindings and filetable initial filling // static button bindings and filetable initial filling
this.init = function() { this.init = function() {
// fill file table
this.refreshFileTable();
// bind static buttons // bind static buttons
$("#refresh").click(function(){ $("#refresh").click(function(){
self.refreshFileTable(); self.refreshFileTable();
@@ -1075,6 +1080,16 @@ function IFM() {
$("#upload").click(function(){ $("#upload").click(function(){
self.uploadFileDialog(); self.uploadFileDialog();
}); });
// handle history manipulation
window.onpopstate = self.historyPopstateHandler;
// load initial file table
if( window.location.hash ) {
self.changeDirectory( window.location.hash.substring( 1 ) );
} else {
this.refreshFileTable();
}
}; };
} }

View File

@@ -136,19 +136,21 @@ function IFM() {
// todo: bootstrap-fancybox for images // todo: bootstrap-fancybox for images
}; };
this.changeDirectory = function( newdir ) { this.changeDirectory = function( newdir, options={ absolute: false, pushState: true } ) {
if( ! options.absolute ) newdir = self.pathCombine( self.currentDir, newdir );
$.ajax({ $.ajax({
url: self.IFM_SCFN, url: self.IFM_SCFN,
type: "POST", type: "POST",
data: ({ data: ({
api: "getRealpath", api: "getRealpath",
dir: self.pathCombine( ifm.currentDir, newdir ) dir: newdir
}), }),
dataType: "json", dataType: "json",
success: function( data ){ success: function( data ) {
self.currentDir = data.realpath; self.currentDir = data.realpath;
self.refreshFileTable(); self.refreshFileTable();
$( "#currentDir" ).val( self.currentDir ); $( "#currentDir" ).val( self.currentDir );
if( options.pushState ) history.pushState( { dir: self.currentDir }, self.currentDir, "#"+self.currentDir );
}, },
error: function() { self.showMessage( "General error occured: No or broken response", "e" ); } error: function() { self.showMessage( "General error occured: No or broken response", "e" ); }
}); });
@@ -633,10 +635,13 @@ function IFM() {
this.JSEncode = function(s) { this.JSEncode = function(s) {
return s.replace(/'/g, '\\x27').replace(/"/g, '\\x22'); return s.replace(/'/g, '\\x27').replace(/"/g, '\\x22');
}; };
this.historyPopstateHandler = function(event) {
var dir = "";
if( event.state && event.state.dir ) dir = event.state.dir;
self.changeDirectory( dir, { pushState: false, absolute: true } );
};
// static button bindings and filetable initial filling // static button bindings and filetable initial filling
this.init = function() { this.init = function() {
// fill file table
this.refreshFileTable();
// bind static buttons // bind static buttons
$("#refresh").click(function(){ $("#refresh").click(function(){
self.refreshFileTable(); self.refreshFileTable();
@@ -650,6 +655,16 @@ function IFM() {
$("#upload").click(function(){ $("#upload").click(function(){
self.uploadFileDialog(); self.uploadFileDialog();
}); });
// handle history manipulation
window.onpopstate = self.historyPopstateHandler;
// load initial file table
if( window.location.hash ) {
self.changeDirectory( window.location.hash.substring( 1 ) );
} else {
this.refreshFileTable();
}
}; };
} }

View File

@@ -11,7 +11,7 @@
*/ */
class IFM { class IFM {
const VERSION = '2.3.0'; const VERSION = '2.3.1';
public function __construct() { public function __construct() {
session_start(); session_start();