Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated fs.js. changed use of createObject url to fileEntryURL.

  • Loading branch information...
commit 9a105f74f31f077e7626ef913b7095d534490362 1 parent c5c1be4
@podviaznikov authored
View
2  app.mf
@@ -1,6 +1,6 @@
CACHE MANIFEST
-index.html
16.png
+index.html
js/app.js
js/lib/libs.bundle.js
css/styles.css
View
23 public/js/app.js
@@ -1026,7 +1026,7 @@ $(function(){
},
initialize: function(){
this.songs=new SongsList();//should be first in this method!
- _.bindAll(this,'addOne', 'addAll','destroyFileURL','currentSong','currentSongIndex',
+ _.bindAll(this,'addOne', 'addAll','currentSong','currentSongIndex',
'randomSong','render','clearPlaylist','selectSong',
'playSongModel','savePlayList','setPlayListModel','removePlayListModel','setSongsAndPlay');
this.songs.bind('selected',this.selectSong);
@@ -1101,7 +1101,7 @@ $(function(){
e.stopPropagation();
e.preventDefault();
var dataTransfer=e.originalEvent.dataTransfer;
- if(dataTransfer&&dataTransfer.getData('text/plain')){
+ if(dataTransfer && dataTransfer.getData('text/plain')){
var transfer=DataTransfer.fromString(dataTransfer.getData('text/plain'));
if(transfer){
if('artist'===transfer.type){
@@ -1140,7 +1140,8 @@ $(function(){
this.songs.add(song);
}
}
- }else{
+ }
+ else{
AppController.appView.dropFiles(e);
}
},
@@ -1151,12 +1152,6 @@ $(function(){
self.infoEl.html(_.template(self.songInfoTpl,song.toJSON()));
});
},
- destroyFileURL:function(){
- var audioURL=AppController.playerCtrl.url;
- if(audioURL){
- fs.util.destroyFileURL(audioURL);
- }
- },
randomSong:function(){
var randomSong=Math.floor(Math.random()*this.songs.length);
if(randomSong===this.currentSong()){
@@ -1197,11 +1192,8 @@ $(function(){
this.playSongModel(previousSong,playSong);
},
playSongModel:function(song,playSong){
- if(playSong){
- this.destroyFileURL();
- if(song && song.view){
- song.view.playSong();
- }
+ if(playSong && song && song.view){
+ song.view.playSong();
}
else if(!playSong && song && song.view){
song.view.selectSong();
@@ -1237,7 +1229,7 @@ $(function(){
AppController.settings.saveLastArtist(this.model.get('artist'));
this.selectSong();
- fs.util.createFileURL(this.model.get('fileName'),function(er,url){
+ fs.util.getFileURL(this.model.get('fileName'),function(er,url){
if(!er){
AppController.playerCtrl.play(url);
}
@@ -1245,7 +1237,6 @@ $(function(){
}
});
});
-
$(function(){
"use strict";
//2nd column view
View
17 public/js/app.min.js
@@ -43,15 +43,14 @@ initialize:function(){Backbone.View.prototype.initialize.apply(this,arguments);_
songsCount:this.model.get("songs").length})},handleDragStart:function(a){var b=a.originalEvent,a=b.dataTransfer,b=DataTransfer.create("playlist",b.srcElement.dataset.playlist);a.effectAllowed="move";a.setData("text/plain",b.toString())},selectPlayList:function(){$(".lib-item-data").removeClass("selected-lib-item");$(this.el).addClass("selected-lib-item");AppController.detailsView.showPlayList(this.model)},playPlayList:function(){this.selectPlayList();AppController.playlistView.setSongsAndPlay(this.model.findSongs())},
deletePlaylist:function(){this.model.destroy();this.$(this.el).remove()}});ui.SoundCloudTrackMenuView=Backbone.View.extend({className:"lib-item-data box",tagName:"article",tplId:"sound_cloud_track_menu_tpl",events:{click:"playTrack"},initialize:function(){Backbone.View.prototype.initialize.apply(this,arguments);_.bindAll(this,"playTrack");this.model.view=this},playTrack:function(){AppController.playerCtrl.play(this.model.get("url"))}})});
$(function(){ui.PlayListView=Backbone.View.extend({el:$("#playing_list"),infoEl:$("#playing_list #song_info_view"),songsEl:$("#playing_list #playing_songs"),dropFileLabel:$("#playing_list #playing_songs label"),statEL:$("#playing_list footer"),songInfoTpl:$("#song_info_tpl").html(),playlistStatTpl:$("#playlist_stat_tpl").html(),newPlayListName:$("#new_play_list"),events:{drop:"handleDrop","blur #new_play_list":"savePlayList","click #clear_playlist":"clearPlaylist"},initialize:function(){this.songs=
-new SongsList;_.bindAll(this,"addOne","addAll","destroyFileURL","currentSong","currentSongIndex","randomSong","render","clearPlaylist","selectSong","playSongModel","savePlayList","setPlayListModel","removePlayListModel","setSongsAndPlay");this.songs.bind("selected",this.selectSong);this.songs.bind("add",this.addOne);this.songs.bind("reset",this.addAll);this.songs.bind("all",this.render);var a=AppController.settings.getPlayList();a&&(this.songs.reset(a.models),(a=AppController.settings.getLastSong())&&
-this.selectSong(new Song(a)))},render:function(){this.statEL.html(_.template(this.playlistStatTpl,{songsCount:this.songs.length}));return this},setSongsAndPlay:function(a){this.songs.reset(a.models);var b=this.songs.first();b&&b.view.playSong();AppController.settings.savePlayList(a)},setPlayListModel:function(a){this.playList=a;this.newPlayListName.val(this.playList.get("name"))},removePlayListModel:function(){this.playList=null;this.newPlayListName.val("Unsaved list")},savePlayList:function(){var a=
-this.newPlayListName.val();if(a!=="Unsaved list"){if(!this.playList)this.playList=new PlayList;var b=this.songs.toJSON();this.playList.set({name:a,songs:b});this.playList.save();AppController.libraryMenu.playLists.add(this.playList)}},clearPlaylist:function(){this.songsEl.empty();this.songs.reset();AppController.settings.savePlayList(this.songs);this.render()},addOne:function(a){if(a.get("fileName")){this.dropFileLabel.remove();var b=new ui.SongMiniView({model:a});a.view=b;this.songsEl.append(b.render().el)}},
-addAll:function(){this.songs.length!==0&&(this.songsEl.empty(),this.songs.each(this.addOne))},handleDrop:function(a){a.stopPropagation();a.preventDefault();var b=a.originalEvent.dataTransfer;if(b&&b.getData("text/plain")){if(a=DataTransfer.fromString(b.getData("text/plain")))if("artist"===a.type){if(a=AppController.libraryMenu.artists.forName(a.value)){var c=this.songs;a.songs.each(function(a){c.add(a)})}}else if("album"===a.type){if(a=AppController.libraryMenu.albums.forName(a.value))c=this.songs,
-a.get("songs").each(function(a){c.add(a)})}else if("playlist"===a.type){if(a=AppController.libraryMenu.playLists.forName(a.value))c=this.songs,a.findSongs().each(function(a){c.add(a)})}else"song"===a.type&&this.songs.add(new Song(a.value))}else AppController.appView.dropFiles(a)},selectSong:function(a){this.selectedSong=a;var b=this;a.findImage(function(){b.infoEl.html(_.template(b.songInfoTpl,a.toJSON()))})},destroyFileURL:function(){var a=AppController.playerCtrl.url;a&&fs.util.destroyFileURL(a)},
-randomSong:function(){var a=Math.floor(Math.random()*this.songs.length);if(a===this.currentSong())return this.randomSong();return a},currentSong:function(){return this.songs.at(this.currentSongIndex())},currentSongIndex:function(){return this.songs.indexOf(this.selectedSong)},next:function(a){var a=!a,b=-1;a&&AppController.settings.isShuffle()?b=this.randomSong():(b=this.currentSongIndex(),b===this.songs.length-1&&(b=-1,AppController.settings.isRepeat()||(a=!1)),b+=1);this.playSongModel(this.songs.at(b),
-a)},previous:function(a){var a=!a,b=this.currentSongIndex();if(b===0)b=this.songs.length;this.playSongModel(this.songs.at(b-1),a)},playSongModel:function(a,b){b?(this.destroyFileURL(),a&&a.view&&a.view.playSong()):!b&&a&&a.view&&a.view.selectSong()}});ui.SongMiniView=Backbone.View.extend({className:"song-data",tplId:"song_mini_tpl",events:{"click .song":"selectSong","dblclick .song":"playSong"},initialize:function(){Backbone.View.prototype.initialize.apply(this,arguments);_.bindAll(this,"selectSong",
-"playSong")},render:function(){this.el.draggable=!0;this.renderTpl();return this},selectSong:function(){$(".song-data").removeClass("selected_song");$(this.el).addClass("selected_song");this.model.trigger("selected",this.model)},playSong:function(){AppController.settings.saveLastSong(this.model.toJSON());AppController.settings.saveLastAlbum(this.model.get("album"));AppController.settings.saveLastArtist(this.model.get("artist"));this.selectSong();fs.util.createFileURL(this.model.get("fileName"),function(a,
-b){a||AppController.playerCtrl.play(b)})}})});
+new SongsList;_.bindAll(this,"addOne","addAll","currentSong","currentSongIndex","randomSong","render","clearPlaylist","selectSong","playSongModel","savePlayList","setPlayListModel","removePlayListModel","setSongsAndPlay");this.songs.bind("selected",this.selectSong);this.songs.bind("add",this.addOne);this.songs.bind("reset",this.addAll);this.songs.bind("all",this.render);var a=AppController.settings.getPlayList();a&&(this.songs.reset(a.models),(a=AppController.settings.getLastSong())&&this.selectSong(new Song(a)))},
+render:function(){this.statEL.html(_.template(this.playlistStatTpl,{songsCount:this.songs.length}));return this},setSongsAndPlay:function(a){this.songs.reset(a.models);var b=this.songs.first();b&&b.view.playSong();AppController.settings.savePlayList(a)},setPlayListModel:function(a){this.playList=a;this.newPlayListName.val(this.playList.get("name"))},removePlayListModel:function(){this.playList=null;this.newPlayListName.val("Unsaved list")},savePlayList:function(){var a=this.newPlayListName.val();
+if(a!=="Unsaved list"){if(!this.playList)this.playList=new PlayList;var b=this.songs.toJSON();this.playList.set({name:a,songs:b});this.playList.save();AppController.libraryMenu.playLists.add(this.playList)}},clearPlaylist:function(){this.songsEl.empty();this.songs.reset();AppController.settings.savePlayList(this.songs);this.render()},addOne:function(a){if(a.get("fileName")){this.dropFileLabel.remove();var b=new ui.SongMiniView({model:a});a.view=b;this.songsEl.append(b.render().el)}},addAll:function(){this.songs.length!==
+0&&(this.songsEl.empty(),this.songs.each(this.addOne))},handleDrop:function(a){a.stopPropagation();a.preventDefault();var b=a.originalEvent.dataTransfer;if(b&&b.getData("text/plain")){if(a=DataTransfer.fromString(b.getData("text/plain")))if("artist"===a.type){if(a=AppController.libraryMenu.artists.forName(a.value)){var c=this.songs;a.songs.each(function(a){c.add(a)})}}else if("album"===a.type){if(a=AppController.libraryMenu.albums.forName(a.value))c=this.songs,a.get("songs").each(function(a){c.add(a)})}else if("playlist"===
+a.type){if(a=AppController.libraryMenu.playLists.forName(a.value))c=this.songs,a.findSongs().each(function(a){c.add(a)})}else"song"===a.type&&this.songs.add(new Song(a.value))}else AppController.appView.dropFiles(a)},selectSong:function(a){this.selectedSong=a;var b=this;a.findImage(function(){b.infoEl.html(_.template(b.songInfoTpl,a.toJSON()))})},randomSong:function(){var a=Math.floor(Math.random()*this.songs.length);if(a===this.currentSong())return this.randomSong();return a},currentSong:function(){return this.songs.at(this.currentSongIndex())},
+currentSongIndex:function(){return this.songs.indexOf(this.selectedSong)},next:function(a){var a=!a,b=-1;a&&AppController.settings.isShuffle()?b=this.randomSong():(b=this.currentSongIndex(),b===this.songs.length-1&&(b=-1,AppController.settings.isRepeat()||(a=!1)),b+=1);this.playSongModel(this.songs.at(b),a)},previous:function(a){var a=!a,b=this.currentSongIndex();if(b===0)b=this.songs.length;this.playSongModel(this.songs.at(b-1),a)},playSongModel:function(a,b){b&&a&&a.view?a.view.playSong():!b&&a&&
+a.view&&a.view.selectSong()}});ui.SongMiniView=Backbone.View.extend({className:"song-data",tplId:"song_mini_tpl",events:{"click .song":"selectSong","dblclick .song":"playSong"},initialize:function(){Backbone.View.prototype.initialize.apply(this,arguments);_.bindAll(this,"selectSong","playSong")},render:function(){this.el.draggable=!0;this.renderTpl();return this},selectSong:function(){$(".song-data").removeClass("selected_song");$(this.el).addClass("selected_song");this.model.trigger("selected",this.model)},
+playSong:function(){AppController.settings.saveLastSong(this.model.toJSON());AppController.settings.saveLastAlbum(this.model.get("album"));AppController.settings.saveLastArtist(this.model.get("artist"));this.selectSong();fs.util.getFileURL(this.model.get("fileName"),function(a,b){a||AppController.playerCtrl.play(b)})}})});
$(function(){ui.DetailsView=Backbone.View.extend({el:$("#filtered_lib"),libDetailsPanel:$("#filtered_lib_content"),artistBioPanel:$("#artist_bio"),events:{dragstart:"handleDragStart"},initialize:function(){Backbone.View.prototype.initialize.apply(this,arguments);_.bindAll(this,"showAlbums","showAlbum","showPlayList","handleDragStart","showBio","hideBio");this.artistBioView=new ui.ArtistBioView},showBio:function(a){this.artistBioPanel.show();this.artistBioView.setArtistModel(a);this.artistBioView.render();
this.libDetailsPanel.hide()},hideBio:function(){this.artistBioPanel.hide();this.artistBioView.clear();this.libDetailsPanel.show();this.libDetailsPanel.empty()},showAlbums:function(a,b){this.hideBio();a&&a.each(this.showAlbum);this.songs=b},showAlbum:function(a){this.hideBio();this.songs=a.get("songs");this.libDetailsPanel.append((new ui.AlbumView({model:a})).render().el)},showPlayList:function(a){this.hideBio();this.libDetailsPanel.append((new ui.PlayListFullView({model:a})).render().el)},handleDragStart:function(a){var b=
a.originalEvent,a=b.dataTransfer,b=b.srcElement.dataset.id;a.effectAllowed="move";this.songs&&(b=this.songs.get(b),b=DataTransfer.create("song",b),a.setData("text/plain",b.toString()))}});ui.ArtistBioView=Backbone.View.extend({el:$("#artist_bio"),tplId:"artist_bio_tpl",initialize:function(){Backbone.View.prototype.initialize.apply(this,arguments);_.bindAll(this,"setArtistModel","renderArtistBio","clear")},setArtistModel:function(a){this.model=a},render:function(){this.model&&dataService.getArtistBio(this.model.get("name"),
View
24 public/js/app/ui.playlist.js
@@ -16,7 +16,7 @@ $(function(){
},
initialize: function(){
this.songs=new SongsList();//should be first in this method!
- _.bindAll(this,'addOne', 'addAll','destroyFileURL','currentSong','currentSongIndex',
+ _.bindAll(this,'addOne', 'addAll','currentSong','currentSongIndex',
'randomSong','render','clearPlaylist','selectSong',
'playSongModel','savePlayList','setPlayListModel','removePlayListModel','setSongsAndPlay');
this.songs.bind('selected',this.selectSong);
@@ -91,7 +91,7 @@ $(function(){
e.stopPropagation();
e.preventDefault();
var dataTransfer=e.originalEvent.dataTransfer;
- if(dataTransfer&&dataTransfer.getData('text/plain')){
+ if(dataTransfer && dataTransfer.getData('text/plain')){
var transfer=DataTransfer.fromString(dataTransfer.getData('text/plain'));
if(transfer){
if('artist'===transfer.type){
@@ -130,7 +130,8 @@ $(function(){
this.songs.add(song);
}
}
- }else{
+ }
+ else{
AppController.appView.dropFiles(e);
}
},
@@ -141,12 +142,6 @@ $(function(){
self.infoEl.html(_.template(self.songInfoTpl,song.toJSON()));
});
},
- destroyFileURL:function(){
- var audioURL=AppController.playerCtrl.url;
- if(audioURL){
- fs.util.destroyFileURL(audioURL);
- }
- },
randomSong:function(){
var randomSong=Math.floor(Math.random()*this.songs.length);
if(randomSong===this.currentSong()){
@@ -187,11 +182,8 @@ $(function(){
this.playSongModel(previousSong,playSong);
},
playSongModel:function(song,playSong){
- if(playSong){
- this.destroyFileURL();
- if(song && song.view){
- song.view.playSong();
- }
+ if(playSong && song && song.view){
+ song.view.playSong();
}
else if(!playSong && song && song.view){
song.view.selectSong();
@@ -227,11 +219,11 @@ $(function(){
AppController.settings.saveLastArtist(this.model.get('artist'));
this.selectSong();
- fs.util.createFileURL(this.model.get('fileName'),function(er,url){
+ fs.util.getFileURL(this.model.get('fileName'),function(er,url){
if(!er){
AppController.playerCtrl.play(url);
}
});
}
});
-});
+});
View
616 public/js/lib/fs.js
@@ -1,616 +0,0 @@
-/**(c) 2011 Enginimation Studio (http://enginimation.com). may be freely distributed under the MIT license.*/
-"use strict";
-var global = this,fs;
-// Fixing API method names
-global.requestFileSystem = global.requestFileSystem || global.webkitRequestFileSystem;
-global.BlobBuilder = global.BlobBuilder || global.WebKitBlobBuilder;
-global.resolveLocalFileSystemURL = global.resolveLocalFileSystemURL || global.webkitResolveLocalFileSystemURL;
-global.URL = global.URL || global.webkitURL;
-//Creating entry point for the library.
-fs=Object.create({},{
- // Current version of the library.
- version:{value:'0.9'},
- // Configuration property. Indicates whether to use logging.
- // Default value is `false` but can be changed.
- log:{value:false,writable:true},
- // Configuration property. Specifies the size of preserved space in file system.
- // Default value is `10 GB` but can be changed.
- maxSize:{value:10*1020*1024*1024,writable:true},
- // This error code used when file is expected but folder was gotten.
- // @see http://www.w3.org/TR/FileAPI/#dfn-fileerror
- FILE_EXPECTED:{value:50},
- // This error code used when browser doesn't support one of the requested features.
- // @see http://www.w3.org/TR/FileAPI/#dfn-fileerror
- BROWSER_NOT_SUPPORTED:{value:51},
- // Get reference to the FileSystem. Method has two parameters:
- //
- // callback function with error or 'FileSystem' reference.
- // optional options objects.
- getNativeFS:{
- value:function(callback,options){
- if (global.requestFileSystem){
- //default scope is PERSISTENT
- var scope = global.PERSISTENT;
- //create empty options object if not exists
- options = options || {};
- //override scope to TEMPORARY if that was specified
- if(options.tmp){
- scope = global.TEMPORARY;
- }
- //request FileSystem access for the provided scope and size
- global.requestFileSystem(scope, this.maxSize,function(fs){
- //return FileSystem reference to the callback
- callback(undefined,fs);
- },
- // error callback
- function(err){
- callback(err);
- });
- }else{
- //browser not support and not expose FileSystem
- callback(fs.BROWSER_NOT_SUPPORTED);
- }
- }
- },
- // Create blob for given content and content/type.
- createBlob:{
- value:function(content,contentType){
- //creating new BlobBuilder instance
- var blobBuilder = new global.BlobBuilder();
- //setting content to blob builder
- blobBuilder.append(content);
- //getting blob from the blob builder
- return blobBuilder.getBlob(contentType);
- }
- },
- // Convert base64 string to blob. Parameters:
- //
- // base64String - string that should be converted.
- // type - content type for the blob.
- base64StringToBlob:{
- value:function(base64String,type){
- //decode string
- var decodedString = global.atob(base64String),
- dataLength = decodedString.length,
- arrayData = new global.Int8Array(dataLength),
- i = 0;
- for(; i < dataLength; i++){
- arrayData[i] = decodedString.charCodeAt(i);
- }
- return this.createBlob(arrayData.buffer,type);
- }
- }
-});
-
-"use strict";
-/**
- * Method shortName for the file will return just name of the file without extension.
- *
- * @return name of the file without extension.
- */
-Object.defineProperty(global.File.prototype,
-'shortName',{
- value:function(){
- var dotIndex = this.name.lastIndexOf('.');
- return this.name.substring(0,dotIndex);
- }
-});
-
-/**
- * Method extension for the file will return just extension.
- *
- * @return extension of the file.
- */
-Object.defineProperty(global.File.prototype,
-'extension',{
- value:function(){
- var dotIndex = this.name.lastIndexOf('.');
- return this.name.substring(dotIndex);
- }
-});
-
-/**
- * Method for getting size of the file in KB.
- *
- * @return size of the file in KB.
- */
-Object.defineProperty(global.File.prototype,
-'sizeInKB',{
- value:function(){
- return (this.size/(1014)).toFixed(1);
- }
-});
-/**
- * Method for getting size of the file in MB.
- *
- * @return size of the file in MB.
- */
-Object.defineProperty(global.File.prototype,
-'sizeInMB',{
- value:function()
- {
- return (this.size/(1024*1014)).toFixed(1);
- }
-});
-/**
- * Method for getting size of the file in GB.
- *
- * @return size of the file in GB.
- */
-Object.defineProperty(global.File.prototype,
-'sizeInGB',{
- value:function(){
- return (this.size/(1024*1014*1024)).toFixed(1);
- }
-});
-/**
- * Method return readable explanation for the error codes.
- *
- * @return message description for the standard error codes.
- * @see http://www.w3.org/TR/FileAPI/#dfn-fileerror
- */
- //todo check this http://dev.w3.org/2009/dap/file-system/file-writer.html!! and http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-fileerror-interface
-Object.defineProperty(global.FileError.prototype,
-'message',{
- value:function(){
- var msg=this.code;
-// switch (this.code){
-// case global.FileError.ENCODING_ERR:
-// msg = 'ENCODING_ERR';
-// break;
-// case global.FileError.NOT_FOUND_ERR:
-// msg = 'NOT_FOUND_ERR';
-// break;
-// case global.FileError.SECURITY_ERR:
-// msg = 'SECURITY_ERR';
-// break;
-// case global.FileError.ABORT_ERR:
-// msg = 'ABORT_ERR';
-// break;
-// case global.FileError.NOT_READABLE_ERR:
-// msg = 'NOT_READABLE_ERR';
-// break;
-// case global.FileError.NO_MODIFICATION_ALLOWED_ERR:
-// msg = 'NO_MODIFICATION_ALLOWED_ERR';
-// case global.FileError.NO_MODIFICATION_ALLOWED_ERR:
-// msg = 'NO_MODIFICATION_ALLOWED_ERR';
-// case fs.FILE_EXPECTED:
-// msg = 'FILE_EXPECTED';
-// break;
-// case fs.BROWSER_NOT_SUPPORTED:
-// msg = 'BROWSER_NOT_SUPPORTED';
-// break;
-// default:
-// msg = 'UNKNOWN_ERROR';
-// break;
-// };
- return msg;
- }
-});
-
-"use strict";
-//Define io module for dealing with FileSystem
-fs.io = Object.create({},{
- // Files
- // -----------------
- // Get file (or create if doesn't exists).
- getFile:{
- value:function(directory,fileName,callback){
- //success
- directory.getFile(fileName,{create:true}, function(fileEntry){
- callback(undefined,fileEntry);
- },
- //error
- function(err){
- callback(err);
- });
- }
- },
- // Get file from root (or create if doesn't exists).
- getFileFromRoot:{
- value:function(fileName,callback,options){
- fs.getNativeFS(function(err,filesystem){
- if(err){
- callback(err);
- }else{
- fs.io.getFile(filesystem.root,fileName,callback);
- }
- },options);
- }
- },
- // Directories
- // -----------------
- // Read directory.
- readDirectory:{
- value:function(directoryName,callback){
- fs.util.getDirectory(directoryName,function(err,directory){
- //error
- if(err){
- callback(err);
- }
- //success
- else{
- fs.util.readEntriesFromDirectory(directory,callback);
- }
- },{});
- }
- },
- // Read root directory
- readRootDirectory:{
- value:function(callback){
- fs.getNativeFS(function(err,filesystem){
- //error
- if(err){
- callback(err);
- }
- //success
- else{
- fs.util.readEntriesFromDirectory(filesystem.root,callback);
- }
- },{});
- }
- },
- // Get directory (or create if doesn't exists).
- getDirectory:{
- value:function(directory,directoryName,callback){
- callback(undefined,directory.getDirectory(directoryName,{create:true}));
- }
- },
- // Get root directory (or create if doesn't exists).
- getDirectoryFromRoot:{
- value:function(directoryName,callback,options){
- fs.getNativeFS(function(err,filesystem){
- //error
- if(err){
- callback(err);
- }
- //success
- else{
- fs.util.getDirectory(filesystem.root,directoryName,callback);
- }
- },options);
- }
- },
-});
-
-
-"use strict";
-// Utils module to deal with FileSystem. Some low-level methods.
-fs.util= Object.create({},{
- // Read utils
- // -----------------
- // Create reader for the file using file name.
- getReaderUsingFileName:{
- value:function(fileName,callback,readerMethod,options)
- {
- fs.io.getFileFromRoot(fileName,function(er,fileEntry){
- // Get a File object representing the file,
- // then use FileReader to read its contents.
- fileEntry.file(function(file){
- fs.util.getReader(file,callback,readerMethod);
- },
- //error
- function(error){
- callback(error);
- });
- },options);
- }
- },
- // Create reader for the file.
- getReader:{
- value:function(file,callback,readerMethod){
- //instantiate reader
- var reader = new global.FileReader(),
- initialFile = file;
- //register handler for `loadend` event.
- reader.onloadend = function()
- {
- //pass read data into the callback
- callback(undefined,this.result,initialFile);
- };
- //call one of the `FileReader`'s methods.
- reader[readerMethod](initialFile);
- }
- },
- // Read entries from directory
- readEntriesFromDirectory:{
- value:function(directory,callback){
- var directoryReader=directory.createReader();
- directoryReader.readEntries(function(entries){
- callback(undefined,entries);
- },
- function(error){
- callback(error);
- });
- }
- },
- // Read file as ArrayBuffer.
- readAsArrayBuffer:{
- value:function(fileName,callback,options){
- this.getReaderUsingFileName(fileName,callback,'readAsArrayBuffer',options);
- }
- },
- // Read file as ArrayBuffer.
- readFileAsArrayBuffer:{
- value:function(file,callback){
- this.getReader(file,callback,'readAsArrayBuffer');
- }
- },
- // Read file as binary string.
- readAsBinaryString:{
- value:function(fileName,callback,options){
- this.getReaderUsingFileName(fileName,callback,'readAsBinaryString',options);
- }
- },
- // Read file as binary string.
- readFileAsBinaryString:{
- value:function(file,callback){
- this.getReader(file,callback,'readAsBinaryString');
- }
- },
- // Read file as data url.
- readAsDataUrl:{
- value:function(fileName,callback,options){
- this.getReaderUsingFileName(fileName,callback,'readAsDataURL',options);
- }
- },
- // Read file as text.
- readAsText:{
- value:function(fileName,callback,options){
- this.getReaderUsingFileName(fileName,callback,'readAsText',options);
- }
- },
- // Remove file from FileSystem.
- remove:{
- value:function(filename,callback){
- fs.io.getFileFromRoot(filename,function(err,fileEntry){
- //success
- fileEntry.remove(function(){callback(undefined);},
- //error
- function(e){callback(e);});
- });
- }
- },
- // Write utils
- // -----------------
- // Write base64String to file.
- writeBase64StrToFile:{
- value:function(fileName,content,contentType,callback,options){
- // Create blob from base64 string.
- var blob = fs.base64StringToBlob(content,contentType);
- // Write blob to file.
- this.writeBlobToFile(fileName,blob,callback,options);
- }
- },
- // Write blob to file.
- writeBlobToFile:{
- value:function(fileName,blob,callback,options){
- // Get reference to file or create new one.
- fs.io.getFileFromRoot(fileName,function(err,fileEntry){
- if(err){
- // Handle error with specified callback.
- callback(err);
- }else{
- // Create writer.
- fileEntry.createWriter(function(fileWriter){
- // Register handler for `writeend` event.
- fileWriter.onwriteend = function(){
- console.log('writing to file finished.');
- // notify caller that blob was written to file
- callback(undefined);
- };
- // Register handler for `error` event.
- fileWriter.onerror = function(){
- console.log('Error writing to file:'+this.error);
- // notify caller about error
- callback(this.error);
- };
- // write blob to file
- fileWriter.write(blob);
- },
- // error during file writer creation
- function(err){callback(err);});
- }
- },options);
- }
- },
- // Write text to file.
- writeTextToFile:{
- value:function(fileName,text,callback,options){
- var blob = fs.createBlob(text,'text/plain');
- fs.util.writeBlobToFile(fileName,blob,callback,options);
- }
- },
- // Write ArrayBuffer to file.
- writeArrayBufferToFile:{
- value:function(fileName,contentType,arrayBuffer,callback,options){
- var blob = fs.createBlob(arrayBuffer,contentType);
- fs.util.writeBlobToFile(fileName,blob,callback,options);
- }
- },
- // Write file to file.
- writeFileToFile:{
- value:function(file,callback,options){
- // name of the file from options or from initial file.
- var filename = options.filename||file.name;
- // Get reference top file or create new.
- fs.io.getFileFromRoot(filename,function(err,fileEntry){
- if(err){
- //
- callback(err);
- }else{
- fileEntry.createWriter(function(fileWriter){
- // Register handler for `writeend` event.
- fileWriter.onwriteend = function(){
- console.log('writing to file finished.');
- // notify caller that file was written to file
- callback(undefined);
- };
- // Register handler for `error` event.
- fileWriter.onerror = function(){
- console.log('Error writing to file:'+this.error);
- // notify caller about error
- callback(this.error);
- };
- fileWriter.write(file);
- },function(err){callback(err);});
- }
- },options);
- }
- },
-
- // URLs
- // -----------------
- // Create file URL.
- createFileURL:{
- value:function(filename,callback){
- fs.io.getFileFromRoot(filename,function(er,fileEntry){
- if(er){
- //notify caller about error
- callback(er);
- }else{
- fileEntry.file(function(file){
- var url=global.URL.createObjectURL(file);
- //notify caller about success.
- callback(undefined,url);
- });
- }
- });
- }
- },
- // Destroy file URL.
- destroyFileURL:{
- value:function(url){global.URL.revokeObjectURL(url);}
- }
-
-});
-
-"use strict";
-//Module for reading operations for FileSystem, API is stable.
-fs.read = Object.create({},{
- // Read file as dataURL.
- asDataUrl:{
- value:function(fileName,callback){
- fs.util.readAsDataUrl(fileName,callback,{});
- }
- },
- // Read temporary file as dataURL.
- tmpFileAsDataUrl:{
- value:function(fileName,callback){
- fs.util.readAsDataUrl(fileName,callback,{tmp:true});
- }
- },
- // Read file as text.
- asText:{
- value:function(fileName,callback){
- fs.util.readAsText(fileName,callback,{});
- }
- },
- // Read temporary file as text.
- tmpFileAsText:{
- value:function(fileName,callback){
- fs.util.readAsText(fileName,callback,{tmp:true});
- }
- },
- // Read file as binary string.
- asBinaryString:{
- value:function(fileName,callback){
- fs.util.readAsBinaryString(fileName,callback,{});
- }
- },
- // Read temporary file as binary string.
- tmpFileAsBinaryString:{
- value:function(fileName,callback){
- fs.util.readAsBinaryString(fileName,callback,{tmp:true});
- }
- },
- // Read file as ArrayBuffer.
- asArrayBuffer:{
- value:function(fileName,callback){
- fs.util.readAsArrayBuffer(fileName,callback,{});
- }
- },
- // Read temporary file as ArrayBuffer.
- tmpFileAsArrayBuffer:{
- value:function(fileName,callback){
- fs.util.readAsArrayBuffer(fileName,callback,{tmp:true});
- }
- },
- // Read file instance as text.
- fileAsText:{
- value:function(file,callback){
- fs.util.getReader(file,callback,'readAsText');
- }
- },
- // Read file instance as dataUrl.
- fileAsDataUrl:{
- value:function(file,callback){
- fs.util.getReader(file,callback,'readAsDataURL');
- }
- },
- // Read file instance as ArrayBuffer.
- fileAsArrayBuffer:{
- value:function(file,callback){
- fs.util.readFileAsArrayBuffer(file,callback);
- }
- },
- // Read file instance as binary string.
- fileAsBinaryString:{
- value:function(file,callback){
- fs.util.readFileAsBinaryString(file,callback);
- }
- }
-});
-"use strict";
-// Module for writing operations with FileSystem, API is stable.
-fs.write = Object.create({},{
- // Write file instance to FileSystem with provided filename.
- file:{
- value:function(file,callback,filename){
- fs.util.writeFileToFile(file,callback,{filename:filename});
- }
- },
- // Write file instance as temporary file to FileSystem with provided filename.
- fileToTmpFile:{
- value:function(file,callback,filename){
- fs.util.writeFileToFile(file,callback,{tmp:true,filename:filename});
- }
- },
- // Write blob to FileSystem with provided name.
- blob:{
- value:function(fileName,blob,callback){
- fs.util.writeBlobToFile(fileName,blob,callback,{});
- }
- },
- // Write blob as temporary file to FileSystem with provided name.
- blobToTmpFile:{
- value:function(fileName,blob,callback){
- fs.util.writeBlobToFile(fileName,blob,callback,{tmp:true});
- }
- },
- // Write text to FileSystem with provided name.
- text:{
- value:function(fileName,text,callback){
- fs.util.writeTextToFile(fileName,text,callback,{});
- }
- },
- // Write text as temporary file to FileSystem with provided name.
- textToTmpFile: {
- value:function(fileName,text,callback){
- fs.util.writeTextToFile(fileName,text,callback,{tmp:true});
- }
- },
- // Write base64 string to FileSystem with provided name.
- base64Str:{
- value:function(fileName,content,contentType,callback){
- fs.util.writeBase64StrToFile(fileName,content,contentType,callback,{});
- }
- },
- // Write base64 string as temporary file to FileSystem with provided name.
- base64StrToTmpFile:{
- value:function(fileName,content,contentType,callback){
- fs.util.writeBase64StrToFile(fileName,content,contentType,callback,{tmp:true});
- }
- }
-});
-
View
5 public/js/lib/libs.bundle.js
@@ -7742,8 +7742,9 @@ UUID._hexAligner=UUID._getIntAligner(16);
// (c) 2011 Enginimation Studio (http://enginimation.com).
// backbone-indexdb.js may be freely distributed under the MIT license.
"use strict",Porridge.Model=Backbone.Model.extend({initialize:function(){this.get("id")||(this.id=UUID.generate(),this.set({id:this.id}))},save:function(){var a=this.constructor.definition.name;Porridge.save(a,this.toJSON(),this.id)},destroy:function(){var a=this.constructor.definition.name,b=this.constructor.definition.key||"id",c=this,d=function(){c.trigger("destroy",c,c.collection)};Porridge.remove(a,this.get(b),d)}},{definition:{}}),Porridge.Collection=Backbone.Collection.extend({fetch:function(a){a||(a={});var b=this,c=this.model.definition.name,d=function(a){b.add(new b.model({attributes:a}))};Porridge.all(c,d,function(){b.trigger("retrieved")},a.error)},fetchByKey:function(a,b){var c=this,d=this.model.definition.name,e=function(a){c.add(new c.model({attributes:a}))};Porridge.allByKey(d,a,b,e,function(){c.trigger("retrieved")})}})
+//fs.js
var global=this,fs;global.requestFileSystem=global.requestFileSystem||global.webkitRequestFileSystem;global.BlobBuilder=global.BlobBuilder||global.WebKitBlobBuilder;global.resolveLocalFileSystemURL=global.resolveLocalFileSystemURL||global.webkitResolveLocalFileSystemURL;global.URL=global.URL||global.webkitURL;
-fs=Object.create({},{version:{value:"0.9"},log:{value:!1,writable:!0},maxSize:{value:10695475200,writable:!0},FILE_EXPECTED:{value:50},BROWSER_NOT_SUPPORTED:{value:51},getNativeFS:{value:function(a,b){if(global.requestFileSystem){var c=global.PERSISTENT,b=b||{};if(b.tmp)c=global.TEMPORARY;global.requestFileSystem(c,this.maxSize,function(b){a(void 0,b)},function(b){a(b)})}else a(fs.BROWSER_NOT_SUPPORTED)}},createBlob:{value:function(a,b){var c=new global.BlobBuilder;c.append(a);return c.getBlob(b)}},
+fs=Object.create({},{version:{value:"0.9.1"},log:{value:!1,writable:!0},maxSize:{value:10695475200,writable:!0},FILE_EXPECTED:{value:50},BROWSER_NOT_SUPPORTED:{value:51},getNativeFS:{value:function(a,b){if(global.requestFileSystem){var c=global.PERSISTENT,b=b||{};if(b.tmp)c=global.TEMPORARY;global.requestFileSystem(c,this.maxSize,function(b){a(void 0,b)},function(b){a(b)})}else a(fs.BROWSER_NOT_SUPPORTED)}},createBlob:{value:function(a,b){var c=new global.BlobBuilder;c.append(a);return c.getBlob(b)}},
base64StringToBlob:{value:function(a,b){for(var c=global.atob(a),d=c.length,e=new global.Int8Array(d),f=0;f<d;f++)e[f]=c.charCodeAt(f);return this.createBlob(e.buffer,b)}}});Object.defineProperty(global.File.prototype,"shortName",{value:function(){return this.name.substring(0,this.name.lastIndexOf("."))}});Object.defineProperty(global.File.prototype,"extension",{value:function(){return this.name.substring(this.name.lastIndexOf("."))}});
Object.defineProperty(global.File.prototype,"sizeInKB",{value:function(){return(this.size/1014).toFixed(1)}});Object.defineProperty(global.File.prototype,"sizeInMB",{value:function(){return(this.size/1038336).toFixed(1)}});Object.defineProperty(global.File.prototype,"sizeInGB",{value:function(){return(this.size/1063256064).toFixed(1)}});Object.defineProperty(global.FileError.prototype,"message",{value:function(){return this.code}});
fs.io=Object.create({},{getFile:{value:function(a,b,c){a.getFile(b,{create:!0},function(b){c(void 0,b)},function(b){c(b)})}},getFileFromRoot:{value:function(a,b,c){fs.getNativeFS(function(c,e){c?b(c):fs.io.getFile(e.root,a,b)},c)}},readDirectory:{value:function(a,b){fs.util.getDirectory(a,function(a,d){a?b(a):fs.util.readEntriesFromDirectory(d,b)},{})}},readRootDirectory:{value:function(a){fs.getNativeFS(function(b,c){b?a(b):fs.util.readEntriesFromDirectory(c.root,a)},{})}},getDirectory:{value:function(a,
@@ -7752,7 +7753,7 @@ fs.util=Object.create({},{getReaderUsingFileName:{value:function(a,b,c,d){fs.io.
c)}},readFileAsArrayBuffer:{value:function(a,b){this.getReader(a,b,"readAsArrayBuffer")}},readAsBinaryString:{value:function(a,b,c){this.getReaderUsingFileName(a,b,"readAsBinaryString",c)}},readFileAsBinaryString:{value:function(a,b){this.getReader(a,b,"readAsBinaryString")}},readAsDataUrl:{value:function(a,b,c){this.getReaderUsingFileName(a,b,"readAsDataURL",c)}},readAsText:{value:function(a,b,c){this.getReaderUsingFileName(a,b,"readAsText",c)}},remove:{value:function(a,b){fs.io.getFileFromRoot(a,
function(a,d){d.remove(function(){b(void 0)},function(a){b(a)})})}},writeBase64StrToFile:{value:function(a,b,c,d,e){b=fs.base64StringToBlob(b,c);this.writeBlobToFile(a,b,d,e)}},writeBlobToFile:{value:function(a,b,c,d){fs.io.getFileFromRoot(a,function(a,d){a?c(a):d.createWriter(function(a){a.onwriteend=function(){console.log("writing to file finished.");c(void 0)};a.onerror=function(){console.log("Error writing to file:"+this.error);c(this.error)};a.write(b)},function(a){c(a)})},d)}},writeTextToFile:{value:function(a,
b,c,d){b=fs.createBlob(b,"text/plain");fs.util.writeBlobToFile(a,b,c,d)}},writeArrayBufferToFile:{value:function(a,b,c,d,e){b=fs.createBlob(c,b);fs.util.writeBlobToFile(a,b,d,e)}},writeFileToFile:{value:function(a,b,c){fs.io.getFileFromRoot(c.filename||a.name,function(c,e){c?b(c):e.createWriter(function(c){c.onwriteend=function(){console.log("writing to file finished.");b(void 0)};c.onerror=function(){console.log("Error writing to file:"+this.error);b(this.error)};c.write(a)},function(a){b(a)})},
-c)}},createFileURL:{value:function(a,b){fs.io.getFileFromRoot(a,function(a,d){a?b(a):d.file(function(a){a=global.URL.createObjectURL(a);b(void 0,a)})})}},destroyFileURL:{value:function(a){global.URL.revokeObjectURL(a)}}});
+c)}},createObjectURL:{value:function(a,b){fs.io.getFileFromRoot(a,function(a,d){a?b(a):d.file(function(a){a=global.URL.createObjectURL(a);b(void 0,a)})})}},destroyObjectURL:{value:function(a){global.URL.revokeObjectURL(a)}},getFileURL:{value:function(a,b){fs.io.getFileFromRoot(a,function(a,d){if(a)b(a);else{var e=d.toURL();b(void 0,e)}})}}});
fs.read=Object.create({},{asDataUrl:{value:function(a,b){fs.util.readAsDataUrl(a,b,{})}},tmpFileAsDataUrl:{value:function(a,b){fs.util.readAsDataUrl(a,b,{tmp:!0})}},asText:{value:function(a,b){fs.util.readAsText(a,b,{})}},tmpFileAsText:{value:function(a,b){fs.util.readAsText(a,b,{tmp:!0})}},asBinaryString:{value:function(a,b){fs.util.readAsBinaryString(a,b,{})}},tmpFileAsBinaryString:{value:function(a,b){fs.util.readAsBinaryString(a,b,{tmp:!0})}},asArrayBuffer:{value:function(a,b){fs.util.readAsArrayBuffer(a,
b,{})}},tmpFileAsArrayBuffer:{value:function(a,b){fs.util.readAsArrayBuffer(a,b,{tmp:!0})}},fileAsText:{value:function(a,b){fs.util.getReader(a,b,"readAsText")}},fileAsDataUrl:{value:function(a,b){fs.util.getReader(a,b,"readAsDataURL")}},fileAsArrayBuffer:{value:function(a,b){fs.util.readFileAsArrayBuffer(a,b)}},fileAsBinaryString:{value:function(a,b){fs.util.readFileAsBinaryString(a,b)}}});
fs.write=Object.create({},{file:{value:function(a,b,c){fs.util.writeFileToFile(a,b,{filename:c})}},fileToTmpFile:{value:function(a,b,c){fs.util.writeFileToFile(a,b,{tmp:!0,filename:c})}},blob:{value:function(a,b,c){fs.util.writeBlobToFile(a,b,c,{})}},blobToTmpFile:{value:function(a,b,c){fs.util.writeBlobToFile(a,b,c,{tmp:!0})}},text:{value:function(a,b,c){fs.util.writeTextToFile(a,b,c,{})}},textToTmpFile:{value:function(a,b,c){fs.util.writeTextToFile(a,b,c,{tmp:!0})}},base64Str:{value:function(a,
Please sign in to comment.
Something went wrong with that request. Please try again.