Commit graph

198 commits

Author SHA1 Message Date
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
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
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 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
Catrope 47f08a0613 Merge "Fixed problem with closing context menu on document blur." 2012-08-01 01:06:42 +00:00
Rob Moen 69ee22fb39 Fixed problem with closing context menu on document blur.
When editor surface loses focus, now checking to see if an inspector
is set or a menu is open prior to closing the context.

This ruling ensures more rational context icon / child menu behavior.

Change-Id: Ic4b74bb51e811e264a2109a3c1c5a8ae503a8c49
2012-07-31 18:02:44 -07:00
Timo Tijhof 077e21867e Kranitor #3: jQuerlyfornication ft. The Cascaders
* Classicifation (JS)
 Use addClass instead of attr( 'class' ) whenever possible.
 addClass will manipulate the properties directly instead of
 (re-)setting an attribute which (most) browsers then sync
 with the properties.

 Difference between:
 elem.className
 and
 elem.setAttribute( 'class', .. );

 Just like .checked, .value, .disabled and other interactive
 properties, the HTML attributes should only be used for initial
 values from the html document. When in javascript, only set
 properties. Attributes are either ignored or slow.

* Styling (JS)
 Use .css() instead of attr( 'style' ).

 Again, setting properties instead of attributes is much faster,
 easier and safer. And this way it takes care of cross-browser
 issues where applicable, and less prone to error due to dealing
 with key-value pairs instead of css strings.

 Difference between:
 elem.style.foo = 'bar';
 and
 elem.setAttribute( 'style', 'foo: bar;' );

* Finding (JS)
 Use .find( 'foo bar' ) instead of .find( 'foo' ).find( 'bar' ).
 It is CSS!

* Vendor prefixes (CSS)
 It is important to always list newer (standards-compliant) versions
 *after* the older/prefixed variants.

 See also http://css-tricks.com/ordering-css3-properties/

 So the following three:
 -webkit-gradient (Chrome, Safari 4)
 -webkit-linear-gradient (Chrome 10, Safari 5+)
 linear-gradient (CSS3 standard)

 ... must be in that order.

 Notes:
  - "-moz-opacity" is from before Mozilla 1.7 (Firefox < 0.8)
    Has not been renamed to "opacity" since Firefox 0.9.
  - Removed redundant "-moz-opacity"
  - Added "filter: alpha(opacity=**);" where missing
  - Fixed order of css3 properties (old to new)
  - Add standardized css3 versions where missing
    (some 'border-radius' groups didn't have the non-prefixed version)
  - Spacing
  - @embed
  - Shorten hex colors where possible (#dddddd -> #ddd)
    $ ack '#([0-9a-f])\1{5}' --css
    $ ack '#([0-9a-f])\1{2};' --css

Change-Id: I386fedb9058c2567fd0af5f55291e9859a53329d
2012-07-28 13:05:57 -07:00
Trevor Parscal 1639b78df7 Merge "Bug 36200 - VisualEditor: Sticky selection popup" 2012-07-27 21:49:39 +00:00
Timo Tijhof 88f6089952 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 14:40:00 -07:00
Rob Moen c656f831d1 Bug 36200 - VisualEditor: Sticky selection popup
Clearing context icon when editor loses focus.
-Reproduce problem by selecting text, then click outside of
the editor.  Selection is lost, and context icon is stuck.

Change-Id: I4b321f16cea73ec0e51540c0e71f265ab47514e9
2012-07-26 16:34:51 -07:00
Catrope 67e11ebbc3 Make VE work again with the link RDFa changes in Parsoid
This is ugly but makes things work again. I intend to clean this up once
we have a better attribute API

* Recognize mw:WikiLink, mw:SimpleWikiLink, mw:ExtLink,
 mw:NumberedExtLink and mw:UrlLink
* Support is incomplete because we can't get to the annotation text with
  the current API
* Preserve all unhandled attributes rather than special-casing data-mw
* Update remaining code using data-mw (sHref and stx extraction) to
  account for the data-mw -> data-rt rename
* Update tests accordingly

Change-Id: Ia13d3008a6d4cdc8828f9acda5aa797566bc597f
2012-07-26 16:23:03 -07:00
Christian Williams 9723bf51e5 Switching to localStorage for copy and paste, remove test
Change-Id: I555b8756afb53680d60f2068b8615787c60e9d8f
2012-07-25 17:07:08 -07:00
Catrope c8ce42c8e3 Do not put slugs after nested lists
But still put slugs before them. Done by overriding canHaveSlugAfter()
in ve.ce.ListNode.

Eventually this should be configurable and MediaWiki-specific

Change-Id: I5ad15ca4085a2d730add4954acbea358819b3986
2012-07-20 14:07:53 -07:00
Catrope 5be1b7798c Split canHaveSlug() into canHaveSlugBefore() and canHaveSlugAfter()
These determine whether a node can have a slug before and after,
respectively. The default implementation in ve.ce.Node is to use the
same rules for both, but individual node types can override this.

I'll need this to suppress slugs after nested lists but not before them.

Change-Id: Id88c0fc98aca7c7f52ce990ed9b8c42181ef6d18
2012-07-20 14:07:53 -07:00
Catrope feab4e58a1 Make Enter in an empty list item unindent
For pressing Enter in an empty list item at the end of a top-level list,
this has the same result as the previous code, but if you're in a nested
list it has the effect of jumping down a level. A previous incarnation
of this change just made Enter insert more list items ad infinitum if
you were in a nested list, but I think this is better.

This fixes a bug where pressing at the end of a nested list inserted a
paragraph in an invalid location

Change-Id: I9c7dbaf29a98f84926ed3a05e71c6294926dfce2
2012-07-20 14:07:53 -07:00
Catrope 5b4554b47f Let Tab and Shift+Tab trigger indentation again
Fix the commented-out code: it caused unindent to be triggered by just
pressing Shift. ASCII 16 is "data link escape", no idea where that came
from, so I removed it and used e.shiftKey instead.

Also check whether indent/outdent is even possible before doing it.
Currently this is done in a very hacky way (by checking the state of the
indent button), ideally we'd refactor things such that toolbar tools can
listen for keydowns and intercept them, that would make the code much
cleaner and we wouldn't have this problem.

Change-Id: I99885ee4b8a79cd24c4958c188addfc2b0453b03
2012-07-20 14:07:53 -07:00
Catrope ce1f4dac55 Work around crazy list rendering bug in Firefox
After indenting or outdenting a list item in a numbered list, the
numbering wasn't updated. So if you had:
1. One
2. Two
3. Three

and you indented "Two", you'd get:
1. One
     1. Two
3. Three

Adding or removing items in the list using the keyboard, or even
inspecting the list in Firebug (!), would trigger a renumbering and fix
the list to display "2. Three". But then the same issue would occur in
in reverse when outdenting "Two" (either using undo or using the
outdent button):
1. One
2. Two
2. Three

The workaround is to force a reflow by requesting the height (thank you
Timo). Implemented this in an override of onSplice() in ve.ce.ListNode, so
the list is detached and reattached every time children are spliced into
or out of it.

I haven't managed to come up with a minimal test case for this, not even
by putting a list in a contentEditable div and doing the same DOM
operations that ve.ce does from a setTimeout callback.

Change-Id: I93b2a309034c411a7b4e4b6c6bd4ef9d473999eb
2012-07-20 14:07:53 -07:00
Trevor Parscal 6b34f09df2 Removed some whitespace
And added a license to some files that didn't have it yet

Change-Id: I3a7e60374d1198d369a0475b8f65f7415012a337
2012-07-19 14:25:16 -07:00
Trevor Parscal c40174b60c Changed to use MIT license per agreement with the VisualEditor team
This license change is aimed at maximizing the reusability of this code
in other projects. VisualEditor is more than just an awesome editor for
MediaWiki, it's the new editor for the entire internet.

Added license and author files, plus mentions of the license to all
VisualEditor PHP, JavaScript and CSS files. Parser files have not been
modified but are effectively re-licensed since there's no overriding
license information. 3rd party libraries are not changed, but are all
already MIT licensed.

Change-Id: I895b256325db7c8689756edab34523de4418b0f2
2012-07-19 13:25:45 -07:00
Krinkle ab47265c34 Merge "JSHint: Added dotfiles and fixed tons of linting warnings." 2012-07-19 17:09:03 +00:00
Trevor Parscal a564f81aa7 JSHint: Added dotfiles and fixed tons of linting warnings.
* "onevar" warning sometimes solved by just merging var statements
  other times solved by making it a function declaration instead
  of a function expression.
* Also fixed several '_this' variable names in ve.es.Surface to
  more descriptive names, and enabled warnings for dangling _
  in identifiers.

Change-Id: I7d411881e3e06cf9a7fe56d689c29375881a81de
2012-07-19 10:01:00 -07:00
Trevor Parscal 3afb270567 Renamed ve.ce.Document.css to ve.ce.DocumentNode.css to match it's contents
Change-Id: I3d7504dfda27309f631a5856ffa4aacd13b6edc7
2012-07-18 18:23:11 -07:00
Rob Moen b71586f296 Bug 37811 - VisualEditor: editing toolbar float trigger also triggers contextView icon, although there is no context to act on
-Remove unused updateContext method.
-Added check for selection length in contextView set method.

Change-Id: I1d5791c69deea80c54cff3e021ba4c90cdac2cc4
2012-07-07 08:47:51 -07:00
Catrope 970873595b Merge "Made extendClass accept a variadic list of base classes to extend with" 2012-07-07 04:31:48 +00:00
Catrope bc0c8ae525 Merge "Rename ve.ce.BranchNode.doSlugs -> ve.ce.BranchNode.addSlugs" 2012-07-07 02:04:17 +00:00
Trevor Parscal 12b8818a02 (bug 37848) Fixing delete key at end of document, removing whitespace.
Change-Id: I64cc9e7a3251b7326b104cd3b8ecb0d07240cd77
2012-07-06 19:02:01 -07:00
Inez Korczynski d4bfa89b32 Rename ve.ce.BranchNode.doSlugs -> ve.ce.BranchNode.addSlugs
Change-Id: I162067be5a544817e36986eeb0acd0497d37f443
2012-07-05 16:55:45 -07:00
Trevor Parscal 1067f84764 Merge "Removing some logging" 2012-06-27 16:42:34 +00:00
Trevor Parscal efe26d9be2 Merge "(bug 36201) Control-K triggers link inspector" 2012-06-27 16:41:51 +00:00
Christian Williams b9f6baba63 (bug 36201) Control-K triggers link inspector
Change-Id: I0ffd237ce51d1899d2151fb76243e818c5f5cfb8
2012-06-27 09:41:06 -07:00
Trevor Parscal 02e24d6a39 Merge "Bugzilla:37804 - Double bound events were causing double backspace bugs" 2012-06-27 16:20:43 +00:00
Christian Williams a26708dd6e Removing some logging
Change-Id: I2876e56d2e3680d21877103618e59afec1c81ef9
2012-06-22 15:49:34 -07:00
Christian Williams 89e0f3d6ad Bugzilla:37804 - Double bound events were causing double backspace bugs
Change-Id: I589185d077e1efe6fb2c0457a290a8ac9ce8bceb
2012-06-22 15:39:43 -07:00
Christian Williams 122a31a021 Bugzilla:33093 - Shift-Enter splits at paragraphs instead of list items
Change-Id: Ie32e878cf9c71f7179143c631a01c0e2e671ed18
2012-06-22 15:05:35 -07:00
Trevor Parscal 02b0c7a6f4 Made extendClass accept a variadic list of base classes to extend with
Change-Id: I6d2307ce39da47ad2673dd439789a2f74632c59f
2012-06-22 10:50:41 -07:00
Catrope a0d87989cf You know what, just don't render hrefs, these links aren't clickable anyway
Change-Id: If5f0c9a2fa41f09569195fe7807aba9a8207a3c9
2012-06-21 16:12:17 -07:00
Trevor Parscal b560924467 Merge "Use title for rendering internal links, and guard against undefined" 2012-06-21 23:04:11 +00:00
Catrope 6ddfc4bcab Use title for rendering internal links, and guard against undefined
Change-Id: I18a4e5e06303fcd9540fde8c3b21fe8f8887417e
2012-06-21 15:52:25 -07:00
Trevor Parscal f021b02ce1 Merge "Reconcile the order and completeness of textStyles in 2 different places" 2012-06-21 22:33:41 +00:00
Catrope 9576f8fc48 Escape the href attribute on links
Change-Id: I3edaa5c9346f5c8c222c482bcb190acad2bac24d
2012-06-21 15:28:07 -07:00
Christian Williams 4f43ecefdf No need to apply selection in this transaction
Change-Id: Ia1ea5800dfbe5d89ef2fe22462712d8a558e5e3b
2012-06-21 15:20:21 -07:00
Inez Korczynski 41f5f7378b In Firefox hitting enter fires both events - keydown and keypress. We want to ignore key press for enter.
Change-Id: I49d19267cc6115342aadf11ea720e82bbf65ddb2
2012-06-21 14:52:43 -07:00
Catrope f58b5b6fc8 Reconcile the order and completeness of textStyles in 2 different places
ve.ce.TextNode listed textStyle annotations that didn't actually exist,
and failed to recognize some that did exist (such as span; bug 37808).

Added all annotations to both places. <span> tags are now tolerated by
the editor in that it doesn't crash anymore, but they're displayed (and
saved!) without any attributes, so <span style="color:yellow;">y</span>
doesn't show a yellow 'y' in the editor and is saved back as
<span>y</span> .

Change-Id: Iaae11ad5044150fa904010983ff83579cb37733d
2012-06-21 14:46:43 -07:00
Trevor Parscal ed33ca373f Merge "Undo and redo keyboard shortcuts" 2012-06-21 20:58:53 +00:00
Christian Williams 050134d55e Undo and redo keyboard shortcuts
Change-Id: Ia1e9db52f6fb2da79be28cdedaaf0dffc6097dc9
2012-06-21 13:58:21 -07:00
Inez Korczynski 07760653b2 Don't use custom handling for left and right arrow while metaKey is pressed as well.
Change-Id: I7e2f73ab085b877169f4a29bec04a294d6e13a2a
2012-06-21 13:56:32 -07:00
Inez Korczynski 6381709703 In case of IE use non-breaking spaces inside slugs instead of invisible separators - as in different browsers.
Change-Id: Ib6ae077206de1ad772e47e212a9f276f6b0081e0
2012-06-21 13:34:13 -07:00
Trevor Parscal 437649e062 Merge "Fix problem in hasSlugAtOffset when a given offset is out of range of the document - so no node is returned from getNodeAtOffset" 2012-06-21 18:19:51 +00:00
Inez Korczynski 82d3040d76 Fix problem in hasSlugAtOffset when a given offset is out of range of the document - so no node is returned from getNodeAtOffset
Change-Id: I91951528c21ddd57f56d7f4854d0e626d96e04a1
2012-06-21 11:09:41 -07:00
Trevor Parscal f35c8adac8 Merge "Aggressive keyboard shortcut fix for all browsers and platforms" 2012-06-21 18:09:24 +00:00