﻿var widgets=[],identifiersToStringLocalizations=[];function Widget(a,e,d,f,c,b){if(a){this.instanceID=a;this.widgetPath=e;this.sharedPath=d;this.sitePath=f;this.preferences=c;this.runningInApp=b===undefined?false:b;this.onloadReceived=false;if(this.preferences&&this.runningInApp==true){this.preferences.widget=this;setTransparentGifURL(this.sharedPath.stringByAppendingPathComponent("None.gif"))}this.div().widget=this;window[a]=this;widgets.push(this);widgets[a]=this;if(!this.constructor.instances)this.constructor.instances=[];this.constructor.instances.push(this)}}Widget.prototype.div=function(){var a=this.instanceID;if(arguments.length==1)a=this.instanceID+"-"+arguments[0];return $(a)};Widget.prototype.onload=function(){this.onloadReceived=true};Widget.prototype.onunload=function(){};Widget.prototype.didBecomeSelected=function(){};Widget.prototype.didBecomeDeselected=function(){};Widget.prototype.didBeginEditing=function(){};Widget.prototype.didEndEditing=function(){};Widget.prototype.setNeedsDisplay=function(){};Widget.prototype.preferenceForKey=function(b){var a;if(this.preferences)a=this.preferences[b];return a};Widget.prototype.initializeDefaultPreferences=function(a){var b=this;Object.keys(a).forEach(function(c){if(b.preferenceForKey(c)===undefined)b.setPreferenceForKey(a[c],c)})};Widget.prototype.setPreferenceForKey=function(c,b,a){if(this.runningInApp){if(a===undefined)a=true;if(a==false&&this.preferences.disableUndoRegistration)this.preferences.disableUndoRegistration();this.preferences[b]=c;if(a==false&&this.preferences.enableUndoRegistration)this.preferences.enableUndoRegistration()}else{this.preferences[b]=c;this.changedPreferenceForKey(b)}};Widget.prototype.changedPreferenceForKey=function(){};Widget.prototype.postNotificationWithNameAndUserInfo=function(b,a){if(window.NotificationCenter!==undefined)NotificationCenter.postNotification(new IWNotification(b,null,a))};Widget.prototype.sizeWillChange=function(){};Widget.prototype.sizeDidChange=function(){};Widget.prototype.widgetWidth=function(){var a=this.div();if(a)return a.offsetWidth;else return null};Widget.prototype.widgetHeight=function(){var a=this.div();if(a)return a.offsetHeight;else return null};Widget.prototype.getInstanceId=function(b){var a=this.instanceID+"-"+b;if(arguments.length==2)a+="$"+arguments[1];return a};Widget.prototype.getElementById=function(){var a=this.getInstanceId.apply(this,arguments);return $(a)};Widget.prototype.localizedString=function(a){return LocalizedString(this.widgetIdentifier,a)};Widget.onload=function(){for(var a=0;a<widgets.length;a++)widgets[a].onload()};Widget.onunload=function(){for(var a=0;a<widgets.length;a++)widgets[a].onunload()};function RegisterWidgetStrings(a,b){identifiersToStringLocalizations[a]=b}function LocalizedString(c,b){var a=undefined,d=identifiersToStringLocalizations[c];if(d===undefined)iWLog("warning: no localizations for widget "+c+", (key:"+b+")");else a=d[b];if(a===undefined){iWLog("warning: couldn't find a localization for '"+b+"' for widget "+c);a=b}return a}function WriteLocalizedString(a,b){document.write(LocalizedString(a,b))}