Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paceOptions can't be used because it's placed after pace-js is loaded (and tried to use it during loading) #5

Open
fredeom opened this issue Jun 11, 2021 · 2 comments

Comments

@fredeom
Copy link

fredeom commented Jun 11, 2021

yii2-pace/src/Pace.php

$this->getView()->registerJs('window.paceOptions=' . Json::encode(ArrayHelper::getValue($paceOptions,'options')), \yii\web\View::POS_BEGIN);

yii2-pace/src/PaceAsset.php

'position' => \yii\web\View::POS_HEAD

You place pace-js library in head and window.paceOptions={...} after that in body, so it isn't used.

Am I right?

@thtmorais
Copy link
Owner

thtmorais commented Jul 6, 2021

Hello @fredeom , all right?

Yes, you right.

You can open a PR?

@fredeom
Copy link
Author

fredeom commented Jul 7, 2021

Hello @fredeom , all right?

Yes, you right.

You can open a PR?

Yes, I can. Yes I would, but I don't.

I've added pace-js in asset bundle and registered my own script with paceOptions there.
Added pace-js hooks on concrete links and am controling ajax calls.

{
  "require": {
    "npm-asset/pace-js": "^1.2",
  }
}
class AppAsset extends AssetBundle
{
    public $js = [
        'js/paceOptions.js',
    ];
}
class PaceAsset extends AssetBundle
{
    public $sourcePath = "@npm/pace-js/";

    public $js = [
        YII_DEBUG ? 'pace.js' : 'pace.min.js'
    ];

    public $jsOptions = [
        'position' => \yii\web\View::POS_END
    ];

    public $depends = [
        'app\assets\AppAsset'
    ];
}
AppAsset::register($this);
PaceAsset::register($this);
paceOptions = {
    ajax: true,
    startOnPageLoad: false,
}
$(".long-get-request").on("click", function (e) {
    e.preventDefault();
    $('#overlay').show();
    Pace.start();
    $.get(e.target.href, () => {
        $('#overlay').hide();
        Pace.stop();
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants