Skip to content

Commit

Permalink
[js:extras] add quicklook.googledocs.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Apr 1, 2016
1 parent d2d788f commit f1661bb
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var dirmode = 0755,
path.join(src, 'composer.json'),
path.join(src, 'elfinder.html')
]
.concat(grep(path.join(src, 'js', 'extras'), '\\.js$'))
};

// plugins files
Expand Down Expand Up @@ -100,7 +101,7 @@ function copyFile(from, to, overwrite) {
console.log('\t' + from);
var srcs = fs.createReadStream(from);
var dsts = fs.createWriteStream(to);
return util.pump(srcs, dsts);
return srcs.pipe(dsts);
}

function getComment() {
Expand Down Expand Up @@ -135,7 +136,7 @@ desc('pre build task');
task('prebuild', function(){
console.log('build dir: ' + path.resolve());
console.log('src dir: ' + src);
var dir = ['css', 'js', 'img', 'sounds', path.join('js', 'i18n'), path.join('js', 'proxy'), 'php', 'files'];
var dir = ['css', 'js', 'img', 'sounds', path.join('js', 'i18n'), path.join('js', 'extras'), path.join('js', 'proxy'), 'php', 'files'];
if (plugins.length) {
dir.push(path.join('php', 'plugins'));
for (var i in plugins) {
Expand Down
5 changes: 4 additions & 1 deletion elfinder.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
<!-- elFinder JS (REQUIRED) -->
<script src="js/elfinder.min.js"></script>

<!-- GoogleDocs Quicklook plugin for GoogleDrive Volume (OPTIONAL) -->
<!--<script src="js/extras/quicklook.googledocs.js"></script>-->

<!-- elFinder translation (OPTIONAL) -->
<script src="js/i18n/elfinder.ru.js"></script>
<!--<script src="js/i18n/elfinder.ru.js"></script>-->

<!-- elFinder initialization (REQUIRED) -->
<script type="text/javascript" charset="utf-8">
Expand Down
3 changes: 3 additions & 0 deletions elfinder.playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
<!-- elfinder 1.x connector API support -->
<script src="js/proxy/elFinderSupportVer1.js"></script>

<!-- GoogleDocs Quicklook plugin for GoogleDrive Volume -->
<script src="js/extras/quicklook.googledocs.js"></script>

<!-- elfinder custom extenstions -->
<script src="extensions/jplayer/elfinder.quicklook.jplayer.js"></script>

Expand Down
3 changes: 3 additions & 0 deletions elfinder.src.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<!-- elfinder 1.x connector API support -->
<script src="js/proxy/elFinderSupportVer1.js"></script>

<!-- GoogleDocs Quicklook plugin for GoogleDrive Volume -->
<script src="js/extras/quicklook.googledocs.js"></script>

<!-- elfinder initialization -->
<script>
$(function() {
Expand Down
59 changes: 59 additions & 0 deletions js/extras/quicklook.googledocs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use strict"

try {
if (! elFinder.prototype.commands.quicklook.plugins) {
elFinder.prototype.commands.quicklook.plugins = [];
}
elFinder.prototype.commands.quicklook.plugins.push(function(ql) {
var fm = ql.fm,
preview = ql.preview;

preview.bind('update', function(e) {
var win = ql.window,
file = e.file, node, loading;

if (file.mime.indexOf('application/vnd.google-apps.') === 0) {
if (file.url == '1') {
$('<div class="elfinder-quicklook-info-data"><button class="elfinder-info-button">'+fm.i18n('getLink')+'</button></div>').appendTo(ql.info.find('.elfinder-quicklook-info'))
.on('click', function() {
$(this).html('<span class="elfinder-info-spinner">');
fm.request({
data : {cmd : 'url', target : file.hash},
preventDefault : true
})
.always(function() {
$(this).html('');
})
.done(function(data) {
var rfile = fm.file(file.hash);
ql.value.url = rfile.url = data.url || '';
if (ql.value.url) {
preview.trigger($.Event('update', {file : ql.value}));
}
});
});
}
if (file.url !== '' && file.url != '1') {
e.stopImmediatePropagation();
preview.one('change', function() {
loading.remove();
node.off('load').remove();
});

loading = $('<div class="elfinder-quicklook-info-data"> Now loading...<span class="elfinder-info-spinner"></div>').appendTo(ql.info.find('.elfinder-quicklook-info'));

node = $('<iframe class="elfinder-quicklook-preview-iframe"/>')
.css('background-color', 'transparent')
.appendTo(preview)
.on('load', function() {
ql.hideinfo();
loading.remove();
$(this).css('background-color', '#fff').show();
})
.attr('src', fm.url(file.hash).replace('/edit', '/embed'));
}
}

});
});
} catch(e) {}

0 comments on commit f1661bb

Please sign in to comment.