2012-07-25 05:39:29 +00:00
|
|
|
/*global mw*/
|
|
|
|
|
2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor user interface LinkInspector class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2011-12-09 01:28:44 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.ui.LinkInspector object.
|
2012-06-20 01:20:28 +00:00
|
|
|
*
|
2011-12-09 01:28:44 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-02-06 23:50:56 +00:00
|
|
|
* @param {ve.ui.Toolbar} toolbar
|
2011-12-09 01:28:44 +00:00
|
|
|
*/
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
ve.ui.LinkInspector = function ( toolbar, context ) {
|
2011-12-09 01:28:44 +00:00
|
|
|
// Inheritance
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.Inspector.call( this, toolbar, context );
|
2012-07-03 20:28:10 +00:00
|
|
|
|
2012-08-15 18:26:11 +00:00
|
|
|
var inspector = this;
|
|
|
|
this.context = context;
|
|
|
|
|
|
|
|
// Elements
|
2012-07-17 18:53:42 +00:00
|
|
|
this.$clearButton = $( '<div class="es-inspector-button es-inspector-clearButton"></div>', context.inspectorDoc )
|
2011-12-09 23:04:55 +00:00
|
|
|
.prependTo( this.$ );
|
2012-06-20 01:20:28 +00:00
|
|
|
this.$.prepend(
|
2012-07-17 18:53:42 +00:00
|
|
|
$( '<div class="es-inspector-title"></div>', context.inspectorDoc )
|
2012-06-20 01:20:28 +00:00
|
|
|
.text( ve.msg( 'visualeditor-linkinspector-title' ) )
|
|
|
|
);
|
2012-08-15 18:26:11 +00:00
|
|
|
// Target
|
2012-08-20 19:32:42 +00:00
|
|
|
this.$locationInput = $( '<input>', context.inspectorDoc )
|
|
|
|
.attr( 'type', 'text' )
|
|
|
|
.prop( 'class', 've-ui-linkInspector-location' )
|
|
|
|
.appendTo( this.$form );
|
2012-08-15 18:26:11 +00:00
|
|
|
|
2011-12-09 23:11:49 +00:00
|
|
|
this.initialValue = null;
|
2011-12-09 01:28:44 +00:00
|
|
|
|
|
|
|
// Events
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
this.$clearButton.click( function () {
|
2011-12-09 23:04:55 +00:00
|
|
|
if ( $(this).is( '.es-inspector-button-disabled' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-16 22:16:15 +00:00
|
|
|
|
2012-07-19 03:40:49 +00:00
|
|
|
var hash,
|
2012-07-03 20:28:10 +00:00
|
|
|
surfaceModel = inspector.context.getSurfaceView().getModel(),
|
2012-07-24 17:42:29 +00:00
|
|
|
annotations = inspector.getAllLinkAnnotationsFromSelection();
|
|
|
|
// Clear all link annotations.
|
2012-07-19 03:40:49 +00:00
|
|
|
for ( hash in annotations ) {
|
2012-06-20 01:20:28 +00:00
|
|
|
surfaceModel.annotate( 'clear', annotations[hash] );
|
|
|
|
}
|
2012-07-03 20:28:10 +00:00
|
|
|
inspector.$locationInput.val( '' );
|
|
|
|
inspector.context.closeInspector();
|
2011-12-09 01:28:44 +00:00
|
|
|
} );
|
2012-08-15 18:26:11 +00:00
|
|
|
|
|
|
|
// Bind events to location input.
|
|
|
|
this.$locationInput.on( 'change mousedown keydown cut paste', function () {
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
setTimeout( function () {
|
2012-08-15 18:26:11 +00:00
|
|
|
// Toggle disabled class
|
2012-07-24 17:42:29 +00:00
|
|
|
if ( inspector.$locationInput.val() !== '' ) {
|
2012-07-03 20:28:10 +00:00
|
|
|
inspector.$acceptButton.removeClass( 'es-inspector-button-disabled' );
|
2011-12-09 23:11:49 +00:00
|
|
|
} else {
|
2012-07-03 20:28:10 +00:00
|
|
|
inspector.$acceptButton.addClass( 'es-inspector-button-disabled' );
|
2011-12-09 23:11:49 +00:00
|
|
|
}
|
2012-08-15 18:26:11 +00:00
|
|
|
|
2011-12-09 23:11:49 +00:00
|
|
|
}, 0 );
|
|
|
|
} );
|
2012-08-15 18:26:11 +00:00
|
|
|
|
|
|
|
// Init multiSuggest for MediaWiki
|
|
|
|
if ( 'mw' in window ) {
|
|
|
|
this.initMultiSuggest();
|
|
|
|
}
|
2011-12-09 01:28:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
ve.ui.LinkInspector.prototype.getAllLinkAnnotationsFromSelection = function () {
|
2011-12-09 01:28:44 +00:00
|
|
|
var surfaceView = this.context.getSurfaceView(),
|
|
|
|
surfaceModel = surfaceView.getModel(),
|
|
|
|
documentModel = surfaceModel.getDocument(),
|
2012-07-24 17:42:29 +00:00
|
|
|
annotations,
|
|
|
|
linkAnnotations = {};
|
2012-06-20 01:20:28 +00:00
|
|
|
|
2012-07-24 17:42:29 +00:00
|
|
|
annotations = documentModel.getAnnotationsFromRange( surfaceModel.getSelection(), true );
|
2012-08-02 18:46:13 +00:00
|
|
|
linkAnnotations = ve.dm.Document.getMatchingAnnotations ( annotations, /^link\// );
|
2012-07-24 17:42:29 +00:00
|
|
|
if ( !ve.isEmptyObject( linkAnnotations ) ) {
|
|
|
|
return linkAnnotations;
|
2011-12-09 01:28:44 +00:00
|
|
|
}
|
2012-07-24 17:42:29 +00:00
|
|
|
|
|
|
|
return null;
|
2012-06-20 01:20:28 +00:00
|
|
|
};
|
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
ve.ui.LinkInspector.prototype.getFirstLinkAnnotation = function ( annotations ) {
|
2012-07-24 17:42:29 +00:00
|
|
|
var hash;
|
2012-07-19 03:40:49 +00:00
|
|
|
for ( hash in annotations ) {
|
2012-08-02 18:46:13 +00:00
|
|
|
// Use the first one with a recognized type (there should only be one, this is just in case)
|
|
|
|
if (
|
2012-08-07 21:43:10 +00:00
|
|
|
annotations[hash].type === 'link/WikiLink' ||
|
2012-08-14 01:03:34 +00:00
|
|
|
annotations[hash].type === 'link/ExtLink' ||
|
|
|
|
annotations[hash].type === 'link/ExtLink/Numbered' ||
|
|
|
|
annotations[hash].type === 'link/ExtLink/URL'
|
2012-08-02 18:46:13 +00:00
|
|
|
) {
|
2012-06-20 01:20:28 +00:00
|
|
|
return annotations[hash];
|
2011-12-09 01:28:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-09 23:04:55 +00:00
|
|
|
return null;
|
2011-12-09 01:28:44 +00:00
|
|
|
};
|
|
|
|
|
2012-06-21 02:43:46 +00:00
|
|
|
// TODO: This should probably be somewhere else but I needed this here for now.
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
ve.ui.LinkInspector.prototype.getSelectionText = function () {
|
2012-07-19 03:40:49 +00:00
|
|
|
var i,
|
|
|
|
surfaceView = this.context.getSurfaceView(),
|
2012-06-21 02:43:46 +00:00
|
|
|
surfaceModel = surfaceView.getModel(),
|
|
|
|
documentModel = surfaceModel.getDocument(),
|
|
|
|
data = documentModel.getData( surfaceModel.getSelection() ),
|
|
|
|
str = '',
|
|
|
|
max = Math.min( data.length, 255 );
|
2012-07-19 03:40:49 +00:00
|
|
|
for ( i = 0; i < max; i++ ) {
|
2012-06-21 02:43:46 +00:00
|
|
|
if ( ve.isArray( data[i] ) ) {
|
|
|
|
str += data[i][0];
|
2012-06-21 04:52:42 +00:00
|
|
|
} else if( typeof data[i] === 'string' ) {
|
2012-06-21 02:43:46 +00:00
|
|
|
str += data[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
|
2012-07-03 20:28:10 +00:00
|
|
|
/*
|
|
|
|
* Method called prior to opening inspector which fixes up
|
|
|
|
* selection to contain the complete annotated link range
|
|
|
|
* OR unwrap outer whitespace from selection.
|
|
|
|
*/
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
ve.ui.LinkInspector.prototype.prepareOpen = function () {
|
2012-07-03 20:28:10 +00:00
|
|
|
var surfaceView = this.context.getSurfaceView(),
|
|
|
|
surfaceModel = surfaceView.getModel(),
|
|
|
|
doc = surfaceModel.getDocument(),
|
2012-07-24 17:42:29 +00:00
|
|
|
annotations = this.getAllLinkAnnotationsFromSelection(),
|
|
|
|
annotation = this.getFirstLinkAnnotation( annotations ),
|
2012-07-03 20:28:10 +00:00
|
|
|
selection = surfaceModel.getSelection(),
|
2012-07-24 17:42:29 +00:00
|
|
|
annotatedRange,
|
2012-07-03 20:28:10 +00:00
|
|
|
newSelection;
|
|
|
|
|
2012-07-24 17:42:29 +00:00
|
|
|
// Trim outer space from range if any.
|
|
|
|
newSelection = doc.trimOuterSpaceFromRange( selection );
|
|
|
|
|
2012-07-03 20:28:10 +00:00
|
|
|
if ( annotation !== null ) {
|
2012-07-24 17:42:29 +00:00
|
|
|
annotatedRange = doc.getAnnotatedRangeFromSelection( newSelection, annotation );
|
|
|
|
|
|
|
|
// Adjust selection if it does not contain the annotated range
|
|
|
|
if ( selection.start > annotatedRange.start ||
|
|
|
|
selection.end < annotatedRange.end
|
|
|
|
) {
|
|
|
|
newSelection = annotatedRange;
|
|
|
|
// if selected from right to left
|
|
|
|
if ( selection.from > selection.start ) {
|
|
|
|
newSelection.flip();
|
|
|
|
}
|
2012-07-03 20:28:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
surfaceModel.change( null, newSelection );
|
|
|
|
};
|
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
ve.ui.LinkInspector.prototype.onOpen = function () {
|
2012-07-24 17:42:29 +00:00
|
|
|
var annotation = this.getFirstLinkAnnotation( this.getAllLinkAnnotationsFromSelection() ),
|
2012-07-03 20:28:10 +00:00
|
|
|
initialValue = '';
|
2012-06-20 01:20:28 +00:00
|
|
|
if ( annotation === null ) {
|
2012-06-21 02:43:46 +00:00
|
|
|
this.$locationInput.val( this.getSelectionText() );
|
2011-12-09 23:04:55 +00:00
|
|
|
this.$clearButton.addClass( 'es-inspector-button-disabled' );
|
2012-08-09 19:36:09 +00:00
|
|
|
} else if ( annotation.type === 'link/WikiLink' ) {
|
2012-06-20 01:20:28 +00:00
|
|
|
// Internal link
|
2012-06-21 04:52:42 +00:00
|
|
|
initialValue = annotation.data.title || '';
|
|
|
|
this.$locationInput.val( initialValue );
|
2012-06-20 01:20:28 +00:00
|
|
|
this.$clearButton.removeClass( 'es-inspector-button-disabled' );
|
|
|
|
} else {
|
|
|
|
// External link
|
2012-06-21 19:40:28 +00:00
|
|
|
initialValue = annotation.data.href || '';
|
2012-06-21 04:52:42 +00:00
|
|
|
this.$locationInput.val( initialValue );
|
2012-06-20 01:20:28 +00:00
|
|
|
this.$clearButton.removeClass( 'es-inspector-button-disabled' );
|
2011-12-09 01:28:44 +00:00
|
|
|
}
|
2012-06-21 04:52:42 +00:00
|
|
|
this.initialValue = initialValue;
|
|
|
|
if ( this.$locationInput.val().length === 0 ) {
|
|
|
|
this.$acceptButton.addClass( 'es-inspector-button-disabled' );
|
|
|
|
} else {
|
|
|
|
this.$acceptButton.removeClass( 'es-inspector-button-disabled' );
|
|
|
|
}
|
2012-07-03 20:28:10 +00:00
|
|
|
|
2012-08-11 08:14:56 +00:00
|
|
|
setTimeout( ve.bind( function () {
|
2012-07-03 20:28:10 +00:00
|
|
|
this.$locationInput.focus().select();
|
|
|
|
}, this ), 0 );
|
2011-12-09 01:28:44 +00:00
|
|
|
};
|
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
ve.ui.LinkInspector.prototype.onClose = function ( accept ) {
|
2012-06-25 22:40:16 +00:00
|
|
|
var surfaceView = this.context.getSurfaceView(),
|
|
|
|
surfaceModel = surfaceView.getModel(),
|
2012-07-24 17:42:29 +00:00
|
|
|
annotations = this.getAllLinkAnnotationsFromSelection(),
|
2012-06-25 22:40:16 +00:00
|
|
|
target = this.$locationInput.val(),
|
|
|
|
hash, annotation;
|
2011-12-09 23:04:55 +00:00
|
|
|
if ( accept ) {
|
2012-07-24 17:42:29 +00:00
|
|
|
if ( !target ) {
|
2011-12-09 23:04:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
// Clear link annotation if it exists
|
2012-06-25 22:40:16 +00:00
|
|
|
for ( hash in annotations ) {
|
2012-06-20 01:20:28 +00:00
|
|
|
surfaceModel.annotate( 'clear', annotations[hash] );
|
|
|
|
}
|
2012-06-25 22:40:16 +00:00
|
|
|
surfaceModel.annotate( 'set', ve.ui.LinkInspector.getAnnotationForTarget( target ) );
|
2012-07-24 17:42:29 +00:00
|
|
|
|
2011-12-09 01:28:44 +00:00
|
|
|
}
|
2012-06-21 01:58:49 +00:00
|
|
|
// Restore focus
|
|
|
|
surfaceView.getDocument().getDocumentNode().$.focus();
|
2011-12-09 01:28:44 +00:00
|
|
|
};
|
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
ve.ui.LinkInspector.getAnnotationForTarget = function ( target ) {
|
2012-06-25 23:25:09 +00:00
|
|
|
var title;
|
2012-06-25 22:40:16 +00:00
|
|
|
// Figure out if this is an internal or external link
|
|
|
|
if ( target.match( /^(https?:)?\/\// ) ) {
|
|
|
|
// External link
|
|
|
|
return {
|
2012-08-07 21:43:10 +00:00
|
|
|
'type': 'link/ExtLink',
|
2012-06-25 22:40:16 +00:00
|
|
|
'data': { 'href': target }
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Internal link
|
2012-06-25 23:25:09 +00:00
|
|
|
// TODO in the longer term we'll want to have autocompletion and existence&validity
|
|
|
|
// checks using AJAX
|
|
|
|
try {
|
2012-07-25 05:39:29 +00:00
|
|
|
// FIXME mw dependency
|
2012-06-25 23:25:09 +00:00
|
|
|
title = new mw.Title( target );
|
|
|
|
if ( title.getNamespaceId() === 6 || title.getNamespaceId() === 14 ) {
|
|
|
|
// File: or Category: link
|
|
|
|
// We have to prepend a colon so this is interpreted as a link
|
|
|
|
// rather than an image inclusion or categorization
|
|
|
|
target = ':' + target;
|
|
|
|
}
|
|
|
|
} catch ( e ) { }
|
|
|
|
|
2012-06-25 22:40:16 +00:00
|
|
|
return {
|
2012-08-07 21:43:10 +00:00
|
|
|
'type': 'link/WikiLink',
|
2012-06-25 22:40:16 +00:00
|
|
|
'data': { 'title': target }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-15 18:26:11 +00:00
|
|
|
ve.ui.LinkInspector.prototype.initMultiSuggest = function() {
|
|
|
|
var inspector = this,
|
|
|
|
context = inspector.context,
|
|
|
|
$overlay = context.$iframeOverlay,
|
|
|
|
options;
|
|
|
|
|
|
|
|
// Multi Suggest configuration.
|
|
|
|
options = {
|
|
|
|
'parent': $overlay,
|
|
|
|
'prefix': 've-ui',
|
|
|
|
// Build suggestion groups in order.
|
|
|
|
'suggestions': function( params ) {
|
|
|
|
var groups = {},
|
|
|
|
results = params.results,
|
|
|
|
query = params.query,
|
|
|
|
modifiedQuery,
|
|
|
|
title,
|
|
|
|
prot;
|
|
|
|
|
|
|
|
// Add existing pages.
|
|
|
|
if ( results.length > 0 ) {
|
|
|
|
groups.internal = {
|
|
|
|
label: ve.msg( 'visualeditor-linkinspector-suggest-existing-page' ),
|
|
|
|
items: results,
|
|
|
|
itemClass: 'existing'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// Run the query through the mw.Title object to handle correct capitalization.
|
|
|
|
try {
|
|
|
|
title = new mw.Title( query );
|
|
|
|
modifiedQuery = title.getPrefixedText();
|
|
|
|
// If page doesn't exist, add New Page group.
|
2012-08-17 22:13:19 +00:00
|
|
|
if ( ve.indexOf( modifiedQuery, results ) === -1 ) {
|
2012-08-15 18:26:11 +00:00
|
|
|
groups['new'] = {
|
|
|
|
label: ve.msg( 'visualeditor-linkinspector-suggest-new-page' ),
|
|
|
|
items: [modifiedQuery],
|
|
|
|
itemClass: 'new'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} catch ( e ) {
|
|
|
|
// invalid input
|
|
|
|
ve.log( e );
|
|
|
|
}
|
|
|
|
// Add external
|
|
|
|
groups.external = {
|
|
|
|
label: ve.msg( 'visualeditor-linkinspector-suggest-external-link' ),
|
|
|
|
items: [],
|
|
|
|
itemClass: 'existing'
|
|
|
|
};
|
|
|
|
// Find a protocol and suggest an external link.
|
|
|
|
prot = query.match(
|
|
|
|
ve.init.platform.getExternalLinkUrlProtocolsRegExp()
|
|
|
|
);
|
|
|
|
if ( prot ) {
|
|
|
|
groups.external.items = [query];
|
|
|
|
// No protocol, default to http
|
|
|
|
} else {
|
|
|
|
groups.external.items = ['http://' + query];
|
|
|
|
}
|
|
|
|
return groups;
|
|
|
|
},
|
|
|
|
// Called on succesfull input.
|
|
|
|
'input': function( callback ) {
|
|
|
|
var $input = $( this ),
|
|
|
|
query = $input.val(),
|
|
|
|
api = new mw.Api();
|
|
|
|
// Make AJAX Request.
|
|
|
|
api.get( {
|
|
|
|
action: 'opensearch',
|
|
|
|
search: query
|
|
|
|
}, {
|
|
|
|
ok: function( data ) {
|
|
|
|
// Position the iframe overlay below the input.
|
|
|
|
context.positionIframeOverlay( {
|
|
|
|
overlay: $overlay,
|
|
|
|
below: $input
|
|
|
|
} );
|
|
|
|
// Build
|
|
|
|
callback( {
|
|
|
|
query: query,
|
|
|
|
results: data[1]
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// Setup Multi Suggest
|
|
|
|
this.$locationInput.multiSuggest( options );
|
|
|
|
};
|
|
|
|
|
2011-12-09 01:28:44 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.extendClass( ve.ui.LinkInspector, ve.ui.Inspector );
|