Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7408746
ve.ui.LinkAnnotationInspector.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
ve.ui.LinkAnnotationInspector.js
View Options
/*!
* VisualEditor UserInterface LinkAnnotationInspector class.
*
* @copyright See AUTHORS.txt
*/
/**
* Inspector for linked content.
*
* @class
* @extends ve.ui.AnnotationInspector
*
* @constructor
* @param {Object} [config] Configuration options
*/
ve
.
ui
.
LinkAnnotationInspector
=
function
VeUiLinkAnnotationInspector
()
{
// Parent constructor
ve
.
ui
.
LinkAnnotationInspector
.
super
.
apply
(
this
,
arguments
);
};
/* Inheritance */
OO
.
inheritClass
(
ve
.
ui
.
LinkAnnotationInspector
,
ve
.
ui
.
AnnotationInspector
);
/* Static properties */
ve
.
ui
.
LinkAnnotationInspector
.
static
.
name
=
'link'
;
ve
.
ui
.
LinkAnnotationInspector
.
static
.
modelClasses
=
[
ve
.
dm
.
LinkAnnotation
];
/* Methods */
/**
* Handle annotation input change events
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
onAnnotationInputChange
=
function
()
{
this
.
labelInput
.
$input
.
attr
(
'placeholder'
,
this
.
getInsertionText
()
);
this
.
updateActions
();
};
/**
* Update the actions based on the annotation state
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
updateActions
=
function
()
{
const
annotation
=
this
.
annotationInput
.
getAnnotation
();
let
isValid
=
false
;
this
.
annotationInput
.
getTextInputWidget
().
getValidity
()
.
then
(
()
=>
{
isValid
=
true
;
}
)
.
always
(
()
=>
{
isValid
=
isValid
&&
!!
annotation
;
this
.
actions
.
forEach
(
{
actions
:
[
'done'
,
'insert'
]
},
(
action
)
=>
{
action
.
setDisabled
(
!
isValid
);
}
);
}
);
};
/**
* @inheritdoc
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
shouldRemoveAnnotation
=
function
()
{
return
!
this
.
annotationInput
.
getAnnotation
();
};
/**
* @inheritdoc
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
getInsertionText
=
function
()
{
return
this
.
labelInput
.
getValue
().
trim
()
||
this
.
annotationInput
.
getHref
();
};
/**
* @inheritdoc
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
getAnnotation
=
function
()
{
return
this
.
annotationInput
.
getAnnotation
();
};
/**
* @inheritdoc
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
getAnnotationFromFragment
=
function
(
fragment
)
{
const
text
=
fragment
.
getText
();
return
text
?
new
ve
.
dm
.
LinkAnnotation
(
{
type
:
'link'
,
attributes
:
{
href
:
text
}
}
)
:
null
;
};
/**
* @inheritdoc
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
initialize
=
function
()
{
// Parent method
ve
.
ui
.
LinkAnnotationInspector
.
super
.
prototype
.
initialize
.
call
(
this
);
// Properties
this
.
labelInput
=
this
.
createLabelInput
();
this
.
annotationInput
=
this
.
createAnnotationInput
();
this
.
labelField
=
new
OO
.
ui
.
FieldLayout
(
this
.
labelInput
,
{
align
:
'top'
,
label
:
ve
.
msg
(
'visualeditor-linkcontext-label-label'
)
}
);
this
.
annotationField
=
new
OO
.
ui
.
FieldLayout
(
this
.
annotationInput
,
{
align
:
'top'
,
label
:
ve
.
msg
(
'visualeditor-linkinspector-title'
)
}
);
// Events
this
.
annotationInput
.
connect
(
this
,
{
change
:
'onAnnotationInputChange'
}
);
this
.
annotationInput
.
getTextInputWidget
().
connect
(
this
,
{
enter
:
'onFormSubmit'
}
);
this
.
labelInput
.
connect
(
this
,
{
enter
:
'onFormSubmit'
}
);
this
.
labelInput
.
connect
(
this
,
{
change
:
'onAnnotationInputChange'
}
);
// Initialization
this
.
form
.
$element
.
append
(
this
.
labelField
.
$element
,
this
.
annotationField
.
$element
);
if
(
!
OO
.
ui
.
isMobile
()
)
{
this
.
annotationField
.
setLabel
(
null
);
this
.
labelField
.
$element
.
detach
();
}
};
/**
* Create a link label widget
*
* @return {OO.ui.TextInputWidget} Link label widget
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
createLabelInput
=
function
()
{
return
new
OO
.
ui
.
TextInputWidget
();
};
/**
* Create a link annotation widget
*
* @return {ve.ui.LinkAnnotationWidget} Link annotation widget
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
createAnnotationInput
=
function
()
{
return
new
ve
.
ui
.
LinkAnnotationWidget
();
};
/**
* @inheritdoc
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
shouldInsertText
=
function
()
{
if
(
ve
.
ui
.
LinkAnnotationInspector
.
super
.
prototype
.
shouldInsertText
.
call
(
this
)
)
{
// Adding a new link
return
true
;
}
if
(
OO
.
ui
.
isMobile
()
)
{
return
!
this
.
labelInput
.
isDisabled
()
&&
// Don't touch it if the plaintext value hasn't changed, to preserve internal annotations if possible
this
.
labelInput
.
getValue
().
trim
()
!==
this
.
initialLabel
.
trim
();
}
return
false
;
};
/**
* @inheritdoc
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
getSetupProcess
=
function
(
data
)
{
return
ve
.
ui
.
LinkAnnotationInspector
.
super
.
prototype
.
getSetupProcess
.
call
(
this
,
data
)
.
next
(
()
=>
{
const
title
=
ve
.
msg
(
this
.
isReadOnly
()
?
'visualeditor-linkinspector-title'
:
(
this
.
isNew
?
'visualeditor-linkinspector-title-add'
:
'visualeditor-linkinspector-title-edit'
)
),
fragment
=
this
.
getFragment
();
this
.
title
.
setLabel
(
title
).
setTitle
(
title
);
this
.
initialLabel
=
fragment
.
getText
();
this
.
labelInput
.
setDisabled
(
!
fragment
.
containsOnlyText
()
);
this
.
labelInput
.
setValue
(
this
.
initialLabel
);
this
.
annotationInput
.
setAnnotation
(
this
.
initialAnnotation
);
this
.
annotationInput
.
setReadOnly
(
this
.
isReadOnly
()
);
this
.
updateActions
();
}
);
};
/**
* @inheritdoc
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
getReadyProcess
=
function
(
data
)
{
return
ve
.
ui
.
LinkAnnotationInspector
.
super
.
prototype
.
getReadyProcess
.
call
(
this
,
data
)
.
next
(
()
=>
{
if
(
!
OO
.
ui
.
isMobile
()
)
{
this
.
annotationInput
.
getTextInputWidget
().
focus
().
select
();
}
// Clear validation state, so that we don't get "invalid" state immediately on focus
this
.
annotationInput
.
getTextInputWidget
().
setValidityFlag
(
true
);
}
);
};
/**
* @inheritdoc
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
getHoldProcess
=
function
(
data
)
{
return
ve
.
ui
.
LinkAnnotationInspector
.
super
.
prototype
.
getHoldProcess
.
call
(
this
,
data
)
.
next
(
()
=>
{
this
.
annotationInput
.
getTextInputWidget
().
blur
();
}
);
};
/**
* @inheritdoc
*/
ve
.
ui
.
LinkAnnotationInspector
.
prototype
.
getTeardownProcess
=
function
(
data
)
{
return
ve
.
ui
.
LinkAnnotationInspector
.
super
.
prototype
.
getTeardownProcess
.
call
(
this
,
data
)
.
next
(
()
=>
{
this
.
annotationInput
.
setAnnotation
(
null
);
this
.
labelInput
.
$input
.
attr
(
'placeholder'
,
''
);
this
.
labelInput
.
setValue
(
''
);
}
);
};
/* Registration */
ve
.
ui
.
windowFactory
.
register
(
ve
.
ui
.
LinkAnnotationInspector
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 21, 21:54 (1 d, 12 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
6e/1e/6223be495f428bd197f5e886ee40
Default Alt Text
ve.ui.LinkAnnotationInspector.js (6 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment