requirejs integration

Questionsrequirejs integration
Chisum asked 8 months ago

is there any requirejs integration magento2 uses it and I really dislike everything about it but I have to use it for this client.  I just keep phpgrid out of the requirejs, the only problem is that there’s no way to delay jQuery being called on load with phpgrid, and any hooks I write to make jquery global aren’t ready yet because requirejs is slow.  I’d need a way to delay the jQuery calls of phpgrid at all until I choose to fire them.  Simply having jQuery load from a script tag breaks other modules that use requirejs and jquery on the page because requirejs should never be used by anyone for any reason.

6 Answers
Abu answered 8 months ago

Hello,

I’ve not tested it with requriejs. Give me some time and i’ll update you back.

Abu answered 8 months ago

One solution could be to move all initialization JS code inside a function and call it when you need.

Edit lib/inc/jqgrid_dist.php

Find this code segment:

< script >
var phpgrid = jQuery(“#<?php echo $grid_id?>”);
var phpgrid_pager = jQuery(“#<?php echo $grid_id.”_pager”?>”);
var fx_ajax_file_upload;
var fx_replace_upload;

…..

jQuery(document).ready(function(){
<?php echo $this->render_js($grid_id,$out);?>
});
< /script >

and then wrap it in a funciton, e.g.

< script >
function phpgrid_init()
{
var phpgrid = jQuery(“#<?php echo $grid_id?>”);
var phpgrid_pager = jQuery(“#<?php echo $grid_id.”_pager”?>”);
var fx_ajax_file_upload;
var fx_replace_upload;

…..

jQuery(document).ready(function(){
<?php echo $this->render_js($grid_id,$out);?>
});
}
< /script >

This way, grid will not call any jQuery code until you call phpgrid_init() function.

Hope it helps.

Abu answered 8 months ago

A little correction, to make phpgrid global JS available, you need to move function vars outside phpgrid_init() declaration.

— script start —
var fx_ajax_file_upload;
var fx_replace_upload;
var fx_bulk_update;
var fx_bulk_unrequire;
var fx_get_dropdown;
var fx_reload_dropdown;
var fx_grid_resize;
var fx_show_form;
var fx_tooltip_init;
var fx_show_view_dialog;

function phpgrid_init()
{
var phpgrid = jQuery(“#<?php echo $grid_id?>”);
var phpgrid_pager = jQuery(“#<?php echo $grid_id.”_pager”?>”);

jQuery(document).ready(function(){
<?php echo $this->render_js($grid_id,$out);?>
});
}

— script end —

Also declare this var outside phpgrid_init:
var fx_tooltip_init;

and replace:
function fx_tooltip_init()

with:
fx_tooltip_init = function ()

Abu Ghufran Staff answered 8 months ago

Just wanted to know if your issue is solved?

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Chisum answered 8 months ago

I keep getting some return not in function error I\’ll have to try again soon

Chisum answered 8 months ago

Your code worked I just had to deal with caching.

I got it to load error free but it was a nightmare for something that would have been braindead simple and no extra work otherwise.   Screw requirejs.

 

require.config({
paths: {
//’jqjquery’: ‘/phpgrid/lib/js/jquery.min’,
‘grid-en’: ‘/phpgrid/lib/js/jqgrid/js/i18n/grid.locale-en’,
‘jqgrid’: ‘/phpgrid/lib/js/jqgrid/js/jquery.jqGrid.min’,
‘jq-ui’: ‘/phpgrid/lib/js/themes/jquery-ui.custom.min’,
},
shim: {
/*’jqjquery’: {
exports:’jquery’
},*/
‘grid-en’: {
deps:[‘jquery’]
},
‘jqgrid’: {
deps:[‘jquery’]
},
‘jq-ui’: {
deps:[‘jquery’]
}
}

});
require([‘jquery’,’grid-en’,’jqgrid’,’jq-ui’], function(jQuery) {

window.$ = jQuery;
window.jQuery = jQuery;
phpgrid_init();
jQuery(document).ready(dobinds);
});

Your Answer

12 + 7 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?