Skip to content

Commit

Permalink
Updated the Link tool to support for fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjb committed Aug 18, 2017
1 parent 1dd9eaf commit 1d6d484
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 7 deletions.
10 changes: 10 additions & 0 deletions build/content-tools.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/content-tools.min.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/content-tools.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ContentTools",
"description": "A JS library for building WYSIWYG editors for HTML content",
"version": "1.5.1",
"version": "1.5.2",
"keywords": [
"wysiwyg",
"inline",
Expand Down
9 changes: 9 additions & 0 deletions sandbox/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ <h1 data-fixture data-name="article-title">
5 rules for naming variables
</h1>

<a
data-ce-tag="p"
data-fixture
data-name="article-title"
href="/test"
>
Test link fixture
</a>

<div
data-ce-tag="img-fixture"
data-fixture
Expand Down
2 changes: 1 addition & 1 deletion sandbox/sandbox.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! ContentTools v1.4.0 by Anthony Blackshaw <[email protected]> (https://github.com/anthonyjb) */
/*! ContentTools v1.5.1 by Anthony Blackshaw <[email protected]> (https://github.com/anthonyjb) */
@charset "UTF-8";
/* Vendor */
html {
Expand Down
5 changes: 4 additions & 1 deletion sandbox/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
window.ImageUploader = ImageUploader;

window.onload = function() {
var FIXTURE_TOOLS, IMAGE_FIXTURE_TOOLS, editor, req;
var FIXTURE_TOOLS, IMAGE_FIXTURE_TOOLS, LINK_FIXTURE_TOOLS, editor, req;
ContentTools.IMAGE_UPLOADER = ImageUploader.createImageUploader;
ContentTools.StylePalette.add([new ContentTools.Style('By-line', 'article__by-line', ['p']), new ContentTools.Style('Caption', 'article__caption', ['p']), new ContentTools.Style('Example', 'example', ['pre']), new ContentTools.Style('Example + Good', 'example--good', ['pre']), new ContentTools.Style('Example + Bad', 'example--bad', ['pre'])]);
editor = ContentTools.EditorApp.get();
Expand All @@ -160,11 +160,14 @@
});
FIXTURE_TOOLS = [['undo', 'redo', 'remove']];
IMAGE_FIXTURE_TOOLS = [['undo', 'redo', 'image']];
LINK_FIXTURE_TOOLS = [['undo', 'redo', 'link']];
ContentEdit.Root.get().bind('focus', function(element) {
var tools;
if (element.isFixed()) {
if (element.type() === 'ImageFixture') {
tools = IMAGE_FIXTURE_TOOLS;
} else if (element.tagName() === 'a') {
tools = LINK_FIXTURE_TOOLS;
} else {
tools = FIXTURE_TOOLS;
}
Expand Down
3 changes: 3 additions & 0 deletions src/sandbox/sandbox.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ window.onload = () ->
# Handle tools available to fixtures
FIXTURE_TOOLS = [['undo', 'redo', 'remove']]
IMAGE_FIXTURE_TOOLS = [['undo', 'redo', 'image']]
LINK_FIXTURE_TOOLS = [['undo', 'redo', 'link']]
ContentEdit.Root.get().bind 'focus', (element) ->
# Determine what tools should be available to the user
if element.isFixed()
if element.type() is 'ImageFixture'
tools = IMAGE_FIXTURE_TOOLS
else if element.tagName() == 'a'
tools = LINK_FIXTURE_TOOLS
else
tools = FIXTURE_TOOLS
else
Expand Down
16 changes: 16 additions & 0 deletions src/scripts/tools.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
if element.a
return element.a[attrName]

# Fixtures
else if element.isFixed() and element.tagName() is 'a'
return element.attr(attrName)

# Text
else
# Find the first character in the selected text that has an `a` tag
Expand All @@ -203,6 +207,8 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
# element/selection.
if element.type() is 'Image'
return true
else if element.isFixed() and element.tagName() is 'a'
return true
else
# Must support content
unless element.content
Expand All @@ -226,6 +232,8 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
# element/selection.
if element.type() is 'Image'
return element.a
else if element.isFixed() and element.tagName() is 'a'
return true
else
return super(element, selection)

Expand All @@ -246,6 +254,10 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
# Images
rect = element.domElement().getBoundingClientRect()

else if element.isFixed() and element.tagName() is 'a'
# Fixtures
rect = element.domElement().getBoundingClientRect()

else
# If the selection is collapsed then we need to select the entire
# entire link.
Expand Down Expand Up @@ -371,6 +383,10 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
element.unmount()
element.mount()

else if element.isFixed() and element.tagName() is 'a'
# Fixtures
element.attr('href', detail.href)

else
# Text elements

Expand Down

0 comments on commit 1d6d484

Please sign in to comment.