1 | /* -------------------------------------------------------------------------- *
|
---|
2 | * Experience Javascript Library (version 1.0b)
|
---|
3 | * (c) 2007 Ahmed Saad <ahmeds@users.sourceforge.net>
|
---|
4 | *
|
---|
5 | * Experience is freely distributable under the terms of an MIT-style license.
|
---|
6 | * For details, see project website at http://experience.sf.net
|
---|
7 | * -------------------------------------------------------------------------- */
|
---|
8 |
|
---|
9 | // global namespace
|
---|
10 | var experience = {
|
---|
11 | Version : '1.0b',
|
---|
12 |
|
---|
13 | Params : $H({
|
---|
14 | Locale: 'pt_BR', /* The language of strings embeded in code is considered the default */
|
---|
15 | InterfaceDir: 'ltr'
|
---|
16 | }),
|
---|
17 |
|
---|
18 | /* The interface to the world */
|
---|
19 | Core : {
|
---|
20 | initialize : function(userParams){
|
---|
21 | experience.Params.merge(userParams);
|
---|
22 |
|
---|
23 | //// PUBLIC METHODS ////////////////////////////
|
---|
24 |
|
---|
25 | this.bindTip = experience.bindTip;
|
---|
26 | this.unbindTip = experience.unbindTip;
|
---|
27 | },
|
---|
28 |
|
---|
29 | bindTip : function(element, html, className){
|
---|
30 | element = $(element);
|
---|
31 | element.tipHTML = html;
|
---|
32 | element.tipClass = className ? className : "experienceTip";
|
---|
33 | Event.observe(element, 'mousemove', experience.showHoverDiv);
|
---|
34 | Event.observe(element, 'mouseout', experience.hideHoverDiv);
|
---|
35 | },
|
---|
36 |
|
---|
37 | unbindTip : function(element){
|
---|
38 | if ($('experienceTip') && $('experienceTip').srcElement == element){
|
---|
39 | experience.hideHoverDiv();
|
---|
40 | }
|
---|
41 |
|
---|
42 | Event.stopObserving(element, 'mousemove', experience.showHoverDiv);
|
---|
43 | Event.stopObserving(element, 'mouseout', experience.hideHoverDiv);
|
---|
44 | }
|
---|
45 | },
|
---|
46 |
|
---|
47 | ///// PRIVATE FUNCTIONS ////////////////////////////////////////////////
|
---|
48 |
|
---|
49 | Console : {
|
---|
50 | isEnabled: true,
|
---|
51 | log : function(obj){
|
---|
52 | if (experience.Console.isEnabled){
|
---|
53 | if(window.console){ // Firebug
|
---|
54 | window.console.log(obj);
|
---|
55 | } else if (typeof(opera) != "undefined"){
|
---|
56 | opera.postError(Object.inspect(obj));
|
---|
57 | } else {
|
---|
58 | alert(Object.inspect(obj));
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 | },
|
---|
63 |
|
---|
64 | // internationalization support
|
---|
65 | tr : function (str, locales){
|
---|
66 | if (
|
---|
67 | locales.keys().include(this.Params.Locale) &&
|
---|
68 | typeof(locales[this.Params.Locale][str]) != 'undefined'
|
---|
69 | ) {
|
---|
70 | return locales[this.Params.Locale][str];
|
---|
71 | } else {
|
---|
72 | return str;
|
---|
73 | }
|
---|
74 | },
|
---|
75 |
|
---|
76 | // browser detection
|
---|
77 | detectBrowser: function (){
|
---|
78 | if (navigator.userAgent.indexOf("MSIE 5") != -1){
|
---|
79 | return "ie5";
|
---|
80 | } else if (navigator.userAgent.indexOf("MSIE 6") != -1){
|
---|
81 | return "ie6";
|
---|
82 | } else if (navigator.userAgent.indexOf("Safari") != -1){
|
---|
83 | return "safari";
|
---|
84 | } else if (navigator.userAgent.indexOf("Firefox") != -1) {
|
---|
85 | return "firefox";
|
---|
86 | } else if (navigator.userAgent.indexOf("Opera") != -1) {
|
---|
87 | return "opera";
|
---|
88 | } else if (navigator.userAgent.indexOf("Konqueror") != -1) {
|
---|
89 | return "konqueror";
|
---|
90 | }
|
---|
91 | },
|
---|
92 |
|
---|
93 | detectEngine: function() {
|
---|
94 | var browser = experience.detectBrowser();
|
---|
95 | if (browser == "ie5" || browser == "ie6"){
|
---|
96 | return "trident";
|
---|
97 | } else if (navigator.userAgent.indexOf("AppleWebKit") != -1){
|
---|
98 | return "webkit";
|
---|
99 | } else if (navigator.userAgent.indexOf("KHTML") != -1){
|
---|
100 | return "khtml";
|
---|
101 | } else if ( navigator.userAgent.indexOf("Gecko") != -1 &&
|
---|
102 | navigator.userAgent.indexOf("like Gecko") == -1 ){
|
---|
103 | return "gecko";
|
---|
104 | }
|
---|
105 | },
|
---|
106 |
|
---|
107 | showHoverDiv : function(e){
|
---|
108 | var el = Event.element(e);
|
---|
109 |
|
---|
110 | if (!$('experienceTip')){
|
---|
111 | var div = document.createElement('div');
|
---|
112 | div.id = 'experienceTip';
|
---|
113 | div.style.position = "absolute";
|
---|
114 | document.getElementsByTagName('body')[0].appendChild(div);
|
---|
115 | }
|
---|
116 |
|
---|
117 | /* A speed optimization (it's slow to reassign on every call */
|
---|
118 | if (experience.lastTipElement != el){
|
---|
119 | $('experienceTip').className = el.tipClass;
|
---|
120 | $('experienceTip').innerHTML = el.tipHTML;
|
---|
121 | $('experienceTip').srcElement = el;
|
---|
122 | }
|
---|
123 |
|
---|
124 | $('experienceTip').style.display = "block";
|
---|
125 | $('experienceTip').style.top = Event.pointerY(e) + 20 + "px";
|
---|
126 | $('experienceTip').style.left = Event.pointerX(e) + "px";
|
---|
127 |
|
---|
128 | experience.lastTipElement = el;
|
---|
129 | },
|
---|
130 |
|
---|
131 | hideHoverDiv : function(e){
|
---|
132 | $('experienceTip').style.display = "none";
|
---|
133 | }
|
---|
134 | }
|
---|