Commit graph

432 commits

Author SHA1 Message Date
Catrope 7319038ed6 Strip generated <p> tags in dataToDom
domToData wraps bare content in paragraph elements, which were then
converted to <p> tags by domToData. With this fix, HTML with "missing"
<p> tags actually round-trips through the editor correctly now, rather
than having <p> tags added wherever VE believes they should exist.

* Mark generated paragraph elements with .internal.generated = 'wrapper'
** This signifies the wrapper was generated but its contents were not,
   so the right thing to do when converting back to HTML is to remove
   the wrapper and keep the contents. We might want to use other values
   of generated in the future.
* Unwrap nodes with generated=wrapper when converting to HTML

Tests:
* Add 'generated': 'wrapper' as appropriate. Only affects 1 test
* Remove 'normalizedHtml' for this test because it is no longer needed
** Need to keep 'normalizedHtml' for now because we normalize hrefs
* Eventually the main example should test bare content, but that
  requires touching a lot of stuff. The main example could use some
  beefing up anyway.

Change-Id: I277ad5fe3f64e07c1bbf49007d6bbaecc90b7466
2012-08-16 16:09:28 -07:00
Catrope ce60b54d33 Rename fringeWhitespace to internal
This allows us to put other internal data in there in the future. Also
passing it through the Node constructor properly now.

* ve.dm.Node
** Rename fringeWhitespace property to internal
** Add internal parameter to constructor
** Remove setFringeWhitespace()
* Increase the number of parameters passed through by ve.Factory to 3
* Pass through .internal from linmod to nodeFactory in ve.dm.Document
* ve.dm.Converter
** Rename .fringeWhitespace to .internal.whitespace and make it an array
** Store a temporary reference to .internal in domElement.veInternal
* Add internal to all node constructors except TextNode

Tests:
* Update for fringeWhitespace->internal rename
* Add third parameter to ve.Factory tests
* Add .internal to getNodeTreeSummary

Change-Id: If20c0bb78fee3efa55f72e51e7fc261283358de7
2012-08-16 15:14:01 -07:00
Trevor Parscal d147504f49 Added support for apex skin
* Made vector specific styles only active in the vector skin
* Added apex specific styles
* Removed override of text size for document node
* Added stylesheet for stand-alone to specify text size for document node

Change-Id: I8a57918912499f9453a5692ff45a04a16ed34cde
2012-08-15 16:35:52 -07:00
Trevor Parscal c8b4a28936 Added key-sorting to make hashes referentially transparent
To do this, we are using the replacer callback of JSON.stringify, which is supported by all of our target browsers including IE8. We are also leaning on Object.keys and Array.reduce, the latter of which required adding a new fallback implementation for some browsers which do not support it yet.

Change-Id: Ifa285ca3da4d94d962464f09414591532bbea79c
2012-08-15 11:14:44 -07:00
Trevor Parscal e113ae3d9f Merge "Update LinkAnnotation for Parsoid href changes" 2012-08-14 20:08:58 +00:00
Catrope 48777cceca Merge "Added setSelection to ve.dm.Surface" 2012-08-14 18:56:19 +00:00
Catrope 6f8307d5d2 Update LinkAnnotation for Parsoid href changes
Because the Parsoid prefix format changed from /mw:Foo to /mw/Foo , the
href format for internal links has changed from "/Foo" to "Foo". So the
href is now simply the title, except that it may be preceded by one or
more "../" if the title of the page we're on contains a '/'.

So instead of stripping the leading slash from internal link hrefs and
putting it back on the way out, only strip any leading "../"s and dump
the titles directly into the hrefs on the way out.

Also update the link test case for this, and add a test case for the ../
stripping.

Change-Id: I3e0bdde20f22cda34eb45fc351de5e780419b6a2
2012-08-14 11:03:37 -07:00
Trevor Parscal cc6f0d17ea Merge "Recognize ExtLink/URL and ExtLink/Numbered in LinkInspector" 2012-08-14 15:50:44 +00:00
Trevor Parscal 0db79e5154 Merge "SimpleWikiLink is no longer used by Parsoid, remove it from VE" 2012-08-14 15:49:27 +00:00
Trevor Parscal d7f99141a2 Added setSelection to ve.dm.Surface
This is a convenience method which also can improve code readability.

Change-Id: If71b83b2861d195b58915f81dc614e2718e75d95
2012-08-14 08:41:32 -07:00
Catrope 70fa9c8aeb Recognize annotation types with multiple slashes correctly
Annotation types with more than one slash such as 'link/ExtLink/URL'
weren't being processed correctly because .split( '/', 2 ) throws away
everything after the second slash. Instead, don't pass a limit to
.split(); the code for reconstructing a slash-separated string from
multiple components was already in place.

Also add test cases for URL links and numbered links.

(Do you like the lines-of-code to lines-of-test ratio in this commit,
Trevor? ;) )

Change-Id: I7add87396447a01b1c23a4f9bfd63d2e8fd861ce
2012-08-13 18:22:31 -07:00
Catrope 5b804df40f SimpleWikiLink is no longer used by Parsoid, remove it from VE
Change-Id: I7f19304dc8bd6819992756a704e215d31f8b2e7e
2012-08-13 18:05:10 -07:00
Catrope 826518c1e1 Recognize ExtLink/URL and ExtLink/Numbered in LinkInspector
Change-Id: Ib13fd3396132695a844db6151296c52fa5f96032
2012-08-13 18:03:34 -07:00
Trevor Parscal f99088b79f Merge "Strip and preserve inner leading&trailing whitespace in the linear model" 2012-08-13 16:56:50 +00:00
Trevor Parscal ea0467fb0e Merge "Refactor ve.js utilities and improve documentation" 2012-08-13 03:24:43 +00:00
Timo Tijhof f06952f2f3 Refactor ve.js utilities and improve documentation
Refactor:
* ve.indexOf
  Renamed from ve.inArray.
  This was named after the jQuery method which in turn has a longer
  story about why it is so unfortunately named. It doesn't return
  a boolean, but an index. Hence the native method being called
  indexOf as well.

* ve.bind
  Renamed from ve.proxy.
  I considered making it use Function.prototype.bind if available.
  As it performs better than $.proxy (which doesn't use to the native
  bind if available). However since bind needs to be bound itself in
  order to use it detached, it turns out with the "call()" and
  "bind()"  it is slower than the $.proxy shim:
  http://jsperf.com/function-bind-shim-perf
  It would've been like this:
  ve.bind = Function.prototype.bind ?
      Function.prototype.call.bind( Function.prototype.bind ) :
      $.proxy;
  But instead sticking to ve.bind = $.proxy;

* ve.extendObject
  Documented the parts of jQuery.extend that we use. This makes it
  easier to replace in the future.

Documentation:
* Added function documentation blocks.
* Added annotations to  functions that we will be able to remove
  in the future in favour of the native methods.
  With "@until + when/how".
  In this case "ES5". Meaning, whenever we drop support for browsers
  that don't support ES5. Although in the developer community ES5 is
  still fairly fresh, browsers have been aware for it long enough
  that thee moment we're able to drop it may be sooner than we think.
  The only blocker so far is IE8. The rest of the browsers have had
  it long enough that the traffic we need to support of non-IE
  supports it.

Misc.:
* Removed 'node: true' from .jshintrc since Parsoid is no longer in
  this repo and thus no more nodejs files.
 - This unraveled two lint errors: Usage of 'module' and 'console'.
   (both were considered 'safe globals' due to nodejs, but not in
   browser code).

* Replaced usage (before renaming):
 - $.inArray -> ve.inArray
 - Function.prototype.bind -> ve.proxy
 - Array.isArray -> ve.isArray
 - [].indexOf -> ve.inArray
 - $.fn.bind/live/delegate/unbind/die/delegate -> $.fn.on/off

Change-Id: Idcf1fa6a685b6ed3d7c99ffe17bd57a7bc586a2c
2012-08-12 20:32:45 +02:00
Catrope 63e6702c52 Strip and preserve inner leading&trailing whitespace in the linear model
This makes things like
== Foo ==
* Bar
render without the leading and trailing spaces, while still
round-tripping those spaces.

* Added a .fringeWhitespace property to the linear model and ve.dm.Node
** Object containing innerPre, innerPost, outerPre, outerPost
** Only inner* are used right now, outer* are planned for future use
** Like .attributes , it's suppressed if it's an empty object
* In getDataFromDom():
** Store the stripped whitespace in .fringeWhitespace
** Move emptiness check up: empty elements with .fringeWhitespace have
   to be preserved
** Move paragraph wrapping up: .fringeWhitespace has to be applied to
   the generated paragraph, not its parent
** Add wrapperElement to keep track of the element .fringeWhitespace has
   to be added to; this is either dataElement or the generated paragraph
   or nothing, but we can't modify dataElement because it's used later
* In getDomFromData():
** When processing an opening, store the fringeWhitespace data in the
   generated DOM node
** When processing a closing, add the stored whitespace back in
* In the ve.dm.Document constructor, pass through .fringeWhitespace from
  the linear model data to the generated nodes

Tests:
* Change one existing test case to account for this change
* Add three new test cases for this behavior
* Add normalizedHtml field so I can test behavior with bare content

Change-Id: I0411544652dd72b923c831c495d69ee4322a2c14
2012-08-10 17:23:53 -07:00
Catrope d93b82347b Clean up a few commas and some indentation
The commas were resulting from converting this:
var foo = 3,
	bar = 5;

to this:

foo = 3,
bar = 5;

Change-Id: I0223b34a30d947c6a51f0601727b0c3850239e66
2012-08-10 16:49:14 -07:00
Catrope 5d974ed1e1 Fix replaceNonBreakingSpace() to not modify the linear model
It was replacing spaces with &nbsp;s in its copy of a slice of linmod
data, but the copy was a shallow copy, so when modifying annotated
spaces it would modify the actual data. Fixed by detecting this case and
cloning the character's array before modifying it.

Change-Id: Ic96ed34605a302af18f274a0faa6d0f650f5b771
2012-08-10 15:47:13 -07:00
Trevor Parscal a0fa371481 Added isNoOp to ve.dm.Transaction
Also added some checks in content branch conversion to make sure that converting from and to the same thing results in a no-op

Change-Id: Ie47520d666e45a77d12c7ebb9457aef7ab6b8097
2012-08-10 15:35:48 -07:00
Trevor Parscal fed1a98dd7 Fixed reversal of next and previous polling results
Change-Id: I504040044721603ae48a844e3f78d735f2c3159d
2012-08-10 14:06:18 -07:00
Catrope 8887a0731b Fix up c0ea02c0bf
Was stripping whitespace before and after annotations as well

Change-Id: Ie49319c15e68de6855fef2beadec0a11beea3ec6
2012-08-10 13:44:35 -07:00
Trevor Parscal 17bf3ef756 Merge "Fix up 62d08588050f576b0728800067b97d41b7eec9fa" 2012-08-10 17:31:56 +00:00
Catrope 3f2a256f86 Fix up 62d0858805
* Per Krinkle's comment, be tolerant of missing .htmlAttributes
* Drop .htmlAttributes if no attributes, fixes some tests

Change-Id: I65589a8b489e19a7c8a41ba2f4a57e68fc52684c
2012-08-10 10:23:14 -07:00
Catrope 946a7e64d6 Rename external link RDFa types to keep up with Parsoid
Change-Id: Ie232a575339a16431cbd1ee216998d1f6bf52d78
2012-08-10 10:15:05 -07:00
Catrope baf965fc50 Merge "Make use of new jshint options" 2012-08-10 01:43:25 +00:00
Timo Tijhof 23c5b0d02c Make use of new jshint options
* Restricting "camelcase":
  No changes, we were passing all of these already

* Explicitly unrestricting "forin" and "plusplus"
  These are off by default in node-jshint, but some distro of jshint
  and editors that use their own wrapper around jshint instead of
  node-jshint (Eclipse?) may have different defaults. Therefor
  setting them to false explicitly. This also serves as a reminder
  for the future so we'll always know we don't pass that, in case
  we would want to change that.

* Fix order ("quotemark" before "regexp")

* Restricting "unused"
  We're not passing all of this, which is why I've set it to false
  for now. But I did put it in .jshintrc as placeholder.
  I've fixed most of them, there's some left where there is no clean
  solution.

* While at it fix a few issues:
 - Unused variables ($target, $window)
 - Bad practices (using jQuery context for find instead of creation)
 - Redundant /*global */ comments
 - Parameters that are not used and don't have documentation either
 - Lines longer than 100 chars @ 4 spaces/tab

* Note:
 - ve.ce.Surface.prototype.onChange takes two arguments but never
   uses the former. And even the second one can be null/undefined.
   Aside from that, the .change() function emits
   another event for the transaction already. Looks like this
   should be refactored a bit, two more separated events probably
   or one that is actually used better.
 - Also cleaned up a lot of comments, some of which were missing,
   others were incorrect
 - Reworked the contentChange event so we are no longer using the
   word new as an object key; expanded a complex object into multiple
   arguments being passed through the event to make it easier to work
   with and document

Change-Id: I8490815a508c6c379d5f9a743bb4aefd14576aa6
2012-08-10 02:50:30 +02:00
Catrope c0ea02c0bf Strip leading and trailing whitespace in text
Right now this means things like headings and list items are rendered
nicer (without the whitespace), but also get their whitespace normalized
when saving back. I'll submit code tomorrow that preserves this
whitespace.

Submitting this now because it's needed to make <br>s look reasonable

Change-Id: I4b5e5ad8ee1bbe2f1eaf0fb860dd59f6e401dc3d
2012-08-09 16:26:35 -07:00
Catrope d6d05a40c5 Merge "Added basic ve.dm.SurfaceFragment class" 2012-08-09 23:19:20 +00:00
Trevor Parscal 72bddc03f0 Added basic ve.dm.SurfaceFragment class
Lots left to do here, but this is the future API for working with documents

Change-Id: I7b7e705ad4d922f37c327042051634a61dc8be66
2012-08-09 16:18:13 -07:00
Trevor Parscal 522eb08fdc Removing redundant overrides for canHaveSlug* methods
Change-Id: I2bfd08eab1cd45a193d91540bc0602549884fa89
2012-08-09 14:53:08 -07:00
Trevor Parscal 5752b3fb72 Merge "Add ve.dm.BreakNode to represent <br>" 2012-08-09 21:50:41 +00:00
Catrope 625161e35c Add ve.dm.BreakNode to represent <br>
Change-Id: I3825199c3c8cbe3b50c01e03f39f20cef7c55a28
2012-08-09 14:50:25 -07:00
Catrope 62d0858805 Preserve HTML attributes for textStyle/* annotations
The new annotation API will do this too; this is a temporary hack to fix
the bugs caused by stripping attributes.

This code doesn't actually render the attributes, but the new annotation
API will.

Change-Id: Ic0ddf822fe02f101f2e825080c6bcc2a03115974
2012-08-09 13:30:21 -07:00
Catrope c6a4e7a896 Rename wikiLink to WikiLink everywhere
Was causing link inspector breakage

Change-Id: Idf12f90aec9cbd2ddca47c66eb9e6e705a0e48f5
2012-08-09 12:36:09 -07:00
Trevor Parscal 8479e3d060 This should never happen, but if it does, lets make sure we know
In the past, this has cause things to break in mysterious ways

Change-Id: I2fcf1e2a9cf776a9ab9b3969d9ec552e23120e79
2012-08-08 15:17:45 -07:00
Trevor Parscal d8ee3c2c29 After much research on error objects, native = good, custom = bad
Stack traces, line numbers, etc. All the approaches I've seen are bad hacks. This is the best way to go.

Change-Id: Ib12e9d2ecfe610bcc89d046005e35cc13efa3d99
2012-08-08 10:48:53 -07:00
Krinkle 08b349d7dd Merge "Throw ve.Error instead of string literals" 2012-08-08 04:20:47 +00:00
Trevor Parscal b4de3ead08 Throw ve.Error instead of string literals
Throwing strings is bad because it doesn't include a lot of important
information that an error object does, such as a stack trace or where
the error was actually thrown from.

ve.Error inherits directly from Error. In the future we may create
more specific subclasses and/or do custom stuff.

Some interesting reading on the subject:
* http://www.devthought.com/2011/12/22/a-string-is-not-an-error/

Change-Id: Ib7c568a1dcb98abac44c6c146e84dde5315b2826
2012-08-08 06:19:00 +02:00
Rob Moen e009d11dca Quick link inspector fix to support recently changed types.
Change-Id: I095968db70b2f523cdd50d51242268894aa7ddec
TODO: Link Inspector needs to support all 6 link types.
2012-08-07 14:43:10 -07:00
Trevor Parscal 1c4f66c49b Merge "(bug 38125) ve.init.mw.ViewPageTarget: Preserve original query" 2012-08-07 16:48:55 +00:00
Timo Tijhof 6b048f4f55 (bug 38125) ve.init.mw.ViewPageTarget: Preserve original query
* Use 'href' of #ca-edit instead of constructing it manually.
  MediaWiki's output of #ca-edit already takes care of all needed
  queries, including "oldid" (bug 38125).

* Misc clean up:
 - Use .get() instead of accessing the array directly.

* Clean up setupSkinTabs and add more inline documentation.

Change-Id: I7d702a3eb1f9ce23a5e3c9e846b00da5cead386e
2012-08-07 11:36:27 +02:00
Timo Tijhof 9b49a7ce81 Clean up: Single quotes
* There were only 3 files with single quotes, fixed them all.

* Added option to .jshintrc (be sure to use the latest version of
  node-jshint since this is a fairly new addition to the library).

Change-Id: I8bf8895ce56bf86e3bed244279a9d32269e44763
2012-08-07 07:02:01 +02:00
Trevor Parscal 2eb0d4e51f Javascript, unlike PHP doesn't need double quotes for \n
This just cleans up a few places where single quotes should have been used instead of double quotes.

Change-Id: I6c53652e71ab96842ed5bb41fb1e0b8c923eb25d
2012-08-07 06:49:44 +02:00
Trevor Parscal 255ce870e2 Puttin' em white-spacers where they aught'a be
function() -> function ()
){ -> ) {

Change-Id: I20a85fcf79d7aec64f7f2559e84c0279550d4eea
2012-08-06 18:52:19 -07:00
Trevor Parscal f0549e0075 Merge "Kill all but one of the Parsoid compat hacks, we don't need them any more" 2012-08-06 21:02:03 +00:00
Catrope 444961af2f Kill all but one of the Parsoid compat hacks, we don't need them any more
Also remove traces of Parsoid workarounds in tests. Tests are now
passing, yay :)

Change-Id: I8a59fc92c567c3595849e3e9377ce6eb6acde280
2012-08-06 13:56:40 -07:00
Catrope 68c5430872 Fix weird bug that was suddenly happening on the live site
When closing annotation nodes, we weren't popping them off
annotationStack. Not sure where this came from, but the code was
definitely bad and this fixes it.

Change-Id: I6d805e9aca3778666212135f76ff34c6baacbbc8
2012-08-06 13:51:51 -07:00
Timo Tijhof c889292adf Kranitor #004: MediaWiki-specific clean up and minor fixes
* Default value of wgVisualEditorParsoidURL is broken.
  Slash is needed, else Api will request to
  http://hostnamePageName
  Roan says double slashes are okay, and look cleaner than string
  search checks etc.

* Use .clone() for mw.Uri instead of converting to string
  and letting mw.Uri parse it, again. Clone creates a basic
  instance and copies over properties internally (deep copy,
  no references).

* No need for hasOwnProperty (and its potential issues)

* Code clean up
 - Whitespace consistency
 - Variable hosting
 - Remove redundant `return false;` statements in event handlers
   e.preventDefault() is a jQuery.Event method that takes care
   of cross-browser issues.
 - Same for e.keyCode||e.which thing, this is already normalized
   by jQuery.Event
 - Add missing parameter to setTimeout
 - Consistent order in success/error handlers in $.ajax options

Change-Id: I5bc24e0cbdf01b3704d4ccb0b45b3052e3b58694
2012-08-03 23:55:52 -07:00
Trevor Parscal 13ccb68ae1 Cleanup - all jshint conditions are now met
Also:
* Removed a lot of dead code in Surface that was used in the now dead and gone sandbox.
* Changed from throwing an exception when calling getBalancedData on a range that produces no results from selectNodes to just returning []

Change-Id: Icf27094724eae5b90eec21308f9e26afe877e3ee
2012-08-03 18:56:04 -07:00