summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/prado
diff options
context:
space:
mode:
authorwei <>2006-01-16 02:59:04 +0000
committerwei <>2006-01-16 02:59:04 +0000
commitce2b2803b78379a2bfca2849a5d5f8933a1634ea (patch)
treecc79e490dcdec6bc14e5c703f273f299fcfc2982 /framework/Web/Javascripts/prado
parentca47a8c7fd5eb9f34ac00a2f1a843859d6123dd8 (diff)
Diffstat (limited to 'framework/Web/Javascripts/prado')
-rw-r--r--framework/Web/Javascripts/prado/activecontrols.js196
-rw-r--r--framework/Web/Javascripts/prado/effects.js22
-rw-r--r--framework/Web/Javascripts/prado/element.js232
3 files changed, 450 insertions, 0 deletions
diff --git a/framework/Web/Javascripts/prado/activecontrols.js b/framework/Web/Javascripts/prado/activecontrols.js
new file mode 100644
index 00000000..72f97511
--- /dev/null
+++ b/framework/Web/Javascripts/prado/activecontrols.js
@@ -0,0 +1,196 @@
+/**
+ * Auto complete textbox via AJAX.
+ */
+Prado.AutoCompleter = Class.create();
+
+
+/**
+ * Overrides parent implementation of updateElement by trimming the value.
+ */
+Prado.AutoCompleter.Base = function(){};
+Prado.AutoCompleter.Base.prototype = Object.extend(Autocompleter.Base.prototype,
+{
+ updateElement: function(selectedElement)
+ {
+ if (this.options.updateElement) {
+ this.options.updateElement(selectedElement);
+ return;
+ }
+
+ var value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
+ var lastTokenPos = this.findLastToken();
+ if (lastTokenPos != -1) {
+ var newValue = this.element.value.substr(0, lastTokenPos + 1);
+ var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/);
+ if (whitespace)
+ newValue += whitespace[0];
+ this.element.value = (newValue + value).trim();
+ } else {
+ this.element.value = value.trim();
+ }
+ this.element.focus();
+
+ if (this.options.afterUpdateElement)
+ this.options.afterUpdateElement(this.element, selectedElement);
+ }
+});
+
+/**
+ * Based on the Prototype Autocompleter class.
+ * This client-side component should be instantiated from a Prado component.
+ * Usage: <t>new Prado.AutoCompleter('textboxID', 'updateDivID', {callbackID : '...'});
+ */
+Prado.AutoCompleter.prototype = Object.extend(new Autocompleter.Base(),
+{
+ /**
+ * This component is initialized by
+ * <code>new Prado.AutoCompleter(...)</code>
+ * @param string the ID of the textbox element to observe
+ * @param string the ID of the div to display the auto-complete options
+ * @param array a hash of options, e.g. auto-completion token separator.
+ */
+ initialize : function(element, update, options)
+ {
+ this.baseInitialize(element, update, options);
+ },
+
+ /**
+ * The callback function, i.e., function called on successful AJAX return.
+ * Calls update choices in the Autocompleter.
+ * @param string new auto-complete options for display
+ */
+ onUpdateReturn : function(result)
+ {
+ if(isString(result) && result.length > 0)
+ this.updateChoices(result);
+ },
+
+ /**
+ * Requesting new choices using Prado's client-side callback scheme.
+ */
+ getUpdatedChoices : function()
+ {
+ Prado.Callback(this.element.id, this.getToken(), this.onUpdateReturn.bind(this));
+ }
+});
+
+/**
+ * Prado TActivePanel client javascript. Usage
+ * <code>
+ * Prado.ActivePanel.register("id", options);
+ * Prado.ActivePanel.update("id", "hello");
+ * </code>
+ */
+Prado.ActivePanel =
+{
+ callbacks : {},
+
+ register : function(id, options)
+ {
+ Prado.ActivePanel.callbacks[id] = options;
+ },
+
+ update : function(id, param)
+ {
+ var request = new Prado.ActivePanel.Request(id,
+ Prado.ActivePanel.callbacks[id]);
+ request.callback(param);
+ }
+}
+
+/**
+ * Client-script for TActivePanel. Uses Callback to notify the server
+ * for updates, if update option is set, the innerHTML of the update ID
+ * is set to the returned output.
+ */
+Prado.ActivePanel.Request = Class.create();
+Prado.ActivePanel.Request.prototype =
+{
+ initialize : function(element, options)
+ {
+ this.element = element;
+ this.setOptions(options);
+ },
+
+ /**
+ * Set some options.
+ */
+ setOptions : function(options)
+ {
+ this.options =
+ {
+ onSuccess : this.onSuccess.bind(this)
+ }
+ Object.extend(this.options, options || {});
+ },
+
+ /**
+ * Make the callback request
+ */
+ callback : function(param)
+ {
+ this.options.params = [param];
+ new Prado.AJAX.Callback(this.element, this.options);
+ },
+
+ /**
+ * Callback onSuccess handler, update the element innerHTML if necessary
+ */
+ onSuccess : function(result, output)
+ {
+ if(this.options.update)
+ {
+ if (!this.options.evalScripts)
+ output = output.stripScripts();
+ Element.update(this.options.update, output);
+ }
+ }
+}
+
+/**
+ * Drop container to accept draggable component drops.
+ */
+Prado.DropContainer = Class.create();
+Prado.DropContainer.prototype = Object.extend(new Prado.ActivePanel.Request(),
+{
+ initialize : function(element, options)
+ {
+ this.element = element;
+ this.setOptions(options);
+ Object.extend(this.options,
+ {
+ onDrop : this.onDrop.bind(this),
+ evalScripts : true,
+ onSuccess : options.onSuccess || this.onSuccess.bind(this)
+ });
+ Droppables.add(element, this.options);
+ },
+
+ onDrop : function(draggable, droppable)
+ {
+ this.callback(draggable.id)
+ }
+});
+
+Prado.ActiveImageButton = Class.create();
+Prado.ActiveImageButton.prototype =
+{
+ initialize : function(element, options)
+ {
+ this.element = $(element);
+ this.options = options;
+ Event.observe(this.element, "click", this.click.bind(this));
+ },
+
+ click : function(e)
+ {
+ var el = $('{$this->ClientID}');
+ var imagePos = Position.cumulativeOffset(this.element);
+ var clickedPos = [e.clientX, e.clientY];
+ var param = (clickedPos[0]-imagePos[0]+1)+","+(clickedPos[1]-imagePos[1]+1);
+ Prado.Callback(this.element, param, null, this.options);
+ Event.stop(e);
+ }
+}
+
+
diff --git a/framework/Web/Javascripts/prado/effects.js b/framework/Web/Javascripts/prado/effects.js
new file mode 100644
index 00000000..cc31d00e
--- /dev/null
+++ b/framework/Web/Javascripts/prado/effects.js
@@ -0,0 +1,22 @@
+Prado.Effect =
+{
+ Highlight : function(element, duration)
+ {
+ new Effect.Highlight(element, {'duration':duration});
+ },
+
+ Scale : function(element, percent)
+ {
+ new Effect.Scale(element, percent);
+ },
+
+ MoveBy : function(element, toTop, toLeft)
+ {
+ new Effect.MoveBy(element, toTop, toLeft);
+ },
+
+ ScrollTo : function(element, duration)
+ {
+ new Effect.ScrollTo(element, {'duration':duration});
+ }
+} \ No newline at end of file
diff --git a/framework/Web/Javascripts/prado/element.js b/framework/Web/Javascripts/prado/element.js
new file mode 100644
index 00000000..163a7d6e
--- /dev/null
+++ b/framework/Web/Javascripts/prado/element.js
@@ -0,0 +1,232 @@
+Prado.Element =
+{
+ /**
+ * Set the value of a particular element.
+ * @param string element id
+ * @param string new element value.
+ */
+ setValue : function(element, value)
+ {
+ var el = $(element);
+ if(el && typeof(el.value) != "undefined")
+ el.value = value;
+ },
+
+ select : function(element, method, value)
+ {
+ var el = $(element);
+ var isList = element.indexOf('[]') > -1;
+ if(!el && !isList) return;
+ method = isList ? 'check'+method : el.tagName.toLowerCase()+method;
+ var selection = Prado.Element.Selection;
+ if(isFunction(selection[method]))
+ selection[method](isList ? element : el,value);
+ },
+
+ click : function(element)
+ {
+ var el = $(element);
+ //Logger.info(el);
+ if(!el) return;
+ if(document.createEvent)
+ {
+ var evt = document.createEvent('HTMLEvents');
+ evt.initEvent('click', true, true);
+ el.dispatchEvent(evt);
+ //Logger.warn("dispatching click for "+el.id);
+ }
+ else if(el.fireEvent)
+ {
+ el.fireEvent('onclick');
+ if(isFunction(el.onclick))
+ el.onclick();
+ }
+ },
+
+ setAttribute : function(element, attribute, value)
+ {
+ var el = $(element);
+ if(attribute == "disabled" && value==false)
+ el.removeAttribute(attribute);
+ else
+ el.setAttribute(attribute, value);
+ },
+
+ setOptions : function(element, options)
+ {
+ var el = $(element);
+ if(el && el.tagName.toLowerCase() == "select")
+ {
+ while(el.length > 0)
+ el.remove(0);
+ for(var i = 0; i<options.length; i++)
+ el.options[el.options.length] = new Option(options[i][0],options[i][1]);
+ }
+ },
+/**
+ * A delayed focus on a particular element
+ * @param {element} element to apply focus()
+ */
+ focus : function(element)
+ {
+ var obj = $(element);
+ if(isObject(obj) && isdef(obj.focus))
+ setTimeout(function(){ obj.focus(); }, 100);
+ return false;
+ }
+}
+
+Prado.Element.Selection =
+{
+ inputValue : function(el, value)
+ {
+ switch(el.type.toLowerCase())
+ {
+ case 'checkbox':
+ case 'radio':
+ return el.checked = value;
+ }
+ },
+
+ selectValue : function(el, value)
+ {
+ $A(el.options).each(function(option)
+ {
+ option.selected = option.value == value;
+ });
+ },
+
+ selectIndex : function(el, index)
+ {
+ if(el.type == 'select-one')
+ el.selectedIndex = index;
+ else
+ {
+ for(var i = 0; i<el.length; i++)
+ {
+ if(i == index)
+ el.options[i].selected = true;
+ }
+ }
+ },
+
+ selectClear : function(el)
+ {
+ el.selectedIndex = -1;
+ },
+
+ selectAll : function(el)
+ {
+ $A(el.options).each(function(option)
+ {
+ option.selected = true;
+ Logger.warn(option.value);
+ });
+ },
+
+ selectInvert : function(el)
+ {
+ $A(el.options).each(function(option)
+ {
+ option.selected = !option.selected;
+ });
+ },
+
+ checkValue : function(name, value)
+ {
+ $A(document.getElementsByName(name)).each(function(el)
+ {
+ el.checked = el.value == value
+ });
+ },
+
+ checkIndex : function(name, index)
+ {
+ var elements = $A(document.getElementsByName(name));
+ for(var i = 0; i<elements.length; i++)
+ {
+ if(i == index)
+ elements[i].checked = true;
+ }
+ },
+
+ checkClear : function(name)
+ {
+ $A(document.getElementsByName(name)).each(function(el)
+ {
+ el.checked = false;
+ });
+ },
+
+ checkAll : function(name)
+ {
+ $A(document.getElementsByName(name)).each(function(el)
+ {
+ el.checked = true;
+ });
+ },
+ checkInvert : function(name)
+ {
+ $A(document.getElementsByName(name)).each(function(el)
+ {
+ el.checked = !el.checked;
+ });
+ }
+};
+
+
+/**
+ * Alias some of the prototype functions.
+ * Insert a html fragment relative to an element.
+ */
+Object.extend(Prado.Element,
+{
+ /**
+ *
+ */
+ Insert :
+ {
+ /**
+ * Insert directly after the element.
+ */
+ After : function(element, innerHTML)
+ {
+ new Insertion.After(element, innerHTML);
+ },
+
+ /**
+ * Insert directly after the element
+ */
+ Before : function(element, innerHTML)
+ {
+ new Insertion.Before(element. innerHTML);
+ },
+
+ /**
+ * Insert below the element container.
+ */
+ Below : function(element, innerHTML)
+ {
+ new Insertion.Bottom(element, innerHTML);
+ },
+
+ /**
+ * Insert above the element container.
+ */
+ Above : function(element, innerHTML)
+ {
+ new Insertion.Top(element, innerHTML);
+ }
+ },
+ CssClass :
+ {
+ /**
+ * Set the css class name of an element.
+ */
+ set : function(element, cssClass)
+ {
+ element = new Element.ClassNames(element);
+ element.set(cssClass);
+ }
+ }
+}); \ No newline at end of file