| 1 |
define([ |
| 2 |
"dojo/_base/kernel", |
| 3 |
"dojo/_base/array", |
| 4 |
"dojo/_base/connect", |
| 5 |
"dojo/_base/declare", |
| 6 |
"dojo/_base/fx", |
| 7 |
"dojo/_base/lang", |
| 8 |
"dojo/_base/sniff", |
| 9 |
"dojo/_base/window", |
| 10 |
"dojo/dom-attr", |
| 11 |
"dojo/dom-class", |
| 12 |
"dojo/dom-construct", |
| 13 |
"dojo/dom-geometry", |
| 14 |
"dojo/dom-style", |
| 15 |
"dojo/cookie", |
| 16 |
"dojo/domReady", |
| 17 |
"dojo/fx", |
| 18 |
"dojo/window", |
| 19 |
"dijit/_WidgetBase", |
| 20 |
"dijit/_TemplatedMixin", |
| 21 |
"dojo/text!./UpgradeBar/UpgradeBar.html" |
| 22 |
], function(dojo, array, connect, declare, baseFx, lang, has, baseWin, |
| 23 |
domAttr, domClass, domConstruct, domGeo, style, cookie, |
| 24 |
domReady, fx, win, _WidgetBase, _TemplatedMixin, template){ |
| 25 |
|
| 26 |
dojo.experimental("dojox.widget.UpgradeBar"); |
| 27 |
|
| 28 |
var UpgradeBar = declare("dojox.widget.UpgradeBar", [_WidgetBase, _TemplatedMixin], { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
notifications:[], |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
buttonCancel:"Close for now", |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
noRemindButton:"Don't Remind Me Again", |
| 72 |
|
| 73 |
templateString: template, |
| 74 |
|
| 75 |
constructor: function(props, node){ |
| 76 |
|
| 77 |
if(!props.notifications && node){ |
| 78 |
|
| 79 |
|
| 80 |
array.forEach(node.childNodes, function(n){ |
| 81 |
if(n.nodeType==1){ |
| 82 |
var val = domAttr.get(n, "validate"); |
| 83 |
this.notifications.push({ |
| 84 |
message:n.innerHTML, |
| 85 |
validate:function(){ |
| 86 |
|
| 87 |
|
| 88 |
var evals = true; |
| 89 |
try{ |
| 90 |
evals = dojo.eval(val); |
| 91 |
}catch(e){ } |
| 92 |
return evals; |
| 93 |
} |
| 94 |
}); |
| 95 |
} |
| 96 |
}, this); |
| 97 |
} |
| 98 |
|
| 99 |
}, |
| 100 |
|
| 101 |
checkNotifications: function(){ |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
if(!this.notifications.length){ |
| 109 |
|
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
for(var i=0;i<this.notifications.length;i++){ |
| 114 |
var evals = this.notifications[i].validate(); |
| 115 |
if(evals){ |
| 116 |
this.notify(this.notifications[i].message); |
| 117 |
|
| 118 |
|
| 119 |
break; |
| 120 |
} |
| 121 |
} |
| 122 |
}, |
| 123 |
|
| 124 |
postCreate: function(){ |
| 125 |
this.inherited(arguments); |
| 126 |
if(this.domNode.parentNode){ |
| 127 |
style.set(this.domNode, "display", "none"); |
| 128 |
} |
| 129 |
lang.mixin(this.attributeMap, { |
| 130 |
message:{ node:"messageNode", type:"innerHTML" } |
| 131 |
}); |
| 132 |
if(!this.noRemindButton){ |
| 133 |
domConstruct.destroy(this.dontRemindButtonNode); |
| 134 |
} |
| 135 |
if(has("ie")==6){ |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
var self = this; |
| 143 |
var setWidth = function(){ |
| 144 |
var v = win.getBox(); |
| 145 |
style.set(self.domNode, "width", v.w+"px"); |
| 146 |
}; |
| 147 |
this.connect(window, "resize", function(){ |
| 148 |
setWidth(); |
| 149 |
}); |
| 150 |
|
| 151 |
setWidth(); |
| 152 |
} |
| 153 |
domReady(lang.hitch(this, "checkNotifications")); |
| 154 |
|
| 155 |
}, |
| 156 |
|
| 157 |
notify: function(msg){ |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
if(cookie("disableUpgradeReminders")){ |
| 165 |
return; |
| 166 |
} |
| 167 |
if(!this.domNode.parentNode || !this.domNode.parentNode.innerHTML){ |
| 168 |
document.body.appendChild(this.domNode); |
| 169 |
} |
| 170 |
style.set(this.domNode, "display", ""); |
| 171 |
if(msg){ |
| 172 |
this.set("message", msg); |
| 173 |
} |
| 174 |
|
| 175 |
}, |
| 176 |
|
| 177 |
show: function(){ |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
this._bodyMarginTop = style.get(baseWin.body(), "marginTop"); |
| 185 |
this._size = domGeo.getContentBox(this.domNode).h; |
| 186 |
style.set(this.domNode, { display:"block", height:0, opacity:0 }); |
| 187 |
|
| 188 |
if(!this._showAnim){ |
| 189 |
this._showAnim = fx.combine([ |
| 190 |
baseFx.animateProperty({ node:baseWin.body(), duration:500, properties:{ marginTop:this._bodyMarginTop+this._size } }), |
| 191 |
baseFx.animateProperty({ node:this.domNode, duration:500, properties:{ height:this._size, opacity:1 } }) |
| 192 |
]); |
| 193 |
} |
| 194 |
this._showAnim.play(); |
| 195 |
}, |
| 196 |
|
| 197 |
hide: function(){ |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
if(!this._hideAnim){ |
| 202 |
this._hideAnim = fx.combine([ |
| 203 |
baseFx.animateProperty({ node:baseWin.body(), duration:500, properties:{ marginTop:this._bodyMarginTop } }), |
| 204 |
baseFx.animateProperty({ node:this.domNode, duration:500, properties:{ height:0, opacity:0 } }) |
| 205 |
]); |
| 206 |
connect.connect(this._hideAnim, "onEnd", this, function(){ |
| 207 |
style.set(this.domNode, {display:"none", opacity:1}); |
| 208 |
}); |
| 209 |
} |
| 210 |
this._hideAnim.play(); |
| 211 |
}, |
| 212 |
|
| 213 |
_onDontRemindClick: function(){ |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
cookie("disableUpgradeReminders", true, { expires:3650 }); |
| 219 |
this.hide(); |
| 220 |
}, |
| 221 |
|
| 222 |
_onCloseEnter: function(){ |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
domClass.add(this.closeButtonNode, "dojoxUpgradeBarCloseIcon-hover"); |
| 228 |
}, |
| 229 |
|
| 230 |
_onCloseLeave: function(){ |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
domClass.remove(this.closeButtonNode, "dojoxUpgradeBarCloseIcon-hover"); |
| 236 |
} |
| 237 |
}); |
| 238 |
|
| 239 |
|
| 240 |
return UpgradeBar; |
| 241 |
}); |