@ -463,12 +463,11 @@ define([
UIElements . createButton = function ( common , type , rightside , data , callback ) {
var AppConfig = common . getAppConfig ( ) ;
var button ;
var size = "17px" ;
var sframeChan = common . getSframeChannel ( ) ;
switch ( type ) {
case 'export' :
button = $ ( '<button>' , {
'class' : 'fa fa-download ',
'class' : 'fa fa-download cp-toolbar-icon-export ',
title : Messages . exportButtonTitle ,
} ) . append ( $ ( '<span>' , { 'class' : 'cp-toolbar-drawer-element' } ) . text ( Messages . exportButton ) ) ;
@ -479,7 +478,7 @@ define([
break ;
case 'import' :
button = $ ( '<button>' , {
'class' : 'fa fa-upload ',
'class' : 'fa fa-upload cp-toolbar-icon-import ',
title : Messages . importButtonTitle ,
} ) . append ( $ ( '<span>' , { 'class' : 'cp-toolbar-drawer-element' } ) . text ( Messages . importButton ) ) ;
if ( callback ) {
@ -525,7 +524,8 @@ define([
if ( ! common . isLoggedIn ( ) ) { return ; }
button = $ ( '<button>' , {
title : Messages . saveTemplateButton ,
} ) . append ( $ ( '<span>' , { 'class' : 'fa fa-bookmark' , style : 'font:' + size + ' FontAwesome' } ) ) ;
class : 'fa fa-bookmark cp-toolbar-icon-template'
} ) ;
if ( data . rt ) {
button
. click ( function ( ) {
@ -570,12 +570,10 @@ define([
break ;
case 'forget' :
button = $ ( '<button>' , {
id : 'cryptpad-forget' ,
title : Messages . forgetButtonTitle ,
'class' : "fa fa-trash cryptpad-forget" ,
style : 'font:' + size + ' FontAwesome'
'class' : "fa fa-trash cp-toolbar-icon-forget"
} ) ;
if ( callback ) {
callback = typeof callback === "function" ? callback : function ( ) { } ;
button
. click ( common . prepareFeedback ( type ) )
. click ( function ( ) {
@ -590,17 +588,26 @@ define([
return ;
} ) ;
} ) ;
} ) ;
}
break ;
case 'present' :
button = $ ( '<button>' , {
title : Messages . presentButtonTitle ,
'class' : "fa fa-play-circle cp-app-slide-present-button" , // used in slide.js
style : 'font:' + size + ' FontAwesome'
'class' : "fa fa-play-circle cp-toolbar-icon-present" , // used in slide.js
} ) ;
break ;
case 'preview' :
button = $ ( '<button>' , {
title : Messages . previewButtonTitle ,
'class' : "fa fa-eye cp-toolbar-icon-preview" ,
} ) ;
break ;
case 'print' :
button = $ ( '<button>' , {
title : Messages . printButtonTitle ,
'class' : "fa fa-print cp-toolbar-icon-print" ,
} ) . append ( $ ( '<span>' , { 'class' : 'cp-toolbar-drawer-element' } ) . text ( Messages . printText ) ) ;
break ;
case 'history' :
if ( ! AppConfig . enableHistory ) {
button = $ ( '<span>' ) ;
@ -608,7 +615,7 @@ define([
}
button = $ ( '<button>' , {
title : Messages . historyButton ,
'class' : "fa fa-history history",
'class' : "fa fa-history cp-toolbar-icon- history",
} ) . append ( $ ( '<span>' , { 'class' : 'cp-toolbar-drawer-element' } ) . text ( Messages . historyText ) ) ;
if ( data . histConfig ) {
button
@ -622,19 +629,25 @@ define([
button = $ ( '<button>' , {
title : Messages . moreActions ,
'class' : "cp-toolbar-drawer-button fa fa-ellipsis-h" ,
style : 'font:' + size + ' FontAwesome'
} ) ;
break ;
case 'mediatag' :
button = $ ( '<button>' , {
'class' : 'fa fa-picture-o cp-toolbar-icon-mediatag' ,
title : Messages . filePickerButton ,
} )
. click ( common . prepareFeedback ( type ) ) ;
break ;
case 'savetodrive' :
button = $ ( '<button>' , {
'class' : 'fa fa-cloud-upload' ,
'class' : 'fa fa-cloud-upload cp-toolbar-icon-savetodrive ',
title : Messages . canvas _saveToDrive ,
} )
. click ( common . prepareFeedback ( type ) ) ;
break ;
case 'hashtag' :
button = $ ( '<button>' , {
'class' : 'fa fa-hashtag ',
'class' : 'fa fa-hashtag cp-toolbar-icon-hashtag ',
title : Messages . tags _title ,
} )
. click ( common . prepareFeedback ( type ) )
@ -642,7 +655,7 @@ define([
break ;
case 'toggle' :
button = $ ( '<button>' , {
'class' : 'fa fa-caret-down ',
'class' : 'fa fa-caret-down cp-toolbar-icon-toggle ',
} )
. click ( common . prepareFeedback ( type ) ) ;
window . setTimeout ( function ( ) {
@ -657,13 +670,18 @@ define([
data . element . toggle ( ) ;
var isVisible = data . element . is ( ':visible' ) ;
if ( callback ) { callback ( isVisible ) ; }
if ( isVisible ) {
button . addClass ( 'cp-toolbar-button-active' ) ;
} else {
button . removeClass ( 'cp-toolbar-button-active' ) ;
}
updateIcon ( isVisible ) ;
} ) ;
updateIcon ( data . element . is ( ':visible' ) ) ;
break ;
case 'properties' :
button = $ ( '<button>' , {
'class' : 'fa fa-info-circle ',
'class' : 'fa fa-info-circle cp-toolbar-icon-properties ',
title : Messages . propertiesButtonTitle ,
} ) . append ( $ ( '<span>' , { 'class' : 'cp-toolbar-drawer-element' } )
. text ( Messages . propertiesButton ) )
@ -679,11 +697,24 @@ define([
} ) ;
break ;
default :
data = data || { } ;
var icon = data . icon || "fa-question" ;
button = $ ( '<button>' , {
'class' : "fa fa-question" ,
style : 'font:' + size + ' FontAwesome'
'class' : "fa " + icon ,
} )
. click ( common . prepareFeedback ( type ) ) ;
if ( data . title ) { button . attr ( 'title' , data . title ) ; }
if ( data . style ) { button . attr ( 'style' , data . style ) ; }
if ( data . id ) { button . attr ( 'id' , data . id ) ; }
if ( data . hiddenReadOnly ) { button . addClass ( 'cp-hidden-if-readonly' ) ; }
if ( data . name ) {
button . addClass ( 'cp-toolbar-icon-' + data . name ) ;
button . click ( common . prepareFeedback ( data . name ) ) ;
}
if ( data . text ) {
$ ( '<span>' , { 'class' : 'cp-toolbar-drawer-element' } ) . text ( data . text )
. appendTo ( button ) ;
}
}
if ( rightside ) {
button . addClass ( 'cp-toolbar-rightside-button' ) ;
@ -860,7 +891,11 @@ define([
var text = h ( 'p.cp-help-text' ) ;
var closeButton = h ( 'span.cp-help-close.fa.fa-window-close' ) ;
var $toolbarButton = common . createButton ( '' , true ) . addClass ( 'cp-toolbar-button-active' ) ;
var $toolbarButton = common . createButton ( '' , true , {
title : Messages . hide _help _button ,
text : Messages . help _button ,
name : 'help'
} ) . addClass ( 'cp-toolbar-button-active' ) ;
var help = h ( 'div.cp-help-container' , [
closeButton ,
text
@ -871,9 +906,11 @@ define([
if ( forceClose ) { return ; }
common . setAttribute ( [ 'hideHelp' , type ] , false ) ;
$toolbarButton . addClass ( 'cp-toolbar-button-active' ) ;
$toolbarButton . attr ( 'title' , Messages . hide _help _button ) ;
return void $ ( help ) . removeClass ( 'cp-help-hidden' ) ;
}
$toolbarButton . removeClass ( 'cp-toolbar-button-active' ) ;
$toolbarButton . attr ( 'title' , Messages . show _help _button ) ;
$ ( help ) . addClass ( 'cp-help-hidden' ) ;
common . setAttribute ( [ 'hideHelp' , type ] , true ) ;
} ;
@ -1528,6 +1565,7 @@ define([
if ( ! $blockContainer . length ) {
$blockContainer = $ ( '<div>' , {
'class' : 'cp-modal-container' ,
tabindex : 1 ,
'id' : cfg . id
} ) ;
}
@ -1559,14 +1597,16 @@ define([
$body : $ ( 'body' )
} ) ;
var $title = $ ( '<h3>' ) . text ( Messages . fm _newFile ) ;
var $description = $ ( '<p>' ) . text ( Messages . creation _newPadModalDescription ) ;
var $description = $ ( '<p>' ) . html ( Messages . creation _newPadModalDescription ) ;
$modal . find ( '.cp-modal' ) . append ( $title ) ;
$modal . find ( '.cp-modal' ) . append ( $description ) ;
var $advanced ;
var $advancedContainer = $ ( '<div>' ) ;
if ( common . isLoggedIn ( ) ) {
var priv = common . getMetadataMgr ( ) . getPrivateData ( ) ;
var c = ( priv . settings . general && priv . settings . general . creation ) || { } ;
if ( AppConfig . displayCreationScreen && common . isLoggedIn ( ) && c . skip ) {
$advanced = $ ( '<input>' , {
type : 'checkbox' ,
checked : 'checked' ,
@ -1575,9 +1615,12 @@ define([
$ ( '<label>' , {
for : 'cp-app-toolbar-creation-advanced'
} ) . text ( Messages . creation _newPadModalAdvanced ) . appendTo ( $advancedContainer ) ;
$description . append ( '<br>' ) ;
$description . append ( Messages . creation _newPadModalDescriptionAdvanced ) ;
}
var $container = $ ( '<div>' ) ;
var i = 0 ;
AppConfig . availablePadTypes . forEach ( function ( p ) {
if ( p === 'drive' ) { return ; }
if ( p === 'contacts' ) { return ; }
@ -1586,7 +1629,8 @@ define([
if ( ! common . isLoggedIn ( ) && AppConfig . registeredOnlyTypes &&
AppConfig . registeredOnlyTypes . indexOf ( p ) !== - 1 ) { return ; }
var $element = $ ( '<li>' , {
'class' : 'cp-icons-element'
'class' : 'cp-icons-element' ,
'id' : 'cp-newpad-icons-' + ( i ++ )
} ) . prepend ( UI . getIcon ( p ) ) . appendTo ( $container ) ;
$element . append ( $ ( '<span>' , { 'class' : 'cp-icons-name' } )
. text ( Messages . type [ p ] ) ) ;
@ -1594,7 +1638,7 @@ define([
$element . click ( function ( ) {
$modal . hide ( ) ;
if ( $advanced && $advanced . is ( ':checked' ) ) {
common . sessionStorage . put ( Constants . displayPadCreationScreen , true , function ( ) {
common . sessionStorage . put ( Constants . displayPadCreationScreen , true , function ( ) {
common . openURL ( '/' + p + '/' ) ;
} ) ;
return ;
@ -1605,11 +1649,41 @@ define([
} ) ;
} ) ;
var selected = - 1 ;
var next = function ( ) {
selected = ++ selected % 5 ;
$container . find ( '.cp-icons-element-selected' ) . removeClass ( 'cp-icons-element-selected' ) ;
$container . find ( '#cp-newpad-icons-' + selected ) . addClass ( 'cp-icons-element-selected' ) ;
} ;
$modal . off ( 'keydown' ) ;
$modal . keydown ( function ( e ) {
if ( e . which === 9 ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
next ( ) ;
return ;
}
if ( e . which === 13 ) {
if ( $container . find ( '.cp-icons-element-selected' ) . length === 1 ) {
$container . find ( '.cp-icons-element-selected' ) . click ( ) ;
}
return ;
}
if ( e . which === 32 && $advanced ) {
$advanced . prop ( 'checked' , ! $advanced . prop ( 'checked' ) ) ;
$modal . focus ( ) ;
e . stopPropagation ( ) ;
e . preventDefault ( ) ;
}
} ) ;
/*var $content = createNewPadIcons($modal, isInRoot);*/
$modal . find ( '.cp-modal' ) . append ( $container ) . append ( $advancedContainer ) ;
window . setTimeout ( function ( ) { $modal . show ( ) ; } ) ;
//addNewPadHandlers($modal, isInRoot);
window . setTimeout ( function ( ) {
$modal . show ( ) ;
$modal . focus ( ) ;
} ) ;
} ;
UIElements . initFilePicker = function ( common , cfg ) {
@ -1702,7 +1776,7 @@ define([
var $body = $ ( 'body' ) ;
var $creationContainer = $ ( '<div>' , { id : 'cp-creation-container' } ) . appendTo ( $body ) ;
var $creation = $ ( '<div>' , { id : 'cp-creation' } ) . appendTo ( $creationContainer ) ;
var $creation = $ ( '<div>' , { id : 'cp-creation' , tabindex : 1 } ) . appendTo ( $creationContainer ) ;
var setHTML = function ( e , html ) {
e . innerHTML = html ;
@ -1802,8 +1876,7 @@ define([
UIElements . setExpirationValue ( cfg . expire , $creation ) ;
// Create the pad
var create = function ( template ) {
$creationContainer . remove ( ) ;
var getFormValues = function ( template ) {
// Type of pad
var ownedVal = parseInt ( $ ( 'input[name="cp-creation-owned"]:checked' ) . val ( ) ) ;
// Life time
@ -1819,11 +1892,16 @@ define([
expireVal = ( $ ( '#cp-creation-expire-val' ) . val ( ) || 0 ) * unit ;
}
common . createPad ( {
return {
owned : ownedVal ,
expire : expireVal ,
template : template
} , function ( ) {
} ;
} ;
var create = function ( template ) {
$creationContainer . remove ( ) ;
common . createPad ( getFormValues ( template ) , function ( ) {
cb ( ) ;
} ) ;
} ;
@ -1868,10 +1946,62 @@ define([
// Settings button
var origin = common . getMetadataMgr ( ) . getPrivateData ( ) . origin ;
$ ( h ( 'div.cp-creation-settings' , h ( 'a' , {
var $ok = $ ( '<span>' , { 'class' : 'fa fa-check' , title : Messages . saved } ) . hide ( ) ;
var $spinner = $ ( '<span>' , { 'class' : 'fa fa-spinner fa-pulse' } ) . hide ( ) ;
var okTo ;
var $saveButton = $ ( '<button>' ) . text ( Messages . creation _saveSettings ) . click ( function ( ) {
if ( okTo ) { clearTimeout ( okTo ) ; }
$ok . hide ( ) ;
$spinner . show ( ) ;
var val = getFormValues ( ) ;
NThen ( function ( waitFor ) {
common . setAttribute ( [ 'general' , 'creation' , 'owned' ] , val . owned , waitFor ( function ( e ) {
if ( e ) { return void console . error ( e ) ; }
} ) ) ;
common . setAttribute ( [ 'general' , 'creation' , 'expire' ] , val . expire , waitFor ( function ( e ) {
if ( e ) { return void console . error ( e ) ; }
} ) ) ;
} ) . nThen ( function ( ) {
$spinner . hide ( ) ;
$ok . show ( ) ;
okTo = setTimeout ( function ( ) {
$ok . hide ( ) ;
} , 5000 ) ;
} ) ;
} ) ;
$ ( h ( 'div.cp-creation-settings' , [
$saveButton [ 0 ] ,
h ( 'br' ) ,
h ( 'a' , {
href : origin + '/settings/#creation' ,
target : '_blank'
} , Messages . creation _settings ) ) ) . appendTo ( $creation ) ;
} , Messages . creation _settings ) ,
$ok [ 0 ] ,
$spinner [ 0 ]
] ) ) . appendTo ( $creation ) ;
var selected = - 1 ;
var next = function ( ) {
selected = ++ selected % $creation . find ( 'button' ) . length ;
$creation . find ( 'button' ) . removeClass ( 'cp-creation-button-selected' ) ;
$ ( $creation . find ( 'button' ) . get ( selected ) ) . addClass ( 'cp-creation-button-selected' ) ;
} ;
$creation . keydown ( function ( e ) {
if ( e . which === 9 ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
next ( ) ;
return ;
}
if ( e . which === 13 ) {
if ( $creation . find ( '.cp-creation-button-selected' ) . length === 1 ) {
$creation . find ( '.cp-creation-button-selected' ) . click ( ) ;
}
return ;
}
} ) ;
$creation . focus ( ) ;
} ;
UIElements . onServerError = function ( common , err , toolbar , cb ) {