Commit graph

244 commits

Author SHA1 Message Date
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
Christian Williams 9723bf51e5 Switching to localStorage for copy and paste, remove test
Change-Id: I555b8756afb53680d60f2068b8615787c60e9d8f
2012-07-25 17:07:08 -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
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
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
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
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
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 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
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
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
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
Christian Williams 8f7ce742de Aggressive keyboard shortcut fix for all browsers and platforms
Change-Id: Ic9e6359a06752861a05526dba090b08ccd39b83f
2012-06-21 11:09:30 -07:00
Inez Korczynski 847fddd639 Fix for drawing selection in IE - temporary approach
Change-Id: Ia944e4c96b1d1d78274f9c23e7120954f694ca08
2012-06-21 11:04:26 -07:00
Christian Williams f27425eb91 Firefox has some crazy bindings for browser features. This prevents it and properly annotates.
Change-Id: Ide294efda8b661e16f24cc1f3584a8f08785ff5b
2012-06-21 10:33:40 -07:00
Trevor Parscal 861ce8d54f Fixed pressing backspace in a slug, now we just move the cursor to some nearby content
Change-Id: Idaf61264fb493169cfef1c48613036c292d590f0
2012-06-21 00:01:32 -07:00
Inez Korczynski ab16987ae8 Better support for left & right arrow keys
Change-Id: Iad56f8179d3ed90828e31ad0203a5cec9e9d2458
2012-06-20 23:06:47 -07:00
Trevor Parscal 88ef5b1517 Merge "Logic for moving cursor left and right programmatically" 2012-06-21 05:54:50 +00:00
Trevor Parscal 7e892daac9 Merge "Fixing backspace when at the beginning of the document." 2012-06-21 05:52:45 +00:00
Trevor Parscal a7b47a2c00 Merge "Pressing enter in the last listItem, if empty, will exit the list" 2012-06-21 05:50:51 +00:00
Inez Korczynski 9b1e96cd46 Logic for moving cursor left and right programmatically
Change-Id: I48844cfbebaf3933ad61dc462ab5ea73be45a8aa
2012-06-20 22:24:12 -07:00
Christian Williams 4df69b01de Fixing backspace when at the beginning of the document.
Change-Id: Ib4c463c6a1eb27897a39c96c46617047d8ee4325
2012-06-20 21:34:11 -07:00
Inez Korczynski 7eae9cdba6 Support for insertion in slugs.
Change-Id: I8e144206520b59271edf854020b87ce947fe0559
2012-06-20 21:32:26 -07:00
Christian Williams 0ab3b65c03 Pressing enter in the last listItem, if empty, will exit the list
Change-Id: I084fabac09654adf50db97b554e937d2772f9a37
2012-06-20 21:10:48 -07:00
Christian Williams 8556888a9a Fixing handleEnter to allow splitting headlines
Change-Id: I4f75ee1b454f66c4b112a1ab59386994bb249792
2012-06-20 20:02:25 -07:00
Trevor Parscal 9c0b8f57b2 Merge "Use getClonedElement() rather than manually building a node" 2012-06-21 02:40:11 +00:00
Catrope ac835c2d69 Merge "Keyboard shortcuts for bold and italic" 2012-06-21 02:09:28 +00:00
Christian Williams 14054becb5 Keyboard shortcuts for bold and italic
Change-Id: I12b80134152bbbbd2dfa42b32fec072cde29baa5
2012-06-20 19:09:06 -07:00
Catrope 7be404f818 Merge "Removed trailing whitespace and other cruft" 2012-06-21 01:59:57 +00:00
Catrope e8702e8f0f Use getClonedElement() rather than manually building a node
Change-Id: I3d6390830c6a01235e55b1484e161d1f6737ac01
2012-06-20 18:59:12 -07:00
Catrope 7f3106802c Merge "Modified handleEnter to insert a paragraph above/below a non-paragraph if at the edges" 2012-06-21 01:57:58 +00:00
Trevor Parscal 3743b75d59 Modified handleEnter to insert a paragraph above/below a non-paragraph if at the edges
Change-Id: Icfe650890ceb32f77c79347bebdf8be9612cfdbb
2012-06-20 18:57:35 -07:00
Catrope 22677ac475 Merge "When there is a selection range, pressing arrow keys should not remove the selection in Firefox." 2012-06-21 01:48:30 +00:00
Christian Williams 58917f5015 When there is a selection range, pressing arrow keys should not remove the selection in Firefox.
Change-Id: I93bca05dd0f37fd8f87eba3f407a68c922ed66e3
2012-06-20 18:48:02 -07:00
Rob Moen 1462a6cf37 Add commented-out tab key support for indentation button tool
Change-Id: I4741182bb79becf08288287142a930ddf7f547ad
2012-06-20 18:45:44 -07:00
Trevor Parscal 6fe115a563 Removed trailing whitespace and other cruft
Change-Id: I8c439d2a272e01b9e26bfd6b13d9e600d324930b
2012-06-20 17:42:12 -07:00
Christian Williams 93594d1c22 Pressing backspace or delete at boundary of dislike nodes will cause adoption
Change-Id: Idd6cd40c8d4f34081851fc9ea1cc70037915244b
2012-06-20 16:28:13 -07:00
Trevor Parscal bcf93eb695 Automatically bind and unbind context's window event bindings on documentNode focus and blur
Change-Id: Ie43165da49a36a7d0d13a52318d9c5438dad9605
2012-06-20 12:34:20 -07:00
Catrope 6afed5e5cc Move ve2/ back to ve/
Change-Id: Ie51d8e48171fb1f84045d1560ee603cee62b91f6
2012-06-19 18:20:28 -07:00
Inez Korczynski d6ae8390f5 Get rid of selectionDirection. Introduce getDirection() methdo in
ve.Range.

Change-Id: Iaf11b2dbfb7ae82a7f54ee205cd6cdc8ee235aef
2012-04-27 17:36:55 -07:00
Inez Korczynski af6a9f9ccc Created a named method inside a Surface (instead of anonymouse one) to
handle logic for rangeChange event handler.

Change-Id: Ief32e647f9399e3ea47c5613902cebcbaaf4874c
2012-04-27 17:31:49 -07:00
Inez Korczynski f188772259 Introduce new method called "proxy" in surfaceView to avoid using the same
construct with anonynous function over and over.

Change-Id: I1e96cf1efaa6fa5d551fdfa8bb5a80c31e519579
2012-04-26 14:49:12 -07:00
Rob Moen 5fc9f1c7e4 Modify rangeChange event to save selection direction.
Renamed Selection method to more suitable name.
Misc cleanup
Patchset 2, whitespace cleanup
Patchset 3: Change values used with selection direction to -1 or 1
1 for left to right (normal)
-1 for right to left (opposite)
Change-Id: If9ecc721ace1c7550903170f92395947f1ccc22c
2012-04-20 16:27:26 -07:00
Rob Moen d37a325f44 Cleanup terms used in annotation method
Change-Id: I509a1f1b680cc8a2973188f0ed7c7d67b8a15f4f
2012-04-12 16:37:23 -07:00
Rob Moen 961f83d326 Elminiated isSelection method
Determine actual selection from model by checking length

Change-Id: I1c58a4de31b26d49b55c7a2c55c9c6462741bdfb
2012-04-12 14:05:14 -07:00
Rob Moen 28e86c8688 New Method isSelection() in Surface View
Used to properly hide/show Context menu and UI elements.

Change-Id: I8b3750c270651498b7e6c54a1921f5012cf33ea6
2012-04-12 10:22:42 -07:00
Rob Moen b5befb1d57 On annotate, get current selection from model
Fixes link annotation, and any annotation that pops up an inspector as selection is lost.

Change-Id: Idd8812b05f4fddfa4e613dea28a1a8421792656d
2012-04-11 14:15:52 -07:00
Rob Moen 224cc1f9a0 Migrate tools from SurfaceObserver Class
ContextView positioning, Italic, and Bold annotations working

Change-Id: Ifc68bd61c8f27b6a14d314dc2999753af6e0ee04
2012-04-11 13:19:58 -07:00
Inez Korczynski 50acc0c785 Make toolbar and context menu works
Change-Id: Ice981390b22a257158b3417dda3a1945d777cb14
2012-04-06 17:43:14 +02:00
Inez Korczynski 68cf13fb1e getLeafNode is now a static method and should be called as a static method
Change-Id: I4f079523add81ef14537c950b29436422e1de850
2012-04-06 17:13:43 +02:00
Inez Korczynski a57ae2692e Merge changes from branch ce-poll
Change-Id: Ibb6da1ac5229ed5afeda1a3944fe7deff3bfb9a7
2012-04-06 17:10:30 +02:00
Inez Korczynski 090e42c8d9 Just a test
Change-Id: I74fb371a26b4b6068fee593bf7e6ee950080bca8
2012-04-06 16:49:30 +02:00
Trevor Parscal a2eee63525 Updated CSS classes and rules for CE, which for the most part uses native elements
Also:
* Simplified ve.ce.Surface.getLeafNode, which may be better to just be removed and be used inline in the few places it's being used.
* Removed method wrapper for static function ve.ce.Surface.getLeafNode

Change-Id: I1d4cf0bb7ecc8f07f030753e40a13ebef7d02daa
2012-04-04 11:54:06 -07:00
Rob Moen d8de26d7e9 On selection, update selection in the model. Fixes selection.clone() error.
Change-Id: Ibd5cf0398002e5fbb2c50549e4a7043ba8fd00a7
2012-04-02 14:19:53 -07:00
Rob Moen c1300ba949 Fixed surfaceView undefined error
Change-Id: Iba3ae54b4e508afbfa132e0f0b2b0b237e685395
2012-04-02 13:49:45 -07:00
Inez Korczynski 299c77db84 Make LinkInspector works (using annotate method in SurfaceView) 2012-03-16 22:16:15 +00:00
Inez Korczynski b2f4b48a9a Use on and off insteaf of bind and unbind. 2012-03-16 22:01:09 +00:00
Inez Korczynski 6ef8ac182a No more endless looping! And fix getSelectionRect to return document relative coordiantes instead of viewport relative. 2012-03-16 21:52:17 +00:00
Rob Moen cde7a3bf7e adapt LinkInspector to use surfaceObserver for selection 2012-03-16 20:18:26 +00:00
Rob Moen 93376d68eb add surfaceObserver on select methods to ui toolbar and surfaceView for responding to select event. tools now updating to selected node annotations. revise getSelectionRect to return actual start & end pos. context icon properly showing on range selection 2012-03-15 22:06:40 +00:00
Inez Korczynski 294d474c54 Replace CursorObserver and ContentObserver with SurfaceObserver 2012-03-14 00:04:24 +00:00
christian d174809b54 replacing showCursorAt calls with correct showCursor method 2012-03-13 18:12:57 +00:00
christian ba437744b3 preventing native contenteditable resizing tools 2012-03-12 23:06:47 +00:00
Rob Moen 22a351e855 small fix: getSelectionRange was breaking the surface layer, changed to saved state member 2012-03-12 22:04:29 +00:00
Rob Moen 65170e13df port over select event listener, and updateSelection methods for setting and removing context icon, add getSelectionRect method for context icon position 2012-03-12 21:50:22 +00:00
christian 56b9068d03 switch to getSelectionRange and fixing IME native menu 2012-03-12 20:39:08 +00:00
Trevor Parscal 02592b3ec0 More cleanup 2012-03-09 22:55:49 +00:00
Trevor Parscal 60c9c484aa More cleanup (jshint complaints) 2012-03-09 22:51:00 +00:00
christian df4f017b21 preserve range after applying annotation 2012-03-07 23:35:38 +00:00
Inez Korczynski ab496f7bc9 Get rid of showCursorAt method. And replace calls to it with calls to showCursor. 2012-03-07 23:33:41 +00:00
Inez Korczynski 8e56acbaca Added getDOMNodeAndOffset and showSelection methods to Surface. Ohhh and little wrapper around it - showCursor. 2012-03-07 23:32:26 +00:00
christian 76b7127e29 removing usage of rangy anchornode for determining rendering scope - using model and autoRender 2012-03-07 21:41:53 +00:00
Inez Korczynski 73f53e89c6 Small refactoring. Changed method name, from Surface.getSelection to Surface.getSelectionRange. 2012-03-07 21:37:39 +00:00
christian 22ce25dc69 replacing cursor after annotating works 2012-03-07 21:06:07 +00:00
Rob Moen 0520e64d97 port over annotation methods from ES to CE, remove unused renderDomNode method 2012-03-07 19:37:17 +00:00
Rob Moen 73fbbe29ab cleanup whitespace 2012-03-07 19:33:00 +00:00
christian 816a6717a6 adding autoRender property to SurfaceView to enable/disable automatic rendering of view when model is updated 2012-03-07 08:13:12 +00:00
Trevor Parscal a82ddeae51 Fixed some jshint complaints and enforced 100char line endings 2012-03-06 23:51:31 +00:00
Inez Korczynski 2e9ab44719 Update class names, from ve.es to ve.cs, and update code that uses those classes 2012-03-06 22:39:43 +00:00
Inez Korczynski 594a0e6d6c Rename bunch of files from ve.es.* to ve.ce.* (and update references) 2012-03-06 22:35:42 +00:00
Renamed from modules/ve/ce/ve.es.Surface.js (Browse further)