Skip to content

Commit 1d6d484

Browse files
committed
Updated the Link tool to support for fixtures.
1 parent 1dd9eaf commit 1d6d484

File tree

9 files changed

+48
-7
lines changed

9 files changed

+48
-7
lines changed

build/content-tools.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/content-tools.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/content-tools.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ContentTools",
33
"description": "A JS library for building WYSIWYG editors for HTML content",
4-
"version": "1.5.1",
4+
"version": "1.5.2",
55
"keywords": [
66
"wysiwyg",
77
"inline",

sandbox/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ <h1 data-fixture data-name="article-title">
1414
5 rules for naming variables
1515
</h1>
1616

17+
<a
18+
data-ce-tag="p"
19+
data-fixture
20+
data-name="article-title"
21+
href="/test"
22+
>
23+
Test link fixture
24+
</a>
25+
1726
<div
1827
data-ce-tag="img-fixture"
1928
data-fixture

sandbox/sandbox.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! ContentTools v1.4.0 by Anthony Blackshaw <[email protected]> (https://github.com/anthonyjb) */
1+
/*! ContentTools v1.5.1 by Anthony Blackshaw <[email protected]> (https://github.com/anthonyjb) */
22
@charset "UTF-8";
33
/* Vendor */
44
html {

sandbox/sandbox.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
window.ImageUploader = ImageUploader;
139139

140140
window.onload = function() {
141-
var FIXTURE_TOOLS, IMAGE_FIXTURE_TOOLS, editor, req;
141+
var FIXTURE_TOOLS, IMAGE_FIXTURE_TOOLS, LINK_FIXTURE_TOOLS, editor, req;
142142
ContentTools.IMAGE_UPLOADER = ImageUploader.createImageUploader;
143143
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'])]);
144144
editor = ContentTools.EditorApp.get();
@@ -160,11 +160,14 @@
160160
});
161161
FIXTURE_TOOLS = [['undo', 'redo', 'remove']];
162162
IMAGE_FIXTURE_TOOLS = [['undo', 'redo', 'image']];
163+
LINK_FIXTURE_TOOLS = [['undo', 'redo', 'link']];
163164
ContentEdit.Root.get().bind('focus', function(element) {
164165
var tools;
165166
if (element.isFixed()) {
166167
if (element.type() === 'ImageFixture') {
167168
tools = IMAGE_FIXTURE_TOOLS;
169+
} else if (element.tagName() === 'a') {
170+
tools = LINK_FIXTURE_TOOLS;
168171
} else {
169172
tools = FIXTURE_TOOLS;
170173
}

src/sandbox/sandbox.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ window.onload = () ->
4444
# Handle tools available to fixtures
4545
FIXTURE_TOOLS = [['undo', 'redo', 'remove']]
4646
IMAGE_FIXTURE_TOOLS = [['undo', 'redo', 'image']]
47+
LINK_FIXTURE_TOOLS = [['undo', 'redo', 'link']]
4748
ContentEdit.Root.get().bind 'focus', (element) ->
4849
# Determine what tools should be available to the user
4950
if element.isFixed()
5051
if element.type() is 'ImageFixture'
5152
tools = IMAGE_FIXTURE_TOOLS
53+
else if element.tagName() == 'a'
54+
tools = LINK_FIXTURE_TOOLS
5255
else
5356
tools = FIXTURE_TOOLS
5457
else

src/scripts/tools.coffee

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
182182
if element.a
183183
return element.a[attrName]
184184

185+
# Fixtures
186+
else if element.isFixed() and element.tagName() is 'a'
187+
return element.attr(attrName)
188+
185189
# Text
186190
else
187191
# Find the first character in the selected text that has an `a` tag
@@ -203,6 +207,8 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
203207
# element/selection.
204208
if element.type() is 'Image'
205209
return true
210+
else if element.isFixed() and element.tagName() is 'a'
211+
return true
206212
else
207213
# Must support content
208214
unless element.content
@@ -226,6 +232,8 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
226232
# element/selection.
227233
if element.type() is 'Image'
228234
return element.a
235+
else if element.isFixed() and element.tagName() is 'a'
236+
return true
229237
else
230238
return super(element, selection)
231239

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

257+
else if element.isFixed() and element.tagName() is 'a'
258+
# Fixtures
259+
rect = element.domElement().getBoundingClientRect()
260+
249261
else
250262
# If the selection is collapsed then we need to select the entire
251263
# entire link.
@@ -371,6 +383,10 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
371383
element.unmount()
372384
element.mount()
373385

386+
else if element.isFixed() and element.tagName() is 'a'
387+
# Fixtures
388+
element.attr('href', detail.href)
389+
374390
else
375391
# Text elements
376392

0 commit comments

Comments
 (0)