Namespace gym.js

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/3e48fac0
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/3e48fac0
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/3e48fac0

Branch: refs/heads/master
Commit: 3e48fac0d9987b07576561333e34c1744dc1596b
Parents: e88526b
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Mon Jun 17 13:48:31 2013 +0200
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Mon Jun 17 13:48:31 2013 +0200

----------------------------------------------------------------------
 .../src/main/webapp/js-test/lib/gym.js          | 184 ++++++++++---------
 .../src/main/webapp/js-test/tests/ajax/form.js  |   6 +-
 .../src/main/webapp/js-test/tests/echo.js       |   6 +-
 .../src/main/webapp/js-test/tests/forminput.js  |   9 +-
 .../src/main/webapp/js-test/tests/helloworld.js |   2 +-
 5 files changed, 111 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/3e48fac0/wicket-examples/src/main/webapp/js-test/lib/gym.js
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/js-test/lib/gym.js 
b/wicket-examples/src/main/webapp/js-test/lib/gym.js
index 57aaf3c..51da391 100644
--- a/wicket-examples/src/main/webapp/js-test/lib/gym.js
+++ b/wicket-examples/src/main/webapp/js-test/lib/gym.js
@@ -1,106 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
-var load = function(url) {
-    var deferred = $q.Deferred();
-    onPageLoad(function(iframe, $) {
-        deferred.resolve(iframe, $);
-    });
-    getIframe().attr('src', url);
+;(function ($) {
 
-    return deferred;
-}
+       'use strict';
 
-var click = function($btn) {
-    var deferred = $q.Deferred();
-    onPageLoad(function(iframe, $$) {
-        deferred.resolve(iframe, $$);
-    });
+       var load = function(url) {
+           var deferred = $.Deferred();
+           _onPageLoad(function(iframe, $$) {
+               deferred.resolve(iframe, $$);
+           });
+           _getIframe().attr('src', url);
 
-       $btn.click();
+           return deferred;
+       }
 
-    return deferred;
-}
+       var click = function($btn) {
+           var deferred = $.Deferred();
+           _onPageLoad(function(iframe, $$) {
+               deferred.resolve(iframe, $$);
+           });
 
-// private
-var getIframe = function() {
-       return $q('#applicationFrame');
-}
+               $btn.click();
 
-// private
-var onPageLoad = function(toExecute) {
+           return deferred;
+       }
 
-       getIframe()
-               .off('load')
-               .on('load', function() {
-                       $q(this).off('load');
+       // private
+       var _getIframe = function() {
+               return $('#applicationFrame');
+       }
 
-                       var newIframe, $;
+       // private
+       var _onPageLoad = function(toExecute) {
 
-                       newIframe = window.frames[0];
-                       $ = newIframe.jQuery || jQueryWithContext;
+               _getIframe()
+                       .off('load')
+                       .on('load', function() {
+                               $(this).off('load');
 
-                       //debug(newIframe);
+                               var newIframe, $$;
 
-                       toExecute.call(newIframe, $);
-               });
-};
+                               newIframe = window.frames[0];
+                               $$ = newIframe.jQuery || _jQueryWithContext;
 
-/**
- * Non-Ajax pages do not have jQuery so we use
- * $q with context to simulate it
- */
-// private
-var jQueryWithContext = function(selector) {
-       return $q(selector, $q(getIframe()).contents());
-};
+                               //debug(newIframe);
 
-var ajaxClick = function($btn) {
-       var deferred = $q.Deferred();
-       var iframeWindow = getIframe()[0].contentWindow;
+                               toExecute.call(newIframe, $$);
+                       });
+       };
 
-       onAjaxComplete(iframeWindow, function($$) {
-               deferred.resolve($$);
-       });
+       /**
+        * Non-Ajax pages do not have jQuery so we use
+        * $ with context to simulate it
+        */
+       // private
+       var _jQueryWithContext = function(selector) {
+               return $(selector, _getIframe().contents());
+       };
 
-       $btn.click();
+       var ajaxClick = function($btn) {
+               var deferred = $.Deferred();
+               var iframeWindow = _getIframe()[0].contentWindow;
 
-       return deferred;
-}
+               _onAjaxComplete(iframeWindow, function($$) {
+                       deferred.resolve($$);
+               });
 
-/**
- * Registers a callback when Wicket Ajax call is completed
- */
-// private
-var onAjaxComplete = function(iframe, toExecute) {
-
-       // unregister any leaked subscriber
-       iframe.jQuery(iframe.document).off('/ajax/call/complete');
-       
-       // register the requested subscriber
-       iframe.Wicket.Event.subscribe('/ajax/call/complete', function(jqEvent, 
attributes, jqXHR, textStatus) {
-               // immediately unregister this subscriber
-               iframe.jQuery(iframe.document).off('/ajax/call/complete');
-               
-               // call back
-               var $$ = iframe.jQuery || jQueryWithContext;
-               toExecute($$);
-       });
-};
-
-// unused
-var followHref = function(iframe, $, $link) {
-       var loc = iframe.document.location;
-//     console.log('Current url', loc.href);
-//     console.log('Link', $link.selector);
-
-       if ($link.length) {
-               var newUrl = $link.attr('href');
-//             console.log('Following href: ', newUrl);
-               loc.replace(newUrl);
+               $btn.click();
+
+               return deferred;
        }
-}
 
-var debug = function(iframe) {
-       "use strict";
+       /**
+        * Registers a callback when Wicket Ajax call is completed
+        */
+       // private
+       var _onAjaxComplete = function(iframe, toExecute) {
+
+               // unregister any leaked subscriber
+               iframe.jQuery(iframe.document).off('/ajax/call/complete');
+
+               // register the requested subscriber
+               iframe.Wicket.Event.subscribe('/ajax/call/complete', 
function(jqEvent, attributes, jqXHR, textStatus) {
+                       // immediately unregister this subscriber
+                       
iframe.jQuery(iframe.document).off('/ajax/call/complete');
+
+                       // call back
+                       var $$ = iframe.jQuery || _jQueryWithContext;
+                       toExecute($$);
+               });
+       };
+
+       var debug = function(iframe) {
+               "use strict";
+
+               console.log('Current url: ', iframe.window.location.href);
+       };
 
-       console.log('Current url: ', iframe.window.location.href);
-}
+       window.gym = {
+               load: load,
+               click: click,
+               ajaxClick: ajaxClick
+       };
+})($q);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/wicket/blob/3e48fac0/wicket-examples/src/main/webapp/js-test/tests/ajax/form.js
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/js-test/tests/ajax/form.js 
b/wicket-examples/src/main/webapp/js-test/tests/ajax/form.js
index e659556..e8ee1be 100644
--- a/wicket-examples/src/main/webapp/js-test/tests/ajax/form.js
+++ b/wicket-examples/src/main/webapp/js-test/tests/ajax/form.js
@@ -6,14 +6,14 @@ $q(document).ready(function() {
        asyncTest('successful ajax form submit', function () {
                expect(3);
 
-               load('/ajax/form').then(function($) {
+               gym.load('/ajax/form').then(function($) {
 
                        // enter just the name field
                        var $nameInput = $('input[name=name]');
                        var name = 'Ajax form name';
                        $nameInput.val(name);
 
-                       
ajaxClick($('input[name=ajax-button]')).then(function($$) {
+                       
gym.ajaxClick($('input[name=ajax-button]')).then(function($$) {
 
                                // an error feedback message that email is 
mandatory is expected
                                var $feedback = $$('li.feedbackPanelERROR > 
span');
@@ -25,7 +25,7 @@ $q(document).ready(function() {
                                var email = '[email protected]';
                                $emailInput.val(email);
 
-                               
ajaxClick($$('input[name=ajax-button]')).then(function($$$) {
+                               
gym.ajaxClick($$('input[name=ajax-button]')).then(function($$$) {
 
                                        // the feedback panel must be empty now
                                        var $feedback = 
$$$('li.feedbackPanelERROR > span');

http://git-wip-us.apache.org/repos/asf/wicket/blob/3e48fac0/wicket-examples/src/main/webapp/js-test/tests/echo.js
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/js-test/tests/echo.js 
b/wicket-examples/src/main/webapp/js-test/tests/echo.js
index 82017e3..b4a6c63 100644
--- a/wicket-examples/src/main/webapp/js-test/tests/echo.js
+++ b/wicket-examples/src/main/webapp/js-test/tests/echo.js
@@ -6,13 +6,13 @@ $q(document).ready(function() {
        asyncTest('echo', function () {
                expect(2);
 
-               load('/echo').then(function($) {
+               gym.load('/echo').then(function($) {
 
                        var $messageInput = $('input[name=msgInput]');
                        var message = 'Hello Functional QUnit';
                        $messageInput.val(message);
-               
-                       click($('input[type=submit]')).then(function($$) {
+
+                       gym.click($('input[type=submit]')).then(function($$) {
 
                                var $msg = $$('#msg');
                                equal($msg.length, 1, 'The entered message is 
here');

http://git-wip-us.apache.org/repos/asf/wicket/blob/3e48fac0/wicket-examples/src/main/webapp/js-test/tests/forminput.js
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/js-test/tests/forminput.js 
b/wicket-examples/src/main/webapp/js-test/tests/forminput.js
index 284bf85..289ac83 100644
--- a/wicket-examples/src/main/webapp/js-test/tests/forminput.js
+++ b/wicket-examples/src/main/webapp/js-test/tests/forminput.js
@@ -6,13 +6,13 @@ $q(document).ready(function() {
        asyncTest('Change StringProperty', function () {
                expect(2);
 
-               load('/forminput').then(function($) {
+               gym.load('/forminput').then(function($) {
 
                        var $stringPropertyInput = $('#stringProperty');
                        var text = 'qunit test value';
                        $stringPropertyInput.val(text);
 
-                       click($('input[value=save]')).then(function($$) {
+                       gym.click($('input[value=save]')).then(function($$) {
 
                                var $feedback = $$('li.feedbackPanelINFO > 
span');
                                equal($feedback.length, 1, 'The feedback is 
here');
@@ -26,13 +26,14 @@ $q(document).ready(function() {
        asyncTest('Change the locale', function () {
                expect(2);
 
-               load('/forminput').then(function($) {
+               gym.load('/forminput').then(function($) {
 
                        var $select = $('select[name=localeSelect]');
                        var locale = '2'; // German
 
                        $select.val(locale);
-                       click($('input[value=save]')).then(function($$) {
+
+                       gym.click($('input[value=save]')).then(function($$) {
 
                                var $integerInRangeProperty = 
$$('label[for=integerInRangeProperty]');
                                equal($integerInRangeProperty.length, 1, 'The 
label for integerInRangeProperty is here');

http://git-wip-us.apache.org/repos/asf/wicket/blob/3e48fac0/wicket-examples/src/main/webapp/js-test/tests/helloworld.js
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/js-test/tests/helloworld.js 
b/wicket-examples/src/main/webapp/js-test/tests/helloworld.js
index 10b96cb..e8b13c2 100644
--- a/wicket-examples/src/main/webapp/js-test/tests/helloworld.js
+++ b/wicket-examples/src/main/webapp/js-test/tests/helloworld.js
@@ -6,7 +6,7 @@ $q(document).ready(function() {
        asyncTest('hello world', function () {
                expect(2);
 
-               load('/helloworld').then(function($) {
+               gym.load('/helloworld').then(function($) {
 
                        var $message = $('#message');
                        equal($message.length, 1, "The greeting is there");

Reply via email to