Skip to content

[#32665] Feature jquery keepalive#2494

Closed
Chris-Jones-Gill wants to merge 10 commits intojoomla:masterfrom
Chris-Jones-Gill:feature-jquery-keepalive
Closed

[#32665] Feature jquery keepalive#2494
Chris-Jones-Gill wants to merge 10 commits intojoomla:masterfrom
Chris-Jones-Gill:feature-jquery-keepalive

Conversation

@Chris-Jones-Gill
Copy link
Copy Markdown

Change the keepalive function to use jQuery instead of MooTools.

Tracker http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=32665&start=600

.gitignore Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This file should not be part of the PR imho.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ooops, it should not have been. How do I remove it?

@wilsonge
Copy link
Copy Markdown
Contributor

You need to fix the unit tests for this :) To do so just remove the JHtml framework part of the array out here: https://github.com/KISS-Web-Design/joomla-cms/blob/feature-jquery-keepalive/tests/unit/suites/libraries/cms/html/JHtmlBehaviorTest.php#L640

If you being really good you might even add to the test to make sure jQuery is present

@piotr-cz
Copy link
Copy Markdown
Contributor

What about moving the keepAlive function to the jQuery().ready so it doesn't leak to global scope?

Also I'd like to see newlines at the beginning and end of script, otherwise rendered page source code becomes unreadable when there are few scripts placed one after another.

// Attach keep alive to document
JFactory::getDocument()->addScriptDeclaration('
    jQuery(document).ready(function() {
        window.setInterval(
            function(){ new jQuery.ajax({ type: "GET" }); },
            ' . $refreshTime . '
        );
    });
');

@Chris-Jones-Gill
Copy link
Copy Markdown
Author

@wilsonge

Thanks, didn't notice the failing test (my bad). I will fix it and update this PR.

@piotr-cz I will add the newlines in, but the jQuery().ready is not the recommended syntax - according to the jQuery API.
=== http://api.jquery.com/ready/ ===
All three of the following syntaxes are equivalent:

$( document ).ready( handler )
$().ready( handler ) (this is not recommended)

$( handler )

Chris.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice :) You haven't defined $document so the test is failing and also this is in the switcher test not the keepalive test (although jquery is being included in this function - so you can leave this set of lines if you want :) )

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

D'oh! Shouldn't try to rush things. Hopefully the latest commit corrects my mistakes. If not I will wait until I've had a good nights sleep before fixing.
Thanks for the feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both jQuery tests still failing which is odd - beginning to wonder if we'd need to mock it in some way as something very odd is going on there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest taking a look at how JHtmlJquery tests are set up and copying
that effort should fix your issues

On Friday, November 15, 2013, George Wilson wrote:

In tests/unit/suites/libraries/cms/html/JHtmlBehaviorTest.php:

@@ -233,6 +233,12 @@ public function testSwitcher()

    JFactory::$application = $mock;
  •   $this->assertArrayHasKey(
    
  •       '/media/jui/js/jquery.min.js',
    
  •       $document->_scripts,
    

Both jQuery tests still failing which is odd - beginning to wonder if we'd
need to mock it in some way as something very odd is going on there.


Reply to this email directly or view it on GitHubhttps://github.com//pull/2494/files#r7705190
.

… instance BEFORE referencing it. D'oh! Added the jQuery test to testSwitcher by mistake previously, but as it is a valid test it has been corrected and left in.
…live because they are failing and I don't understand why - as the jQuery test is not part of the original test structure, removing what I added (hoping to improve the test, but failing) is probably the best idea for now.

The test for jQuery presence could be added at a later date by someone who understands the test structure and phpUnit better than I.
@betweenbrain
Copy link
Copy Markdown
Contributor

From what I can tell, the code looks good. We just need some test instructions and good tests. @KISS-Web-Design can you provide instructions on testing this?

@Chris-Jones-Gill
Copy link
Copy Markdown
Author

No problem, I'll write something up and post it here and on the tracker.

Chris.

On Wednesday, 11 December 2013, Matt Thomas wrote:

From what I can tell, the code looks good. We just need some test
instructions and good tests. @KISS-Web-Designhttps://github.com/KISS-Web-Designcan you provide instructions on testing this?


Reply to this email directly or view it on GitHubhttps://github.com//pull/2494#issuecomment-30288817
.

Chris Jones-Gill
KISS Web Design
Company number: 7486736
VAT Registration: 107800539

@betweenbrain
Copy link
Copy Markdown
Contributor

No problem, I'll write something up and post it here and on the tracker.

Awesome, thanks.

@Chris-Jones-Gill
Copy link
Copy Markdown
Author

Test Instructions

You will need to be comfortable using the web inspector tools of your preferred browser, I use Chrome Inspector and Firebug (on Firefox).

1. Before applying the patch ensure that the MooTools keepAlive function is loaded.

visit yoursitename/index.php/component/users/?view=login

Check the <head> for the following code

function keepAlive() {  var myAjax = new Request({method: "get", url: "index.php"}).send();} window.addEvent("domready", function(){ keepAlive.periodical(840000); });

It will look something like this

moo-keepalive

Wait for at least 15 minutes, then use the inspector to check that the site has been reloaded in the background - evidenced by a GET of the page.

It will look something like this

moo-keepalive-evidence

2. Apply the patch, and reload the site page.

Or navigate back to yoursitename/index.php/component/users/?view=login

Check the <head> for the following code

            jQuery(document).ready(function() {
                window.setInterval(
                    function(){ new jQuery.ajax({ type: "GET" }); },
                    840000
                );
            });

It will look something like this

jquery-keepalive

Wait for at least 15 minutes, then use the inspector to check that the site has been reloaded in the background - evidenced by a GET of the page.

It will look something like this

jquery-keepalive-eveidence

3. Respond here

With a +1, success, or other positive test result affirmation.
OR
With a -1, fails, or other negative test result affirmation - along with a good description of your environment, which part doesn't work (with screenshots and/or source copy/paste), and any other helpful information.

Thanks for testing.

Chris.

@Bakual
Copy link
Copy Markdown
Contributor

Bakual commented Dec 12, 2013

Thanks for the instructions. Just a note: The test results should be posted in the tracker. Of course you can also add them here, but the tracker is currently still the point of thruth.

@Chris-Jones-Gill
Copy link
Copy Markdown
Author

@Bakual , I have also posted the same instructions on the tracker - but there are some people that don't have tracker accounts (or refuse to use it), so I would rather have test results posted here and there than exclude people.

I don't mind doing a copy/paste from here to the tracker to keep all the results together.

@Bakual
Copy link
Copy Markdown
Contributor

Bakual commented Dec 12, 2013

@KISS-Web-Design agreed :)

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented Apr 8, 2014

Closed in favor of #3376

@Chris-Jones-Gill Chris-Jones-Gill changed the title Feature jquery keepalive [#32665] Feature jquery keepalive Apr 8, 2014
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

Successfully merging this pull request may close these issues.

7 participants