2019-01-03 23:30:27 +01:00
var link = ( function ( ) {
2018-12-28 08:04:22 +01:00
2019-05-11 09:33:19 +02:00
var _previousFocusLink = null ;
var _returnToPreviousFocusLink = function ( ) {
if ( _previousFocusLink != null ) {
helper . eA ( ".link-panel-back" ) [ _previousFocusLink ] . querySelectorAll ( ".link-control-item" ) [ 0 ] . focus ( ) ;
_previousFocusLink = null
2019-01-03 23:30:27 +01:00
} ;
2019-05-11 09:33:19 +02:00
} ;
var stagedBookmarkData = {
display : null ,
letter : null ,
icon : {
name : null ,
prefix : null ,
label : null
} ,
name : null ,
url : null ,
timeStamp : null ,
accent : {
override : null ,
color : {
r : null ,
g : null ,
b : null
2018-12-26 08:45:53 +01:00
}
2019-05-11 09:33:19 +02:00
}
2018-12-26 08:45:53 +01:00
} ;
2019-05-11 09:33:19 +02:00
var initStagedBookmarkData = function ( ) {
link . stagedBookmarkData . display = "letter" ;
link . stagedBookmarkData . accent . override = false ;
} ;
var resetStagedBookmarkData = function ( ) {
link . stagedBookmarkData . display = null ;
link . stagedBookmarkData . letter = null ;
link . stagedBookmarkData . icon . name = null ;
link . stagedBookmarkData . icon . prefix = null ;
link . stagedBookmarkData . icon . label = null ;
link . stagedBookmarkData . name = null ;
link . stagedBookmarkData . url = null ;
link . stagedBookmarkData . timeStamp = null ;
link . stagedBookmarkData . accent . override = null ;
link . stagedBookmarkData . accent . color . r = null ;
link . stagedBookmarkData . accent . color . g = null ;
link . stagedBookmarkData . accent . color . b = null ;
2018-12-26 08:45:53 +01:00
} ;
2019-01-13 23:54:48 +01:00
var add = function ( ) {
2019-05-11 09:33:19 +02:00
initStagedBookmarkData ( ) ;
2018-12-26 08:45:53 +01:00
var form = _makeLinkForm ( ) ;
modal . render ( {
2019-01-13 23:54:48 +01:00
heading : "Add a new bookmark" ,
2019-05-11 09:33:19 +02:00
successAction : function ( ) {
link . stagedBookmarkData . timeStamp = new Date ( ) . getTime ( ) ;
bookmarks . add ( JSON . parse ( JSON . stringify ( link . stagedBookmarkData ) ) ) ;
data . save ( ) ;
clear ( ) ;
2019-05-23 20:15:14 +02:00
render . link ( ) ;
2019-06-04 20:34:17 +02:00
render . tabIndex ( ) ;
2019-01-13 23:54:48 +01:00
control . dependents ( ) ;
control . render ( ) ;
2019-05-11 09:33:19 +02:00
resetStagedBookmarkData ( ) ;
} ,
cancelAction : function ( ) {
resetStagedBookmarkData ( ) ;
2019-05-23 20:51:59 +02:00
autoSuggest . destroy ( ) ;
2019-01-13 23:54:48 +01:00
} ,
actionText : "Add" ,
2018-12-26 08:45:53 +01:00
size : "small" ,
content : form
} ) ;
} ;
2019-05-11 09:33:19 +02:00
var edit = function ( bookmarkData ) {
link . stagedBookmarkData = JSON . parse ( JSON . stringify ( bookmarkData ) ) ;
var form = _makeLinkForm ( ) ;
if ( link . stagedBookmarkData . display == "letter" || link . stagedBookmarkData . display == null ) {
form . querySelector ( ".link-form-input-letter" ) . removeAttribute ( "disabled" ) ;
form . querySelector ( ".link-form-input-icon" ) . setAttribute ( "disabled" , "" ) ;
form . querySelector ( ".form-group-text" ) . setAttribute ( "disabled" , "" ) ;
form . querySelector ( ".link-form-input-icon" ) . setAttribute ( "disabled" , "" ) ;
form . querySelector ( ".link-form-input-helper-icon" ) . setAttribute ( "disabled" , "" ) ;
form . querySelector ( ".link-form-icon-clear" ) . setAttribute ( "disabled" , "" ) ;
form . querySelector ( ".link-form-text-icon" ) . tabIndex = - 1 ;
} else if ( link . stagedBookmarkData . display == "icon" ) {
form . querySelector ( ".link-form-input-letter" ) . setAttribute ( "disabled" , "" ) ;
form . querySelector ( ".link-form-input-icon" ) . removeAttribute ( "disabled" ) ;
form . querySelector ( ".form-group-text" ) . removeAttribute ( "disabled" ) ;
form . querySelector ( ".link-form-input-icon" ) . removeAttribute ( "disabled" ) ;
form . querySelector ( ".link-form-input-helper-icon" ) . removeAttribute ( "disabled" ) ;
form . querySelector ( ".link-form-icon-clear" ) . removeAttribute ( "disabled" ) ;
form . querySelector ( ".link-form-input-display-icon" ) . checked = true ;
form . querySelector ( ".link-form-text-icon" ) . tabIndex = 1 ;
2019-01-13 23:54:48 +01:00
} ;
2019-05-11 09:33:19 +02:00
if ( link . stagedBookmarkData . icon . name != null && link . stagedBookmarkData . icon . prefix != null && link . stagedBookmarkData . icon . label != null ) {
form . querySelector ( ".link-form-text-icon" ) . appendChild ( helper . node ( "span|class:link-form-icon " + link . stagedBookmarkData . icon . prefix + " fa-" + link . stagedBookmarkData . icon . name ) ) ;
2019-01-13 23:54:48 +01:00
} ;
2019-05-11 09:33:19 +02:00
form . querySelector ( ".link-form-input-letter" ) . value = link . stagedBookmarkData . letter ;
form . querySelector ( ".link-form-input-icon" ) . value = link . stagedBookmarkData . icon . label ;
form . querySelector ( ".link-form-input-name" ) . value = link . stagedBookmarkData . name ;
form . querySelector ( ".link-form-input-url" ) . value = link . stagedBookmarkData . url ;
if ( link . stagedBookmarkData . accent . override ) {
form . querySelector ( ".link-form-input-color" ) . value = helper . rgbToHex ( link . stagedBookmarkData . accent . color ) ;
2018-12-26 08:45:53 +01:00
} ;
2019-05-11 09:33:19 +02:00
modal . render ( {
heading : "Edit " + link . stagedBookmarkData . name ,
successAction : function ( ) {
bookmarks . edit ( JSON . parse ( JSON . stringify ( link . stagedBookmarkData ) ) ) ;
data . save ( ) ;
clear ( ) ;
2019-05-23 20:15:14 +02:00
render . link ( ) ;
2019-06-04 20:34:17 +02:00
render . tabIndex ( ) ;
2019-05-11 09:33:19 +02:00
_returnToPreviousFocusLink ( ) ;
resetStagedBookmarkData ( ) ;
} ,
cancelAction : function ( ) {
_returnToPreviousFocusLink ( ) ;
resetStagedBookmarkData ( ) ;
} ,
actionText : "Save" ,
size : "small" ,
content : form
} ) ;
2018-12-26 08:45:53 +01:00
} ;
2019-01-13 23:54:48 +01:00
var remove = function ( bookmarkData ) {
2019-05-11 09:33:19 +02:00
bookmarks . remove ( bookmarkData ) ;
2019-03-16 21:46:28 +01:00
_checkCount ( ) ;
2018-12-26 08:45:53 +01:00
data . save ( ) ;
2019-01-13 23:54:48 +01:00
clear ( ) ;
2019-05-23 20:15:14 +02:00
render . link ( ) ;
2018-12-26 08:45:53 +01:00
} ;
2019-03-16 21:46:28 +01:00
var _checkCount = function ( ) {
if ( bookmarks . get ( ) . length <= 0 ) {
helper . setObject ( {
object : state . get ( ) ,
2019-05-23 20:15:14 +02:00
path : "link.edit" ,
2019-03-16 21:46:28 +01:00
newValue : false
} ) ;
} ;
} ;
2018-12-26 08:45:53 +01:00
var _makeLinkForm = function ( ) {
2019-05-11 09:33:19 +02:00
var form = helper . node ( "form|class:link-form" ) ;
var fieldset = helper . node ( "fieldset" ) ;
var letterFormIndet = helper . node ( "div|class:form-indent" ) ;
var letterInput = helper . node ( "input|type:text,class:link-form-input-letter,id:link-form-input-letter,placeholder:E,tabindex:1,autocomplete:off,autocorrect:off,autocapitalize:off,spellcheck:false" ) ;
var iconFormIndet = helper . node ( "div|class:form-indent" ) ;
var iconFormGroup = helper . node ( "div|class:form-group auto-suggest-wrapper" ) ;
var iconInput = helper . node ( "input|type:text,class:link-form-input-icon auto-suggest-input,id:link-form-input-icon,placeholder:Search for Brands or Icons,tabindex:1,autocomplete:off,autocorrect:off,autocapitalize:off,spellcheck:false,disabled" ) ;
var iconFormGroupText = helper . node ( "div|class:form-group-text link-form-text-icon,tabindex:-1,disabled" ) ;
var iconFormGroupClear = helper . node ( "button|class:link-form-icon-clear button mb-0,type:button,tabindex:1,disabled" ) ;
var iconFormGroupClearIcon = helper . node ( "span|class:icon-close" ) ;
var iconPara = helper . node ( "p:Refer to the \"Free\" and \"Brand\" icons from FontAwesome for full set of icons supported.|class:link-form-input-helper-icon input-helper small muted,disabled" ) ;
var nameLabel = helper . node ( "label:Name|for:link-form-input-name" ) ;
var nameInput = helper . node ( "input|type:text,class:link-form-input-name,id:link-form-input-name,placeholder:Example,tabindex:1,autocomplete:off,autocorrect:off,autocapitalize:off,spellcheck:false" ) ;
var urlLabel = helper . node ( "label:URL|for:link-form-input-url" ) ;
var urlInput = helper . node ( "input|type:text,class:link-form-input-url mb-0,id:link-form-input-url,placeholder:https://www.example.com/,tabindex:1,autocomplete:off,autocorrect:off,autocapitalize:off,spellcheck:false" ) ;
var colorInputWrap = helper . node ( "div|class:input-wrap py-0" ) ;
var colorFormGroup = helper . node ( "div|class:form-group" ) ;
var colorInputLabel = helper . node ( "label:Accent override|for:link-form-input-color" ) ;
var colorInputInput = helper . node ( "input|id:link-form-input-color,class:link-form-input-color mb-0,type:color,value:" + helper . rgbToHex ( state . get ( ) . theme . accent . current ) + ",tabindex:1" ) ;
var colorButtonRefresh = helper . node ( "button|class:button mb-0,type:button,tabindex:1" ) ;
var colorButtonRefreshIcon = helper . node ( "span|class:icon-refresh" ) ;
var colorPara = helper . node ( "p:Use this colour to override the global Accent colour.|class:input-helper small muted" ) ;
var letterRadioInputWrap = helper . node ( "div|class:input-wrap" ) ;
var letterRadioInput = helper . node ( "input|class:link-form-input-display-letter,id:link-form-input-display-letter,type:radio,name:link-form-input-display,tabindex:1,checked,value:letter" ) ;
var letterRadioLable = helper . node ( "label:Letters|for:link-form-input-display-letter" ) ;
var iconRadioInputWrap = helper . node ( "div|class:input-wrap" ) ;
var iconRadioInput = helper . node ( "input|class:link-form-input-display-icon,id:link-form-input-display-icon,type:radio,name:link-form-input-display,tabindex:1,value:icon" ) ;
var iconRadioLable = helper . node ( "label:Icon|for:link-form-input-display-icon" ) ;
letterRadioInputWrap . appendChild ( letterRadioInput ) ;
letterRadioInputWrap . appendChild ( letterRadioLable ) ;
fieldset . appendChild ( letterRadioInputWrap ) ;
letterFormIndet . appendChild ( letterInput ) ;
fieldset . appendChild ( letterFormIndet ) ;
iconRadioInputWrap . appendChild ( iconRadioInput ) ;
iconRadioInputWrap . appendChild ( iconRadioLable ) ;
fieldset . appendChild ( iconRadioInputWrap ) ;
iconFormGroupClear . appendChild ( iconFormGroupClearIcon ) ;
iconFormGroup . appendChild ( iconInput ) ;
iconFormGroup . appendChild ( iconFormGroupText ) ;
iconFormGroup . appendChild ( iconFormGroupClear ) ;
iconFormIndet . appendChild ( iconFormGroup ) ;
iconFormIndet . appendChild ( iconPara ) ;
fieldset . appendChild ( iconFormIndet ) ;
fieldset . appendChild ( helper . node ( "hr" ) ) ;
2018-12-26 08:45:53 +01:00
fieldset . appendChild ( nameLabel ) ;
fieldset . appendChild ( nameInput ) ;
fieldset . appendChild ( urlLabel ) ;
fieldset . appendChild ( urlInput ) ;
2019-05-11 09:33:19 +02:00
fieldset . appendChild ( helper . node ( "hr" ) ) ;
2019-05-04 14:53:18 +02:00
fieldset . appendChild ( colorInputLabel ) ;
colorFormGroup . appendChild ( colorInputInput ) ;
colorButtonRefresh . appendChild ( colorButtonRefreshIcon ) ;
colorFormGroup . appendChild ( colorButtonRefresh ) ;
colorInputWrap . appendChild ( colorFormGroup ) ;
fieldset . appendChild ( colorInputWrap ) ;
fieldset . appendChild ( colorPara ) ;
2018-12-26 08:45:53 +01:00
form . appendChild ( fieldset ) ;
2019-05-11 09:33:19 +02:00
letterRadioInput . addEventListener ( "change" , function ( event ) {
link . stagedBookmarkData . display = this . value ;
} , false ) ;
iconRadioInput . addEventListener ( "change" , function ( event ) {
link . stagedBookmarkData . display = this . value ;
} , false ) ;
letterInput . addEventListener ( "input" , function ( event ) {
link . stagedBookmarkData . letter = this . value ;
} , false ) ;
nameInput . addEventListener ( "input" , function ( event ) {
link . stagedBookmarkData . name = this . value ;
} , false ) ;
urlInput . addEventListener ( "input" , function ( event ) {
link . stagedBookmarkData . url = this . value ;
} , false ) ;
colorInputInput . addEventListener ( "change" , function ( event ) {
link . stagedBookmarkData . accent . override = true ;
link . stagedBookmarkData . accent . color = helper . hexToRgb ( this . value ) ;
} , false ) ;
colorButtonRefresh . addEventListener ( "click" , function ( event ) {
colorInputInput . value = helper . rgbToHex ( state . get ( ) . theme . accent . current ) ;
link . stagedBookmarkData . accent . override = false ;
link . stagedBookmarkData . accent . color = {
r : null ,
g : null ,
b : null
} ;
} , false ) ;
iconFormGroupClear . addEventListener ( "click" , function ( event ) {
link . stagedBookmarkData . icon . name = null ;
link . stagedBookmarkData . icon . prefix = null ;
link . stagedBookmarkData . icon . label = null ;
var existingIcon = helper . e ( ".link-form-icon" ) ;
if ( existingIcon ) {
existingIcon . remove ( ) ;
} ;
iconInput . value = "" ;
} , false ) ;
letterRadioInput . addEventListener ( "change" , function ( event ) {
letterInput . removeAttribute ( "disabled" ) ;
iconInput . setAttribute ( "disabled" , "" ) ;
iconFormGroupText . setAttribute ( "disabled" , "" ) ;
iconPara . setAttribute ( "disabled" , "" ) ;
iconFormGroupClear . setAttribute ( "disabled" , "" ) ;
iconFormGroupText . tabIndex = - 1 ;
} , false ) ;
iconRadioInput . addEventListener ( "change" , function ( event ) {
letterInput . setAttribute ( "disabled" , "" ) ;
iconInput . removeAttribute ( "disabled" ) ;
iconFormGroupText . removeAttribute ( "disabled" ) ;
iconPara . removeAttribute ( "disabled" ) ;
iconFormGroupClear . removeAttribute ( "disabled" ) ;
iconFormGroupText . tabIndex = 1 ;
} , false ) ;
autoSuggest . bind ( {
input : iconInput ,
type : "fontawesomeIcon" ,
postFocus : iconFormGroupText
} ) ;
2018-12-26 08:45:53 +01:00
return form ;
} ;
2019-05-11 09:33:19 +02:00
var _makeLink = function ( data , index ) {
2019-05-04 14:53:18 +02:00
var linkItemOptions = {
2018-12-28 08:04:22 +01:00
tag : "div" ,
attr : [ {
key : "class" ,
value : "link-item"
} ]
2019-05-04 14:53:18 +02:00
} ;
if ( data . accent . override ) {
linkItemOptions . attr . push ( {
key : "style" ,
value : "--accent: " + data . accent . color . r + ", " + data . accent . color . g + ", " + data . accent . color . b
} ) ;
} ;
var linkItem = helper . makeNode ( linkItemOptions ) ;
var linkPanelFrontOptions = {
2018-12-28 08:04:22 +01:00
tag : "a" ,
attr : [ {
key : "class" ,
value : "link-panel-front"
} , {
key : "href" ,
value : data . url
} , {
key : "tabindex" ,
value : 1
} ]
2019-01-03 23:30:27 +01:00
} ;
2019-05-23 20:15:14 +02:00
if ( state . get ( ) . link . newTab ) {
2019-05-04 14:53:18 +02:00
linkPanelFrontOptions . attr . push ( {
2019-01-03 23:30:27 +01:00
key : "target" ,
value : "_blank"
} ) ;
} ;
2019-05-04 14:53:18 +02:00
var linkPanelFront = helper . makeNode ( linkPanelFrontOptions ) ;
2019-01-03 23:30:27 +01:00
var linkPanelBack = helper . makeNode ( {
2018-12-28 08:04:22 +01:00
tag : "div" ,
attr : [ {
key : "class" ,
value : "link-panel-back"
} ]
} ) ;
2019-06-04 17:14:04 +02:00
var linkDisplay = helper . makeNode ( {
tag : "div" ,
attr : [ {
key : "class" ,
value : "link-display"
} ]
} ) ;
var linkDisplayLetter = null ;
var linkDisplayIcon = null ;
2019-05-11 09:33:19 +02:00
if ( data . display == "letter" ) {
2019-06-04 17:14:04 +02:00
linkDisplayLetter = helper . makeNode ( {
2019-05-11 09:33:19 +02:00
tag : "p" ,
text : data . letter ,
attr : [ {
key : "class" ,
value : "link-display-letter"
} ]
} ) ;
} else if ( data . display == "icon" && data . icon . prefix != null && data . icon . name != null ) {
2019-06-04 17:14:04 +02:00
linkDisplayIcon = helper . makeNode ( {
2019-05-11 09:33:19 +02:00
tag : "div" ,
attr : [ {
key : "class" ,
value : "link-display-icon " + data . icon . prefix + " fa-" + data . icon . name
} ]
} ) ;
} ;
2019-01-03 23:30:27 +01:00
var linkName = helper . makeNode ( {
2018-12-28 08:04:22 +01:00
tag : "p" ,
text : data . name ,
attr : [ {
key : "class" ,
value : "link-name"
} ]
} ) ;
2019-01-03 23:30:27 +01:00
var linkUrl = helper . makeNode ( {
2018-12-28 08:04:22 +01:00
tag : "div" ,
attr : [ {
key : "class" ,
value : "link-url"
} ]
} ) ;
2019-05-11 09:33:19 +02:00
var url = "" ;
if ( data . url != null ) {
url = data . url . replace ( /^https?\:\/\//i , "" ) . replace ( /\/$/ , "" ) ;
} ;
2019-01-03 23:30:27 +01:00
var linkUrlText = helper . makeNode ( {
2018-12-28 08:04:22 +01:00
tag : "p" ,
2019-05-11 09:33:19 +02:00
text : url ,
2018-12-28 08:04:22 +01:00
attr : [ {
key : "class" ,
value : "link-url-text"
2019-04-02 13:23:47 +02:00
} , {
key : "title" ,
2019-05-11 09:33:19 +02:00
value : url
2018-12-28 08:04:22 +01:00
} ]
} ) ;
2019-01-03 23:30:27 +01:00
var linkControl = helper . makeNode ( {
2018-12-28 08:04:22 +01:00
tag : "div" ,
attr : [ {
key : "class" ,
value : "link-control"
} ]
} ) ;
2019-01-03 23:30:27 +01:00
var linkEdit = helper . makeNode ( {
2018-12-28 08:04:22 +01:00
tag : "button" ,
attr : [ {
key : "class" ,
2019-01-13 23:54:48 +01:00
value : "button button-small link-control-item"
2018-12-28 08:04:22 +01:00
} , {
key : "tabindex" ,
value : - 1
} ]
} ) ;
2019-01-03 23:30:27 +01:00
var linkEditIcon = helper . makeNode ( {
2018-12-28 08:04:22 +01:00
tag : "span" ,
attr : [ {
key : "class" ,
value : "button-icon icon-edit"
} ]
} ) ;
2019-01-13 23:54:48 +01:00
var linkRemove = helper . makeNode ( {
2018-12-28 08:04:22 +01:00
tag : "button" ,
attr : [ {
key : "class" ,
2019-01-13 23:54:48 +01:00
value : "button button-small link-control-item"
2018-12-28 08:04:22 +01:00
} , {
key : "tabindex" ,
value : - 1
} ]
} ) ;
2019-01-13 23:54:48 +01:00
var linkRemoveIcon = helper . makeNode ( {
2018-12-28 08:04:22 +01:00
tag : "span" ,
attr : [ {
key : "class" ,
value : "button-icon icon-close"
} ]
} ) ;
2019-06-04 17:14:04 +02:00
if ( data . display == "letter" ) {
linkDisplay . appendChild ( linkDisplayLetter ) ;
} else if ( data . display == "icon" && data . icon . prefix != null && data . icon . name != null ) {
linkDisplay . appendChild ( linkDisplayIcon ) ;
} ;
2019-05-11 09:33:19 +02:00
linkPanelFront . appendChild ( linkDisplay ) ;
2018-12-28 08:04:22 +01:00
linkPanelFront . appendChild ( linkName ) ;
linkEdit . appendChild ( linkEditIcon ) ;
2019-01-13 23:54:48 +01:00
linkRemove . appendChild ( linkRemoveIcon ) ;
2018-12-28 08:04:22 +01:00
linkControl . appendChild ( linkEdit ) ;
2019-01-13 23:54:48 +01:00
linkControl . appendChild ( linkRemove ) ;
2018-12-28 08:04:22 +01:00
linkUrl . appendChild ( linkUrlText ) ;
linkPanelBack . appendChild ( linkUrl ) ;
linkPanelBack . appendChild ( linkControl ) ;
linkItem . appendChild ( linkPanelFront ) ;
linkItem . appendChild ( linkPanelBack ) ;
2019-05-11 09:33:19 +02:00
linkEdit . addEventListener ( "click" , function ( ) {
_previousFocusLink = index ;
edit ( data ) ;
} , false ) ;
linkRemove . addEventListener ( "click" , function ( ) {
2019-06-05 10:13:12 +02:00
modal . render ( {
heading : "Remove " + data . name + " bookmark" ,
content : "Are you sure you want to remove this bookmark? This can not be undone." ,
successAction : function ( ) {
remove ( data ) ;
control . dependents ( ) ;
control . render ( ) ;
} ,
actionText : "Remove" ,
cancelText : "Cancel" ,
size : "small"
} ) ;
2019-05-11 09:33:19 +02:00
} , false ) ;
2018-12-28 08:04:22 +01:00
return linkItem ;
} ;
2018-12-26 08:45:53 +01:00
2019-05-11 09:33:19 +02:00
var autoSuggestIconAction = function ( autoSuggestData ) {
link . stagedBookmarkData . icon . label = autoSuggestData . label ;
link . stagedBookmarkData . icon . name = autoSuggestData . name ;
if ( autoSuggestData . styles . includes ( "solid" ) ) {
link . stagedBookmarkData . icon . prefix = "fas" ;
} else if ( autoSuggestData . styles . includes ( "brands" ) ) {
link . stagedBookmarkData . icon . prefix = "fab" ;
} ;
var existingIcon = helper . e ( ".link-form-icon" ) ;
if ( existingIcon ) {
existingIcon . remove ( ) ;
} ;
helper . e ( ".link-form-input-icon" ) . value = autoSuggestData . label ;
helper . e ( ".link-form-text-icon" ) . appendChild ( helper . node ( "span|class:link-form-icon " + link . stagedBookmarkData . icon . prefix + " fa-" + link . stagedBookmarkData . icon . name ) ) ;
helper . e ( ".link-form-text-icon" ) . focus ( ) ;
} ;
2019-01-13 23:54:48 +01:00
var _makeEmptySearch = function ( ) {
var searchInput = helper . e ( ".search-input" ) ;
var div = helper . makeNode ( {
tag : "div" ,
attr : [ {
key : "class" ,
value : "link-empty"
} ]
} ) ;
var h1 = helper . makeNode ( {
tag : "h1" ,
attr : [ {
key : "class" ,
value : "link-empty-heading"
} ] ,
text : "No matching bookmarks found"
} ) ;
div . appendChild ( h1 ) ;
return div ;
} ;
var _makeEmptyBookmarks = function ( ) {
var searchInput = helper . e ( ".search-input" ) ;
var div = helper . makeNode ( {
tag : "div" ,
attr : [ {
key : "class" ,
value : "link-empty"
} ]
} ) ;
var h1 = helper . makeNode ( {
tag : "h1" ,
attr : [ {
key : "class" ,
value : "link-empty-heading"
} ] ,
text : "No bookmarks added"
2019-01-03 23:30:27 +01:00
} ) ;
2019-01-13 23:54:48 +01:00
div . appendChild ( h1 ) ;
return div ;
} ;
2019-05-23 20:15:14 +02:00
var render = {
width : {
set : function ( ) {
_width ( ) ;
} ,
match : function ( ) {
_match ( ) ;
}
} ,
2019-06-04 17:14:04 +02:00
displayLetterIcon : {
size : function ( ) {
_size ( ) ;
} ,
} ,
2019-05-23 20:15:14 +02:00
link : function ( ) {
_link ( ) ;
} ,
2019-06-04 20:34:17 +02:00
tabIndex : function ( ) {
_tabIndex ( ) ;
} ,
2019-05-23 20:15:14 +02:00
items : function ( ) {
_items ( ) ;
}
} ;
var _link = function ( ) {
2019-01-13 23:54:48 +01:00
var linkArea = helper . e ( ".link-area" ) ;
var bookmarksToRender = false ;
2019-02-03 14:51:54 +01:00
if ( state . get ( ) . search ) {
2019-01-13 23:54:48 +01:00
bookmarksToRender = search . get ( ) ;
} else {
bookmarksToRender = bookmarks . get ( ) ;
} ;
var action = {
render : {
bookmarks : function ( array ) {
array . forEach ( function ( arrayItem , index ) {
2019-05-11 09:33:19 +02:00
linkArea . appendChild ( _makeLink ( arrayItem , index ) ) ;
2019-01-13 23:54:48 +01:00
} ) ;
} ,
empty : {
search : function ( ) {
linkArea . appendChild ( _makeEmptySearch ( ) ) ;
} ,
bookmarks : function ( ) {
linkArea . appendChild ( _makeEmptyBookmarks ( ) ) ;
}
}
}
} ;
// if searching
2019-02-03 14:51:54 +01:00
if ( state . get ( ) . search ) {
2019-01-13 23:54:48 +01:00
// if bookmarks exist to be searched
if ( bookmarksToRender . total > 0 ) {
// if matching bookmarks found
if ( bookmarksToRender . matching . length > 0 ) {
action . render . bookmarks ( bookmarksToRender . matching ) ;
} else {
action . render . empty . search ( ) ;
} ;
} else {
action . render . empty . bookmarks ( ) ;
} ;
} else {
// if bookmarks exist
if ( bookmarksToRender . length > 0 ) {
action . render . bookmarks ( bookmarksToRender ) ;
} else {
action . render . empty . bookmarks ( ) ;
} ;
} ;
2018-12-26 08:45:53 +01:00
} ;
2019-05-23 20:15:14 +02:00
var _width = function ( ) {
var html = helper . e ( "html" ) ;
html . style . setProperty ( "--link-area-width" , state . get ( ) . link . area . width + "%" ) ;
} ;
2019-06-04 17:14:04 +02:00
var _size = function ( ) {
var html = helper . e ( "html" ) ;
html . style . setProperty ( "--link-display-letter-size" , state . get ( ) . link . display . letter . size + "em" ) ;
html . style . setProperty ( "--link-display-icon-size" , state . get ( ) . link . display . icon . size + "em" ) ;
} ;
2019-05-23 20:15:14 +02:00
var _match = function ( ) {
helper . setObject ( {
object : state . get ( ) ,
path : "link.area.width" ,
newValue : state . get ( ) . header . area . width
} ) ;
render . width . set ( ) ;
} ;
var _items = function ( ) {
var html = helper . e ( "html" ) ;
html . style . setProperty ( "--link-items-width" , state . get ( ) . link . items . width + "%" ) ;
} ;
2019-06-04 20:34:17 +02:00
var _tabIndex = function ( ) {
2018-12-26 08:45:53 +01:00
var allLinkControlItem = helper . eA ( ".link-control-item" ) ;
2019-05-23 20:15:14 +02:00
if ( state . get ( ) . link . edit ) {
2018-12-26 08:45:53 +01:00
allLinkControlItem . forEach ( function ( arrayItem , index ) {
arrayItem . tabIndex = 1 ;
} ) ;
} else {
allLinkControlItem . forEach ( function ( arrayItem , index ) {
arrayItem . tabIndex = - 1 ;
} ) ;
} ;
} ;
var clear = function ( ) {
2019-01-03 23:30:27 +01:00
var linkArea = helper . e ( ".link-area" ) ;
while ( linkArea . lastChild ) {
linkArea . removeChild ( linkArea . lastChild ) ;
2018-12-26 08:45:53 +01:00
} ;
} ;
var init = function ( ) {
2019-05-23 20:15:14 +02:00
render . link ( ) ;
2019-06-04 17:14:04 +02:00
render . displayLetterIcon . size ( ) ;
2019-05-23 20:15:14 +02:00
render . width . set ( ) ;
render . items ( ) ;
2018-12-26 08:45:53 +01:00
} ;
// exposed methods
return {
2019-05-11 09:33:19 +02:00
stagedBookmarkData : stagedBookmarkData ,
autoSuggestIconAction : autoSuggestIconAction ,
2018-12-26 08:45:53 +01:00
init : init ,
clear : clear ,
add : add ,
edit : edit ,
remove : remove ,
2019-06-04 20:34:17 +02:00
render : render
2018-12-26 08:45:53 +01:00
} ;
} ) ( ) ;