зеркало из https://github.com/mozilla/FlightDeck.git
the removal the huge Package.js
* converted various Files to use Models now
This commit is contained in:
Родитель
5a0584a6ba
Коммит
de89cd75fb
|
@ -16,7 +16,6 @@
|
|||
<script src="/media/lib/ace/mode-html.js"></script>
|
||||
<script src="/media/lib/meio/Meio.Autocomplete.HTML-1.3.js"></script>
|
||||
<script src="/media/base/js/FlightDeck.Autocomplete.js"></script>
|
||||
<script src="/media/jetpack/js/Package.js"></script>
|
||||
<script src="/media/lib/FloatingTips.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
<script src="/media/lib/ace/mode-html.js"></script>
|
||||
<script src="/media/lib/meio/Meio.Autocomplete.HTML-1.3.js"></script>
|
||||
<script src="/media/base/js/FlightDeck.Autocomplete.js"></script>
|
||||
<script src="/media/jetpack/js/Package.js"></script>
|
||||
<script src="/media/lib/FloatingTips.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -1,325 +0,0 @@
|
|||
var File = new Class({
|
||||
|
||||
Implements: [Options, Events],
|
||||
|
||||
options: {
|
||||
path: null
|
||||
//events
|
||||
//onDestroy: function() {}
|
||||
},
|
||||
|
||||
initialize: function(pack, options) {
|
||||
this.pack = pack;
|
||||
this.setOptions(options);
|
||||
},
|
||||
|
||||
getShortName: function() {
|
||||
return this.getFullName().split('/').pop();
|
||||
},
|
||||
|
||||
getFullName: function() {
|
||||
var name = this.options.filename;
|
||||
if(this.options.type) {
|
||||
name += '.' + this.options.type;
|
||||
}
|
||||
return name;
|
||||
},
|
||||
|
||||
is_editable: function() {
|
||||
return ['css', 'txt', 'js', 'html'].contains(this.options.type);
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
if (this.active) {
|
||||
// switch editor!
|
||||
mod = null;
|
||||
// try to switch to first element
|
||||
first = false;
|
||||
Object.each(this.pack.modules, function(mod) {
|
||||
if (!first) {
|
||||
first = true;
|
||||
editor.sidebar.setSelectedFile(mod);
|
||||
}
|
||||
});
|
||||
if (!first) {
|
||||
this.pack.editor.setContent('');
|
||||
}
|
||||
}
|
||||
|
||||
if(this.tab) {
|
||||
this.tab.destroy();
|
||||
|
||||
}
|
||||
this.fireEvent('destroy');
|
||||
},
|
||||
|
||||
setChanged: function(isChanged) {
|
||||
if (this.changed != isChanged) {
|
||||
this.fireEvent(isChanged ? 'change' : 'reset');
|
||||
}
|
||||
this.changed = isChanged;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
File.sanitize = function(name) {
|
||||
return name.replace(/[^a-zA-Z0-9=!@#\$%\^&\(\)\+\-_\/\.]+/g, '-');
|
||||
};
|
||||
|
||||
var Library = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
options: {
|
||||
append: true
|
||||
},
|
||||
|
||||
initialize: function(pack, options) {
|
||||
this.parent(pack, options);
|
||||
|
||||
this.addEvent('destroy', function(){
|
||||
delete pack.libraries[this.options.id_number];
|
||||
});
|
||||
},
|
||||
|
||||
getID: function() {
|
||||
return 'Library-' + this.options.id_number;
|
||||
},
|
||||
|
||||
getShortName: function() {
|
||||
return this.options.full_name;
|
||||
},
|
||||
|
||||
getFullName: function() {
|
||||
return this.getID();
|
||||
},
|
||||
|
||||
storeNewVersion: function(version_data) {
|
||||
this._latest_version = version_data;
|
||||
},
|
||||
|
||||
retrieveNewVersion: function() {
|
||||
return this._latest_version;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var Attachment = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
options: {
|
||||
code_trigger_suffix: '_attachment_switch', // id of an element which is used to switch editors
|
||||
code_editor_suffix: '_attachment_textarea', // id of the textarea
|
||||
active: false,
|
||||
type: 'js',
|
||||
append: false,
|
||||
filename: '',
|
||||
readonly: false,
|
||||
counter: 'attachments'
|
||||
},
|
||||
|
||||
is_image: function() {
|
||||
return ['jpg', 'gif', 'png'].contains(this.options.type);
|
||||
},
|
||||
|
||||
initialize: function(pack, options) {
|
||||
this.parent(pack, options);
|
||||
this.options.path = options.filename + '.' + options.type;
|
||||
// uid for editor items
|
||||
this.uid = this.getEditorID();
|
||||
|
||||
this.addEvent('destroy', function(){
|
||||
delete pack.attachments[this.options.uid];
|
||||
});
|
||||
// create editor
|
||||
pack.editor.registerItem(this);
|
||||
},
|
||||
|
||||
loadContent: function() {
|
||||
var that = this,
|
||||
spinnerEl = $(this.tab);
|
||||
new Request({
|
||||
method: 'get',
|
||||
url: this.options.get_url,
|
||||
useSpinner: !!spinnerEl,
|
||||
spinnerTarget: spinnerEl,
|
||||
spinnerOptions: {
|
||||
img: {
|
||||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
},
|
||||
onSuccess: function() {
|
||||
var content = this.response.text || '';
|
||||
that.content = content;
|
||||
that.original_content = content;
|
||||
that.fireEvent('loadcontent', content);
|
||||
}
|
||||
}).send();
|
||||
},
|
||||
|
||||
isLoaded: function() {
|
||||
return this.content != null;
|
||||
},
|
||||
|
||||
getID: function() {
|
||||
return 'Attachment-'+this.uid;
|
||||
},
|
||||
|
||||
getEditorID: function() {
|
||||
return this.options.uid + this.options.code_editor_suffix;
|
||||
},
|
||||
|
||||
reassign: function(options) {
|
||||
// every revision, attachments that have changed get a new `uid`.
|
||||
// since Attachments are currently kept track of via the `uid`,
|
||||
// we must adjust all instances that keep track of this
|
||||
// attachment to use the new id, and any other new options that
|
||||
// comes with it
|
||||
|
||||
var packAttachments = this.pack.attachments,
|
||||
editorItems = this.pack.editor.items,
|
||||
oldUID = this.options.uid;
|
||||
|
||||
delete packAttachments[oldUID];
|
||||
|
||||
this.setOptions(options);
|
||||
this.options.path = options.filename + '.' + options.type;
|
||||
packAttachments[options.uid] = this;
|
||||
|
||||
var editorUID = this.getEditorID();
|
||||
editorItems[editorUID] = editorItems[this.uid];
|
||||
delete editorItems[this.uid];
|
||||
this.uid = editorUID;
|
||||
|
||||
if (options.append) {
|
||||
this.append();
|
||||
}
|
||||
|
||||
if (this.tab) {
|
||||
this.tab.setLabel(this.getShortName());
|
||||
}
|
||||
this.fireEvent('reassign', this.options.uid);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Attachment.exists = function(filename, ext) {
|
||||
return Object.some(fd.item.attachments, function(att) {
|
||||
return (att.options.filename == filename) &&
|
||||
att.options.type == ext;
|
||||
});
|
||||
};
|
||||
|
||||
var Module = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
options: {
|
||||
// data
|
||||
// filename: '',
|
||||
// code: '',
|
||||
// author: '',
|
||||
// DOM
|
||||
code_trigger_suffix: '_switch', // id of an element which is used to switch editors
|
||||
suffix: '_module',
|
||||
readonly: false,
|
||||
main: false,
|
||||
executable: false,
|
||||
active: false,
|
||||
type: 'js',
|
||||
append: false,
|
||||
counter: 'modules'
|
||||
},
|
||||
|
||||
initialize: function(pack, options) {
|
||||
this.parent(pack, options);
|
||||
this.options.path = this.options.filename + '.' + this.options.type;
|
||||
|
||||
this.addEvent('destroy', function(){
|
||||
delete pack.modules[this.options.filename];
|
||||
});
|
||||
|
||||
// an uid for the editor
|
||||
this.uid = this.options.filename + this.options.suffix;
|
||||
// create editor
|
||||
pack.editor.registerItem(this);
|
||||
},
|
||||
|
||||
loadContent: function() {
|
||||
// load data synchronously
|
||||
var spinnerEl = $(this.tab);
|
||||
new Request.JSON({
|
||||
method: 'get',
|
||||
url: this.options.get_url,
|
||||
useSpinner: !!spinnerEl,
|
||||
spinnerTarget: spinnerEl,
|
||||
spinnerOptions: {
|
||||
img: {
|
||||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
},
|
||||
onSuccess: function(mod) {
|
||||
var code = mod.code || '';
|
||||
this.original_content = code;
|
||||
this.content = code;
|
||||
this.fireEvent('loadcontent', code);
|
||||
}.bind(this)
|
||||
}).send();
|
||||
},
|
||||
|
||||
isLoaded: function() {
|
||||
return this.content != null;
|
||||
},
|
||||
|
||||
getID: function() {
|
||||
return 'Module-' + this.options.filename.replace(/\//g, '-');
|
||||
}
|
||||
});
|
||||
|
||||
Module.exists = function(filename) {
|
||||
return Object.some(fd.item.modules, function(mod) {
|
||||
return mod.options.filename == filename;
|
||||
});
|
||||
};
|
||||
|
||||
var Folder = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
options: {
|
||||
root_dir: 'l',
|
||||
name: ''
|
||||
},
|
||||
|
||||
initialize: function(pack, options) {
|
||||
this.parent(pack, options);
|
||||
|
||||
this.addEvent('destroy', function(){
|
||||
delete pack.folders[this.options.root_dir + '/' +this.options.name];
|
||||
});
|
||||
},
|
||||
|
||||
getFullName: function() {
|
||||
return this.options.name;
|
||||
},
|
||||
|
||||
getID: function() {
|
||||
return this.options.root_dir + '-'+
|
||||
this.options.name.replace(/\//g, '-');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Folder.ROOT_DIR_LIB = 'l';
|
||||
Folder.ROOT_DIR_DATA = 'd';
|
||||
|
||||
Folder.exists = function(filename, root_dir) {
|
||||
return Object.some(fd.item.folders, function(folder) {
|
||||
return (folder.options.root_dir == root_dir &&
|
||||
folder.options.name == filename);
|
||||
});
|
||||
};
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -41,7 +41,7 @@ module.exports = new Class({
|
|||
if(file.changed) {
|
||||
fd.showQuestion({
|
||||
title: 'Lose unsaved changes?',
|
||||
message: 'The tab "'+file.getShortName()+'" that you are trying to close has unsaved changes.',
|
||||
message: 'The tab "'+file.get('shortName')+'" that you are trying to close has unsaved changes.',
|
||||
buttons: [
|
||||
{
|
||||
'type': 'reset',
|
||||
|
@ -83,7 +83,7 @@ module.exports = new Class({
|
|||
addTab: function(file) {
|
||||
var controller = this;
|
||||
var tab = new tabs.Tab(this.tabs, {
|
||||
title: file.getShortName()
|
||||
title: file.get('shortName')
|
||||
});
|
||||
|
||||
function change() {
|
||||
|
|
|
@ -19,6 +19,10 @@ module.exports = new Class({
|
|||
fields: {
|
||||
url: fields.TextField(),
|
||||
data: fields.TextField()
|
||||
},
|
||||
|
||||
uid: function uid() {
|
||||
return this.get('pk');
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
var Class = require('shipyard/class/Class'),
|
||||
Model = require('shipyard/model/Model'),
|
||||
fields = require('shipyard/model/fields'),
|
||||
Syncable = require('shipyard/sync/Syncable');
|
||||
Syncable = require('shipyard/sync/Syncable'),
|
||||
Request = require('shipyard/http/Request'),
|
||||
string = require('shipyard/utils/string');
|
||||
|
||||
var File = module.exports = new Class({
|
||||
|
||||
|
@ -14,7 +16,12 @@ var File = module.exports = new Class({
|
|||
id: fields.NumberField(),
|
||||
filename: fields.TextField({ required: true }),
|
||||
ext: fields.TextField({ 'default': 'js' }),
|
||||
content: fields.TextField()
|
||||
content: fields.TextField(),
|
||||
main: fields.BooleanField({ 'default': false, write: false }),
|
||||
readonly: fields.BooleanField({ 'default': false, write: false }),
|
||||
|
||||
url: fields.TextField({ write: false }),
|
||||
get_url: fields.TextField({ write: false })
|
||||
},
|
||||
|
||||
shortName: function() {
|
||||
|
@ -32,10 +39,63 @@ var File = module.exports = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
uid: function() {
|
||||
//TODO: this should be the unique hash from the new API
|
||||
return this._uid || (this._uid = string.uniqueID());
|
||||
},
|
||||
|
||||
isEditable: function() {
|
||||
return this.constructor.EDITABLE_EXTS.indexOf(this.get('ext')) !== -1;
|
||||
},
|
||||
|
||||
//TODO: Shipyard Models should probably has a isDirty API
|
||||
setChanged: function(isChanged) {
|
||||
this.changed = isChanged;
|
||||
if (isChanged) {
|
||||
this.fireEvent('change');
|
||||
} else {
|
||||
this.fireEvent('reset');
|
||||
}
|
||||
},
|
||||
|
||||
loadContent: function(callback) {
|
||||
var file = this;
|
||||
var spinnerEl;
|
||||
return new Request({
|
||||
method: 'get',
|
||||
url: this.get('get_url'),
|
||||
useSpinner: !!spinnerEl,
|
||||
spinnerTarget: spinnerEl,
|
||||
spinnerOptions: {
|
||||
img: {
|
||||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
},
|
||||
onSuccess: function(text) {
|
||||
var content = text || '';
|
||||
file.original_content = content;
|
||||
file.set('content', content);
|
||||
file.fireEvent('loadcontent', content);
|
||||
if (callback) callback.call(this, content);
|
||||
}
|
||||
}).send();
|
||||
|
||||
},
|
||||
|
||||
isLoaded: function() {
|
||||
return this.get('content') != null;
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
return this.get('fullName');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
File.EDITABLE_EXTS = ['js', 'html', 'css', 'txt', 'json', 'md'];
|
||||
|
||||
var sanitizeRE = /[^a-zA-Z0-9=!@#\$%\^&\(\)\+\-_\/\.]+/g;
|
||||
File.sanitize = function(name) {
|
||||
return name.replace(sanitizeRE, '-');
|
||||
};
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
var Class = require('shipyard/class/Class'),
|
||||
Model = require('shipyard/model/Model'),
|
||||
fields = require('shipyard/model/fields'),
|
||||
Syncable = require('shipyard/sync/Syncable'),
|
||||
string = require('shipyard/utils/string');
|
||||
|
||||
var Folder = module.exports = new Class({
|
||||
|
||||
Extends: Model,
|
||||
|
||||
Implements: Syncable,
|
||||
|
||||
fields: {
|
||||
name: fields.TextField({ required: true }),
|
||||
root_dir: fields.TextField({ required: true }) //ChoiceField
|
||||
},
|
||||
|
||||
shortName: function() {
|
||||
return this.get('name');
|
||||
},
|
||||
|
||||
fullName: function() {
|
||||
return this.get('name');
|
||||
},
|
||||
|
||||
uid: function() {
|
||||
return this.get('root_dir') + '/' + this.get('name');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Folder.ROOT_DIR_LIB = 'l';
|
||||
Folder.ROOT_DIR_DATA = 'd';
|
|
@ -1,7 +1,8 @@
|
|||
var Class = require('shipyard/class/Class'),
|
||||
File = require('./File'),
|
||||
fields = require('shipyard/model/fields'),
|
||||
ServerSync = require('shipyard/sync/Server');
|
||||
ServerSync = require('shipyard/sync/Server'),
|
||||
Request = require('shipyard/http/Request');
|
||||
|
||||
module.exports = new Class({
|
||||
|
||||
|
@ -15,6 +16,35 @@ module.exports = new Class({
|
|||
},
|
||||
|
||||
fields: {
|
||||
}
|
||||
},
|
||||
|
||||
uid: function() {
|
||||
return this.get('filename');
|
||||
},
|
||||
|
||||
loadContent: function(callback) {
|
||||
var spinnerEl,
|
||||
file = this;
|
||||
return new Request({
|
||||
method: 'get',
|
||||
url: this.get('get_url'),
|
||||
useSpinner: !!spinnerEl,
|
||||
spinnerTarget: spinnerEl,
|
||||
spinnerOptions: {
|
||||
img: {
|
||||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
},
|
||||
onSuccess: function(text) {
|
||||
var mod = JSON.parse(text);
|
||||
var code = mod.code || '';
|
||||
this.original_content = code;
|
||||
this.set('content', code);
|
||||
this.fireEvent('loadcontent', code);
|
||||
if (callback) callback.call(this, code);
|
||||
}.bind(this)
|
||||
}).send();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -32,13 +32,33 @@ var Package = module.exports = new Class({
|
|||
version_name: fields.TextField(),
|
||||
revision_number: fields.NumberField(),
|
||||
|
||||
latest: fields.NumberField(), // a FK to PackageRevision
|
||||
latest: fields.NumberField() // a FK to PackageRevision
|
||||
|
||||
// modules: FK from Module
|
||||
// attachments: FK from Attachment
|
||||
// dependencies: ManyToManyField('self')
|
||||
},
|
||||
|
||||
uid: function() {
|
||||
return this.get('id_number');
|
||||
},
|
||||
|
||||
shortName: function() {
|
||||
return this.get('name');
|
||||
},
|
||||
|
||||
fullName: function() {
|
||||
return this.get('full_name');
|
||||
},
|
||||
|
||||
storeNewVersion: function(version_data) {
|
||||
this._latest_version = version_data;
|
||||
},
|
||||
|
||||
retrieveNewVersion: function() {
|
||||
return this._latest_version;
|
||||
},
|
||||
|
||||
isAddon: function isAddon() {
|
||||
return this.get('type') === this.constructor.TYPE_ADDON;
|
||||
},
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
"shipyard": {
|
||||
"app": "./",
|
||||
"mini_require": true,
|
||||
"min": "../editor-min.js",
|
||||
"target": "../editor-min.js",
|
||||
"min": false,
|
||||
|
||||
"test": "./tests"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
var File = require('../../models/File');
|
||||
|
||||
module.exports = {
|
||||
|
||||
'File.sanitize': function(it, setup) {
|
||||
it('should clean out unwanted characters', function(expect) {
|
||||
var val = File.sanitize('<script>window.open()');
|
||||
expect(val).toBe('-script-window.open()');
|
||||
});
|
||||
|
||||
it('should not strip plus characters', function(expect) {
|
||||
var val = File.sanitize('unload+');
|
||||
expect(val).toBe('unload+');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -1,4 +1,6 @@
|
|||
var Module = require('../../models/Module');
|
||||
var Module = require('../../models/Module'),
|
||||
mockXHR = require('shipyard/test/mockXHR'),
|
||||
Spy = require('shipyard/test/Spy');
|
||||
|
||||
module.exports = {
|
||||
'Module': function(it, setup) {
|
||||
|
@ -14,6 +16,19 @@ module.exports = {
|
|||
|
||||
m.set('filename', 'events/key.down');
|
||||
expect(m.get('shortName')).toBe('key.down.js');
|
||||
})
|
||||
});
|
||||
|
||||
it('should be able to loadContent', function(expect) {
|
||||
mockXHR('test content');
|
||||
var m = new Module();
|
||||
var fn = new Spy;
|
||||
m.addEvent('loadcontent', fn);
|
||||
m.loadContent(function(content) {
|
||||
expect(content).toBe('test content');
|
||||
expect(m.get('content')).toBe('test content');
|
||||
expect(fn.getCallCount()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
*/
|
||||
var Class = require('shipyard/class/Class'),
|
||||
Events = require('shipyard/class/Events'),
|
||||
Options = require('shipyard/class/Options')
|
||||
Options = require('shipyard/class/Options'),
|
||||
object = require('shipyard/utils/object');
|
||||
|
||||
// globals: Element, Spinner, Element.addVolatileEvent, fd
|
||||
// globals: Element, Spinner, fd
|
||||
|
||||
var FDEditor = module.exports = new Class({
|
||||
|
||||
|
@ -45,8 +45,8 @@ var FDEditor = module.exports = new Class({
|
|||
});
|
||||
},
|
||||
|
||||
registerItem: function(item){
|
||||
this.items[item.uid] = item;
|
||||
registerItem: function(uid, item){
|
||||
this.items[uid] = item;
|
||||
},
|
||||
|
||||
getItem: function(uid){
|
||||
|
@ -62,38 +62,39 @@ var FDEditor = module.exports = new Class({
|
|||
|
||||
activateItem: function(item){
|
||||
// activate load and hook events
|
||||
var editor = this;
|
||||
this.current = item;
|
||||
this.current.active = true;
|
||||
if (!this.current.isLoaded()) {
|
||||
this.spinner.show();
|
||||
this.setContent('', true);
|
||||
this.current.addVolatileEvent('loadcontent', function(content) {
|
||||
//if item == this.current still
|
||||
if (item == this.current) {
|
||||
this.setContent(content);
|
||||
this.spinner.hide();
|
||||
this.current.loadContent(function(content) {
|
||||
if (item == editor.current) {
|
||||
editor.setContent(content);
|
||||
editor.spinner.hide();
|
||||
}
|
||||
//else another file has become active
|
||||
}.bind(this));
|
||||
this.current.loadContent();
|
||||
});
|
||||
} else {
|
||||
this.setContent(this.current.content);
|
||||
this.setContent(this.current.get('content'));
|
||||
this.spinner.hide();
|
||||
}
|
||||
if (this.current.options.readonly) {
|
||||
if (this.current.get('readonly')) {
|
||||
this.setReadOnly();
|
||||
} else {
|
||||
this.setEditable();
|
||||
}
|
||||
this.setSyntax(this.current.options.type);
|
||||
this.setSyntax(this.current.get('ext'));
|
||||
},
|
||||
|
||||
switchTo: function(item){
|
||||
$log('FD: DEBUG: FDEditor.switchTo ' + item.uid);
|
||||
switchTo: function(uid){
|
||||
$log('FD: DEBUG: FDEditor.switchTo ' + uid);
|
||||
var self = this;
|
||||
this.switching = true;
|
||||
if (!this.getItem(item.uid)) {
|
||||
this.registerItem(item);
|
||||
var item = this.getItem(uid);
|
||||
if (!item) {
|
||||
//this.registerItem(item);
|
||||
$log('no item wtf');
|
||||
}
|
||||
if (this.current) {
|
||||
this.deactivateCurrent();
|
||||
|
@ -103,7 +104,7 @@ var FDEditor = module.exports = new Class({
|
|||
},
|
||||
|
||||
dumpCurrent: function() {
|
||||
this.current.content = this.getContent();
|
||||
this.current.set('content', this.getContent());
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@ -126,13 +127,13 @@ var FDEditor = module.exports = new Class({
|
|||
item.setChanged(false);
|
||||
item.change_hooked = false;
|
||||
// refresh original content
|
||||
item.original_content = item.content;
|
||||
item.original_content = item.get('content');
|
||||
});
|
||||
this.hookChangeIfNeeded();
|
||||
},
|
||||
|
||||
hookChangeIfNeeded: function() {
|
||||
if (!this.current.options.readonly) {
|
||||
if (!this.current.get('readonly')) {
|
||||
if (!this.current.changed && !this.change_hooked) {
|
||||
this.hookChange();
|
||||
} else if (this.current.changed && this.change_hooked) {
|
||||
|
@ -156,8 +157,8 @@ var FDEditor = module.exports = new Class({
|
|||
if (!this.switching && this.getContent() != this.current.original_content) {
|
||||
this.current.setChanged(true);
|
||||
this.fireEvent('change');
|
||||
$log('FD: DEBUG: changed, code is considered dirty and will remain'
|
||||
+'be treated as such even if changes are reverted');
|
||||
$log('DEBUG: changed, code is considered dirty and will remain'+
|
||||
'be treated as such even if changes are reverted');
|
||||
this.unhookChange();
|
||||
} else if (!this.switching && this.current.changed) {
|
||||
this.current.setChanged(false);
|
||||
|
|
|
@ -1,348 +1,355 @@
|
|||
var /*Class = require('shipyard/class'),
|
||||
shipyard/class only lets Class extends from other shipyard/class,
|
||||
and FileTree extends from Tree (which is a regular Moo Class)
|
||||
*/
|
||||
object = require('shipyard/utils/object');
|
||||
shipyard/class only lets Class extends from other shipyard/class,
|
||||
and FileTree extends from Tree (which is a regular Moo Class)
|
||||
*/
|
||||
object = require('shipyard/utils/object'),
|
||||
|
||||
Module = require('../models/Module'),
|
||||
Attachment = require('../models/Attachment');
|
||||
|
||||
// globals: Class, Tree, Collapse.LocalStorage, Element, String.implement
|
||||
|
||||
var FileTree = module.exports = new Class({
|
||||
|
||||
Extends: Tree,
|
||||
|
||||
options: {
|
||||
branch: {
|
||||
'rel': 'file',
|
||||
'title': 'Untitled',
|
||||
'id': null,
|
||||
'class': ''
|
||||
},
|
||||
editable: true,
|
||||
actions: {
|
||||
//add: false,
|
||||
//edit: false,
|
||||
//remove: false
|
||||
},
|
||||
snap: 3,
|
||||
id_prefix: '',
|
||||
|
||||
// if container is null, container will default to the Tree el
|
||||
// "false" will cancel the container
|
||||
container: true,
|
||||
//onAddBranch: function(el, attributes, target){}
|
||||
//onRenameStart: function(li, span){}
|
||||
//onRenameComplete: function(li, span){}
|
||||
//onDeleteBranch: function(li, span){}
|
||||
},
|
||||
|
||||
initialize: function(element, options) {
|
||||
this.addEvent('change', function() {
|
||||
this.setFullPath(this.current);
|
||||
}, true);
|
||||
this.parent(element, options);
|
||||
},
|
||||
|
||||
attach: function(){
|
||||
this.parent();
|
||||
var that = this;
|
||||
this.element.addEvents({
|
||||
'mousedown:relay(.actions .edit)': function(e) {
|
||||
var li = e.target.getParent('li');
|
||||
if (li.hasClass('editing')) {
|
||||
that.renameBranchEnd($(e.target).getParent('li'));
|
||||
} else {
|
||||
that.renameBranch($(e.target).getParent('li'));
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
'click:relay(li[rel="directory"] > .holder .label, li[rel="directory"] > .holder .icon)': function(e, labelEl){
|
||||
var li = e.target.getParent('li');
|
||||
that.toggleBranch(li);
|
||||
},
|
||||
'keypress:relay(span)': function(e){
|
||||
if(e.key == 'enter') that.renameBranchEnd($(e.target).getParent('li'));
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
mousedown: function(element, event) {
|
||||
//tree.js prevents event immediately, when really we only want
|
||||
//the event prevents when it drags. This is because if the element
|
||||
//has contentEditable active, we want the default mousedown action,
|
||||
//which is to move the cursor around the text node. If it's not,
|
||||
//then preventDefault will be called twice, and the dragging will still
|
||||
//work. :)
|
||||
|
||||
var oldDefault = event.preventDefault;
|
||||
event.preventDefault = function(){
|
||||
event.preventDefault = oldDefault;
|
||||
};
|
||||
|
||||
this.parent(element, event);
|
||||
if (this.clone) {
|
||||
this.clone.setStyle('display', 'none');
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
onDrag: function(el, event) {
|
||||
this.parent(el, event);
|
||||
if (this.clone) {
|
||||
this.clone.setStyle('display', null); //default snap is already 6px
|
||||
}
|
||||
},
|
||||
|
||||
toggleBranch: function(branch) {
|
||||
if (branch && this.collapse) {
|
||||
this.collapse.toggle(branch);
|
||||
}
|
||||
},
|
||||
|
||||
removeBranch: function(branch) {
|
||||
var parent = branch.getParent('li');
|
||||
|
||||
branch.dispose();
|
||||
|
||||
if (parent && !parent.getElements('li').length && this.collapse) {
|
||||
this.collapse.collapse(parent);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
addBranch: function(attr, target, options){
|
||||
attr = object.merge({}, this.options.branch, attr);
|
||||
target = $(target) || this.element;
|
||||
if (target.get('tag') !== 'ul') {
|
||||
target = target.getElement('ul');
|
||||
}
|
||||
|
||||
var isEditable = this.options.editable;
|
||||
|
||||
options = object.merge({}, {
|
||||
add: attr.rel == 'directory',
|
||||
edit: attr.rel != 'directory',
|
||||
remove: true, //can delete anything
|
||||
collapsed: true
|
||||
}, this.options.actions, options);
|
||||
|
||||
if (!isEditable) {
|
||||
delete options.add;
|
||||
delete options.edit;
|
||||
delete options.remove;
|
||||
}
|
||||
|
||||
attr.html = ('<a class="expand" href="#"></a>' +
|
||||
'<div class="holder">' +
|
||||
'<span id="{id}" class="label" title="{title}">{title}</span><span class="icon"></span>' +
|
||||
'<div class="actions">{add}{edit}{remove}</div>' +
|
||||
'</div>{dir}').substitute({
|
||||
title: attr.title,
|
||||
id: attr.name ? attr.name + '_switch' : attr.title + '_folder',
|
||||
dir: attr.rel == 'directory' ? '<ul' + (options.collapsed ? ' style="display:none;"' : '') + '></ul>' : '',
|
||||
add: options.add ? '<span class="add" title="Add"></span>' : '',
|
||||
edit: options.edit ? '<span class="edit" title="Rename"></span>' : '',
|
||||
remove: options.remove ? '<span class="delete" title="Delete"></span>' : ''
|
||||
});
|
||||
|
||||
var li = new Element('li', attr),
|
||||
where = 'bottom';
|
||||
|
||||
//branches should always be in alpha order
|
||||
//so, find the place to inject the new branch
|
||||
target.getChildren('li').some(function(el) {
|
||||
if (el.get('title') > attr.title) {
|
||||
target = el;
|
||||
where = 'before';
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
li.inject(target, where);
|
||||
this.fireEvent('addBranch', [li].combine(arguments));
|
||||
return li;
|
||||
},
|
||||
|
||||
renameBranch: function(element, hasExtension){
|
||||
var li = (element.get('tag') == 'li') ? element : element.getParent('li'),
|
||||
label = li.getElement('.label'),
|
||||
text = label.get('text').trim();
|
||||
|
||||
this.fireEvent('renameStart', [li, label]);
|
||||
|
||||
|
||||
label.set('tabIndex', 0).set('contenteditable', true).focus();
|
||||
li.addClass('editing');
|
||||
label.store('$text', text);
|
||||
|
||||
label.store('$blur', function blur(e) {
|
||||
label.removeEvent('blur', blur);
|
||||
this.renameBranchCancel(element);
|
||||
}.bind(this))
|
||||
|
||||
label.addEvent('blur', label.retrieve('$blur'))
|
||||
|
||||
hasExtension = hasExtension || !!text.getFileExtension();
|
||||
|
||||
var range = document.createRange(),
|
||||
node = label.firstChild;
|
||||
range.setStart(node, 0);
|
||||
range.setEnd(node, hasExtension ? text.length - text.getFileExtension().length -1 : text.length);
|
||||
sel = window.getSelection();
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
renameBranchCancel: function(element) {
|
||||
|
||||
Extends: Tree,
|
||||
|
||||
options: {
|
||||
branch: {
|
||||
'rel': 'file',
|
||||
'title': 'Untitled',
|
||||
'id': null,
|
||||
'class': ''
|
||||
},
|
||||
editable: true,
|
||||
actions: {
|
||||
//add: false,
|
||||
//edit: false,
|
||||
//remove: false
|
||||
},
|
||||
snap: 3,
|
||||
id_prefix: '',
|
||||
|
||||
// if container is null, container will default to the Tree el
|
||||
// "false" will cancel the container
|
||||
container: true
|
||||
//onAddBranch: function(el, attributes, target){}
|
||||
//onRenameStart: function(li, span){}
|
||||
//onRenameComplete: function(li, span){}
|
||||
//onDeleteBranch: function(li, span){}
|
||||
},
|
||||
|
||||
initialize: function(element, options) {
|
||||
this.addEvent('change', function() {
|
||||
this.setFullPath(this.current);
|
||||
}, true);
|
||||
this.parent(element, options);
|
||||
},
|
||||
|
||||
attach: function(){
|
||||
this.parent();
|
||||
var that = this;
|
||||
this.element.addEvents({
|
||||
'mousedown:relay(.actions .edit)': function(e) {
|
||||
var li = e.target.getParent('li');
|
||||
if (li.hasClass('editing')) {
|
||||
that.renameBranchEnd($(e.target).getParent('li'));
|
||||
} else {
|
||||
that.renameBranch($(e.target).getParent('li'));
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
'click:relay(li[rel="directory"] > .holder .label, li[rel="directory"] > .holder .icon)': function(e, labelEl){
|
||||
var li = e.target.getParent('li');
|
||||
that.toggleBranch(li);
|
||||
},
|
||||
'keypress:relay(span)': function(e){
|
||||
if(e.key == 'enter') that.renameBranchEnd($(e.target).getParent('li'));
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
mousedown: function(element, event) {
|
||||
//tree.js prevents event immediately, when really we only want
|
||||
//the event prevents when it drags. This is because if the element
|
||||
//has contentEditable active, we want the default mousedown action,
|
||||
//which is to move the cursor around the text node. If it's not,
|
||||
//then preventDefault will be called twice, and the dragging will still
|
||||
//work. :)
|
||||
|
||||
var oldDefault = event.preventDefault;
|
||||
event.preventDefault = function(){
|
||||
event.preventDefault = oldDefault;
|
||||
};
|
||||
|
||||
this.parent(element, event);
|
||||
if (this.clone) {
|
||||
this.clone.setStyle('display', 'none');
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
onDrag: function(el, event) {
|
||||
this.parent(el, event);
|
||||
if (this.clone) {
|
||||
this.clone.setStyle('display', null); //default snap is already 6px
|
||||
}
|
||||
},
|
||||
|
||||
toggleBranch: function(branch) {
|
||||
if (branch && this.collapse) {
|
||||
this.collapse.toggle(branch);
|
||||
}
|
||||
},
|
||||
|
||||
removeBranch: function(branch) {
|
||||
var parent = branch.getParent('li');
|
||||
|
||||
branch.dispose();
|
||||
|
||||
if (parent && !parent.getElements('li').length && this.collapse) {
|
||||
this.collapse.collapse(parent);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
addBranch: function(attr, target, options){
|
||||
attr = object.merge({}, this.options.branch, attr);
|
||||
target = $(target) || this.element;
|
||||
if (target.get('tag') !== 'ul') {
|
||||
target = target.getElement('ul');
|
||||
}
|
||||
|
||||
var isEditable = this.options.editable;
|
||||
|
||||
options = object.merge({}, {
|
||||
add: attr.rel == 'directory',
|
||||
edit: attr.rel != 'directory',
|
||||
remove: true, //can delete anything
|
||||
collapsed: true
|
||||
}, this.options.actions, options);
|
||||
|
||||
if (!isEditable) {
|
||||
delete options.add;
|
||||
delete options.edit;
|
||||
delete options.remove;
|
||||
}
|
||||
|
||||
attr.html = ('<a class="expand" href="#"></a>' +
|
||||
'<div class="holder">' +
|
||||
'<span id="{id}" class="label" title="{title}">{title}</span><span class="icon"></span>' +
|
||||
'<div class="actions">{add}{edit}{remove}</div>' +
|
||||
'</div>{dir}').substitute({
|
||||
title: attr.title,
|
||||
id: attr.name ? attr.name + '_switch' : attr.title + '_folder',
|
||||
dir: attr.rel == 'directory' ? '<ul' + (options.collapsed ? ' style="display:none;"' : '') + '></ul>' : '',
|
||||
add: options.add ? '<span class="add" title="Add"></span>' : '',
|
||||
edit: options.edit ? '<span class="edit" title="Rename"></span>' : '',
|
||||
remove: options.remove ? '<span class="delete" title="Delete"></span>' : ''
|
||||
});
|
||||
|
||||
var li = new Element('li', attr),
|
||||
where = 'bottom';
|
||||
|
||||
//branches should always be in alpha order
|
||||
//so, find the place to inject the new branch
|
||||
target.getChildren('li').some(function(el) {
|
||||
if (el.get('title') > attr.title) {
|
||||
target = el;
|
||||
where = 'before';
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
li.inject(target, where);
|
||||
this.fireEvent('addBranch', [li].combine(arguments));
|
||||
return li;
|
||||
},
|
||||
|
||||
renameBranch: function(element, hasExtension){
|
||||
var li = (element.get('tag') == 'li') ? element : element.getParent('li'),
|
||||
label = li.getElement('.label'),
|
||||
text = label.retrieve('$text').trim();
|
||||
|
||||
label.set('contenteditable', false);
|
||||
if (text) {
|
||||
label.set('text', text);
|
||||
}
|
||||
label.eliminate('$text');
|
||||
li.removeClass('editing');
|
||||
|
||||
},
|
||||
|
||||
renameBranchEnd: function(element) {
|
||||
var li = (element.get('tag') == 'li') ? element : element.getParent('li'),
|
||||
label = li.getElement('.label'),
|
||||
text = label.get('text').trim();
|
||||
|
||||
if(label.get('contenteditable') == 'true'){
|
||||
|
||||
//validation
|
||||
text = File.sanitize(text);
|
||||
|
||||
|
||||
if (!text.getFileName()) {
|
||||
fd.error.alert('Filename must be valid', 'Your file must not contain special characters, and requires a file extension.');
|
||||
return this;
|
||||
}
|
||||
|
||||
label.removeEvent('blur', label.retrieve('$blur'));
|
||||
label.eliminate('$text');
|
||||
label.set('contenteditable', false).blur();
|
||||
window.getSelection().removeAllRanges();
|
||||
|
||||
|
||||
li.removeClass('editing');
|
||||
//fire a renameCancel if the name didnt change
|
||||
if (text == label.get('title').trim()) {
|
||||
this.fireEvent('renameCancel', li);
|
||||
return this;
|
||||
}
|
||||
|
||||
label.set('title', text);
|
||||
label.set('text', text);
|
||||
label = li.getElement('.label'),
|
||||
text = label.get('text').trim();
|
||||
|
||||
this.fireEvent('renameStart', [li, label]);
|
||||
|
||||
|
||||
label.set('tabIndex', 0).set('contenteditable', true).focus();
|
||||
li.addClass('editing');
|
||||
label.store('$text', text);
|
||||
|
||||
label.store('$blur', function blur(e) {
|
||||
label.removeEvent('blur', blur);
|
||||
this.renameBranchCancel(element);
|
||||
}.bind(this));
|
||||
|
||||
label.addEvent('blur', label.retrieve('$blur'));
|
||||
|
||||
hasExtension = hasExtension || !!text.getFileExtension();
|
||||
|
||||
var range = document.createRange(),
|
||||
node = label.firstChild;
|
||||
range.setStart(node, 0);
|
||||
range.setEnd(node, hasExtension ? text.length - text.getFileExtension().length -1 : text.length);
|
||||
sel = window.getSelection();
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
renameBranchCancel: function(element) {
|
||||
var li = (element.get('tag') == 'li') ? element : element.getParent('li'),
|
||||
label = li.getElement('.label'),
|
||||
text = label.retrieve('$text').trim();
|
||||
|
||||
label.set('contenteditable', false);
|
||||
if (text) {
|
||||
label.set('text', text);
|
||||
}
|
||||
label.eliminate('$text');
|
||||
li.removeClass('editing');
|
||||
|
||||
},
|
||||
|
||||
renameBranchEnd: function(element) {
|
||||
var li = (element.get('tag') == 'li') ? element : element.getParent('li'),
|
||||
label = li.getElement('.label'),
|
||||
text = label.get('text').trim();
|
||||
|
||||
if(label.get('contenteditable') == 'true'){
|
||||
|
||||
//validation
|
||||
text = File.sanitize(text);
|
||||
|
||||
|
||||
if (!text.getFileName()) {
|
||||
fd.error.alert('Filename must be valid', 'Your file must not contain special characters, and requires a file extension.');
|
||||
return this;
|
||||
}
|
||||
|
||||
label.removeEvent('blur', label.retrieve('$blur'));
|
||||
label.eliminate('$text');
|
||||
label.set('contenteditable', false).blur();
|
||||
window.getSelection().removeAllRanges();
|
||||
|
||||
|
||||
li.removeClass('editing');
|
||||
//fire a renameCancel if the name didnt change
|
||||
if (text == label.get('title').trim()) {
|
||||
this.fireEvent('renameCancel', li);
|
||||
return this;
|
||||
}
|
||||
|
||||
label.set('title', text);
|
||||
label.set('text', text);
|
||||
|
||||
li.set('name', text);
|
||||
li.set('title', text);
|
||||
var path = this.getFullPath(li)
|
||||
li.set('path', path);
|
||||
|
||||
|
||||
this.fireEvent('renameComplete', [li, path]);
|
||||
return false;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
deleteBranch: function(element) {
|
||||
element.dispose();
|
||||
this.collapse.prepare();
|
||||
this.fireEvent('deleteBranch', element);
|
||||
},
|
||||
|
||||
addPath: function(obj, options){
|
||||
options = options || {};
|
||||
var suffix = options.suffix || '',
|
||||
splitted = obj.getFullName().split('/'),
|
||||
elements = Array.clone(splitted),
|
||||
end = splitted.length - 1,
|
||||
selector = '',
|
||||
el,
|
||||
target = options.target,
|
||||
id_prefix = this.options.id_prefix;
|
||||
|
||||
if (id_prefix) {
|
||||
id_prefix += '-';
|
||||
}
|
||||
|
||||
elements.each(function(name, i){
|
||||
var path = splitted.slice(0, i + 1).join('/');
|
||||
if (i == end){
|
||||
var previous = elements[i - 1] ? elements[i - 1].getElement('ul') : (options.target.getElement('ul') || options.target);
|
||||
el = elements[i] = previous.getChildren(selector += 'li[title='+ name + suffix +'] ')[0] || this.addBranch({
|
||||
'title': obj.getShortName(),
|
||||
'name': obj.getShortName(),
|
||||
'path': path,
|
||||
'url': obj.options.url,
|
||||
'id': obj.getID(),
|
||||
'rel': obj.options.type ? 'file' : 'directory',
|
||||
'class': 'UI_File_Normal' + (options.nodrag ? ' nodrag' : '')
|
||||
}, previous, options);
|
||||
|
||||
elements[i].store('file', obj);
|
||||
} else {
|
||||
target = elements[i] = options.target.getElement(selector += '> ul > li[title='+ name +'] ') || this.addBranch({
|
||||
'title': name,
|
||||
'name': name,
|
||||
'rel': 'directory',
|
||||
'id': id_prefix + path.replace(/\//g, '-'),
|
||||
'path': path
|
||||
}, target, options);
|
||||
}
|
||||
|
||||
}, this);
|
||||
|
||||
return el;
|
||||
},
|
||||
|
||||
getFullPath: function(branch) {
|
||||
var name = branch.get('title'),
|
||||
parentEl = branch.getParent('li');
|
||||
|
||||
if (!parentEl.hasClass('top_branch')) {
|
||||
name = this.getFullPath(parentEl) + '/' + name;
|
||||
}
|
||||
return name;
|
||||
},
|
||||
|
||||
setFullPath: function(branch, path) {
|
||||
if (!path) path = this.getFullPath(branch);
|
||||
branch.set('path', path);
|
||||
return branch;
|
||||
},
|
||||
|
||||
toElement: function() {
|
||||
return this.element;
|
||||
}
|
||||
li.set('title', text);
|
||||
var path = this.getFullPath(li);
|
||||
li.set('path', path);
|
||||
|
||||
|
||||
this.fireEvent('renameComplete', [li, path]);
|
||||
return false;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
deleteBranch: function(element) {
|
||||
element.dispose();
|
||||
this.collapse.prepare();
|
||||
this.fireEvent('deleteBranch', element);
|
||||
},
|
||||
|
||||
addPath: function(obj, options){
|
||||
options = options || {};
|
||||
var suffix = options.suffix || '',
|
||||
splitted = obj.get('fullName').split('/'),
|
||||
elements = Array.clone(splitted),
|
||||
end = splitted.length - 1,
|
||||
selector = '',
|
||||
el,
|
||||
url = options.url,
|
||||
target = options.target,
|
||||
id_prefix = this.options.id_prefix,
|
||||
rel = (obj instanceof Module || obj instanceof Attachment) ?
|
||||
'file':
|
||||
'directory';
|
||||
|
||||
if (id_prefix) {
|
||||
id_prefix += '-';
|
||||
}
|
||||
|
||||
elements.each(function(name, i){
|
||||
var path = splitted.slice(0, i + 1).join('/');
|
||||
if (i == end){
|
||||
var previous = elements[i - 1] ? elements[i - 1].getElement('ul') : (options.target.getElement('ul') || options.target);
|
||||
el = elements[i] = previous.getChildren(selector += 'li[title='+ name + suffix +'] ')[0] || this.addBranch({
|
||||
'title': obj.get('shortName'),
|
||||
'name': obj.get('shortName'),
|
||||
'path': path,
|
||||
'url': url,
|
||||
'id': options.id,
|
||||
'rel': rel,
|
||||
'class': 'UI_File_Normal' + (options.nodrag ? ' nodrag' : '')
|
||||
}, previous, options);
|
||||
|
||||
elements[i].store('file', obj);
|
||||
} else {
|
||||
target = elements[i] = options.target.getElement(selector += '> ul > li[title='+ name +'] ') || this.addBranch({
|
||||
'title': name,
|
||||
'name': name,
|
||||
'rel': 'directory',
|
||||
'id': id_prefix + path.replace(/\//g, '-'),
|
||||
'path': path
|
||||
}, target, options);
|
||||
}
|
||||
|
||||
}, this);
|
||||
|
||||
return el;
|
||||
},
|
||||
|
||||
getFullPath: function(branch) {
|
||||
var name = branch.get('title'),
|
||||
parentEl = branch.getParent('li');
|
||||
|
||||
if (!parentEl.hasClass('top_branch')) {
|
||||
name = this.getFullPath(parentEl) + '/' + name;
|
||||
}
|
||||
return name;
|
||||
},
|
||||
|
||||
setFullPath: function(branch, path) {
|
||||
if (!path) path = this.getFullPath(branch);
|
||||
branch.set('path', path);
|
||||
return branch;
|
||||
},
|
||||
|
||||
toElement: function() {
|
||||
return this.element;
|
||||
}
|
||||
});
|
||||
|
||||
FileTree.Collapse = new Class({
|
||||
|
||||
Extends: Collapse.LocalStorage,
|
||||
|
||||
updateElement: function(element){
|
||||
this.parent(element);
|
||||
this.updatePath(element);
|
||||
},
|
||||
|
||||
updatePath: function(element){
|
||||
var parent = element.getParent('li'),
|
||||
path = parent ? parent.get('path') : false;
|
||||
element.set('path', (path ? path + '/' : '') + (element.get('path') || '').split('/').getLast());
|
||||
}
|
||||
|
||||
|
||||
Extends: Collapse.LocalStorage,
|
||||
|
||||
updateElement: function(element){
|
||||
this.parent(element);
|
||||
this.updatePath(element);
|
||||
},
|
||||
|
||||
updatePath: function(element){
|
||||
var parent = element.getParent('li'),
|
||||
path = parent ? parent.get('path') : false;
|
||||
element.set('path', (path ? path + '/' : '') + (element.get('path') || '').split('/').getLast());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
String.implement('getFileExtension', function() {
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче