-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f4f134a
Showing
15 changed files
with
535 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Element Link Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## 1.0.0 - 2019-05-07 | ||
### Added | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Marion Newlevant | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Element Link plugin for Craft CMS 3.x | ||
|
||
Add a link to the CP edit page for Entries, Categories, and other Elements | ||
|
||
![Screenshot](resources/screenshots/ElementLink.png) | ||
|
||
## Requirements | ||
|
||
This plugin requires Craft CMS 3.0.0-beta.23 or later. | ||
|
||
## Installation | ||
|
||
To install the plugin, follow these instructions. | ||
|
||
1. Open your terminal and go to your Craft project: | ||
|
||
cd /path/to/project | ||
|
||
2. Then tell Composer to load the plugin: | ||
|
||
composer require craft-element_link/element-link | ||
|
||
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Element Link. | ||
|
||
or | ||
|
||
1. Install via the Plugin Store | ||
|
||
Brought to you by [Marion Newlevant](http://marion.newlevant.com) | ||
|
||
Inspired in part by the [Download Assets](https://plugins.craftcms.com/download-assets) plugin. | ||
|
||
Icon: link by Gregor Cresnar from the Noun Project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "marionnewlevant/element-link", | ||
"description": "Add a link to the CP edit page for Entries, Categories, and other Elements", | ||
"type": "craft-plugin", | ||
"version": "1.0.0", | ||
"keywords": [ | ||
"craft", | ||
"cms", | ||
"craftcms", | ||
"craft-plugin", | ||
"element link" | ||
], | ||
"support": { | ||
"docs": "https://github.com/craft-element_link/element-link/blob/master/README.md", | ||
"issues": "https://github.com/craft-element_link/element-link/issues" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Marion Newlevant", | ||
"homepage": "http://marion.newlevant.com" | ||
} | ||
], | ||
"require": { | ||
"craftcms/cms": "^3.0.0-RC1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"marionnewlevant\\elementlink\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"name": "Element Link", | ||
"handle": "element-link", | ||
"hasCpSettings": false, | ||
"hasCpSection": false, | ||
"changelogUrl": "https://raw.githubusercontent.com/craft-element_link/element-link/master/CHANGELOG.md", | ||
"components": { | ||
"elementLinkService": "marionnewlevant\\elementlink\\services\\ElementLinkService" | ||
}, | ||
"class": "marionnewlevant\\elementlink\\ElementLink" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* Element Link plugin for Craft CMS 3.x | ||
* | ||
* Add a link to the CP edit page for Entries, Categories, and other Elements | ||
* | ||
* @link http://marion.newlevant.com | ||
* @copyright Copyright (c) 2019 Marion Newlevant | ||
*/ | ||
|
||
namespace marionnewlevant\elementlink; | ||
|
||
use marionnewlevant\elementlink\assetbundles\elementlink\ElementLinkAsset; | ||
|
||
use Craft; | ||
use craft\base\Plugin; | ||
|
||
/** | ||
* | ||
* @author Marion Newlevant | ||
* @package ElementLink | ||
* @since 1.0.0 | ||
* | ||
* @property ElementLinkServiceService $elementLinkService | ||
*/ | ||
class ElementLink extends Plugin | ||
{ | ||
// Static Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* Static property that is an instance of this plugin class so that it can be accessed via | ||
* ElementLink::$plugin | ||
* | ||
* @var ElementLink | ||
*/ | ||
public static $plugin; | ||
|
||
// Public Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* To execute your plugin’s migrations, you’ll need to increase its schema version. | ||
* | ||
* @var string | ||
*/ | ||
public $schemaVersion = '1.0.0'; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* Set our $plugin static property to this class so that it can be accessed via | ||
* ElementLink::$plugin | ||
* | ||
* Called after the plugin class is instantiated; do any one-time initialization | ||
* here such as hooks and events. | ||
* | ||
* If you have a '/vendor/autoload.php' file, it will be loaded for you automatically; | ||
* you do not need to load it in your init() method. | ||
* | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
self::$plugin = $this; | ||
|
||
if (Craft::$app->getRequest()->getIsCpRequest() && !Craft::$app->getUser()->getIsGuest() && !Craft::$app->getRequest()->getIsAjax()) | ||
{ | ||
// Register our asset bundle | ||
Craft::$app->getView()->registerAssetBundle(ElementLinkAsset::class); | ||
} | ||
|
||
Craft::info( | ||
Craft::t( | ||
'element-link', | ||
'{name} plugin loaded', | ||
['name' => $this->name] | ||
), | ||
__METHOD__ | ||
); | ||
} | ||
|
||
// Protected Methods | ||
// ========================================================================= | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace marionnewlevant\elementlink\assetbundles\ElementLink; | ||
|
||
use Craft; | ||
use craft\web\AssetBundle; | ||
use craft\web\assets\cp\CpAsset; | ||
|
||
/** | ||
* ElementLinkAsset AssetBundle | ||
* | ||
* AssetBundle represents a collection of asset files, such as CSS, JS, images. | ||
* | ||
* Each asset bundle has a unique name that globally identifies it among all asset bundles used in an application. | ||
* The name is the [fully qualified class name](http://php.net/manual/en/language.namespaces.rules.php) | ||
* of the class representing it. | ||
* | ||
* An asset bundle can depend on other asset bundles. When registering an asset bundle | ||
* with a view, all its dependent asset bundles will be automatically registered. | ||
* | ||
* http://www.yiiframework.com/doc-2.0/guide-structure-assets.html | ||
* | ||
* | ||
* @author Marion Newlevant | ||
* @package ElementLink | ||
* @since 1.0.0 | ||
*/ | ||
class ElementLinkAsset extends AssetBundle | ||
{ | ||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* Initializes the bundle. | ||
*/ | ||
public function init() | ||
{ | ||
// define the path that your publishable resources live | ||
$this->sourcePath = "@marionnewlevant/elementlink/assetbundles/elementlink/dist"; | ||
|
||
// define the dependencies | ||
$this->depends = [ | ||
CpAsset::class, | ||
]; | ||
|
||
// define the relative path to CSS/JS files that should be registered with the page | ||
// when this asset bundle is registered | ||
$this->js = [ | ||
'js/elementlink.js', | ||
]; | ||
|
||
$this->css = [ | ||
'css/elementlink.css', | ||
]; | ||
|
||
parent::init(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
positioning with css. The .linked class is from download assets plugin. | ||
*/ | ||
/* styles to make space on the label */ | ||
body.ltr .element.elementLinkYes .label { | ||
padding-right: 20px; | ||
} | ||
body.ltr .element.elementLinkYes.linked .label { | ||
padding-right: 40px; | ||
} | ||
|
||
body.ltr .element.removable.elementLinkYes .label { | ||
padding-right: 40px; | ||
} | ||
body.ltr .element.removable.elementLinkYes.linked .label { | ||
padding-right: 60px; | ||
} | ||
|
||
body.rtl .element.elementLinkYes .label { | ||
padding-left: 20px; | ||
} | ||
body.rtl .element.elementLinkYes.linked .label { | ||
padding-left: 40px; | ||
} | ||
|
||
body.rtl .element.removable.elementLinkYes .label { | ||
padding-left: 40px; | ||
} | ||
body.rtl .element.removable.elementLinkYes.linked .label { | ||
padding-left: : 60px; | ||
} | ||
|
||
/* anchor styles */ | ||
body.ltr .element .elementLink { | ||
position: absolute; | ||
right: 22px; | ||
} | ||
|
||
body.ltr .element.linked .elementLink { | ||
right: 42px; | ||
} | ||
|
||
body.rtl .element .elementLink { | ||
position: absolute; | ||
left: 22px; | ||
} | ||
|
||
body.rtl .element.linked .elementLink { | ||
left: 42px; | ||
} | ||
|
||
.element .elementLink::before { | ||
content: ''; | ||
display: inline-block; | ||
width: 19px; | ||
height: 14px; | ||
background-image: url('../img/elementLink.svg'); | ||
background-size: 19px 14px; | ||
line-height: 1; | ||
vertical-align: middle; | ||
} | ||
|
||
.element .elementLink:hover::before { | ||
background-image: url('../img/elementLink-focus.svg'); | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
src/assetbundles/elementlink/dist/img/elementLink-focus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
$(function () { // for namespacing if nothing else... | ||
var g_lastRequest = null; | ||
|
||
// called every second to look for new elements to add the cp link to | ||
var addLinks = function() { | ||
// find the elements not yet tagged w/ class .elementLink | ||
var $elements = $('.field .input .element:not(.elementLink)'); | ||
|
||
$elements.each(function() { | ||
var $thisElement = $(this); | ||
var $label = $thisElement.find('.label'); | ||
$thisElement.addClass('elementLink'); | ||
// phone home to get the cpEditUrl for the element | ||
g_lastRequest = Craft.postActionRequest( | ||
'element-link/default/element-edit-url', | ||
{ | ||
elementType: $thisElement.data('type'), | ||
elementId: $thisElement.data('id'), | ||
siteId: $thisElement.data('site-id') | ||
}, | ||
function(response, textStatus) { | ||
if (textStatus == 'success' && response && response['editUrl']) { | ||
// add the link to the dom | ||
$thisElement.addClass('elementLinkYes'); | ||
var $a = $('<a>', { | ||
class: 'elementLink', | ||
target: '_blank', | ||
href: response['editUrl'] | ||
}); | ||
$a.insertBefore($label); | ||
} | ||
} | ||
); | ||
}); | ||
}; | ||
|
||
addLinks(); | ||
window.setInterval(addLinks, 1000); | ||
}); |
Oops, something went wrong.