Add highlightjs editor to view files

This commit is contained in:
2015-04-10 12:43:31 +00:00
parent c143a84841
commit a6634c4207
9 changed files with 210 additions and 120 deletions

View File

@@ -5,10 +5,11 @@ requirejs.config({
'plugins' : '../lib/durandal/js/plugins',
'transitions' : '../lib/durandal/js/transitions',
'knockout' : '../lib/knockout.js/knockout',
'knockout.mapping' : '../lib/bower-knockout-mapping/dist/knockout.mapping.min',
'knockout.validation': '../lib/knockout-validation/dist/knockout.validation.min',
'jquery' : '../lib/jquery/jquery.min',
'perfect.scrollbar' : '../lib/perfect-scrollbar/js/perfect-scrollbar.jquery'
'knockout.mapping' : '../lib/bower-knockout-mapping/dist/knockout.mapping.min',
'knockout.validation' : '../lib/knockout-validation/dist/knockout.validation.min',
'jquery' : '../lib/jquery/jquery.min',
'perfect.scrollbar' : '../lib/perfect-scrollbar/js/perfect-scrollbar.jquery',
'highlightjs' : '../lib/highlightjs/highlight.pack'
},
shim: {
'knockout.mapping': {

View File

@@ -1,13 +1,15 @@
<div class="row-fluid">
<aside class="col-md-3" id="filebrowser">
<div data-bind="widget: {kind:'filebrowser'}"></div>
</aside>
<main class="col-md-6" id="main">
<div class="scrollable" id="mainOutput">
</div>
</main>
<aside class="col-md-3" id="helpPane">
</aside>
<div data-bind="widget: {kind:'filebrowser'}"></div>
</aside>
<main class="col-md-6" id="main">
<pre data-bind="visible: content">
<code data-bind="attr: {css: type}, text: content" id="editor"></code>
</pre>
<span class="text-center" data-bind="visible: !content()">Open file to view it.</span>
</main>
<aside class="col-md-3" id="helpPane">
</aside>
</div>

View File

@@ -1,7 +1,26 @@
define(function (require) {
var app = require('durandal/app'),
ko = require('knockout');
return {
};
define(['durandal/app', 'knockout', 'highlightjs'], function (app, ko) {
var type = ko.observable(),
content = ko.observable();
var sub = app.on('filebrowser:open_file').then(function(message) {
type(message.type);
if( message.type === "json" ) {
content(ko.utils.stringifyJson(message.content));
} else {
content(message.content);
}
hljs.highlightBlock($('#editor')[0]);
}, this);
return {
attached: function () {
hljs.configure({
tabReplace: ' '
});
hljs.initHighlighting();
},
type: type,
content: content
};
});

View File

@@ -3,7 +3,8 @@
<!-- ko let: { loopRoot: $data } -->
<ul data-bind="template: { name: 'tree-template', foreach: folder().children() }" class="tree-file"></ul>
<!-- /ko -->
<!-- /ko -->
<!-- /ko -->
<span data-bind="visible: !folder()" class="text-center">Loading workspace...</span>
<script id="tree-template" type="text/html">
<!-- ko if: $data.type() === "folder" -->

View File

@@ -37,8 +37,15 @@ define(['durandal/app', 'durandal/composition', 'plugins/http',
};
ctor.prototype.openFile = function(object, event) {
console.log('File dblclick ', arguments);
};
var type = arguments[0].extra();
http.get(arguments[0].path()).then(function(response) {
app.trigger('filebrowser:open_file', {
type: type,
content: response
});
});
};
ctor.prototype.select = function(object, event) {
if( !event.ctrlKey ) {
$('li > span.select').removeClass('select');
@@ -72,7 +79,7 @@ define(['durandal/app', 'durandal/composition', 'plugins/http',
posX = Math.min(posX - 45, windowWidth - menuWidth - 15);
posY = Math.min(posY - 80, windowHeight - menuHeight - 10);
// affichage
// display
contextMenu.css({
left : posX + 'px',
top : posY + 'px'
@@ -126,10 +133,9 @@ define(['durandal/app', 'durandal/composition', 'plugins/http',
/** End of Context Menu */
http.get('/data/filesystem.json').then(function(response) {
console.log(response);
folder(ko.mapping.fromJS(response));
$('#filebrowser').perfectScrollbar();
});
return ctor;
});

View File

@@ -1,5 +1,6 @@
{
"name": "filebrowser-durandal-widget",
"name": "filebrowser-durandal-widget",
"version": "0.0.1-SNAPSHOT",
"dependencies" : {
"durandal" : "~2.1.0",
"knockout-validation" : "~2.0.2",
@@ -9,6 +10,6 @@
"fontawesome" : "~4.3.0",
"less.js" : "~2.4.0",
"lesshat" : "~3.0.2",
"ace-min-noconflict" : "~1.1.8"
"highlightjs" : "~8.4.0"
}
}

View File

@@ -1,88 +1,147 @@
{
"uuid":"folder1",
"name":"root",
"uuid":"workspace",
"name":"workspace",
"type":"folder",
"children":[
{
"uuid":"docs",
"name":"docs",
"uuid":"app",
"name":"app",
"type":"folder",
"children":[
{
"uuid":"multimedia",
"name":"multimedia",
"uuid":"widgets",
"name":"widgets",
"type":"folder",
"children":[
{
"name":"movie.mov",
"uuid":"movie.mov",
"type":"video",
"extra":false
},
{
"name":"icon.ico",
"uuid":"icon.ico",
"type":"image",
"extra":false
},
{
"name":"picture.png",
"uuid":"picture.png",
"type":"image",
"extra":false
}
{
"uuid":"filebrowser",
"name":"filebrowser",
"type":"folder",
"children": [
{
"name":"newItemModal.html",
"uuid":"newItemModalhtml",
"type":"code",
"extra":"html",
"path": "/app/widgets/filebrowser/newItemModal.html"
},
{
"name":"newItemModal.js",
"uuid":"newItemModaljs",
"type":"code",
"extra":"javascript",
"path": "/app/widgets/filebrowser/newItemModal.js"
},
{
"name":"renameModal.html",
"uuid":"renameModalhtml",
"type":"code",
"extra":"html",
"path": "/app/widgets/filebrowser/renameModal.html"
},
{
"name":"renameModal.js",
"uuid":"renameModaljs",
"type":"code",
"extra":"javascript",
"path": "/app/widgets/filebrowser/renameModal.js"
},
{
"name":"view.html",
"uuid":"viewhtml",
"type":"code",
"extra":"html",
"path": "/app/widgets/filebrowser/view.html"
},
{
"name":"viewmodel.js",
"uuid":"viewmodeljs",
"type":"code",
"extra":"javascript",
"path": "/app/widgets/filebrowser/viewmodel.js"
}
]
}
]
},
{
"name":"readme.txt",
"uuid":"readme.txt",
"type":"text",
"extra":false
},
{
"name":"slideshow.mov",
"uuid":"slideshow.mov",
"type":"video",
"extra":false
},
{
"name":"slideshow.ppt",
"uuid":"slideshow.ppt",
"type":"powerpoint",
"extra":false
},
{
"name":"slideshow.docx",
"uuid":"slideshow.docx",
"type":"word",
"extra":false
}
{
"name":"main.js",
"uuid":"mainjs",
"type":"code",
"extra":"javascript",
"path": "/app/main.js"
},
{
"name":"shell.html",
"uuid":"shellhtml",
"type":"code",
"extra":"html",
"path": "/app/shell.html"
},
{
"name":"shell.js",
"uuid":"shelljs",
"type":"code",
"extra":"javascript",
"path": "/app/shell.js"
}
]
},
{
"uuid":"structural",
"name":"structural",
"uuid":"data",
"name":"data",
"type":"folder",
"children":[
{
"name":"structure.json",
"uuid":"structure.json",
"name":"filesystem.json",
"uuid":"filesystemjson",
"type":"code",
"extra":"json"
},
{
"name":"structure.xml",
"uuid":"structure.xml",
"type":"code",
"extra":"xml"
},
{
"name":"structure.csv",
"uuid":"structure.csv",
"type":"code",
"extra":"csv"
"extra":"json",
"path": "/data/filesystem.json"
}
]
}
},
{
"uuid": "style",
"name": "style",
"type": "folder",
"children": [
{
"name": "filebrowser.less",
"uuid": "filebrowserless",
"type": "code",
"extra": "less",
"path": "/style/filebrowser.less"
},
{
"name": "starterkit.css",
"uuid": "starterkitcss",
"type": "code",
"extra": "less",
"path": "/style/starterkit.css"
}
]
},
{
"uuid": "bowerrc",
"name": ".bowerrc",
"type": "code",
"extra": "json",
"path": "/.bowerrc"
},
{
"uuid": "bowerjson",
"name": "bower.json",
"type": "code",
"extra": "json",
"path": "/bower.json"
},
{
"uuid": "indexhtml",
"name": "index.html",
"type": "code",
"extra": "html",
"path": "/index.html"
}
]
}

View File

@@ -4,34 +4,36 @@
<link rel="stylesheet" href="lib/bootstrap/dist/css/bootstrap.css"/>
<link rel="stylesheet" href="lib/fontawesome/css/font-awesome.css"/>
<link rel="stylesheet" href="lib/durandal/css/durandal.css"/>
<link rel="stylesheet" href="lib/perfect-scrollbar/css/perfect-scrollbar.css" />
<link rel="stylesheet" href="style/starterkit.css" />
<link rel="stylesheet/less" href="style/filebrowser.less" />
<script>
less = {
env: "development"
};
</script>
<script src="lib/less.js/dist/less.min.js"></script>
<link rel="stylesheet" href="lib/perfect-scrollbar/css/perfect-scrollbar.css" />
<link rel="stylesheet" href="lib/highlightjs/styles/github.css" />
<link rel="stylesheet" href="style/starterkit.css" />
<link rel="stylesheet/less" href="style/filebrowser.less" />
<script>
less = {
env: "development"
};
</script>
<script src="lib/less.js/dist/less.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Filebrowser Durandal Widget</a>
</div>
</div>
</nav>
</div>
</div>
</nav>
<div id="applicationHost">
<div class="splash">
<h1 class="message">Filebrowser Durandal widget</h1>
<i class="fa fa-spinner fa-2x fa-spin active"></i>
</div>
<div class="splash">
<h1 class="message">Filebrowser Durandal widget</h1>
<i class="fa fa-spinner fa-2x fa-spin active"></i>
</div>
</div>
<script src="lib/requirejs/require.js" data-main="app/main"></script>
<script src="lib/requirejs/require.js" data-main="app/main"></script>
</body>
</html>

View File

@@ -1,8 +1,7 @@
@import "../lib/lesshat/build/lesshat.less";
.filebrowser {
width: 300px;
height: 500px;
max-height: 500px;
position: relative;