Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge Modalbox.js and .css, builder.js, and the logic for the Confirm…

… dialog into the tapx-core stack
  • Loading branch information...
commit 7bcd27c7d9f301f210327d867ca77b88eaee0524 1 parent 84fd6b4
@hlship authored
View
20 tapx-core/src/main/java/com/howardlewisship/tapx/core/mixins/Confirm.java
@@ -1,4 +1,4 @@
-// Copyright 2010 Howard M. Lewis Ship
+// Copyright 2010, 2011 Howard M. Lewis Ship
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,19 +14,15 @@
package com.howardlewisship.tapx.core.mixins;
-import org.apache.tapestry5.Asset;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.ClientElement;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectContainer;
import org.apache.tapestry5.annotations.Parameter;
-import org.apache.tapestry5.annotations.Path;
import org.apache.tapestry5.corelib.components.EventLink;
import org.apache.tapestry5.corelib.components.PageLink;
import org.apache.tapestry5.corelib.components.Zone;
-import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.javascript.InitializationPriority;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
@@ -47,8 +43,7 @@
* test mode} behavior is changed: the Modalbox dialog is replaced with a simple JavaScript
* <code>window.confirm()</code>.
*/
-@Import(stack = "tapx-core", library =
-{ "${tapestry.scriptaculous}/builder.js", "modalbox.js", "confirm.js" }, stylesheet = "modalbox.css")
+@Import(stack = "tapx-core")
public class Confirm
{
@InjectContainer
@@ -63,19 +58,8 @@
@Environmental
private JavaScriptSupport javascriptSupport;
- @Inject
- @Path("confirm-testmode.js")
- private Asset testModeLibrary;
-
- @Inject
- @Symbol(CoreSymbols.TEST_MODE)
- private boolean testMode;
-
void afterRender()
{
- if (testMode)
- javascriptSupport.importJavaScriptLibrary(testModeLibrary);
-
JSONObject spec = new JSONObject("clientId", container.getClientId(), "message", message, "title", title);
// Late, to overwrite other event handlers
View
23 tapx-core/src/main/java/com/howardlewisship/tapx/core/services/CoreModule.java
@@ -151,10 +151,18 @@ public static void basicConditions(MappedConfiguration<String, Condition> config
* <dl>
* <dt>CoreJS</dt>
* <dd>Core JavaScript library</dd>
+ * <dt>CoreJS-TestMode</dt>
+ * <dd>Only in {@link CoreSymbols#TEST_MODE}</dd>
+ * <dt>ScriptaculousBuilder</dt2>
+ * <dd>builder.js (needed by Modalbox)</dd>
* <dt>CoreJS-MultiSelect</dd>
* <dd>Support for the MultiSelect component</dd>
+ * <dt>CoreJS-Modalbox</dd>
+ * <dd>JavaScript for the Modalbox component (used by the Confirm mixin, and elsewhere)</dd>
* <dt>CoreCSS</dt>
* <dd>Core Stylesheet</dd>
+ * <dt>CoreCSS-Modalbox</dt>
+ * <dd>Stylesheet used by Modalbox</dd>
* </dl>
* <p>
* If contributing additional values, you will typically want them expressly ordered <em>after</em> these
@@ -164,12 +172,23 @@ public static void basicConditions(MappedConfiguration<String, Condition> config
*/
@Contribute(JavaScriptStack.class)
@TapxCore
- public static void basicCoreStackElements(OrderedConfiguration<StackExtension> configuration)
+ public static void basicCoreStackElements(OrderedConfiguration<StackExtension> configuration,
+ @Symbol(CoreSymbols.TEST_MODE)
+ boolean testMode)
{
configuration.add("CoreJS", new StackExtension(StackExtensionType.LIBRARY, PATH + "/tapx.js"));
configuration.add("CoreJS-MultiSelect", new StackExtension(StackExtensionType.LIBRARY, PATH
+ "/tapx-multiselect.js"), "after:CoreJS");
+ configuration.add("CoreJS-Modalbox", new StackExtension(StackExtensionType.LIBRARY, PATH + "/modalbox.js"),
+ "after:CoreJS");
configuration.add("CoreCSS", new StackExtension(StackExtensionType.STYLESHEET, PATH + "/tapx-core.css"));
-
+ configuration
+ .add("CoreCSS-Modalbox", new StackExtension(StackExtensionType.STYLESHEET, PATH + "/modalbox.css"));
+ configuration.add("ScriptaculousBuilder", new StackExtension(StackExtensionType.LIBRARY,
+ "${tapestry.scriptaculous}/builder.js"));
+
+ if (testMode)
+ configuration.add("CoreJS-TestMode", new StackExtension(StackExtensionType.LIBRARY, PATH
+ + "/tapx-testmode.js"), "after:CoreJS");
}
}
View
8 tapx-core/src/main/resources/com/howardlewisship/tapx/core/mixins/confirm-testmode.js
@@ -1,8 +0,0 @@
-/*
- * Replace the ModalBox dialog with a simple window.confirm() dialog (which can be properly
- * scripted by Selenium).
- */
-Tapx.runModalDialog = function(title, message, proceed) {
- if (window.confirm(message))
- proceed.defer();
-};
View
97 tapx-core/src/main/resources/com/howardlewisship/tapx/core/mixins/confirm.js
@@ -1,97 +0,0 @@
-Tapx.runModalDialog = function(title, message, proceed) {
- var div = new Element('div', {
- className : 'mb-confirm'
- }).update(new Element('p').update(message));
-
- /*
- * Have to assign ids and reconnect at after load, because ModalBox copies
- * DOM elements, rather than move them.
- */
- var baseId = "mb-" + new Date().getTime();
- var yesId = baseId + "-yes";
- var noId = baseId + "-no";
-
- var yesButton = new Element('button', {
- className : 'mb-yes-button',
- id : yesId
- }).update('Yes');
-
- var noButton = new Element('button', {
- className : 'mb-no-button',
- id : noId
- }).update('No');
-
- div.insert(yesButton).insert(noButton);
-
- Modalbox.show(div, {
- title : title,
- afterLoad : function() {
- $(noId).observe("click", function(event) {
- Modalbox.hide();
- });
- $(yesId).observe("click", function(event) {
- event.stop();
- Modalbox.hide();
- proceed.defer();
- });
- }
- });
-};
-
-Tapestry.Initializer.tapxConfirm = function(spec) {
-
- var element = $(spec.clientId);
- var type = element.type;
-
- var interceptClickEvent = true;
-
- /*
- * Replace the normal click event, knowing that in most cases, the original
- * link or button has an Tapestry.ACTION_EVENT event handler to do its real
- * work.
- */
- element.stopObserving("click");
-
- function doAction() {
- if ($T(element).hasAction) {
- element.fire(Tapestry.ACTION_EVENT, event);
- return;
- }
-
- /*
- * Is it a submit element (i.e., it has a click() method)? Try that
- * next.
- */
-
- if (element.click) {
- interceptClickEvent = false;
-
- element.click();
- return;
- }
-
- /*
- * Not a zone update, so just do a full page refresh to the indicated
- * URL.
- */
- window.location = element.href;
- }
-
- element.observe("click", function(event) {
-
- if (interceptClickEvent) {
-
- event.stop();
-
- if ($(element).hasClassName('tx-disable-confirm')) {
- doAction();
- return;
- }
-
- Tapx.runModalDialog(spec.title, spec.message, doAction);
- } else {
- interceptClickEvent = true;
- }
- });
-
-};
View
0  ...com/howardlewisship/tapx/core/mixins/modalbox.css → ...ources/com/howardlewisship/tapx/core/modalbox.css
File renamed without changes
View
0  .../com/howardlewisship/tapx/core/mixins/modalbox.js → ...sources/com/howardlewisship/tapx/core/modalbox.js
File renamed without changes
View
0  .../com/howardlewisship/tapx/core/mixins/spinner.gif → ...sources/com/howardlewisship/tapx/core/spinner.gif
File renamed without changes
View
1  tapx-core/src/main/resources/com/howardlewisship/tapx/core/tapx-testmode.js
@@ -0,0 +1 @@
+Tapx.TEST_MODE = true;
View
125 tapx-core/src/main/resources/com/howardlewisship/tapx/core/tapx.js
@@ -1,10 +1,12 @@
Tapx = {
+ TEST_MODE : false,
+
/**
* Extends an object using a source. In the simple case, the source object's
* properties are overlayed on top of the destination object. In the typical
* case, the source parameter is a function that returns the source object
- * ... this is to faciliate modularity and encapsulation.
+ * ... this is to facilitate modularity and encapsulation.
*
* @param destination
* object to receive new or updated properties
@@ -19,6 +21,13 @@ Tapx = {
Object.extend(destination, source);
},
+ /**
+ * A convienience for extending Tapestry.Initializer.
+ *
+ * @param source
+ * source object (or function returning source object) for
+ * properties applied to Tapestry.Initializer
+ */
extendInitializer : function(source) {
this.extend(Tapestry.Initializer, source);
},
@@ -276,4 +285,116 @@ Tapestry.Initializer.tapxExpando = function(spec) {
$(spec.clientId).down(".tx-expand").observe("click", expand);
$(spec.clientId).down(".tx-collapse").observe("click", collapse);
-};
+};
+
+Tapx.extendInitializer(function() {
+
+ function runModalDialog(title, message, proceed) {
+
+ if (Tapx.testMode) {
+ if (window.confirm(message))
+ proceed.defer();
+
+ return;
+ }
+
+ var div = new Element('div', {
+ className : 'mb-confirm'
+ }).update(new Element('p').update(message));
+
+ /*
+ * Have to assign ids and reconnect at after load, because ModalBox
+ * copies DOM elements, rather than move them.
+ */
+ var baseId = "mb-" + new Date().getTime();
+ var yesId = baseId + "-yes";
+ var noId = baseId + "-no";
+
+ var yesButton = new Element('button', {
+ className : 'mb-yes-button',
+ id : yesId
+ }).update('Yes');
+
+ var noButton = new Element('button', {
+ className : 'mb-no-button',
+ id : noId
+ }).update('No');
+
+ div.insert(yesButton).insert(noButton);
+
+ Modalbox.show(div, {
+ title : title,
+ afterLoad : function() {
+ $(noId).observe("click", function(event) {
+ Modalbox.hide();
+ });
+ $(yesId).observe("click", function(event) {
+ event.stop();
+ Modalbox.hide();
+ proceed.defer();
+ });
+ }
+ });
+ }
+
+ function initializer(spec) {
+
+ var element = $(spec.clientId);
+ var type = element.type;
+
+ var interceptClickEvent = true;
+
+ /*
+ * Replace the normal click event, knowing that in most cases, the
+ * original link or button has an Tapestry.ACTION_EVENT event handler to
+ * do its real work.
+ */
+ element.stopObserving("click");
+
+ function doAction() {
+ if ($T(element).hasAction) {
+ element.fire(Tapestry.ACTION_EVENT, event);
+ return;
+ }
+
+ /*
+ * Is it a submit element (i.e., it has a click() method)? Try that
+ * next.
+ */
+
+ if (element.click) {
+ interceptClickEvent = false;
+
+ element.click();
+ return;
+ }
+
+ /*
+ * Not a zone update, so just do a full page refresh to the
+ * indicated URL.
+ */
+ window.location = element.href;
+ }
+
+ element.observe("click", function(event) {
+
+ if (interceptClickEvent) {
+
+ event.stop();
+
+ if ($(element).hasClassName('tx-disable-confirm')) {
+ doAction();
+ return;
+ }
+
+ runModalDialog(spec.title, spec.message, doAction);
+ } else {
+ interceptClickEvent = true;
+ }
+ });
+ }
+
+ return {
+ tapxConfirm : initializer
+ };
+});
Please sign in to comment.
Something went wrong with that request. Please try again.