From 4d3b4b85df5cd5e3471b523c2b13ba2985e6082a Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Tue, 16 Oct 2012 17:04:04 +0200 Subject: [PATCH 001/130] Updates version to 0.23-dev. --- README.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1660cc29..eb85785f 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,12 @@ It profits from these great projects: ## Changelog (**h5ai** uses [semantic versioning](http://semver.org/)) + +### v0.23 + +* + + ### v0.22.1 - *2012-10-16* * bug fix concerning API requests in PHP mode diff --git a/package.json b/package.json index 85301372..0b17b040 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "h5ai", - "version": "0.22.1", + "version": "0.23-dev", "description": "a modern HTTP web server index", "url": "http://larsjung.de/h5ai/", "author": "Lars Jung", From e6bbb7c2cdf5c5648af3c0304513673d970af2a0 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Tue, 16 Oct 2012 20:44:59 +0200 Subject: [PATCH 002/130] Changes versioning. --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eb85785f..d4b79e19 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ It profits from these great projects: (**h5ai** uses [semantic versioning](http://semver.org/)) -### v0.23 +### develop branch * diff --git a/package.json b/package.json index 0b17b040..5f0ba87a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "h5ai", - "version": "0.23-dev", + "version": "0.22.1-dev", "description": "a modern HTTP web server index", "url": "http://larsjung.de/h5ai/", "author": "Lars Jung", From e43d43933a346cce08ff4f072d149c976ec4b181 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Tue, 16 Oct 2012 22:50:41 +0200 Subject: [PATCH 003/130] Updates storage. --- src/_h5ai/client/js/inc/core/store.js | 38 ++++++++++++++-------- src/_h5ai/client/js/inc/ext/l10n.js | 2 +- src/_h5ai/client/js/inc/ext/preview-img.js | 2 +- src/_h5ai/client/js/inc/ext/sort.js | 2 +- src/_h5ai/client/js/inc/view/viewmode.js | 2 +- src/_h5ai/client/js/lib/modernizr-2.6.2.js | 18 ++++++++-- 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/_h5ai/client/js/inc/core/store.js b/src/_h5ai/client/js/inc/core/store.js index c7c2a7c3..1278470e 100644 --- a/src/_h5ai/client/js/inc/core/store.js +++ b/src/_h5ai/client/js/inc/core/store.js @@ -1,25 +1,37 @@ -modulejs.define('core/store', ['_'], function (_) { +modulejs.define('core/store', ['_', 'modernizr'], function (_, modernizr) { - var store = window.localStorage, + var store = modernizr.localstorage ? window.localStorage : null, + + key = '_h5ai', + + load = function () { + + if (store) { + try { + return JSON.parse(store[key]); + } catch (e) {} + } + return {}; + }, + + save = function (obj) { + + if (store) { + store[key] = JSON.stringify(obj); + } + }, put = function (key, value) { - if (store && _.isString(key)) { - store[key] = JSON.stringify({data: value}); - } + var obj = load(); + obj[key] = value; + return save(obj); }, get = function (key) { - if (store && _.isString(key)) { - var json = store[key], - obj = {}; - - try { obj = JSON.parse(json); } catch (e) {} - - return obj.data; - } + return load()[key]; }; return { diff --git a/src/_h5ai/client/js/inc/ext/l10n.js b/src/_h5ai/client/js/inc/ext/l10n.js index 66a8a3de..8095f872 100644 --- a/src/_h5ai/client/js/inc/ext/l10n.js +++ b/src/_h5ai/client/js/inc/ext/l10n.js @@ -34,7 +34,7 @@ modulejs.define('ext/l10n', ['_', '$', 'core/settings', 'core/langs', 'core/form '', langOptionTemplate = '
  • ', - storekey = 'h5ai.language', + storekey = 'l10n.lang', loaded = { en: _.extend({}, defaultTranslations) diff --git a/src/_h5ai/client/js/inc/ext/preview-img.js b/src/_h5ai/client/js/inc/ext/preview-img.js index ba015f3c..78ea5fd9 100644 --- a/src/_h5ai/client/js/inc/ext/preview-img.js +++ b/src/_h5ai/client/js/inc/ext/preview-img.js @@ -28,7 +28,7 @@ modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/resource', '' + '', - storekey = 'h5ai.preview-img.isFullscreen', + storekey = 'preview-img.isFullscreen', currentEntries = [], currentIdx = 0, diff --git a/src/_h5ai/client/js/inc/ext/sort.js b/src/_h5ai/client/js/inc/ext/sort.js index 389498e5..89031b21 100644 --- a/src/_h5ai/client/js/inc/ext/sort.js +++ b/src/_h5ai/client/js/inc/ext/sort.js @@ -6,7 +6,7 @@ modulejs.define('ext/sort', ['_', '$', 'core/settings', 'core/resource', 'core/e order: 'na' }, allsettings.sort), - storekey = 'h5ai.sortorder', + storekey = 'sort.order', type = function (entry) { diff --git a/src/_h5ai/client/js/inc/view/viewmode.js b/src/_h5ai/client/js/inc/view/viewmode.js index 1943f342..b8360c04 100644 --- a/src/_h5ai/client/js/inc/view/viewmode.js +++ b/src/_h5ai/client/js/inc/view/viewmode.js @@ -7,7 +7,7 @@ modulejs.define('view/viewmode', ['_', '$', 'core/settings', 'core/resource', 'c modes: modes }, allsettings.view), - storekey = 'h5ai.viewmode', + storekey = 'viewmode', template = '
  • ' + '' + diff --git a/src/_h5ai/client/js/lib/modernizr-2.6.2.js b/src/_h5ai/client/js/lib/modernizr-2.6.2.js index e4382d16..17158e12 100644 --- a/src/_h5ai/client/js/lib/modernizr-2.6.2.js +++ b/src/_h5ai/client/js/lib/modernizr-2.6.2.js @@ -1,5 +1,5 @@ /* Modernizr 2.6.2 (Custom Build) | MIT & BSD - * Build: http://modernizr.com/download/#-opacity-rgba-canvas-history-audio-video-shiv-cssclasses-prefixes + * Build: http://modernizr.com/download/#-opacity-rgba-canvas-history-audio-video-localstorage-shiv-cssclasses-prefixes */ ; @@ -182,7 +182,21 @@ window.Modernizr = (function( window, document, undefined ) { } catch(e) { } return bool; - }; for ( var feature in tests ) { + }; + + + tests['localstorage'] = function() { + try { + localStorage.setItem(mod, mod); + localStorage.removeItem(mod); + return true; + } catch(e) { + return false; + } + }; + + + for ( var feature in tests ) { if ( hasOwnProp(tests, feature) ) { featureName = feature.toLowerCase(); Modernizr[featureName] = tests[feature](); From 70f4500232528f07f14307801306be3c98a6ebe4 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Tue, 16 Oct 2012 23:10:05 +0200 Subject: [PATCH 004/130] Removes aai. --- src/_h5ai/client/js/inc/core/server.js | 120 ------------------------- src/_h5ai/client/js/scripts.js | 41 +-------- src/_h5ai/server/aai/aai.htaccess | 23 ----- src/_h5ai/server/aai/footer.html.jade | 3 - src/_h5ai/server/aai/header.html.jade | 45 ---------- 5 files changed, 1 insertion(+), 231 deletions(-) delete mode 100644 src/_h5ai/server/aai/aai.htaccess delete mode 100644 src/_h5ai/server/aai/footer.html.jade delete mode 100644 src/_h5ai/server/aai/header.html.jade diff --git a/src/_h5ai/client/js/inc/core/server.js b/src/_h5ai/client/js/inc/core/server.js index 7870d219..759b81bb 100644 --- a/src/_h5ai/client/js/inc/core/server.js +++ b/src/_h5ai/client/js/inc/core/server.js @@ -20,8 +20,6 @@ modulejs.define('core/server', ['$', '_', 'config'], function ($, _, config) { callback(); } }); - } else if (server.backend === 'aai') { - return modulejs.require('core/server-request-mock-aai')(data, callback); } else { callback(); } @@ -30,121 +28,3 @@ modulejs.define('core/server', ['$', '_', 'config'], function ($, _, config) { return server; }); - - - -modulejs.define('core/server-request-mock-aai', ['$', '_', 'core/settings', 'core/format'], function ($, _, allsettings, format) { - - var loadText = function (href) { - - var deferred = $.Deferred(); - - $.ajax(href, {dataType: 'text'}).always(function (content) { - - content = content.replace ? content : null; - deferred.resolve(content); - }); - - return deferred; - }, - - loadJson = function (href) { - - var deferred = $.Deferred(); - - loadText(href).always(function (content) { - - var json = content.replace ? JSON.parse(content.replace(/\/\*[\s\S]*?\*\/|\/\/.*?(\n|$)/g, '')) : {}; - deferred.resolve(json); - }); - - return deferred; - }, - - parse = function (absHref, html) { - - html = '
    ' + html.replace(/^[\s\S]*|<\/body>[\s\S]*$/g, '') + '
    '; - var $table = $(html).find('#data-apache-autoindex table'); - - return _.compact(_.map($table.find('td').closest('tr'), function (tr) { - - var $tds = $(tr).find('td'), - $a = $tds.eq(1).find('a'); - - return $a.text() === 'Parent Directory' ? null : { - absHref: absHref + $a.attr('href'), - time: format.parseDate($tds.eq(2).text(), ['YYYY-MM-DD HH:mm', 'DD-MMM-YYYY HH:mm']), - size: format.parseSize($tds.eq(3).text()) - }; - })); - }; - - return function (data, callback) { - - if (data.action === 'get' && data.l10n === true) { - - var isoCodes = data.l10nCodes.split(':'); - var isoCode = data.l10nCodes.split(':')[0]; - loadJson(allsettings.h5aiAbsHref + 'conf/l10n/' + isoCode + '.json').done(function (json) { - - var result = {code: 0, l10n: {}}; - - if (json) { - result.l10n[isoCode] = json; - } - callback(result); - }); - - } else if (data.action === 'get' && data.custom === true) { - - $.when( - loadText('_h5ai.header.html'), - loadText('_h5ai.footer.html') - ).done(function (header, footer) { - - callback({ - code: 0, - custom: { - header: header, - footer: footer - } - }); - }); - - } else if (data.action === 'get' && data.entries === true) { - - var absHref = data.entriesHref, - what = data.entriesWhat, - magicSequence = '=h5ai=', - reContentType = /^text\/html;h5ai=/; - - $.ajax({ - url: absHref, - type: what === 0 ? 'HEAD' : 'GET', - complete: function (xhr) { - - var entries = [], - status = xhr.status; - - if (status === 200 && reContentType.test(xhr.getResponseHeader('Content-Type'))) { - status = magicSequence; - } - - if (status === magicSequence && what > 0) { - entries = parse(absHref, xhr.responseText); - } - entries.push({absHref: absHref, status: status, content: what > 0}); - - callback({ - code: 0, - entries: entries - }); - } - }); - - } else { - - callback(); - } - }; -}); diff --git a/src/_h5ai/client/js/scripts.js b/src/_h5ai/client/js/scripts.js index 0b714814..7036d680 100644 --- a/src/_h5ai/client/js/scripts.js +++ b/src/_h5ai/client/js/scripts.js @@ -39,52 +39,13 @@ $(function () { modulejs.require('info'); }); - } else if (mode === 'php') { + } else { $.getJSON('.', {action: 'get', options: true, types: true, langs: true, server: true}, function (config) { modulejs.define('config', config); $(function () { modulejs.require('main'); }); }); - - } else if (mode === 'aai') { - - var src = $script.attr('src'), - appHref = src.substr(0, src.length - filename.length), - loadJson = function (href) { - - var deferred = $.Deferred(); - - $.ajax(href, {dataType: 'text'}).always(function (content) { - - var json = content.replace ? JSON.parse(content.replace(/\/\*[\s\S]*?\*\/|\/\/.*?(\n|$)/g, '')) : {}; - deferred.resolve(json); - }); - - return deferred; - }; - - $.when( - loadJson(appHref + 'conf/options.json'), - loadJson(appHref + 'conf/types.json'), - loadJson(appHref + 'conf/langs.json') - ).done(function (options, types, langs) { - - var config = { - options: options, - types: types, - langs: langs, - server: { - backend: mode, - api: false, - name: 'apache', - version: null - } - }; - - modulejs.define('config', config); - $(function () { modulejs.require('main'); }); - }); } }()); diff --git a/src/_h5ai/server/aai/aai.htaccess b/src/_h5ai/server/aai/aai.htaccess deleted file mode 100644 index 497f7381..00000000 --- a/src/_h5ai/server/aai/aai.htaccess +++ /dev/null @@ -1,23 +0,0 @@ -################################ -# {{pkg.name}} {{pkg.version}} -# customized .htaccess -################################ - -Options +Indexes -Options +FollowSymLinks - -HeaderName /_{{pkg.name}}/server/aai/header.html -ReadmeName /_{{pkg.name}}/server/aai/footer.html - -IndexIgnore _{{pkg.name}}* - -IndexOptions Charset=UTF-8 -IndexOptions FancyIndexing -IndexOptions FoldersFirst -IndexOptions HTMLTable -IndexOptions NameWidth=* -IndexOptions SuppressDescription -IndexOptions SuppressHTMLPreamble -IndexOptions SuppressRules -IndexOptions Type=text/html;{{pkg.name}}={{pkg.version}} -IndexOptions XHTML diff --git a/src/_h5ai/server/aai/footer.html.jade b/src/_h5ai/server/aai/footer.html.jade deleted file mode 100644 index 4b4a411d..00000000 --- a/src/_h5ai/server/aai/footer.html.jade +++ /dev/null @@ -1,3 +0,0 @@ - -// generated code ends here -| diff --git a/src/_h5ai/server/aai/header.html.jade b/src/_h5ai/server/aai/header.html.jade deleted file mode 100644 index 29106464..00000000 --- a/src/_h5ai/server/aai/header.html.jade +++ /dev/null @@ -1,45 +0,0 @@ - -- var href = "/_{{pkg.name}}/" - -doctype 5 -//if lt IE 9 - -//[if gt IE 8]> -// - -div#topbar.clearfix - ul#navbar - -div#content - div#extended.clearfix - -div#bottombar.clearfix - span.left - a#h5ai-reference( href="{{pkg.url}}", title="{{pkg.name}} · {{pkg.description}}" ) - | {{pkg.name}} {{pkg.version}} - span.hideOnJs.noJsMsg - | ⚡ JavaScript is disabled! ⚡ - span.oldBrowser - | ⚡ Some features disabled! Works best in - a( href="http://browsehappy.com" ) modern browsers - | . ⚡ - span.right - span.center - -|
    -// The following code was generated by Apache's autoindex module. From 396bc6662ffd45130da15e90b7779418dd8b4ade Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Wed, 17 Oct 2012 00:17:22 +0200 Subject: [PATCH 005/130] Cleans code. --- ...allback-table.less => no-js-fallback.less} | 2 +- src/_h5ai/client/css/styles.less | 2 +- src/_h5ai/client/js/inc/core/entry.js | 45 +++---------------- src/_h5ai/client/js/scripts.js | 6 +-- src/_h5ai/conf/langs.json | 34 -------------- src/_h5ai/server/php/inc/init.php | 1 - src/_h5ai/server/php/index.php.jade | 9 ++-- 7 files changed, 12 insertions(+), 87 deletions(-) rename src/_h5ai/client/css/inc/{fallback-table.less => no-js-fallback.less} (96%) delete mode 100644 src/_h5ai/conf/langs.json diff --git a/src/_h5ai/client/css/inc/fallback-table.less b/src/_h5ai/client/css/inc/no-js-fallback.less similarity index 96% rename from src/_h5ai/client/css/inc/fallback-table.less rename to src/_h5ai/client/css/inc/no-js-fallback.less index c2180336..c1e2bb97 100644 --- a/src/_h5ai/client/css/inc/fallback-table.less +++ b/src/_h5ai/client/css/inc/no-js-fallback.less @@ -1,5 +1,5 @@ -#data-apache-autoindex, #data-php-no-js-fallback { +#no-js-fallback { max-width: 960px; margin: 0 auto 80px auto; diff --git a/src/_h5ai/client/css/styles.less b/src/_h5ai/client/css/styles.less index 631aba7d..bf62e7c2 100644 --- a/src/_h5ai/client/css/styles.less +++ b/src/_h5ai/client/css/styles.less @@ -26,7 +26,7 @@ @import "inc/extended-grid"; // @import "inc/context-menu"; @import "inc/dropbox"; -@import "inc/fallback-table"; +@import "inc/no-js-fallback"; @import "inc/responsive"; diff --git a/src/_h5ai/client/js/inc/core/entry.js b/src/_h5ai/client/js/inc/core/entry.js index 53431840..ace3e99f 100644 --- a/src/_h5ai/client/js/inc/core/entry.js +++ b/src/_h5ai/client/js/inc/core/entry.js @@ -1,47 +1,12 @@ -modulejs.define('core/entry', ['_', '$', 'core/format', 'model/entry'], function (_, $, format, Entry) { +modulejs.define('core/entry', ['_', 'config', 'model/entry'], function (_, config, Entry) { - var parseGenericJson = function (absHref, $container) { + _.each(config.entries || [], function (entry) { - return JSON.parse($.trim($container.text()) || '{}').entries; - }, + Entry.get(entry.absHref, entry.time, entry.size, entry.status, entry.content); + }); - parseApacheTable = function (absHref, $table) { - - return _.compact(_.map($table.find('td').closest('tr'), function (tr) { - - var $tds = $(tr).find('td'), - $a = $tds.eq(1).find('a'); - - return $a.text() === 'Parent Directory' ? null : { - absHref: absHref + $a.attr('href'), - time: format.parseDate($tds.eq(2).text(), ['YYYY-MM-DD HH:mm', 'DD-MMM-YYYY HH:mm']), - size: format.parseSize($tds.eq(3).text()) - }; - })); - }, - - parse = function (absHref, $html) { - - var $generic = $html.find('#data-generic-json'), - $apache = $html.find('#data-apache-autoindex table'), - json = []; - - if ($generic.length) { - json = parseGenericJson(absHref, $generic); - } else if ($apache.length) { - json = parseApacheTable(absHref, $apache); - } - - return _.map(json, function (entry) { - - return Entry.get(entry.absHref, entry.time, entry.size, entry.status, entry.content); - }); - }, - - entry = Entry.get(); - - parse(entry.absHref, $('body')); + var entry = Entry.get(); entry.status = '=h5ai='; return entry; diff --git a/src/_h5ai/client/js/scripts.js b/src/_h5ai/client/js/scripts.js index 7036d680..ea476ec2 100644 --- a/src/_h5ai/client/js/scripts.js +++ b/src/_h5ai/client/js/scripts.js @@ -31,9 +31,7 @@ // @include "inc/**/*.js" var $ = jQuery, - filename = 'client/js/scripts.js', - $script = $('script[src$="' + filename + '"]'), - mode = $script.data('mode'); + mode = $('script[src$="scripts.js"]').data('mode'); if (mode === 'info') { @@ -41,7 +39,7 @@ } else { - $.getJSON('.', {action: 'get', options: true, types: true, langs: true, server: true}, function (config) { + $.getJSON('.', {action: 'get', options: true, types: true, langs: true, server: true, entries: true}, function (config) { modulejs.define('config', config); $(function () { modulejs.require('main'); }); diff --git a/src/_h5ai/conf/langs.json b/src/_h5ai/conf/langs.json deleted file mode 100644 index 8a5081c9..00000000 --- a/src/_h5ai/conf/langs.json +++ /dev/null @@ -1,34 +0,0 @@ -/* -{{pkg.name}} {{pkg.version}} -{{pkg.url}} - -Available translations -*/ - -{ - "en": "english", - - "bg": "български", - "cs": "čeština", - "de": "deutsch", - "el": "ελληνικά", - "es": "español", - "fr": "français", - "he": "עברית", - "hu": "magyar", - "it": "italiano", - "ja": "日本語", - "lv": "latviešu", - "nb": "norwegian", - "nl": "nederlands", - "pl": "polski", - "pt": "português", - "ro": "română", - "ru": "русский", - "sk": "slovenčina", - "sr": "srpski", - "sv": "svenska", - "tr": "türkçe", - "zh-cn": "简体中文", - "zh-tw": "正體中文" -} diff --git a/src/_h5ai/server/php/inc/init.php b/src/_h5ai/server/php/inc/init.php index 38890720..9761dde1 100644 --- a/src/_h5ai/server/php/inc/init.php +++ b/src/_h5ai/server/php/inc/init.php @@ -35,7 +35,6 @@ if (array_key_exists("action", $_REQUEST)) { } else { $HREF = $app->get_app_abs_href(); - $JSON = $app->get_generic_json(); $FALLBACK = $app->get_no_js_fallback(); } diff --git a/src/_h5ai/server/php/index.php.jade b/src/_h5ai/server/php/index.php.jade index ac4ef7d2..c9f0bd2d 100644 --- a/src/_h5ai/server/php/index.php.jade +++ b/src/_h5ai/server/php/index.php.jade @@ -1,7 +1,6 @@ | - var href = "" -- var json = "" - var fallback = "" doctype 5 @@ -21,9 +20,9 @@ html.no-js( lang="en" ) link( rel="apple-touch-icon", type="image/png", href!="#{href}client/images/app-48x48.png" ) link( rel="stylesheet", href="//fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic,700italic|Ubuntu:400,700,400italic,700italic" ) link( rel="stylesheet", href!="#{href}client/css/styles.css" ) - script( src!="#{href}client/js/scripts.js", data-mode="php" ) + script( src!="#{href}client/js/scripts.js" ) - body#h5ai-main + body div#topbar.clearfix ul#navbar @@ -44,6 +43,4 @@ html.no-js( lang="en" ) span.right span.center - div#data-generic-json.hidden !{json} - - div#data-php-no-js-fallback.hideOnJs !{fallback} + div#no-js-fallback.hideOnJs !{fallback} From cecc5c57a2484e8bdc40c87b31ec404c51c20abf Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Wed, 17 Oct 2012 00:53:28 +0200 Subject: [PATCH 006/130] Cleans code. --- src/_h5ai/client/js/inc/core/location.js | 2 +- src/_h5ai/client/js/inc/core/store.js | 2 +- src/_h5ai/server/php/inc/init.php | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/_h5ai/client/js/inc/core/location.js b/src/_h5ai/client/js/inc/core/location.js index 0ebcb24e..bea9577b 100644 --- a/src/_h5ai/client/js/inc/core/location.js +++ b/src/_h5ai/client/js/inc/core/location.js @@ -1,5 +1,5 @@ -modulejs.define('core/location', ['$', 'core/event'], function ($, event) { +modulejs.define('core/location', [], function () { var doc = document, diff --git a/src/_h5ai/client/js/inc/core/store.js b/src/_h5ai/client/js/inc/core/store.js index 1278470e..e4a66222 100644 --- a/src/_h5ai/client/js/inc/core/store.js +++ b/src/_h5ai/client/js/inc/core/store.js @@ -1,5 +1,5 @@ -modulejs.define('core/store', ['_', 'modernizr'], function (_, modernizr) { +modulejs.define('core/store', ['modernizr'], function (modernizr) { var store = modernizr.localstorage ? window.localStorage : null, diff --git a/src/_h5ai/server/php/inc/init.php b/src/_h5ai/server/php/inc/init.php index 9761dde1..333478e7 100644 --- a/src/_h5ai/server/php/inc/init.php +++ b/src/_h5ai/server/php/inc/init.php @@ -21,7 +21,6 @@ normalized_require_once("/server/php/inc/Entry.php"); $app = new App(APP_ABS_PATH, APP_ABS_HREF, ABS_HREF); -// if (count($_REQUEST)) { if (array_key_exists("action", $_REQUEST)) { header("Content-type: application/json"); From 885ce9e9e928db08e85e7bd2e249f8142062ccd2 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Wed, 17 Oct 2012 01:33:26 +0200 Subject: [PATCH 007/130] Cleans code. --- src/_h5ai/client/js/inc/core/format.js | 38 +------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/src/_h5ai/client/js/inc/core/format.js b/src/_h5ai/client/js/inc/core/format.js index edebc71d..d2267d5c 100644 --- a/src/_h5ai/client/js/inc/core/format.js +++ b/src/_h5ai/client/js/inc/core/format.js @@ -1,8 +1,7 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) { - var reParseSize = /^\s*([\.\d]+)\s*([kmgt]?)b?\s*$/i, - decimalMetric = { + var decimalMetric = { t: 1000.0, k: 1000.0, u: ['B', 'KB', 'MB', 'GB', 'TB'] @@ -15,30 +14,6 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) { defaultMetric = decimalMetric, defaultDateFormat = 'YYYY-MM-DD HH:mm', - parseSize = function (str) { - - var match = reParseSize.exec(str), - kilo = decimalMetric.k, - val, unit; - - if (!match) { - return null; - } - - val = parseFloat(match[1]); - unit = match[2].toLowerCase(); - if (unit === 'k') { - val *= kilo; - } else if (unit === 'm') { - val *= kilo * kilo; - } else if (unit === 'g') { - val *= kilo * kilo * kilo; - } else if (unit === 't') { - val *= kilo * kilo * kilo * kilo; - } - return val; - }, - setDefaultMetric = function (metric) { if (!metric) { @@ -73,15 +48,6 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) { defaultDateFormat = dateFormat; }, - parseDate = function (str, dateFormat) { - - try { // problems with ie < 9 :( - return moment(str, dateFormat || defaultDateFormat).valueOf() || null; - } catch (err) {} - - return Date.parse(str).valueOf() || null; - }, - formatDate = function (millis, dateFormat) { if (!_.isNumber(millis) || !millis) { @@ -92,11 +58,9 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) { }; return { - parseSize: parseSize, setDefaultMetric: setDefaultMetric, formatSize: formatSize, setDefaultDateFormat: setDefaultDateFormat, - parseDate: parseDate, formatDate: formatDate }; }); From 910312f7ce8914dce97a0417d80fea9a9790254b Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Wed, 17 Oct 2012 01:54:05 +0200 Subject: [PATCH 008/130] Cleans code. --- src/_h5ai/client/js/inc/core/resource.js | 1 + src/_h5ai/client/js/inc/core/settings.js | 17 +++--- src/_h5ai/client/js/inc/ext/folderstatus.js | 30 ---------- src/_h5ai/client/js/inc/model/entry.js | 29 ---------- src/_h5ai/conf/options.json | 62 +++++++++------------ 5 files changed, 35 insertions(+), 104 deletions(-) delete mode 100644 src/_h5ai/client/js/inc/ext/folderstatus.js diff --git a/src/_h5ai/client/js/inc/core/resource.js b/src/_h5ai/client/js/inc/core/resource.js index 1be1a4cc..f89007b7 100644 --- a/src/_h5ai/client/js/inc/core/resource.js +++ b/src/_h5ai/client/js/inc/core/resource.js @@ -5,6 +5,7 @@ modulejs.define('core/resource', ['core/settings'], function (settings) { return settings.h5aiAbsHref + 'client/images/' + id + (noPngExt ? '' : '.png'); }, + icon = function (id, big) { return settings.h5aiAbsHref + 'client/icons/' + (big ? '48x48' : '16x16') + '/' + id + '.png'; diff --git a/src/_h5ai/client/js/inc/core/settings.js b/src/_h5ai/client/js/inc/core/settings.js index 6afde834..03112e74 100644 --- a/src/_h5ai/client/js/inc/core/settings.js +++ b/src/_h5ai/client/js/inc/core/settings.js @@ -1,16 +1,17 @@ modulejs.define('core/settings', ['config', '_', '$'], function (config, _, $) { - var settings = _.extend({ - h5aiAbsHref: '/_h5ai/' - }, config.options), - - filename = 'client/js/scripts.js', + var filename = 'client/js/scripts.js', src = $('script[src$="' + filename + '"]').attr('src'), - appHref = src.substr(0, src.length - filename.length); + appHref = src.substr(0, src.length - filename.length), - settings.h5aiAbsHref = src.substr(0, src.length - filename.length).replace(/\/*$/, '/'); - settings.rootAbsHref = /^(.*\/)[^\/]+\/?$/.exec(settings.h5aiAbsHref)[1]; + h5aiAbsHref = src.substr(0, src.length - filename.length).replace(/\/*$/, '/'), + rootAbsHref = /^(.*\/)[^\/]+\/?$/.exec(h5aiAbsHref)[1], + + settings = _.extend({}, config.options, { + h5aiAbsHref: h5aiAbsHref, + rootAbsHref: rootAbsHref + }); return settings; }); diff --git a/src/_h5ai/client/js/inc/ext/folderstatus.js b/src/_h5ai/client/js/inc/ext/folderstatus.js deleted file mode 100644 index 929f7e79..00000000 --- a/src/_h5ai/client/js/inc/ext/folderstatus.js +++ /dev/null @@ -1,30 +0,0 @@ - -modulejs.define('ext/folderstatus', ['_', '$', 'core/settings', 'core/event', 'core/entry'], function (_, $, allsettings, event, entry) { - - var settings = _.extend({ - enabled: false, - maxChecks: 16, - delay: 2000 - }, allsettings.folderstatus), - - init = function () { - - if (!settings.enabled) { - return; - } - - event.sub('ready', function () { - - var count = 0; - _.each(entry.content, function (e) { - - if (e.isFolder() && e.status === null && count <= settings.maxChecks) { - count += 1; - setTimeout(function () { e.fetchStatus(); }, settings.delay); - } - }); - }); - }; - - init(); -}); diff --git a/src/_h5ai/client/js/inc/model/entry.js b/src/_h5ai/client/js/inc/model/entry.js index 162c59fe..21ebf124 100644 --- a/src/_h5ai/client/js/inc/model/entry.js +++ b/src/_h5ai/client/js/inc/model/entry.js @@ -106,30 +106,6 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett } }, - fetchStatus = function (absHref, callback) { - - var self = getEntry(absHref); - - if (!_.isFunction(callback)) { - callback = function () {}; - } - - if (self.status !== null) { - callback(self); - } else { - server.request({action: 'get', entries: true, entriesHref: self.absHref, entriesWhat: 0}, function (response) { - - if (response.entries) { - _.each(response.entries, function (entry) { - getEntry(entry.absHref, entry.time, entry.size, entry.status, entry.content); - }); - } - - callback(self); - }); - } - }, - fetchContent = function (absHref, callback) { var self = getEntry(absHref); @@ -224,11 +200,6 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett return _.keys(this.content).length === 0; }, - fetchStatus: function (callback) { - - return fetchStatus(this.absHref, callback); - }, - fetchContent: function (callback) { return fetchContent(this.absHref, callback); diff --git a/src/_h5ai/conf/options.json b/src/_h5ai/conf/options.json index a5f4ec61..ec68c0b6 100644 --- a/src/_h5ai/conf/options.json +++ b/src/_h5ai/conf/options.json @@ -6,7 +6,7 @@ Options */ { - /* [all] + /* Spacing of the main content. Left and right will be added to a minimum of 30px. Top and bottom @@ -20,7 +20,7 @@ Options "left": "auto" }, - /* [all] + /* General view options. - modes: array of "details", "icons", "grid" and/or "list" @@ -45,7 +45,7 @@ Options /*** Extensions (in alphabetical order) ***/ - /* [php] + /* Watch and update current folder content. - interval: number, update interval in milliseconds, at least 1000 @@ -55,14 +55,14 @@ Options "interval": 5000 }, - /* [all] + /* Show a clickable breadcrumb. */ "crumb": { "enabled": true }, - /* [all] + /* Filenames of customized header and footer files to look for in each folder. */ @@ -72,14 +72,14 @@ Options "footer": "_{{pkg.name}}.footer.html" }, - /* [php, EXPERIMENTAL] + /* [EXPERIMENTAL] Allow file deletion. */ "delete": { "enabled": false }, - /* [php, EXPERIMENTAL] + /* [EXPERIMENTAL] File upload via drag'n'drop. Folders are not supported. The working file size seems to be very browser dependent. @@ -92,7 +92,7 @@ Options "maxfilesize": 1000 }, - /* [php] + /* Enable packaged download of selected entries. - execution: "php" or "shell" @@ -106,7 +106,7 @@ Options "packageName": null }, - /* [all] + /* Allow filtering the displayed files and folders. Will check entries for right order of characters, i.e. "ab" matches "ab", "axb", "xaxbx" but not "ba". @@ -119,26 +119,14 @@ Options "enabled": true }, - /* [php] + /* Calc the size of folders. */ "foldersize": { "enabled": true }, - /* [aai] - Fetch status for subfolders of the current folder. - - - maxChecks: number, max number of status requests in the current folder - - delay: number, delay in milliseconds after "dom-ready" before starting the requests - */ - "folderstatus": { - "enabled": false, - "maxChecks": 16, - "delay": 2000 - }, - - /* [all] + /* Adds Google Analytics asynchronous tracking code. for example: @@ -156,7 +144,7 @@ Options "gaq": [] }, - /* [all] + /* Localization, for example "en", "de" etc. - see "langs" below for possible values. Adjust it to your needs. If lang is not found in "langs" it defaults to "en". @@ -170,14 +158,14 @@ Options "useBrowserLang": true }, - /* [all] + /* Link the hover effects between crumb, main view and tree. */ "link-hover-states": { "enabled": true }, - /* [all] + /* Shows the server mode in the bottom left corner. - display: @@ -190,7 +178,7 @@ Options "display": 2 }, - /* [all] + /* Adds Piwik tracker javascript code. - baseURL: do not include the protocol, e.g. "mydomain.tld/piwik" @@ -202,7 +190,7 @@ Options "idSite": 1 }, - /* [all] + /* Show an image preview on click. - types: array of types @@ -212,7 +200,7 @@ Options "types": ["bmp", "gif", "ico", "image", "jpg", "png", "tiff"] }, - /* [all] + /* Show text file preview on click. "types" maps file types to SyntaxHighligher brushes. Special case: "markdown" will be rendered as HTML. @@ -250,7 +238,7 @@ Options } }, - /* [all] + /* Show QRCodes on hovering files. - size: width and height in pixel @@ -260,7 +248,7 @@ Options "size": 150 }, - /* [php, EXPERIMENTAL] + /* [EXPERIMENTAL] Allow to rename files. No GUI yet. */ @@ -268,14 +256,14 @@ Options "enabled": false }, - /* [all] + /* Make entries selectable. At the moment only needed for packaged download and delete. */ "select": { "enabled": true }, - /* [all] + /* Default sort order is a two letter code. The first letter specifies the column: "n" for "Name", "d" for "Date" or "s" for "Size". The second letter specifies the sort order: "a" for "ascending" or "d" @@ -288,14 +276,14 @@ Options "order": "na" }, - /* [all] + /* Show additional info in a statusbar. */ "statusbar": { "enabled": true }, - /* [php] + /* Show thumbnails for image files. Needs the "/_{{pkg.name}}/cache" folder to be writable for the web Server. @@ -312,14 +300,14 @@ Options "delay": 1 }, - /* [all] + /* Replace window title with current breadcrumb. */ "title": { "enabled": true }, - /* [all] + /* Show a folder tree. Note that this might affect performance significantly. From c7a9d444afe63bce25ab9c3f1be2d665bf1e7033 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Thu, 18 Oct 2012 20:52:47 +0200 Subject: [PATCH 009/130] Adds notifications. --- src/_h5ai/client/css/inc/notify.less | 17 +++++++++++++++ src/_h5ai/client/js/inc/core/notify.js | 29 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/_h5ai/client/css/inc/notify.less create mode 100644 src/_h5ai/client/js/inc/core/notify.js diff --git a/src/_h5ai/client/css/inc/notify.less b/src/_h5ai/client/css/inc/notify.less new file mode 100644 index 00000000..19e38cef --- /dev/null +++ b/src/_h5ai/client/css/inc/notify.less @@ -0,0 +1,17 @@ + +#notify { + position: fixed; + left: 50%; + top: 3px; + width: 200px; + margin-left: -100px; + z-index: 100; + padding: 2px 6px 2px 6px; + color: #fff; + // background-color: rgba(240, 100, 0, 0.5); + // border: 2px solid rgba(255, 255, 255, 0.5); + // border: 2px solid rgba(240, 100, 0, 0.9); + background-color: rgba(0, 0, 0, 0.2); + .border-radius(4px); + text-align: center; +} diff --git a/src/_h5ai/client/js/inc/core/notify.js b/src/_h5ai/client/js/inc/core/notify.js new file mode 100644 index 00000000..b4e7c9c7 --- /dev/null +++ b/src/_h5ai/client/js/inc/core/notify.js @@ -0,0 +1,29 @@ + +modulejs.define('core/notify', ['$'], function ($) { + + var test = null, + + template = '
    ', + + id = 0, + + set = function (content) { + + if (content) { + $('#notify').stop(true, true).html(content).fadeIn(400); + } else { + $('#notify').stop(true, true).fadeOut(400); + } + }, + + init = function () { + + $(template).hide().appendTo('body'); + }; + + init(); + + return { + set: set + }; +}); From ecc05d3a8b347aab84a7e82c0773c09f981d3ebc Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Thu, 18 Oct 2012 20:53:38 +0200 Subject: [PATCH 010/130] Adds notifications. --- src/_h5ai/client/css/styles.less | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_h5ai/client/css/styles.less b/src/_h5ai/client/css/styles.less index bf62e7c2..27c23fa9 100644 --- a/src/_h5ai/client/css/styles.less +++ b/src/_h5ai/client/css/styles.less @@ -17,6 +17,7 @@ @import "inc/qrcode"; @import "inc/preview-img"; @import "inc/preview-txt"; +@import "inc/notify"; @import "inc/content"; @import "inc/extended"; From 499013f4fb4537a2472826e8c6f299603766f58a Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Thu, 18 Oct 2012 21:27:09 +0200 Subject: [PATCH 011/130] Initial switch to smart browsing. --- src/_h5ai/client/js/inc/core/entry.js | 12 +- src/_h5ai/client/js/inc/core/location.js | 117 +++++++++++++++--- src/_h5ai/client/js/inc/core/refresh.js | 4 +- src/_h5ai/client/js/inc/core/server.js | 4 +- src/_h5ai/client/js/inc/ext/crumb.js | 54 +++++--- src/_h5ai/client/js/inc/ext/custom.js | 34 +++-- .../client/js/inc/ext/link-hover-states.js | 19 ++- src/_h5ai/client/js/inc/main.js | 4 +- src/_h5ai/client/js/inc/model/entry.js | 24 +++- .../js/inc/view/{extended.js => items.js} | 61 +++++---- src/_h5ai/conf/options.json | 5 +- src/_h5ai/server/php/index.php.jade | 3 - 12 files changed, 244 insertions(+), 97 deletions(-) rename src/_h5ai/client/js/inc/view/{extended.js => items.js} (75%) diff --git a/src/_h5ai/client/js/inc/core/entry.js b/src/_h5ai/client/js/inc/core/entry.js index ace3e99f..03e374a4 100644 --- a/src/_h5ai/client/js/inc/core/entry.js +++ b/src/_h5ai/client/js/inc/core/entry.js @@ -1,13 +1,5 @@ -modulejs.define('core/entry', ['_', 'config', 'model/entry'], function (_, config, Entry) { +modulejs.define('core/entry', ['core/location'], function (location) { - _.each(config.entries || [], function (entry) { - - Entry.get(entry.absHref, entry.time, entry.size, entry.status, entry.content); - }); - - var entry = Entry.get(); - entry.status = '=h5ai='; - - return entry; + return location.getItem(); }); diff --git a/src/_h5ai/client/js/inc/core/location.js b/src/_h5ai/client/js/inc/core/location.js index bea9577b..8a870525 100644 --- a/src/_h5ai/client/js/inc/core/location.js +++ b/src/_h5ai/client/js/inc/core/location.js @@ -1,7 +1,13 @@ -modulejs.define('core/location', [], function () { +modulejs.define('core/location', ['_', 'modernizr', 'core/settings', 'core/event', 'core/notify'], function (_, modernizr, allsettings, event, notify) { - var doc = document, + var settings = _.extend({ + smartBrowsing: false + }, allsettings.view), + + doc = document, + + history = settings.smartBrowsing && modernizr.history ? window.history : null, forceEncoding = function (href) { @@ -17,36 +23,109 @@ modulejs.define('core/location', [], function () { .replace(/\=/g, '%3D'); }, - absHref = (function () { + reUriToPathname = /^.*:\/\/[^\/]*|[^\/]*$/g, + uriToPathname = function (uri) { - var rePrePathname = /.*:\/\/[^\/]*/, - rePostPathname = /[^\/]*$/, + return uri.replace(reUriToPathname, ''); + }, - uriToPathname = function (uri) { + hrefsAreDecoded = (function () { - return uri.replace(rePrePathname, '').replace(rePostPathname, ''); - }, - - testpathname = '/a b', - a = doc.createElement('a'), - isDecoded, location; + var testpathname = '/a b', + a = doc.createElement('a'); a.href = testpathname; - isDecoded = uriToPathname(a.href) === testpathname; + return uriToPathname(a.href) === testpathname; + }()), - a.href = doc.location.href; + encodedHref = function (href) { + + var a = doc.createElement('a'), + location; + + a.href = href; location = uriToPathname(a.href); - if (isDecoded) { + if (hrefsAreDecoded) { location = encodeURIComponent(location).replace(/%2F/ig, '/'); } return forceEncoding(location); - }()); + }; + + + var absHref = null, + + getDomain = function () { + + return doc.domain; + }, + + getAbsHref = function () { + + return absHref; + }, + + getItem = function () { + + return modulejs.require('model/entry').get(absHref); + }, + + setLocation = function (newAbsHref, keepBrowserUrl) { + + newAbsHref = encodedHref(newAbsHref); + if (absHref !== newAbsHref) { + absHref = newAbsHref; + event.pub('location.changed', absHref); + + notify.set('loading...'); + modulejs.require('core/refresh')(function () { notify.set(); }); + + if (history) { + if (keepBrowserUrl) { + history.replaceState({absHref: absHref}, '', absHref); + } else { + history.pushState({absHref: absHref}, '', absHref); + } + } + } + }, + + setLink = function ($el, item) { + + $el.attr('href', item.absHref); + + if (history && item.isFolder() && item.status === '=h5ai=') { + $el.on('click', function () { + + setLocation(item.absHref); + return false; + }); + } + + if (item.status !== '=h5ai=') { + $el.attr('target', '_blank'); + } + }; + + + if (history) { + window.onpopstate = function (e) { + + if (e.state && e.state.absHref) { + setLocation(e.state.absHref, true); + } + }; + } + return { - domain: doc.domain, - absHref: absHref, - forceEncoding: forceEncoding + forceEncoding: forceEncoding, + encodedHref: encodedHref, + getDomain: getDomain, + getAbsHref: getAbsHref, + getItem: getItem, + setLocation: setLocation, + setLink: setLink }; }); diff --git a/src/_h5ai/client/js/inc/core/refresh.js b/src/_h5ai/client/js/inc/core/refresh.js index 23d60b84..0ac66bcf 100644 --- a/src/_h5ai/client/js/inc/core/refresh.js +++ b/src/_h5ai/client/js/inc/core/refresh.js @@ -1,5 +1,5 @@ -modulejs.define('core/refresh', ['_', 'core/server', 'model/entry'], function (_, server, Entry) { +modulejs.define('core/refresh', ['_', 'config', 'core/server', 'model/entry', 'core/location'], function (_, config, server, Entry, location) { var parseJson = function (entry, json) { @@ -20,7 +20,7 @@ modulejs.define('core/refresh', ['_', 'core/server', 'model/entry'], function (_ refresh = function (callback) { - var entry = Entry.get(); + var entry = Entry.get(location.getAbsHref()); server.request({action: 'get', entries: true, entriesHref: entry.absHref, entriesWhat: 1}, function (json) { diff --git a/src/_h5ai/client/js/inc/core/server.js b/src/_h5ai/client/js/inc/core/server.js index 759b81bb..3ca818f6 100644 --- a/src/_h5ai/client/js/inc/core/server.js +++ b/src/_h5ai/client/js/inc/core/server.js @@ -1,5 +1,5 @@ -modulejs.define('core/server', ['$', '_', 'config'], function ($, _, config) { +modulejs.define('core/server', ['$', '_', 'config', 'core/location'], function ($, _, config, location) { var server = _.extend({}, config.server, { @@ -7,7 +7,7 @@ modulejs.define('core/server', ['$', '_', 'config'], function ($, _, config) { if (server.api) { $.ajax({ - url: '.', + url: location.getAbsHref(), data: data, type: 'POST', dataType: 'json', diff --git a/src/_h5ai/client/js/inc/ext/crumb.js b/src/_h5ai/client/js/inc/ext/crumb.js index da128980..72ebfbd3 100644 --- a/src/_h5ai/client/js/inc/ext/crumb.js +++ b/src/_h5ai/client/js/inc/ext/crumb.js @@ -1,5 +1,5 @@ -modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/entry'], function (_, $, allsettings, resource, event, entry) { +modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/location'], function (_, $, allsettings, resource, event, location) { var settings = _.extend({ enabled: false @@ -26,11 +26,11 @@ modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/ $html .addClass(entry.isFolder() ? 'folder' : 'file') + .data('item', entry) .data('status', entry.status); - $a - .attr('href', entry.absHref) - .find('span').text(entry.label).end(); + location.setLink($a, entry); + $a.find('span').text(entry.label).end(); if (entry.isDomain()) { $html.addClass('domain'); @@ -69,25 +69,49 @@ modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/ } }, - // creates the complete crumb from entry down to the root - init = function (entry) { + onLocationChanged = function (item) { + + var crumb = item.getCrumb(), + $ul = $('#navbar'), + found = false; + + $ul.find('.crumb').each(function () { + + var $html = $(this); + if ($html.data('item') === item) { + found = true; + $html.addClass('current'); + } else { + $html.removeClass('current'); + } + }); + + if (!found) { + $ul.find('.crumb').remove(); + _.each(crumb, function (e) { + + $ul.append(update(e)); + }); + } + }, + + init = function () { if (!settings.enabled) { return; } - var crumb = entry.getCrumb(), - $ul = $('#navbar'); - - _.each(crumb, function (e) { - - $ul.append(update(e)); - }); - // event.sub('entry.created', onContentChanged); // event.sub('entry.removed', onContentChanged); event.sub('entry.changed', onContentChanged); + + event.sub('location.changed', function () { + + onLocationChanged(location.getItem()); + }); + + onLocationChanged(location.getItem()); }; - init(entry); + init(); }); diff --git a/src/_h5ai/client/js/inc/ext/custom.js b/src/_h5ai/client/js/inc/ext/custom.js index 5da2495b..649fcc70 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -1,5 +1,5 @@ -modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server'], function (_, $, allsettings, server) { +modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/event'], function (_, $, allsettings, server, event) { var settings = _.extend({ enabled: false, @@ -7,23 +7,35 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server'], functi footer: '_h5ai.footer.html' }, allsettings.custom), + onLocationChanged = function () { + + $('#content-header, #content-footer').stop(true, true).slideUp(200); + + server.request({action: 'get', custom: true}, function (response) { + + if (response) { + if (response.custom.header) { + $('#content-header').html(response.custom.header).stop(true, true).slideDown(400); + } + if (response.custom.footer) { + $('#content-footer').html(response.custom.footer).stop(true, true).slideDown(400); + } + } + }); + }, + init = function () { if (!settings.enabled) { return; } - server.request({action: 'get', custom: true}, function (response) { + $('
    ').hide().prependTo('#content'); + $('
  • ' + '', emptyTemplate = '
    ', + contentTemplate = '
    ', // updates this single entry update = function (entry, force) { @@ -40,14 +41,14 @@ modulejs.define('view/extended', ['_', '$', 'core/settings', 'core/resource', 'c $label = $html.find('.label'), $date = $html.find('.date'), $size = $html.find('.size'); - // escapedHref = entry.absHref.replace(/'/g, "%27").replace(/"/g, "%22"); $html .addClass(entry.isFolder() ? 'folder' : 'file') .data('entry', entry) .data('status', entry.status); - $a.attr('href', entry.absHref); + location.setLink($a, entry); + $imgSmall.attr('src', resource.icon(entry.type)).attr('alt', entry.type); $imgBig.attr('src', resource.icon(entry.type, true)).attr('alt', entry.type); $label.text(entry.label); @@ -94,32 +95,42 @@ modulejs.define('view/extended', ['_', '$', 'core/settings', 'core/resource', 'c event.pub('entry.mouseleave', entry); }, - // creates the view for entry content - init = function (entry) { + onLocationChanged = function (item) { var $extended = $('#extended'), - $ul = $(listTemplate), - $emtpy = $(emptyTemplate); + $ul = $extended.find('ul'), + $empty = $extended.find('.empty'); - format.setDefaultMetric(settings.binaryPrefix); + $ul.find('.entry').remove(); - if (entry.parent) { - $ul.append(update(entry.parent)); + if (item.parent) { + $ul.append(update(item.parent)); } - _.each(entry.content, function (e) { + _.each(item.content, function (e) { $ul.append(update(e)); }); - $extended.append($ul); - $extended.append($emtpy); - - if (!entry.isEmpty()) { - $emtpy.hide(); + if (item.isEmpty()) { + $empty.show(); + } else { + $empty.hide(); } + }, + + init = function () { + + var $content = $(contentTemplate), + $extended = $content.find('#extended'), + $ul = $(listTemplate), + $emtpy = $(emptyTemplate).hide(); + + format.setDefaultMetric(settings.binaryPrefix); $extended + .append($ul) + .append($emtpy) .on('mouseenter', '.entry a', onMouseenter) .on('mouseleave', '.entry a', onMouseleave); @@ -133,24 +144,32 @@ modulejs.define('view/extended', ['_', '$', 'core/settings', 'core/resource', 'c event.sub('entry.created', function (entry) { if (entry.isInCurrentFolder() && !entry.$extended) { - update(entry, true).hide().appendTo($ul).slideDown(400); - $emtpy.slideUp(400); + $emtpy.fadeOut(100, function () { + update(entry, true).hide().appendTo($ul).fadeIn(400); + }); } }); event.sub('entry.removed', function (entry) { if (entry.isInCurrentFolder() && entry.$extended) { - entry.$extended.slideUp(400, function () { + entry.$extended.fadeOut(400, function () { entry.$extended.remove(); if (entry.parent.isEmpty()) { - $emtpy.slideDown(400); + $emtpy.fadeIn(100); } }); } }); + + event.sub('location.changed', function () { + + onLocationChanged(location.getItem()); + }); + + $content.appendTo('body'); }; - init(entry); + init(); }); diff --git a/src/_h5ai/conf/options.json b/src/_h5ai/conf/options.json index ec68c0b6..dfbef51b 100644 --- a/src/_h5ai/conf/options.json +++ b/src/_h5ai/conf/options.json @@ -38,7 +38,8 @@ Options "setParentFolderLabels": true, "binaryPrefix": false, "indexFiles": ["index.html", "index.htm", "index.php"], - "ignore": ["^\\.", "^_{{pkg.name}}"] + "ignore": ["^\\.", "^_{{pkg.name}}"], + "smartBrowsing": true }, @@ -67,7 +68,7 @@ Options in each folder. */ "custom": { - "enabled": false, + "enabled": true, "header": "_{{pkg.name}}.header.html", "footer": "_{{pkg.name}}.footer.html" }, diff --git a/src/_h5ai/server/php/index.php.jade b/src/_h5ai/server/php/index.php.jade index c9f0bd2d..8ea6cbe1 100644 --- a/src/_h5ai/server/php/index.php.jade +++ b/src/_h5ai/server/php/index.php.jade @@ -27,9 +27,6 @@ html.no-js( lang="en" ) div#topbar.clearfix ul#navbar - div#content - div#extended.clearfix - div#bottombar.clearfix span.left a#h5ai-reference( href="{{pkg.url}}", title="{{pkg.name}} · {{pkg.description}}" ) From e956a496806a9703985a1220effa39dc76140f64 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Thu, 18 Oct 2012 23:08:48 +0200 Subject: [PATCH 012/130] More changes to enable smart browsing. --- src/_h5ai/client/js/inc/core/entry.js | 5 --- src/_h5ai/client/js/inc/core/location.js | 2 +- src/_h5ai/client/js/inc/ext/crumb.js | 7 +---- src/_h5ai/client/js/inc/ext/custom.js | 2 -- src/_h5ai/client/js/inc/ext/download.js | 4 +-- src/_h5ai/client/js/inc/ext/dropbox.js | 4 +-- src/_h5ai/client/js/inc/ext/preview-img.js | 14 ++++++--- src/_h5ai/client/js/inc/ext/preview-txt.js | 14 ++++++--- src/_h5ai/client/js/inc/ext/statusbar.js | 21 +++++++------ src/_h5ai/client/js/inc/ext/thumbnails.js | 20 +++++++----- src/_h5ai/client/js/inc/ext/title.js | 21 ++++++++----- src/_h5ai/client/js/inc/ext/tree.js | 36 +++++++++++++--------- src/_h5ai/client/js/inc/main.js | 4 +-- src/_h5ai/client/js/inc/view/items.js | 5 +-- 14 files changed, 85 insertions(+), 74 deletions(-) delete mode 100644 src/_h5ai/client/js/inc/core/entry.js diff --git a/src/_h5ai/client/js/inc/core/entry.js b/src/_h5ai/client/js/inc/core/entry.js deleted file mode 100644 index 03e374a4..00000000 --- a/src/_h5ai/client/js/inc/core/entry.js +++ /dev/null @@ -1,5 +0,0 @@ - -modulejs.define('core/entry', ['core/location'], function (location) { - - return location.getItem(); -}); diff --git a/src/_h5ai/client/js/inc/core/location.js b/src/_h5ai/client/js/inc/core/location.js index 8a870525..4e12a2a2 100644 --- a/src/_h5ai/client/js/inc/core/location.js +++ b/src/_h5ai/client/js/inc/core/location.js @@ -76,7 +76,7 @@ modulejs.define('core/location', ['_', 'modernizr', 'core/settings', 'core/event newAbsHref = encodedHref(newAbsHref); if (absHref !== newAbsHref) { absHref = newAbsHref; - event.pub('location.changed', absHref); + event.pub('location.changed', getItem()); notify.set('loading...'); modulejs.require('core/refresh')(function () { notify.set(); }); diff --git a/src/_h5ai/client/js/inc/ext/crumb.js b/src/_h5ai/client/js/inc/ext/crumb.js index 72ebfbd3..b4656b50 100644 --- a/src/_h5ai/client/js/inc/ext/crumb.js +++ b/src/_h5ai/client/js/inc/ext/crumb.js @@ -105,12 +105,7 @@ modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/ // event.sub('entry.removed', onContentChanged); event.sub('entry.changed', onContentChanged); - event.sub('location.changed', function () { - - onLocationChanged(location.getItem()); - }); - - onLocationChanged(location.getItem()); + event.sub('location.changed', onLocationChanged); }; init(); diff --git a/src/_h5ai/client/js/inc/ext/custom.js b/src/_h5ai/client/js/inc/ext/custom.js index 649fcc70..33df86e8 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -34,8 +34,6 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/e $('