Skip to content

Commit f6143ae

Browse files
committed
Initial commit
0 parents  commit f6143ae

File tree

10 files changed

+366
-0
lines changed

10 files changed

+366
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © 2017 Ihor Vansach ([email protected]). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\RocketJavaScript\Block\Adminhtml\System\Config\Form;
10+
11+
use Magento\Store\Model\ScopeInterface;
12+
13+
/**
14+
* Admin blog configurations information block
15+
*/
16+
class Info extends \Magento\Config\Block\System\Config\Form\Field
17+
{
18+
/**
19+
* @var \Magento\Framework\Module\ModuleListInterface
20+
*/
21+
protected $moduleList;
22+
23+
/**
24+
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
25+
* @param \Magento\Backend\Block\Template\Context $context
26+
* @param array $data
27+
*/
28+
public function __construct(
29+
\Magento\Framework\Module\ModuleListInterface $moduleList,
30+
\Magento\Backend\Block\Template\Context $context,
31+
array $data = []
32+
) {
33+
parent::__construct($context, $data);
34+
$this->moduleList = $moduleList;
35+
}
36+
37+
/**
38+
* Return info block html
39+
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
40+
* @return string
41+
*/
42+
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
43+
{
44+
$m = $this->moduleList->getOne($this->getModuleName());
45+
$html = '<div style="padding:10px;background-color:#f8f8f8;border:1px solid #ddd;margin-bottom:7px;">
46+
Rocket JavaScript Extension v' . $m['setup_version'] . ' was developed by <a href="http://magefan.com/" target="_blank">Magefan</a>.
47+
</div>';
48+
49+
return $html;
50+
}
51+
52+
}

LICENSE.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work:
2+
3+
Licensed under the Open Software License version 3.0
4+
5+
1) Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:
6+
7+
a) to reproduce the Original Work in copies, either alone or as part of a collective work;
8+
9+
b) to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work;
10+
11+
c) to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License;
12+
13+
d) to perform the Original Work publicly; and
14+
15+
e) to display the Original Work publicly.
16+
17+
2) Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
18+
19+
3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.
20+
21+
4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.
22+
23+
5) External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).
24+
25+
6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
26+
27+
7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.
28+
29+
8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.
30+
31+
9) Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).
32+
33+
10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
34+
35+
11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.
36+
37+
12) Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
38+
39+
13) Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
40+
41+
14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
42+
43+
15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
44+
45+
16) Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.

Model/Controller/ResultPlugin.php

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Copyright © 2017 Ihor Vansach ([email protected]). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\RocketJavaScript\Model\Controller;
10+
11+
use Magento\Framework\App\Response\Http as ResponseHttp;
12+
13+
/**
14+
* Plugin for processing relocation of javascript
15+
*/
16+
class ResultPlugin
17+
{
18+
const EXCLUDE_FLAG_PATTERN = 'data-rocketjavascript="false"';
19+
20+
/**
21+
* Core store config
22+
*
23+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
24+
*/
25+
protected $scopeConfig;
26+
27+
/**
28+
* Request
29+
* @var \Magento\Framework\App\RequestInterface
30+
*/
31+
protected $request;
32+
33+
/**
34+
* @param \Magento\Framework\App\RequestInterface $request
35+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
36+
*/
37+
public function __construct(
38+
\Magento\Framework\App\RequestInterface $request,
39+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
40+
) {
41+
$this->request = $request;
42+
$this->scopeConfig = $scopeConfig;
43+
}
44+
45+
/**
46+
* @param \Magento\Framework\Controller\ResultInterface $subject
47+
* @param callable $proceed
48+
* @param ResponseHttp $response
49+
* @return \Magento\Framework\Controller\ResultInterface
50+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
51+
*/
52+
public function aroundRenderResult(
53+
\Magento\Framework\Controller\ResultInterface $subject,
54+
\Closure $proceed,
55+
ResponseHttp $response
56+
) {
57+
$result = $proceed($response);
58+
59+
if ($this->request->isXmlHttpRequest() || !$this->isEnabled()) {
60+
return $result;
61+
}
62+
63+
$html = $response->getBody();
64+
65+
$patterns = [
66+
'js' => '#(\s*<!--(\[if[^\n]*>)?\s*(<script.*</script>)+\s*(<!\[endif\])?-->)|(\s*<script.*</script>)#isU',
67+
];
68+
69+
$jsHtml = [];
70+
71+
foreach ($patterns as $pattern) {
72+
$matches = array();
73+
$success = preg_match_all($pattern, $html, $matches);
74+
if ($success) {
75+
foreach ($matches[0] as $i => $js) {
76+
if (strpos($js, self::EXCLUDE_FLAG_PATTERN) !== false) {
77+
unset($matches[0][$i]);
78+
} else {
79+
$jsHtml[] = $matches[0][$i];
80+
}
81+
}
82+
83+
$html = str_replace($matches[0], '', $html);
84+
}
85+
}
86+
87+
$jsHtml = implode($jsHtml);
88+
if ($end = strrpos($html, '</body>')) {
89+
$html = substr($html, 0, $end) . $jsHtml . substr($html, $end);
90+
} else {
91+
$html .= $jsHtml;
92+
}
93+
94+
$response->setBody($html);
95+
96+
return $result;
97+
}
98+
99+
private function isEnabled()
100+
{
101+
return $this->scopeConfig->getValue(
102+
'mfrocketjavascript/general/enabled',
103+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
104+
);
105+
}
106+
}

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# [Magefan](http://magefan.com/) Rocket JavaScript Extension for Magento 2
2+
3+
Move all javascripts to the footer.
4+
5+
## Features
6+
* Rocket JavaScript module allows you to move all javascript tags to the footer of the storefront page on your [Magento 2](http://magento.com/) Store.
7+
8+
## Configuration
9+
* To enable or disable extension please navigate to Magento 2 Admin Panel > Stores > Magefan Extensions > Rocket JavaScript
10+
11+
## Requirements
12+
* Magento Community Edition 2.1.x or Magento Enterprise Edition 2.1.x
13+
14+
## Installation Method 1 - Installing via composer
15+
* Open command line
16+
* Using command "cd" navigate to your magento2 root directory
17+
* Run command: composer require magefan/module-rocketjavascript
18+
19+
20+
## Installation Method 2 - Installing using archive
21+
* Download [ZIP Archive](https://github.com/magefan/module-rocketjavascript/archive/master.zip)
22+
* Extract files
23+
* In your Magento 2 root directory create folder app/code/Magefan/Blog
24+
* Copy files and folders from archive to that folder
25+
* In command line, using "cd", navigate to your Magento 2 root directory
26+
* Run commands:
27+
```
28+
php bin/magento setup:upgrade
29+
php bin/magento setup:di:compile
30+
php bin/magento setup:static-content:deploy
31+
```
32+
33+
## Support
34+
If you have any issues, please [contact us](mailto:[email protected])
35+
then if you still need help, open a bug report in GitHub's
36+
[issue tracker](https://github.com/magefan/module-rocketjavascript/issues).
37+
38+
Please do not use Magento Marketplace's Reviews or (especially) the Q&A for support.
39+
There isn't a way for us to reply to reviews and the Q&A moderation is very slow.
40+
41+
## Donate to us
42+
All Magefan extension are absolutely free and licensed under the Open Software License version 3.0. We want to create more awesome features for you and bring up new releases as fast as we can. We hope for your support.
43+
http://magefan.com/donate/
44+
45+
## License
46+
The code is licensed under [Open Software License ("OSL") v. 3.0](http://opensource.org/licenses/osl-3.0.php).

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "magefan/module-rocketjavascript",
3+
"description": "Move all javascripts to the footer on Magento 2 store.",
4+
"type": "magento2-module",
5+
"version": "2.0.0",
6+
"license": "OSL-3.0",
7+
"authors": [
8+
{
9+
"name": "Magefan",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"autoload": {
14+
"files": [
15+
"registration.php"
16+
],
17+
"psr-4": {
18+
"Magefan\\RocketJavaScript\\": ""
19+
}
20+
}
21+
}

etc/acl.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © 2017 Ihor Vansach ([email protected]). All rights reserved.
5+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
6+
*
7+
* Glory to Ukraine! Glory to the heroes!
8+
*/
9+
-->
10+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
11+
<acl>
12+
<resources>
13+
<resource id="Magento_Backend::admin">
14+
<resource id="Magento_Backend::stores">
15+
<resource id="Magento_Backend::stores_settings">
16+
<resource id="Magento_Config::config">
17+
<resource id="Magefan_RocketJavaScript::config_magefan_rocketjavascript" title="Rocket JavasSript"/>
18+
</resource>
19+
</resource>
20+
</resource>
21+
</resource>
22+
</resources>
23+
</acl>
24+
</config>

etc/adminhtml/system.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © 2017 Ihor Vansach ([email protected]). All rights reserved.
5+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
6+
*
7+
* Glory to Ukraine! Glory to the heroes!
8+
*/
9+
-->
10+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
11+
<system>
12+
<tab id="magefan" sortOrder="110" translate="label">
13+
<label>Magefan Extensions</label>
14+
</tab>
15+
<section id="mfrocketjavascript" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
16+
<label>Rocket JavasSript</label>
17+
<tab>magefan</tab>
18+
<resource>Magefan_RocketJavaScript::config_magefan_rocketjavascript</resource>
19+
<group id="general" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
20+
<label>General</label>
21+
<attribute type="expanded">1</attribute>
22+
<field id="version" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
23+
<frontend_model>Magefan\RocketJavaScript\Block\Adminhtml\System\Config\Form\Info</frontend_model>
24+
</field>
25+
<field id="enabled" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="20" translate="label" type="select">
26+
<label>Enabled</label>
27+
<comment>If enabled all JavaScript on storefront will be moved to the end of the page.</comment>
28+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
29+
</field>
30+
</group>
31+
</section>
32+
</system>
33+
</config>

0 commit comments

Comments
 (0)