Skip to content

Commit

Permalink
Fixed issue with updating a file link and the Link update popup window.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert Oost committed Jul 16, 2018
1 parent 10e5f7a commit a5b5571
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changed

- Fixed issue with updating a file link and the Link update popup window.
- Fixed issue regarding inserting a file link with correct Craft's Asset referenced-tag `{asset:<id>}`.

## v2.8.4 - 2018-07-15
Expand Down
53 changes: 47 additions & 6 deletions src/assets/field/dist/js/plugins/craft.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,56 @@
);
}

function showFileInsertModal() {
function showFileInsertModal(viaPopup) {
var viaPopup = viaPopup || false,
disabledElementIds = [],
selectedText = (editor.selection.text() || false);

if (viaPopup) {
var $popup = editor.popups.get('link.insert');

// check the src url containing '#asset:{id}[:{transform}]'
var urlValue = $popup.find('input[name="href"]').val();
if (urlValue && urlValue.indexOf('#') !== -1) {

var hashValue = urlValue.substr(urlValue.indexOf('#'));
hashValue = decodeURIComponent(hashValue);

if (hashValue.indexOf(':') !== -1) {
disabledElementIds.push(hashValue.split(':')[1]);
}
}
}

// save selection before modal is shown
editor.selection.save();

var selectedText = (editor.selection.text() || false);

_elementModal(
editor.opts.craftAssetElementType,
editor.opts.craftFileStorageKey,
editor.opts.craftFileSources,
editor.opts.craftFileCriteria,
null,
{
disabledElementIds: disabledElementIds
},
function (elements) {

// re-focus the popup
if (viaPopup && !editor.popups.isVisible('link.insert')) {
editor.popups.show('link.insert');
}

if (elements.length) {
var element = elements[0],
url = element.url + '#' + editor.opts.craftAssetElementRefHandle + ':' + element.id,
title = selectedText.length > 0 ? selectedText : element.label;

editor.link.insert(url, title);
if (viaPopup) {
// no title replace at update
$popup.find('input[name="href"]').val(url);
} else {
editor.link.insert(url, title);
}

return true;
}
Expand Down Expand Up @@ -244,8 +275,18 @@
}
});

$.FE.DefineIcon('craftLinkAsset', { NAME: 'file-o' });
$.FE.RegisterCommand('craftLinkAsset', {
title: 'Link to Craft Asset',
focus: true,
refreshOnCallback: true,
callback: function () {
this.craft.showFileInsertModal(true);
}
});

$.extend($.FE.DEFAULTS, {
linkInsertButtons: ['craftLinkEntry']
linkInsertButtons: ['craftLinkEntry','craftLinkAsset']
});

/*
Expand Down

0 comments on commit a5b5571

Please sign in to comment.