@ -11,10 +11,12 @@ define([
'/common/hyperscript.js' ,
'/customize/messages.js' ,
'/customize/pages.js' ,
'/bower_components/nthen/index.js' ,
'/common/media-tag.js' ,
'/bower_components/file-saver/FileSaver.min.js' ,
'/bower_components/tweetnacl/nacl-fast.min.js' ,
] , function ( $ , ApiConfig , FileCrypto , MakeBackup , Thumb , UI , UIElements , Util , Hash , h , Messages , Pages ) {
] , function ( $ , ApiConfig , FileCrypto , MakeBackup , Thumb , UI , UIElements , Util , Hash , h , Messages , Pages , nThen , MT ) {
var Nacl = window . nacl ;
var module = { } ;
@ -312,7 +314,11 @@ define([
} ) ;
return manualStore ;
} ;
var fileUploadModal = function ( defaultFileName , cb ) {
Messages . upload _modal _alt = "Alt text" ; // XXX
Messages . upload _addOptionalAlt = "Add descriptive text (optional)" ; // XXX
var fileUploadModal = function ( defaultFileName , cb , preview ) {
var parsedName = /^(\.?.+?)(\.[^.]+)?$/ . exec ( defaultFileName ) || [ ] ;
var ext = parsedName [ 2 ] || "" ;
@ -321,9 +327,15 @@ define([
// Ask for name, password and owner
var content = h ( 'div' , [
h ( 'h4' , Messages . upload _modal _title ) ,
( preview ? h ( 'div#cp-upload-preview-container' , preview ) : undefined ) ,
UIElements . setHTML ( h ( 'label' , { for : 'cp-upload-name' } ) ,
Messages . _getKey ( 'upload_modal_filename' , [ ext ] ) ) ,
h ( 'input#cp-upload-name' , { type : 'text' , placeholder : defaultFileName , value : defaultFileName } ) ,
h ( 'label' , { for : 'cp-upload-alt' } , Messages . upload _addOptionalAlt ) , // XXX alt text for uploads
h ( 'input#cp-upload-alt' , { type : 'text' , placeholder : Messages . upload _modal _alt } ) ,
h ( 'label' , { for : 'cp-upload-password' } , Messages . addOptionalPassword ) ,
UI . passwordInput ( { id : 'cp-upload-password' } ) ,
h ( 'span' , {
@ -335,7 +347,8 @@ define([
manualStore
] ) ;
$ ( content ) . find ( '#cp-upload-owned' ) . on ( 'change' , function ( ) {
var $content = $ ( content ) ;
$content . find ( '#cp-upload-owned' ) . on ( 'change' , function ( ) {
var val = Util . isChecked ( $ ( content ) . find ( '#cp-upload-owned' ) ) ;
if ( val ) {
$ ( content ) . find ( '#cp-upload-store' ) . prop ( 'checked' , true ) . prop ( 'disabled' , true ) ;
@ -348,8 +361,9 @@ define([
if ( ! yes ) { return void cb ( ) ; }
// Get the values
var newName = $ ( content ) . find ( '#cp-upload-name' ) . val ( ) ;
var password = $ ( content ) . find ( '#cp-upload-password' ) . val ( ) || undefined ;
var newName = $content . find ( '#cp-upload-name' ) . val ( ) ;
var password = $content . find ( '#cp-upload-password' ) . val ( ) || undefined ;
var alt = $content . find ( '#cp-upload-alt' ) . val ( ) || undefined ;
var owned = Util . isChecked ( $ ( content ) . find ( '#cp-upload-owned' ) ) ;
var forceSave = owned || Util . isChecked ( $ ( content ) . find ( '#cp-upload-store' ) ) ;
@ -366,7 +380,8 @@ define([
name : newName ,
password : password ,
owned : owned ,
forceSave : forceSave
forceSave : forceSave ,
alt : alt ,
} ) ;
} ) ;
} ;
@ -437,6 +452,8 @@ define([
}
var thumb ;
var preview ;
var alt ;
var file _arraybuffer ;
var name = file . name ;
var password ;
@ -447,6 +464,7 @@ define([
var metadata = {
name : name ,
type : type ,
alt : alt ,
} ;
if ( thumb ) { metadata . thumbnail = thumb ; }
queue . push ( {
@ -486,8 +504,9 @@ define([
password = obj . password ;
owned = obj . owned ;
forceSave = obj . forceSave ;
alt = obj . alt ;
finish ( ) ;
} );
} , preview );
}
} ;
@ -495,11 +514,20 @@ define([
if ( e ) { console . error ( e ) ; }
file _arraybuffer = buffer ;
if ( ! Thumb . isSupportedType ( file ) ) { return getName ( ) ; }
// make a resized thumbnail from the image..
Thumb . fromBlob ( file , function ( e , thumb64 ) {
if ( e ) { console . error ( e ) ; }
if ( ! thumb64 ) { return getName ( ) ; }
thumb = thumb64 ;
nThen ( function ( w ) {
// make a resized thumbnail from the image..
Thumb . fromBlob ( file , w ( function ( e , thumb64 ) {
if ( e ) { console . error ( e ) ; }
if ( ! thumb64 ) { return ; }
thumb = thumb64 ;
} ) ) ;
MT . preview ( buffer , {
type : file . type ,
} , void 0 , w ( function ( err , el ) {
if ( err ) { return void console . error ( err ) ; }
preview = el ;
} ) ) ;
} ) . nThen ( function ( ) {
getName ( ) ;
} ) ;
} ) ;