Skip to content

Support for script dependencies#12

Closed
csrui wants to merge 3 commits intogetherbert:devfrom
csrui:patch-1
Closed

Support for script dependencies#12
csrui wants to merge 3 commits intogetherbert:devfrom
csrui:patch-1

Conversation

@csrui
Copy link

@csrui csrui commented Jul 31, 2015

Implements script dependencies through the use:

$enqueue->front([
    'as'     => 'ShirtCreatorInterface',
    'src'    => Helper::assetUrl('/js/app.js'),
    'dep'   => ['jquery'],
    'filter' => [ 'page' => '*' ]
]);

Implements script dependencies through the use:

```
$enqueue->front([
    'as'     => 'ShirtCreatorInterface',
    'src'    => Helper::assetUrl('/js/app.js'),
    'dep'   => ['jquery'],
    'filter' => [ 'page' => '*' ]
]);
```
@csrui csrui mentioned this pull request Aug 5, 2015
@ConnorVG
Copy link
Contributor

ConnorVG commented Aug 5, 2015

This makes sense to me. Though, you should allow dep to be passed a string if there is only one of them, for sure 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd either new line this and use curlies or, on L77 use array_get($attrs, 'dep', []) instead.

@csrui
Copy link
Author

csrui commented Aug 5, 2015

Most definitely a worthy improvement. Will take care of that.

csrui added 2 commits August 9, 2015 18:02
Improve dependency attributes fetching for enqueue.
Changes the way scripts are called now using wp_register_script first in order to localize scripts.

Ex:

```
$enqueue->front([
    'as'     => 'MyScript',
    'src'    => Helper::assetUrl('/js/app.js'),
    'dep'   => 'jquery',
    'filter' => [ 'page' => '*' ],
    'localize' =>  array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) )
]);
```
@csrui
Copy link
Author

csrui commented Aug 9, 2015

Not sure if I should have created a new branch but since the source code affects the same area...

@JacobDorman
Copy link

+1

@PrafullaKumarSahu
Copy link

@csrui I have just started learning herbert from nearly a month and I do feel like a looser, as I am unable to do things usually I can do in wordpress, in last one month, using even your code


public function __construct(Enqueue $enqueue){
        $this->enqueue = $enqueue;
    }


    $this->enqueue->front([
            'as' => 'analytica',
            'src' => Helper::assetUrl('/jquery/analytica.js'),
            'dep' => ['jquery'],
            'filter' => [ 'page' => '*' ]
        ]);






It gives me error Fatal error: Using $this when not in object context in E:\plugins\Analytica\app\Controllers\AnalyticaController.php on line 168

and if I will call front with Enqueue::fronT() , it gives me no error neither it enqueue the script.

@tormjens
Copy link
Contributor

Hi @PrafullaKumarSahu

You need can't use $this directly in a class without having it in a method.

Move your code up to the __construct-method, should work.

public function __construct(Enqueue $enqueue){
        $this->enqueue = $enqueue;

        $this->enqueue->front([
            'as' => 'analytica',
            'src' => Helper::assetUrl('/jquery/analytica.js'),
            'dep' => ['jquery'],
            'filter' => [ 'page' => '*' ]
        ]);
}

@PrafullaKumarSahu
Copy link

Hi @tormjens I have already solved this issue by en-queuing my scripts in enqueue.php
like below, any way thank you for your effort.

<?php namespace Analytica;

/** @var \Herbert\Framework\Enqueue $enqueue */

$enqueue->admin([
    'as'     => 'jquery',
    'src'    => 'jquery',
    'filter' => [ 'panel' => 'analytica-admin-settings' ]
]);

$enqueue->admin([
    'as'  => 'popup',
    'src' => Helper::assetUrl('/jquery/popup.js'), // => /resources/assets/js/popup.js
], 'footer');

$enqueue->admin([
    'as'  => 'analytica',
    'src' => Helper::assetUrl('/jquery/analytica.js'), // => /resources/assets/js/analytica.js
    'filter' => ['panel'=>'analytica-admin-settings']

], 'footer');

$enqueue->admin([
    'as'     => 'jquery-ui-datepicker',
    'src'    => 'jquery-ui-datepicker',
    'filter' => [ 'panel' => 'analytica-admin-settings' ]
], 'footer');

$enqueue->admin([
    'as'     => 'jquery-ui-datepicker',
    'src'    => 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css',
    'filter' => [ 'panel' => 'analytica-admin-settings' ]
]);

$enqueue->admin([
    'as'     => 'datepicker',
    'src'    => Helper::assetUrl('/jquery/datepicker.js'),
    'filter' => [ 'panel' => 'analytica-admin-settings' ]
], 'footer');

@jeremyzahner
Copy link
Contributor

@onnimonni This feature is crucial. Since the commits look firm, I see no reason for further delaying a merge.

@jeremyzahner
Copy link
Contributor

@csrui Could you resolve the merge conflicts? Thanks!

@jeremyzahner
Copy link
Contributor

@csrui Ping. =)

@csrui csrui closed this Sep 25, 2018
@csrui
Copy link
Author

csrui commented Sep 25, 2018

This project seems dead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants