Dojo-Widget AddressReferrer 26 May 2008
Posted by Oliver Köhler in Dojo-Widget.Tags: AddressReferrer, dojo, Pavone, Skype, widget
add a comment
Now that we got suitable webspace we would like to present our widgets.
The first widget we developed is the AddressReferrer. It transforms a usual inputfield into an inputfield with a predefined contextual function.
Example: If you have a field with a phonenumber you could generate a bottom that starts skype to call this number.
How to use:
In the head of the page you have to include some scripts like it is displayed below.
In the body:
- declare your inputfield with the dojoType “pavone.widget.AddressReferrer”
- reftype is the type of the protocol that you want to use
- predefined types are
- “skype” for skype-protocol
- “email” for e-mail
- “http” for website links
- predefined types are
- label is the image that should be displayed
- title is the alternative text of the image
- assign a unique id to every inputfield
<input dojoType=“pavone.widget.AddressReferrer” value=“2355” reftype=“skype” id=“ID1” label=“images/skype.gif” title=“anrufen”/>
Include in your html-file:
- <html>
- <head>
- …
- <style type=“text/css”>
-
@import “../../AddressReferrer.css”; //path to your stylesheet
- </style>
- …
-
<script type=“text/javascript” src=“../../dojo/dojo.js” djConfig=“isDebug:true, parseOnLoad: true”></script> //path to dojo
-
<script type=“text/javascript” src=“../../dojo/pavone/AddressReferrer.js”></script> //path to the widget
- <script type=“text/javascript”>
- dojo.require(“dojo.parser”); // scan page for widgets and instantiate them
- </script>
- …
- </head>
- <body>
- …
- <input dojoType=“pavone.widget.AddressReferrer” value=“2355” reftype=“skype” id=“ID1” label=“images/skype.gif” title=“anrufen”/>
- …
- </body>
- </head>
Sourcecode of AddressReferrer.js:
- /*——————————————————————————–
- *
- * Developed for a project at the University of Paderborn under the direction of
- * the PAVONE AG (www.pavone.de) and the Groupware Competence Centers (gcc.upb.de)
- *
- * Licensed under the Academic Free License
- *
- * Developed by Oliver Koehler, Coskun Durmaz, Natnael Tesfamariam
- *
- ——————————————————————————–*/
- if(!dojo._hasResource[“pavone.widget.AddressReferrer”]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
- dojo._hasResource[“pavone.widget.AddressReferrer”] = true;
- dojo.provide(“pavone.widget.AddressReferrer”);
- dojo.require(“dijit.form._FormWidget”);
- dojo.require(“dijit._Templated”);
- dojo.require(‘dijit.form.Button’);
- dojo.declare(“pavone.widget.AddressReferrer”,
- [dijit.form._FormWidget],
- {
- label: “”,
- reftype: “”,
- target: “”,
- templateString: ‘<div class=\”AddressRef\”>’+
- ‘<input type=\”text\” dojoAttachEvent=\”onchange:_onChange\” id=\”ID${id}\” value=\”${value}\” reftype=\”${reftype}\” dojoType=\”dijit.form.TextBox\” dojoAttachPoint=\”focusNode, inputNode\” trim=\”true\” propercase=\”true\” />’+
- ‘<button class=\”AddressRefButton \” dojoType=\”dijit.form.Button\” dojoAttachEvent=\”onclick:_onClick\” dojoAttachPoint=\”focusNode, inputNode\”><image src=\”${label}\” title=\”${title}\” alt=\”${title}\”>’+
- ‘</img></button> \n\t<\div>’,
- _onChange: function () {
- this.value = dojo.byId(‘ID’+this.id).value;
- },
- _onClick: function () {
- var refType = this.reftype;
- var tar = this.target;
- var ref;
- var target;
- switch (refType) {
- case “skype”: ref = “skype://”;
- target = “self”;
- break;
- case “email”: ref = “mailto:”;
- target = “self”;
- break;
- case “http”: ref = “”;
- target = “new”;
- break;
- default: ref = refType;
- target = tar;
- }
- var address = this.value;
- address = address.replace(/[‘ ‘]/g , ”);
- if (target==”self”) {
- document.location.href=ref+””+address;
- } else if (target==”new”) {
- window.open(ref+””+address);
- }
- }
- });
- }