PageRenderTime 137ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 2ms

/static-site/exhibit/api-dev/exhibit-bundle-debug.js

http://simile-widgets.googlecode.com/
JavaScript | 8540 lines | 8361 code | 119 blank | 60 comment | 750 complexity | 01208033a36d116b807203bd1aa30c74 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /* authentication.js */
  2. Exhibit.Authentication={};
  3. Exhibit.Authentication.Enabled=false;
  4. Exhibit.Authentication.GoogleToken=null;
  5. Exhibit.Authentication.GoogleSessionToken=null;
  6. Exhibit.Authentication.authenticate=function(){if(!window.Exhibit.params.authenticated){return ;
  7. }var links=document.getElementsByTagName("head")[0].childNodes;
  8. for(var i=0;
  9. i<links.length;
  10. i++){var link=links[i];
  11. if(link.rel=="exhibit/output"&&link.getAttribute("ex:authenticated")){Exhibit.Authentication.handleGoogleAuthentication();
  12. return ;
  13. }}};
  14. Exhibit.Authentication.parseLocationParams=function(){var params=document.location.search.substr(1).split("&");
  15. var ret={};
  16. for(var i=0;
  17. i<params.length;
  18. i++){var p=params[i];
  19. if(p.indexOf("=")!=-1){var components=p.split("=");
  20. if(components.length!=2){SimileAjax.Debug.warn("Error parsing location parameter "+p);
  21. }else{ret[components[0]]=components[1];
  22. }}else{ret[p]=true;
  23. }}return ret;
  24. };
  25. Exhibit.Authentication.GoogleAuthenticationURL="https://www.google.com/accounts/AuthSubRequest";
  26. Exhibit.Authentication.handleGoogleAuthentication=function(){var params=Exhibit.Authentication.parseLocationParams();
  27. if(params.token){Exhibit.Authentication.GoogleToken=params.token;
  28. Exhibit.Authentication.Enabled=true;
  29. }else{var authURL=Exhibit.Authentication.GoogleAuthenticationURL;
  30. authURL+="?session=1";
  31. authURL+="&scope=http://spreadsheets.google.com/feeds/";
  32. authURL+="&next="+document.location.href;
  33. document.location.href=authURL;
  34. }};
  35. /* collection.js */
  36. Exhibit.Collection=function(id,database){this._id=id;
  37. this._database=database;
  38. this._listeners=new SimileAjax.ListenerQueue();
  39. this._facets=[];
  40. this._updating=false;
  41. this._items=null;
  42. this._restrictedItems=null;
  43. };
  44. Exhibit.Collection.createAllItemsCollection=function(id,database){var collection=new Exhibit.Collection(id,database);
  45. collection._update=Exhibit.Collection._allItemsCollection_update;
  46. Exhibit.Collection._initializeBasicCollection(collection,database);
  47. return collection;
  48. };
  49. Exhibit.Collection.createSubmissionsCollection=function(id,database){var collection=new Exhibit.Collection(id,database);
  50. collection._update=Exhibit.Collection._submissionCollection_update;
  51. Exhibit.Collection._initializeBasicCollection(collection,database);
  52. return collection;
  53. };
  54. Exhibit.Collection.create=function(id,configuration,database){var collection=new Exhibit.Collection(id,database);
  55. if("itemTypes" in configuration){collection._itemTypes=configuration.itemTypes;
  56. collection._update=Exhibit.Collection._typeBasedCollection_update;
  57. }else{collection._update=Exhibit.Collection._allItemsCollection_update;
  58. }Exhibit.Collection._initializeBasicCollection(collection,database);
  59. return collection;
  60. };
  61. Exhibit.Collection.createFromDOM=function(id,elmt,database){var collection=new Exhibit.Collection(id,database);
  62. var itemTypes=Exhibit.getAttribute(elmt,"itemTypes",",");
  63. if(itemTypes!=null&&itemTypes.length>0){collection._itemTypes=itemTypes;
  64. collection._update=Exhibit.Collection._typeBasedCollection_update;
  65. }else{collection._update=Exhibit.Collection._allItemsCollection_update;
  66. }Exhibit.Collection._initializeBasicCollection(collection,database);
  67. return collection;
  68. };
  69. Exhibit.Collection.create2=function(id,configuration,uiContext){var database=uiContext.getDatabase();
  70. if("expression" in configuration){var collection=new Exhibit.Collection(id,database);
  71. collection._expression=Exhibit.ExpressionParser.parse(configuration.expression);
  72. collection._baseCollection=("baseCollectionID" in configuration)?uiContext.getExhibit().getCollection(configuration.baseCollectionID):uiContext.getCollection();
  73. collection._restrictBaseCollection=("restrictBaseCollection" in configuration)?configuration.restrictBaseCollection:false;
  74. if(collection._restrictBaseCollection){Exhibit.Collection._initializeRestrictingBasedCollection(collection);
  75. }else{Exhibit.Collection._initializeBasedCollection(collection);
  76. }return collection;
  77. }else{return Exhibit.Collection.create(id,configuration,database);
  78. }};
  79. Exhibit.Collection.createFromDOM2=function(id,elmt,uiContext){var database=uiContext.getDatabase();
  80. var collection;
  81. if(Exhibit.getAttribute(elmt,"submissionsCollection")){return Exhibit.Collection.createSubmissionsCollection(id,database);
  82. }var expressionString=Exhibit.getAttribute(elmt,"expression");
  83. if(expressionString!=null&&expressionString.length>0){collection=new Exhibit.Collection(id,database);
  84. collection._expression=Exhibit.ExpressionParser.parse(expressionString);
  85. var baseCollectionID=Exhibit.getAttribute(elmt,"baseCollectionID");
  86. collection._baseCollection=(baseCollectionID!=null&&baseCollectionID.length>0)?uiContext.getExhibit().getCollection(baseCollectionID):uiContext.getCollection();
  87. collection._restrictBaseCollection=Exhibit.getAttribute(elmt,"restrictBaseCollection")=="true";
  88. if(collection._restrictBaseCollection){Exhibit.Collection._initializeRestrictingBasedCollection(collection,database);
  89. }else{Exhibit.Collection._initializeBasedCollection(collection);
  90. }}else{collection=Exhibit.Collection.createFromDOM(id,elmt,database);
  91. }return collection;
  92. };
  93. Exhibit.Collection._initializeBasicCollection=function(collection,database){var update=function(){collection._update();
  94. };
  95. collection._listener={onAfterLoadingItems:update,onAfterRemovingAllStatements:update};
  96. database.addListener(collection._listener);
  97. collection._update();
  98. };
  99. Exhibit.Collection._initializeBasedCollection=function(collection){collection._update=Exhibit.Collection._basedCollection_update;
  100. collection._listener={onItemsChanged:function(){collection._update();
  101. }};
  102. collection._baseCollection.addListener(collection._listener);
  103. collection._update();
  104. };
  105. Exhibit.Collection._initializeRestrictingBasedCollection=function(collection,database){collection._cache=new Exhibit.FacetUtilities.Cache(database,collection._baseCollection,collection._expression);
  106. collection._isUpdatingBaseCollection=false;
  107. collection.onFacetUpdated=Exhibit.Collection._restrictingBasedCollection_onFacetUpdated;
  108. collection.restrict=Exhibit.Collection._restrictingBasedCollection_restrict;
  109. collection.update=Exhibit.Collection._restrictingBasedCollection_update;
  110. collection.hasRestrictions=Exhibit.Collection._restrictingBasedCollection_hasRestrictions;
  111. collection._baseCollection.addFacet(collection);
  112. };
  113. Exhibit.Collection._allItemsCollection_update=function(){this.setItems(this._database.getAllItems());
  114. this._onRootItemsChanged();
  115. };
  116. Exhibit.Collection._submissionCollection_update=function(){this.setItems(this._database.getAllSubmissions());
  117. this._onRootItemsChanged();
  118. };
  119. Exhibit.Collection._typeBasedCollection_update=function(){var newItems=new Exhibit.Set();
  120. for(var i=0;
  121. i<this._itemTypes.length;
  122. i++){this._database.getSubjects(this._itemTypes[i],"type",newItems);
  123. }this.setItems(newItems);
  124. this._onRootItemsChanged();
  125. };
  126. Exhibit.Collection._basedCollection_update=function(){this.setItems(this._expression.evaluate({"value":this._baseCollection.getRestrictedItems()},{"value":"item"},"value",this._database).values);
  127. this._onRootItemsChanged();
  128. };
  129. Exhibit.Collection._restrictingBasedCollection_onFacetUpdated=function(facetChanged){if(!this._updating){Exhibit.Collection.prototype.onFacetUpdated.call(this,facetChanged);
  130. this._isUpdatingBaseCollection=true;
  131. this._baseCollection.onFacetUpdated(this);
  132. this._isUpdatingBaseCollection=false;
  133. }};
  134. Exhibit.Collection._restrictingBasedCollection_restrict=function(items){if(this._restrictedItems.size()==this._items.size()){return items;
  135. }return this._cache.getItemsFromValues(this._restrictedItems,items);
  136. };
  137. Exhibit.Collection._restrictingBasedCollection_update=function(items){if(!this._isUpdatingBaseCollection){this.setItems(this._cache.getValuesFromItems(items));
  138. this._onRootItemsChanged();
  139. }};
  140. Exhibit.Collection._restrictingBasedCollection_hasRestrictions=function(){return(this._items!=null)&&(this._restrictedItems!=null)&&(this._restrictedItems.size()!=this._items.size());
  141. };
  142. Exhibit.Collection.prototype.getID=function(){return this._id;
  143. };
  144. Exhibit.Collection.prototype.dispose=function(){if("_baseCollection" in this){this._baseCollection.removeListener(this._listener);
  145. this._baseCollection=null;
  146. this._expression=null;
  147. }else{this._database.removeListener(this._listener);
  148. }this._database=null;
  149. this._listener=null;
  150. this._listeners=null;
  151. this._items=null;
  152. this._restrictedItems=null;
  153. };
  154. Exhibit.Collection.prototype.addListener=function(listener){this._listeners.add(listener);
  155. };
  156. Exhibit.Collection.prototype.removeListener=function(listener){this._listeners.remove(listener);
  157. };
  158. Exhibit.Collection.prototype.addFacet=function(facet){this._facets.push(facet);
  159. if(facet.hasRestrictions()){this._computeRestrictedItems();
  160. this._updateFacets(null);
  161. this._listeners.fire("onItemsChanged",[]);
  162. }else{facet.update(this.getRestrictedItems());
  163. }};
  164. Exhibit.Collection.prototype.removeFacet=function(facet){for(var i=0;
  165. i<this._facets.length;
  166. i++){if(facet==this._facets[i]){this._facets.splice(i,1);
  167. if(facet.hasRestrictions()){this._computeRestrictedItems();
  168. this._updateFacets(null);
  169. this._listeners.fire("onItemsChanged",[]);
  170. }break;
  171. }}};
  172. Exhibit.Collection.prototype.clearAllRestrictions=function(){var restrictions=[];
  173. this._updating=true;
  174. for(var i=0;
  175. i<this._facets.length;
  176. i++){restrictions.push(this._facets[i].clearAllRestrictions());
  177. }this._updating=false;
  178. this.onFacetUpdated(null);
  179. return restrictions;
  180. };
  181. Exhibit.Collection.prototype.applyRestrictions=function(restrictions){this._updating=true;
  182. for(var i=0;
  183. i<this._facets.length;
  184. i++){this._facets[i].applyRestrictions(restrictions[i]);
  185. }this._updating=false;
  186. this.onFacetUpdated(null);
  187. };
  188. Exhibit.Collection.prototype.getAllItems=function(){return new Exhibit.Set(this._items);
  189. };
  190. Exhibit.Collection.prototype.countAllItems=function(){return this._items.size();
  191. };
  192. Exhibit.Collection.prototype.getRestrictedItems=function(){return new Exhibit.Set(this._restrictedItems);
  193. };
  194. Exhibit.Collection.prototype.countRestrictedItems=function(){return this._restrictedItems.size();
  195. };
  196. Exhibit.Collection.prototype.onFacetUpdated=function(facetChanged){if(!this._updating){this._computeRestrictedItems();
  197. this._updateFacets(facetChanged);
  198. this._listeners.fire("onItemsChanged",[]);
  199. }};
  200. Exhibit.Collection.prototype._onRootItemsChanged=function(){this._listeners.fire("onRootItemsChanged",[]);
  201. this._computeRestrictedItems();
  202. this._updateFacets(null);
  203. this._listeners.fire("onItemsChanged",[]);
  204. };
  205. Exhibit.Collection.prototype._updateFacets=function(facetChanged){var restrictedFacetCount=0;
  206. for(var i=0;
  207. i<this._facets.length;
  208. i++){if(this._facets[i].hasRestrictions()){restrictedFacetCount++;
  209. }}for(var i=0;
  210. i<this._facets.length;
  211. i++){var facet=this._facets[i];
  212. if(facet.hasRestrictions()){if(restrictedFacetCount<=1){facet.update(this.getAllItems());
  213. }else{var items=this.getAllItems();
  214. for(var j=0;
  215. j<this._facets.length;
  216. j++){if(i!=j){items=this._facets[j].restrict(items);
  217. }}facet.update(items);
  218. }}else{facet.update(this.getRestrictedItems());
  219. }}};
  220. Exhibit.Collection.prototype._computeRestrictedItems=function(){this._restrictedItems=this._items;
  221. for(var i=0;
  222. i<this._facets.length;
  223. i++){var facet=this._facets[i];
  224. if(facet.hasRestrictions()){this._restrictedItems=facet.restrict(this._restrictedItems);
  225. }}};
  226. Exhibit.Collection.prototype.setItems=function(items){this._items=items;
  227. };
  228. /* controls.js */
  229. Exhibit.Controls={};
  230. Exhibit.Controls["if"]={f:function(args,roots,rootValueTypes,defaultRootName,database){var conditionCollection=args[0].evaluate(roots,rootValueTypes,defaultRootName,database);
  231. var condition=false;
  232. conditionCollection.forEachValue(function(v){if(v){condition=true;
  233. return true;
  234. }});
  235. if(condition){return args[1].evaluate(roots,rootValueTypes,defaultRootName,database);
  236. }else{return args[2].evaluate(roots,rootValueTypes,defaultRootName,database);
  237. }}};
  238. Exhibit.Controls["foreach"]={f:function(args,roots,rootValueTypes,defaultRootName,database){var collection=args[0].evaluate(roots,rootValueTypes,defaultRootName,database);
  239. var oldValue=roots["value"];
  240. var oldValueType=rootValueTypes["value"];
  241. rootValueTypes["value"]=collection.valueType;
  242. var results=[];
  243. var valueType="text";
  244. collection.forEachValue(function(element){roots["value"]=element;
  245. var collection2=args[1].evaluate(roots,rootValueTypes,defaultRootName,database);
  246. valueType=collection2.valueType;
  247. collection2.forEachValue(function(result){results.push(result);
  248. });
  249. });
  250. roots["value"]=oldValue;
  251. rootValueTypes["value"]=oldValueType;
  252. return new Exhibit.Expression._Collection(results,valueType);
  253. }};
  254. Exhibit.Controls["default"]={f:function(args,roots,rootValueTypes,defaultRootName,database){for(var i=0;
  255. i<args.length;
  256. i++){var collection=args[i].evaluate(roots,rootValueTypes,defaultRootName,database);
  257. if(collection.size>0){return collection;
  258. }}return new Exhibit.Expression._Collection([],"text");
  259. }};
  260. Exhibit.Controls["filter"]={f:function(args,roots,rootValueTypes,defaultRootName,database){var collection=args[0].evaluate(roots,rootValueTypes,defaultRootName,database);
  261. var oldValue=roots["value"];
  262. var oldValueType=rootValueTypes["value"];
  263. var results=new Exhibit.Set();
  264. rootValueTypes["value"]=collection.valueType;
  265. collection.forEachValue(function(element){roots["value"]=element;
  266. var collection2=args[1].evaluate(roots,rootValueTypes,defaultRootName,database);
  267. if(collection2.size>0&&collection2.contains("true")){results.add(element);
  268. }});
  269. roots["value"]=oldValue;
  270. rootValueTypes["value"]=oldValueType;
  271. return new Exhibit.Expression._Collection(results,collection.valueType);
  272. }};
  273. /* database.js */
  274. Exhibit.Database=new Object();
  275. Exhibit.Database.create=function(){Exhibit.Database.handleAuthentication();
  276. return new Exhibit.Database._Impl();
  277. };
  278. Exhibit.Database.handleAuthentication=function(){if(window.Exhibit.params.authenticated){var links=document.getElementsByTagName("head")[0].childNodes;
  279. for(var i=0;
  280. i<links.length;
  281. i++){var link=links[i];
  282. if(link.rel=="exhibit/output"&&link.getAttribute("ex:authenticated")){}}}};
  283. Exhibit.Database.makeISO8601DateString=function(date){date=date||new Date();
  284. var pad=function(i){return i>9?i.toString():"0"+i;
  285. };
  286. var s=date.getFullYear()+"-"+pad(date.getMonth()+1)+"-"+pad(date.getDate());
  287. return s;
  288. };
  289. Exhibit.Database.TimestampPropertyName="addedOn";
  290. Exhibit.Database._Impl=function(){this._types={};
  291. this._properties={};
  292. this._propertyArray={};
  293. this._submissionRegistry={};
  294. this._originalValues={};
  295. this._newItems={};
  296. this._listeners=new SimileAjax.ListenerQueue();
  297. this._spo={};
  298. this._ops={};
  299. this._items=new Exhibit.Set();
  300. var l10n=Exhibit.Database.l10n;
  301. var itemType=new Exhibit.Database._Type("Item");
  302. itemType._custom=Exhibit.Database.l10n.itemType;
  303. this._types["Item"]=itemType;
  304. var labelProperty=new Exhibit.Database._Property("label",this);
  305. labelProperty._uri="http://www.w3.org/2000/01/rdf-schema#label";
  306. labelProperty._valueType="text";
  307. labelProperty._label=l10n.labelProperty.label;
  308. labelProperty._pluralLabel=l10n.labelProperty.pluralLabel;
  309. labelProperty._reverseLabel=l10n.labelProperty.reverseLabel;
  310. labelProperty._reversePluralLabel=l10n.labelProperty.reversePluralLabel;
  311. labelProperty._groupingLabel=l10n.labelProperty.groupingLabel;
  312. labelProperty._reverseGroupingLabel=l10n.labelProperty.reverseGroupingLabel;
  313. this._properties["label"]=labelProperty;
  314. var typeProperty=new Exhibit.Database._Property("type");
  315. typeProperty._uri="http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
  316. typeProperty._valueType="text";
  317. typeProperty._label="type";
  318. typeProperty._pluralLabel=l10n.typeProperty.label;
  319. typeProperty._reverseLabel=l10n.typeProperty.reverseLabel;
  320. typeProperty._reversePluralLabel=l10n.typeProperty.reversePluralLabel;
  321. typeProperty._groupingLabel=l10n.typeProperty.groupingLabel;
  322. typeProperty._reverseGroupingLabel=l10n.typeProperty.reverseGroupingLabel;
  323. this._properties["type"]=typeProperty;
  324. var uriProperty=new Exhibit.Database._Property("uri");
  325. uriProperty._uri="http://simile.mit.edu/2006/11/exhibit#uri";
  326. uriProperty._valueType="url";
  327. uriProperty._label="URI";
  328. uriProperty._pluralLabel="URIs";
  329. uriProperty._reverseLabel="URI of";
  330. uriProperty._reversePluralLabel="URIs of";
  331. uriProperty._groupingLabel="URIs";
  332. uriProperty._reverseGroupingLabel="things named by these URIs";
  333. this._properties["uri"]=uriProperty;
  334. var changeProperty=new Exhibit.Database._Property("change",this);
  335. changeProperty._uri="http://simile.mit.edu/2006/11/exhibit#change";
  336. changeProperty._valueType="text";
  337. changeProperty._label="change type";
  338. changeProperty._pluralLabel="change types";
  339. changeProperty._reverseLabel="change type of";
  340. changeProperty._reversePluralLabel="change types of";
  341. changeProperty._groupingLabel="change types";
  342. changeProperty._reverseGroupingLabel="changes of this type";
  343. this._properties["change"]=changeProperty;
  344. var changedItemProperty=new Exhibit.Database._Property("changedItem",this);
  345. changedItemProperty._uri="http://simile.mit.edu/2006/11/exhibit#changedItem";
  346. changedItemProperty._valueType="text";
  347. changedItemProperty._label="changed item";
  348. changedItemProperty._pluralLabel="changed item";
  349. changedItemProperty._groupingLabel="changed items";
  350. this._properties["changedItem"]=changedItemProperty;
  351. var modifiedProperty=new Exhibit.Database._Property(Exhibit.Database.ModifiedPropertyName,this);
  352. modifiedProperty._uri="http://simile.mit.edu/2006/11/exhibit#modified";
  353. modifiedProperty._valueType="text";
  354. modifiedProperty._label="modified";
  355. modifiedProperty._pluralLabel="modified";
  356. modifiedProperty._groupingLabel="was modified";
  357. this._properties["modified"]=modifiedProperty;
  358. };
  359. Exhibit.Database._Impl.prototype.createDatabase=function(){return Exhibit.Database.create();
  360. };
  361. Exhibit.Database._Impl.prototype.addListener=function(listener){this._listeners.add(listener);
  362. };
  363. Exhibit.Database._Impl.prototype.removeListener=function(listener){this._listeners.remove(listener);
  364. };
  365. Exhibit.Database._Impl.prototype.loadDataLinks=function(fDone){var links=SimileAjax.jQuery('link[rel="exhibit/data"]').add('a[rel="exhibit/data"]').get();
  366. var self=this;
  367. var fDone2=function(){self.loadDataElements(self,fDone);
  368. if(fDone){fDone();
  369. }};
  370. this._loadLinks(links,this,fDone2);
  371. };
  372. Exhibit.Database._Impl.prototype.loadLinks=function(links,fDone){this._loadLinks(links,this,fDone);
  373. };
  374. Exhibit.Database._Impl.prototype.loadDataElements=function(database){var findFunction=function(s){if(typeof (s)=="string"){if(s in Exhibit){s=Exhibit[s];
  375. }else{try{s=eval(s);
  376. }catch(e){s=null;
  377. }}}return s;
  378. };
  379. var url=window.location.href;
  380. var loadElement=function(element){var e=SimileAjax.jQuery(element);
  381. var content=e.html();
  382. if(content){if(!e.attr("href")){e.attr("href",url);
  383. }var type=Exhibit.getAttribute(element,"type");
  384. if(type==null||type.length==0){type="application/json";
  385. }var importer=Exhibit.importers[type];
  386. var parser=findFunction(Exhibit.getAttribute(element,"parser"))||(importer&&importer.parse);
  387. if(parser){var o=null;
  388. try{o=parser(content,element,url);
  389. }catch(e){SimileAjax.Debug.exception(e,"Error parsing Exhibit data from "+url);
  390. }if(o!=null){try{database.loadData(o,Exhibit.Persistence.getBaseURL(url));
  391. e.hide();
  392. }catch(e){SimileAjax.Debug.exception(e,"Error loading Exhibit data from "+url);
  393. }}}else{SimileAjax.Debug.log("No parser for data of type "+type);
  394. }}};
  395. var safeLoadElement=function(){try{loadElement(this);
  396. }catch(e){}};
  397. var elements;
  398. try{elements=SimileAjax.jQuery('[ex\\:role="data"]');
  399. }catch(e){elements=$("*").filter(function(){var attrs=this.attributes;
  400. for(i=0;
  401. i<attrs.length;
  402. i++){if((attrs[i].nodeName=="ex:role")&&(attrs[i].nodeValue=="data")){return true;
  403. }}return false;
  404. });
  405. }elements.each(safeLoadElement);
  406. };
  407. Exhibit.Database._Impl.prototype.loadSubmissionLinks=function(fDone){var db=this;
  408. var dbProxy={loadData:function(o,baseURI){if("types" in o){db.loadTypes(o.types,baseURI);
  409. }if("properties" in o){db.loadProperties(o.properties,baseURI);
  410. }if("items" in o){db._listeners.fire("onBeforeLoadingItems",[]);
  411. db.loadItems(o.items,baseURI);
  412. db._listeners.fire("onAfterLoadingItems",[]);
  413. }}};
  414. var links=SimileAjax.jQuery("head > link[rel=exhibit/submissions]").get();
  415. this._loadLinks(links,dbProxy,fDone);
  416. };
  417. Exhibit.Database._Impl.defaultGetter=function(link,database,parser,cont){var url=typeof link=="string"?link:link.href;
  418. url=Exhibit.Persistence.resolveURL(url);
  419. var fError=function(){Exhibit.UI.hideBusyIndicator();
  420. Exhibit.UI.showHelp(Exhibit.l10n.failedToLoadDataFileMessage(url));
  421. if(cont){cont();
  422. }};
  423. var fDone=function(content){Exhibit.UI.hideBusyIndicator();
  424. if(url.indexOf("#")>=0){var fragment=url.match(/(#.*)/)[1];
  425. content=SimileAjax.jQuery("<div>"+content+"</div>").find(fragment).html();
  426. }var o;
  427. try{o=parser(content,link,url);
  428. }catch(e){SimileAjax.Debug.log(e,"Error parsing Exhibit data from "+url);
  429. }if(o!=null){try{database.loadData(o,Exhibit.Persistence.getBaseURL(url));
  430. }catch(e){SimileAjax.Debug.log(e,"Error loading Exhibit data from "+url);
  431. }}if(cont){cont();
  432. }};
  433. Exhibit.UI.showBusyIndicator();
  434. SimileAjax.jQuery.ajax({url:url,dataType:"text",success:fDone,error:fError});
  435. };
  436. Exhibit.Database._Impl.prototype.findLoader=function(elt){var findFunction=function(s){if(typeof (s)=="string"){if(s in Exhibit){s=Exhibit[s];
  437. }else{try{s=eval(s);
  438. }catch(e){s=null;
  439. }}}return s;
  440. };
  441. var type=Exhibit.getAttribute(link,"type");
  442. if(type==null||type.length==0){type="application/json";
  443. }var importer=Exhibit.importers[type];
  444. var parser=findFunction(Exhibit.getAttribute(link,"parser"))||(importer&&importer.parse);
  445. var getter=findFunction(Exhibit.getAttribute(link,"getter"))||(importer&&importer.getter)||Exhibit.Database._Impl.defaultGetter;
  446. if(parser){return function(link,database,fNext){(getter)(link,database,parser,fNext);
  447. };
  448. }else{if(importer){return importer.load;
  449. }else{return null;
  450. }}};
  451. Exhibit.Database._Impl.prototype._loadLinks=function(links,database,fDone){var findFunction=function(s){if(typeof (s)=="string"){if(s in Exhibit){s=Exhibit[s];
  452. }else{try{s=eval(s);
  453. }catch(e){s=null;
  454. }}}return s;
  455. };
  456. links=[].concat(links);
  457. var fNext=function(){while(links.length>0){var link=links.shift();
  458. var type=link.type;
  459. if(type==null||type.length==0){type="application/json";
  460. }var importer=Exhibit.importers[type];
  461. var parser=findFunction(Exhibit.getAttribute(link,"parser"))||(importer&&importer.parse);
  462. var getter=findFunction(Exhibit.getAttribute(link,"getter"))||(importer&&importer.getter)||Exhibit.Database._Impl.defaultGetter;
  463. if(parser){(getter)(link,database,parser,fNext);
  464. return ;
  465. }else{if(importer){importer.load(link,database,fNext);
  466. return ;
  467. }else{SimileAjax.Debug.log("No importer for data of type "+type);
  468. }}}if(fDone!=null){fDone();
  469. }};
  470. fNext();
  471. };
  472. Exhibit.Database._Impl.prototype.loadData=function(o,baseURI){if(typeof baseURI=="undefined"){baseURI=location.href;
  473. }if("types" in o){this.loadTypes(o.types,baseURI);
  474. }if("properties" in o){this.loadProperties(o.properties,baseURI);
  475. }if("items" in o){this.loadItems(o.items,baseURI);
  476. }};
  477. Exhibit.Database._Impl.prototype.loadTypes=function(typeEntries,baseURI){this._listeners.fire("onBeforeLoadingTypes",[]);
  478. try{var lastChar=baseURI.substr(baseURI.length-1);
  479. if(lastChar=="#"){baseURI=baseURI.substr(0,baseURI.length-1)+"/";
  480. }else{if(lastChar!="/"&&lastChar!=":"){baseURI+="/";
  481. }}for(var typeID in typeEntries){if(typeof typeID!="string"){continue;
  482. }var typeEntry=typeEntries[typeID];
  483. if(typeof typeEntry!="object"){continue;
  484. }var type;
  485. if(typeID in this._types){type=this._types[typeID];
  486. }else{type=new Exhibit.Database._Type(typeID);
  487. this._types[typeID]=type;
  488. }for(var p in typeEntry){type._custom[p]=typeEntry[p];
  489. }if(!("uri" in type._custom)){type._custom["uri"]=baseURI+"type#"+encodeURIComponent(typeID);
  490. }if(!("label" in type._custom)){type._custom["label"]=typeID;
  491. }}this._listeners.fire("onAfterLoadingTypes",[]);
  492. }catch(e){SimileAjax.Debug.exception(e,"Database.loadTypes failed");
  493. }};
  494. Exhibit.Database._Impl.prototype.loadProperties=function(propertyEntries,baseURI){this._listeners.fire("onBeforeLoadingProperties",[]);
  495. try{var lastChar=baseURI.substr(baseURI.length-1);
  496. if(lastChar=="#"){baseURI=baseURI.substr(0,baseURI.length-1)+"/";
  497. }else{if(lastChar!="/"&&lastChar!=":"){baseURI+="/";
  498. }}for(var propertyID in propertyEntries){if(typeof propertyID!="string"){continue;
  499. }var propertyEntry=propertyEntries[propertyID];
  500. if(typeof propertyEntry!="object"){continue;
  501. }var property;
  502. if(propertyID in this._properties){property=this._properties[propertyID];
  503. }else{property=new Exhibit.Database._Property(propertyID,this);
  504. this._properties[propertyID]=property;
  505. }property._uri=("uri" in propertyEntry)?propertyEntry.uri:(baseURI+"property#"+encodeURIComponent(propertyID));
  506. property._valueType=("valueType" in propertyEntry)?propertyEntry.valueType:"text";
  507. property._label=("label" in propertyEntry)?propertyEntry.label:propertyID;
  508. property._pluralLabel=("pluralLabel" in propertyEntry)?propertyEntry.pluralLabel:property._label;
  509. property._reverseLabel=("reverseLabel" in propertyEntry)?propertyEntry.reverseLabel:("!"+property._label);
  510. property._reversePluralLabel=("reversePluralLabel" in propertyEntry)?propertyEntry.reversePluralLabel:("!"+property._pluralLabel);
  511. property._groupingLabel=("groupingLabel" in propertyEntry)?propertyEntry.groupingLabel:property._label;
  512. property._reverseGroupingLabel=("reverseGroupingLabel" in propertyEntry)?propertyEntry.reverseGroupingLabel:property._reverseLabel;
  513. if("origin" in propertyEntry){property._origin=propertyEntry.origin;
  514. }}this._propertyArray=null;
  515. this._listeners.fire("onAfterLoadingProperties",[]);
  516. }catch(e){SimileAjax.Debug.exception(e,"Database.loadProperties failed");
  517. }};
  518. Exhibit.Database._Impl.prototype.loadItems=function(itemEntries,baseURI){this._listeners.fire("onBeforeLoadingItems",[]);
  519. try{var lastChar=baseURI.substr(baseURI.length-1);
  520. if(lastChar=="#"){baseURI=baseURI.substr(0,baseURI.length-1)+"/";
  521. }else{if(lastChar!="/"&&lastChar!=":"){baseURI+="/";
  522. }}var spo=this._spo;
  523. var ops=this._ops;
  524. var indexPut=Exhibit.Database._indexPut;
  525. var indexTriple=function(s,p,o){indexPut(spo,s,p,o);
  526. indexPut(ops,o,p,s);
  527. };
  528. for(var i=0;
  529. i<itemEntries.length;
  530. i++){var entry=itemEntries[i];
  531. if(typeof entry=="object"){this._loadItem(entry,indexTriple,baseURI);
  532. }}this._propertyArray=null;
  533. this._listeners.fire("onAfterLoadingItems",[]);
  534. }catch(e){SimileAjax.Debug.exception(e,"Database.loadItems failed");
  535. }};
  536. Exhibit.Database._Impl.prototype.getType=function(typeID){return this._types[typeID];
  537. };
  538. Exhibit.Database._Impl.prototype.getProperty=function(propertyID){return propertyID in this._properties?this._properties[propertyID]:null;
  539. };
  540. Exhibit.Database._Impl.prototype.getAllProperties=function(){if(this._propertyArray==null){this._propertyArray=[];
  541. for(var propertyID in this._properties){this._propertyArray.push(propertyID);
  542. }}return[].concat(this._propertyArray);
  543. };
  544. Exhibit.Database._Impl.prototype.isSubmission=function(id){return id in this._submissionRegistry;
  545. };
  546. Exhibit.Database._Impl.prototype.getAllItems=function(){var ret=new Exhibit.Set();
  547. var self=this;
  548. this._items.visit(function(item){if(!self.isSubmission(item)){ret.add(item);
  549. }});
  550. return ret;
  551. };
  552. Exhibit.Database._Impl.prototype.getAllSubmissions=function(){var ret=new Exhibit.Set();
  553. var itemList=this._items.toArray();
  554. for(var i in itemList){var item=itemList[i];
  555. if(this.isSubmission(item)){ret.add(item);
  556. }}return ret;
  557. };
  558. Exhibit.Database._Impl.prototype.getAllItemsCount=function(){return this._items.size();
  559. };
  560. Exhibit.Database._Impl.prototype.containsItem=function(itemID){return this._items.contains(itemID);
  561. };
  562. Exhibit.Database._Impl.prototype.getNamespaces=function(idToQualifiedName,prefixToBase){var bases={};
  563. for(var propertyID in this._properties){var property=this._properties[propertyID];
  564. var uri=property.getURI();
  565. var hash=uri.indexOf("#");
  566. if(hash>0){var base=uri.substr(0,hash+1);
  567. bases[base]=true;
  568. idToQualifiedName[propertyID]={base:base,localName:uri.substr(hash+1)};
  569. continue;
  570. }var slash=uri.lastIndexOf("/");
  571. if(slash>0){var base=uri.substr(0,slash+1);
  572. bases[base]=true;
  573. idToQualifiedName[propertyID]={base:base,localName:uri.substr(slash+1)};
  574. continue;
  575. }}var baseToPrefix={};
  576. var letters="abcdefghijklmnopqrstuvwxyz";
  577. var i=0;
  578. for(var base in bases){var prefix=letters.substr(i++,1);
  579. prefixToBase[prefix]=base;
  580. baseToPrefix[base]=prefix;
  581. }for(var propertyID in idToQualifiedName){var qname=idToQualifiedName[propertyID];
  582. qname.prefix=baseToPrefix[qname.base];
  583. }};
  584. Exhibit.Database._Impl.prototype._loadItem=function(itemEntry,indexFunction,baseURI){if(!("label" in itemEntry)&&!("id" in itemEntry)){SimileAjax.Debug.warn("Item entry has no label and no id: "+SimileAjax.JSON.toJSONString(itemEntry));
  585. itemEntry.label="item"+Math.ceil(Math.random()*1000000);
  586. }var id;
  587. if(!("label" in itemEntry)){id=itemEntry.id;
  588. if(!this._items.contains(id)){SimileAjax.Debug.warn("Cannot add new item containing no label: "+SimileAjax.JSON.toJSONString(itemEntry));
  589. }}else{var label=itemEntry.label;
  590. var id=("id" in itemEntry)?itemEntry.id:label;
  591. var uri=("uri" in itemEntry)?itemEntry.uri:(baseURI+"item#"+encodeURIComponent(id));
  592. var type=("type" in itemEntry)?itemEntry.type:"Item";
  593. var isArray=function(obj){if(!obj||(obj.constructor.toString().indexOf("Array")==-1)){return false;
  594. }else{return true;
  595. }};
  596. if(isArray(label)){label=label[0];
  597. }if(isArray(id)){id=id[0];
  598. }if(isArray(uri)){uri=uri[0];
  599. }if(isArray(type)){type=type[0];
  600. }this._items.add(id);
  601. indexFunction(id,"uri",uri);
  602. indexFunction(id,"label",label);
  603. indexFunction(id,"type",type);
  604. this._ensureTypeExists(type,baseURI);
  605. }for(var p in itemEntry){if(typeof p!="string"){continue;
  606. }if(p!="uri"&&p!="label"&&p!="id"&&p!="type"){this._ensurePropertyExists(p,baseURI)._onNewData();
  607. var v=itemEntry[p];
  608. if(v instanceof Array){for(var j=0;
  609. j<v.length;
  610. j++){indexFunction(id,p,v[j]);
  611. }}else{if(v!=undefined&&v!=null){indexFunction(id,p,v);
  612. }}}}};
  613. Exhibit.Database._Impl.prototype._ensureTypeExists=function(typeID,baseURI){if(!(typeID in this._types)){var type=new Exhibit.Database._Type(typeID);
  614. type._custom["uri"]=baseURI+"type#"+encodeURIComponent(typeID);
  615. type._custom["label"]=typeID;
  616. this._types[typeID]=type;
  617. }};
  618. Exhibit.Database._Impl.prototype._ensurePropertyExists=function(propertyID,baseURI){if(!(propertyID in this._properties)){var property=new Exhibit.Database._Property(propertyID,this);
  619. property._uri=baseURI+"property#"+encodeURIComponent(propertyID);
  620. property._valueType="text";
  621. property._label=propertyID;
  622. property._pluralLabel=property._label;
  623. property._reverseLabel="reverse of "+property._label;
  624. property._reversePluralLabel="reverse of "+property._pluralLabel;
  625. property._groupingLabel=property._label;
  626. property._reverseGroupingLabel=property._reverseLabel;
  627. this._properties[propertyID]=property;
  628. this._propertyArray=null;
  629. return property;
  630. }else{return this._properties[propertyID];
  631. }};
  632. Exhibit.Database._indexPut=function(index,x,y,z){var hash=index[x];
  633. if(!hash){hash={};
  634. index[x]=hash;
  635. }var array=hash[y];
  636. if(!array){array=new Array();
  637. hash[y]=array;
  638. }else{for(var i=0;
  639. i<array.length;
  640. i++){if(z==array[i]){return ;
  641. }}}array.push(z);
  642. };
  643. Exhibit.Database._indexPutList=function(index,x,y,list){var hash=index[x];
  644. if(!hash){hash={};
  645. index[x]=hash;
  646. }var array=hash[y];
  647. if(!array){hash[y]=list;
  648. }else{hash[y]=hash[y].concat(list);
  649. }};
  650. Exhibit.Database._indexRemove=function(index,x,y,z){function isEmpty(obj){for(p in obj){return false;
  651. }return true;
  652. }var hash=index[x];
  653. if(!hash){return false;
  654. }var array=hash[y];
  655. if(!array){return false;
  656. }for(var i=0;
  657. i<array.length;
  658. i++){if(z==array[i]){array.splice(i,1);
  659. if(array.length==0){delete hash[y];
  660. if(isEmpty(hash)){delete index[x];
  661. }}return true;
  662. }}};
  663. Exhibit.Database._indexRemoveList=function(index,x,y){var hash=index[x];
  664. if(!hash){return null;
  665. }var array=hash[y];
  666. if(!array){return null;
  667. }delete hash[y];
  668. return array;
  669. };
  670. Exhibit.Database._Impl.prototype._indexFillSet=function(index,x,y,set,filter){var hash=index[x];
  671. if(hash){var array=hash[y];
  672. if(array){if(filter){for(var i=0;
  673. i<array.length;
  674. i++){var z=array[i];
  675. if(filter.contains(z)){set.add(z);
  676. }}}else{for(var i=0;
  677. i<array.length;
  678. i++){set.add(array[i]);
  679. }}}}};
  680. Exhibit.Database._Impl.prototype._indexCountDistinct=function(index,x,y,filter){var count=0;
  681. var hash=index[x];
  682. if(hash){var array=hash[y];
  683. if(array){if(filter){for(var i=0;
  684. i<array.length;
  685. i++){if(filter.contains(array[i])){count++;
  686. }}}else{count=array.length;
  687. }}}return count;
  688. };
  689. Exhibit.Database._Impl.prototype._get=function(index,x,y,set,filter){if(!set){set=new Exhibit.Set();
  690. }this._indexFillSet(index,x,y,set,filter);
  691. return set;
  692. };
  693. Exhibit.Database._Impl.prototype._getUnion=function(index,xSet,y,set,filter){if(!set){set=new Exhibit.Set();
  694. }var database=this;
  695. xSet.visit(function(x){database._indexFillSet(index,x,y,set,filter);
  696. });
  697. return set;
  698. };
  699. Exhibit.Database._Impl.prototype._countDistinctUnion=function(index,xSet,y,filter){var count=0;
  700. var database=this;
  701. xSet.visit(function(x){count+=database._indexCountDistinct(index,x,y,filter);
  702. });
  703. return count;
  704. };
  705. Exhibit.Database._Impl.prototype._countDistinct=function(index,x,y,filter){return this._indexCountDistinct(index,x,y,filter);
  706. };
  707. Exhibit.Database._Impl.prototype._getProperties=function(index,x){var hash=index[x];
  708. var properties=[];
  709. if(hash){for(var p in hash){properties.push(p);
  710. }}return properties;
  711. };
  712. Exhibit.Database._Impl.prototype.getObjects=function(s,p,set,filter){return this._get(this._spo,s,p,set,filter);
  713. };
  714. Exhibit.Database._Impl.prototype.countDistinctObjects=function(s,p,filter){return this._countDistinct(this._spo,s,p,filter);
  715. };
  716. Exhibit.Database._Impl.prototype.getObjectsUnion=function(subjects,p,set,filter){return this._getUnion(this._spo,subjects,p,set,filter);
  717. };
  718. Exhibit.Database._Impl.prototype.countDistinctObjectsUnion=function(subjects,p,filter){return this._countDistinctUnion(this._spo,subjects,p,filter);
  719. };
  720. Exhibit.Database._Impl.prototype.getSubjects=function(o,p,set,filter){return this._get(this._ops,o,p,set,filter);
  721. };
  722. Exhibit.Database._Impl.prototype.countDistinctSubjects=function(o,p,filter){return this._countDistinct(this._ops,o,p,filter);
  723. };
  724. Exhibit.Database._Impl.prototype.getSubjectsUnion=function(objects,p,set,filter){return this._getUnion(this._ops,objects,p,set,filter);
  725. };
  726. Exhibit.Database._Impl.prototype.countDistinctSubjectsUnion=function(objects,p,filter){return this._countDistinctUnion(this._ops,objects,p,filter);
  727. };
  728. Exhibit.Database._Impl.prototype.getObject=function(s,p){var hash=this._spo[s];
  729. if(hash){var array=hash[p];
  730. if(array){return array[0];
  731. }}return null;
  732. };
  733. Exhibit.Database._Impl.prototype.getSubject=function(o,p){var hash=this._ops[o];
  734. if(hash){var array=hash[p];
  735. if(array){return array[0];
  736. }}return null;
  737. };
  738. Exhibit.Database._Impl.prototype.getForwardProperties=function(s){return this._getProperties(this._spo,s);
  739. };
  740. Exhibit.Database._Impl.prototype.getBackwardProperties=function(o){return this._getProperties(this._ops,o);
  741. };
  742. Exhibit.Database._Impl.prototype.getSubjectsInRange=function(p,min,max,inclusive,set,filter){var property=this.getProperty(p);
  743. if(property!=null){var rangeIndex=property.getRangeIndex();
  744. if(rangeIndex!=null){return rangeIndex.getSubjectsInRange(min,max,inclusive,set,filter);
  745. }}return(!set)?new Exhibit.Set():set;
  746. };
  747. Exhibit.Database._Impl.prototype.getTypeIDs=function(set){return this.getObjectsUnion(set,"type",null,null);
  748. };
  749. Exhibit.Database._Impl.prototype.addStatement=function(s,p,o){var indexPut=Exhibit.Database._indexPut;
  750. indexPut(this._spo,s,p,o);
  751. indexPut(this._ops,o,p,s);
  752. };
  753. Exhibit.Database._Impl.prototype.removeStatement=function(s,p,o){var indexRemove=Exhibit.Database._indexRemove;
  754. var removedObject=indexRemove(this._spo,s,p,o);
  755. var removedSubject=indexRemove(this._ops,o,p,s);
  756. return removedObject||removedSubject;
  757. };
  758. Exhibit.Database._Impl.prototype.removeObjects=function(s,p){var indexRemove=Exhibit.Database._indexRemove;
  759. var indexRemoveList=Exhibit.Database._indexRemoveList;
  760. var objects=indexRemoveList(this._spo,s,p);
  761. if(objects==null){return false;
  762. }else{for(var i=0;
  763. i<objects.length;
  764. i++){indexRemove(this._ops,objects[i],p,s);
  765. }return true;
  766. }};
  767. Exhibit.Database._Impl.prototype.removeSubjects=function(o,p){var indexRemove=Exhibit.Database._indexRemove;
  768. var indexRemoveList=Exhibit.Database._indexRemoveList;
  769. var subjects=indexRemoveList(this._ops,o,p);
  770. if(subjects==null){return false;
  771. }else{for(var i=0;
  772. i<subjects.length;
  773. i++){indexRemove(this._spo,subjects[i],p,o);
  774. }return true;
  775. }};
  776. Exhibit.Database._Impl.prototype.removeAllStatements=function(){this._listeners.fire("onBeforeRemovingAllStatements",[]);
  777. try{this._spo={};
  778. this._ops={};
  779. this._items=new Exhibit.Set();
  780. for(var propertyID in this._properties){this._properties[propertyID]._onNewData();
  781. }this._propertyArray=null;
  782. this._listeners.fire("onAfterRemovingAllStatements",[]);
  783. }catch(e){SimileAjax.Debug.exception(e,"Database.removeAllStatements failed");
  784. }};
  785. Exhibit.Database._Type=function(id){this._id=id;
  786. this._custom={};
  787. };
  788. Exhibit.Database._Type.prototype={getID:function(){return this._id;
  789. },getURI:function(){return this._custom["uri"];
  790. },getLabel:function(){return this._custom["label"];
  791. },getOrigin:function(){return this._custom["origin"];
  792. },getProperty:function(p){return this._custom[p];
  793. }};
  794. Exhibit.Database._Property=function(id,database){this._id=id;
  795. this._database=database;
  796. this._rangeIndex=null;
  797. };
  798. Exhibit.Database._Property.prototype={getID:function(){return this._id;
  799. },getURI:function(){return this._uri;
  800. },getValueType:function(){return this._valueType;
  801. },getLabel:function(){return this._label;
  802. },getPluralLabel:function(){return this._pluralLabel;
  803. },getReverseLabel:function(){return this._reverseLabel;
  804. },getReversePluralLabel:function(){return this._reversePluralLabel;
  805. },getGroupingLabel:function(){return this._groupingLabel;
  806. },getGroupingPluralLabel:function(){return this._groupingPluralLabel;
  807. },getOrigin:function(){return this._origin;
  808. }};
  809. Exhibit.Database._Property.prototype._onNewData=function(){this._rangeIndex=null;
  810. };
  811. Exhibit.Database._Property.prototype.getRangeIndex=function(){if(this._rangeIndex==null){this._buildRangeIndex();
  812. }return this._rangeIndex;
  813. };
  814. Exhibit.Database._Property.prototype._buildRangeIndex=function(){var getter;
  815. var database=this._database;
  816. var p=this._id;
  817. switch(this.getValueType()){case"date":getter=function(item,f){database.getObjects(item,p,null,null).visit(function(value){if(value!=null&&!(value instanceof Date)){value=SimileAjax.DateTime.parseIso8601DateTime(value);
  818. }if(value instanceof Date){f(value.getTime());
  819. }});
  820. };
  821. break;
  822. default:getter=function(item,f){database.getObjects(item,p,null,null).visit(function(value){if(typeof value!="number"){value=parseFloat(value);
  823. }if(!isNaN(value)){f(value);
  824. }});
  825. };
  826. break;
  827. }this._rangeIndex=new Exhibit.Database._RangeIndex(this._database.getAllItems(),getter);
  828. };
  829. Exhibit.Database._RangeIndex=function(items,getter){pairs=[];
  830. items.visit(function(item){getter(item,function(value){pairs.push({item:item,value:value});
  831. });
  832. });
  833. pairs.sort(function(p1,p2){var c=p1.value-p2.value;
  834. return(isNaN(c)===false)?c:p1.value.localeCompare(p2.value);
  835. });
  836. this._pairs=pairs;
  837. };
  838. Exhibit.Database._RangeIndex.prototype.getCount=function(){return this._pairs.length;
  839. };
  840. Exhibit.Database._RangeIndex.prototype.getMin=function(){return this._pairs.length>0?this._pairs[0].value:Number.POSITIVE_INFINITY;
  841. };
  842. Exhibit.Database._RangeIndex.prototype.getMax=function(){return this._pairs.length>0?this._pairs[this._pairs.length-1].value:Number.NEGATIVE_INFINITY;
  843. };
  844. Exhibit.Database._RangeIndex.prototype.getRange=function(visitor,min,max,inclusive){var startIndex=this._indexOf(min);
  845. var pairs=this._pairs;
  846. var l=pairs.length;
  847. inclusive=(inclusive);
  848. while(startIndex<l){var pair=pairs[startIndex++];
  849. var value=pair.value;
  850. if(value<max||(value==max&&inclusive)){visitor(pair.item);
  851. }else{break;
  852. }}};
  853. Exhibit.Database._RangeIndex.prototype.getSubjectsInRange=function(min,max,inclusive,set,filter){if(!set){set=new Exhibit.Set();
  854. }var f=(filter!=null)?function(item){if(filter.contains(item)){set.add(item);
  855. }}:function(item){set.add(item);
  856. };
  857. this.getRange(f,min,max,inclusive);
  858. return set;
  859. };
  860. Exhibit.Database._RangeIndex.prototype.countRange=function(min,max,inclusive){var startIndex=this._indexOf(min);
  861. var endIndex=this._indexOf(max);
  862. if(inclusive){var pairs=this._pairs;
  863. var l=pairs.length;
  864. while(endIndex<l){if(pairs[endIndex].value==max){endIndex++;
  865. }else{break;
  866. }}}return endIndex-startIndex;
  867. };
  868. Exhibit.Database._RangeIndex.prototype._indexOf=function(v){var pairs=this._pairs;
  869. if(pairs.length==0||pairs[0].value>=v){return 0;
  870. }var from=0;
  871. var to=pairs.length;
  872. while(from+1<to){var middle=(from+to)>>1;
  873. var v2=pairs[middle].value;
  874. if(v2>=v){to=middle;
  875. }else{from=middle;
  876. }}return to;
  877. };
  878. Exhibit.Database._Impl.prototype.isNewItem=function(id){return id in this._newItems;
  879. };
  880. Exhibit.Database._Impl.prototype.getItem=function(id){var item={id:id};
  881. var properties=this.getAllProperties();
  882. for(var i in properties){var prop=properties[i];
  883. var val=this.getObject(id,prop);
  884. if(val){item[prop]=val;
  885. }}return item;
  886. };
  887. Exhibit.Database._Impl.prototype.addItem=function(item){if(!item.id){item.id=item.label;
  888. }if(!item.modified){item.modified="yes";
  889. }this._ensurePropertyExists(Exhibit.Database.TimestampPropertyName);
  890. item[Exhibit.Database.TimestampPropertyName]=Exhibit.Database.makeISO8601DateString();
  891. this.loadItems([item],"");
  892. this._newItems[item.id]=true;
  893. this._listeners.fire("onAfterLoadingItems",[]);
  894. };
  895. Exhibit.Database._Impl.prototype.editItem=function(id,prop,value){if(prop.toLowerCase()=="id"){Exhibit.UI.showHelp("We apologize, but changing the IDs of items in the Exhibit isn't supported at the moment.");
  896. return ;
  897. }var prevValue=this.getObject(id,prop);
  898. this._originalValues[id]=this._originalValues[id]||{};
  899. this._originalValues[id][prop]=this._originalValues[id][prop]||prevValue;
  900. var origVal=this._originalValues[id][prop];
  901. if(origVal==value){this.removeObjects(id,"modified");
  902. this.addStatement(id,"modified","no");
  903. delete this._originalValues[id][prop];
  904. }else{if(this.getObject(id,"modified")!="yes"){this.removeObjects(id,"modified");
  905. this.addStatement(id,"modified","yes");
  906. }}this.removeObjects(id,prop);
  907. this.addStatement(id,prop,value);
  908. var propertyObject=this._ensurePropertyExists(prop);
  909. propertyObject._onNewData();
  910. this._listeners.fire("onAfterLoadingItems",[]);
  911. };
  912. Exhibit.Database._Impl.prototype.removeItem=function(id){if(!this.containsItem(id)){throw"Removing non-existent item "+id;
  913. }this._items.remove(id);
  914. delete this._spo[id];
  915. if(this._newItems[id]){delete this._newItems[id];
  916. }if(this._originalValues[id]){delete this._originalValues[id];
  917. }var properties=this.getAllProperties();
  918. for(var i in properties){var prop=properties[i];
  919. this.removeObjects(id,prop);
  920. }this._listeners.fire("onAfterLoadingItems",[]);
  921. };
  922. Exhibit.Database.defaultIgnoredProperties=["uri","modified"];
  923. Exhibit.Database._Impl.prototype.fixAllChanges=function(){this._originalValues={};
  924. this._newItems={};
  925. var items=this._items.toArray();
  926. for(var i in items){var id=items[i];
  927. this.removeObjects(id,"modified");
  928. this.addStatement(id,"modified","no");
  929. }};
  930. Exhibit.Database._Impl.prototype.fixChangesForItem=function(id){delete this._originalValues[id];
  931. delete this._newItems[id];
  932. this.removeObjects(id,"modified");
  933. this.addStatement(id,"modified","no");
  934. };
  935. Exhibit.Database._Impl.prototype.collectChangesForItem=function(id,ignoredProperties){ignoredProperties=ignoredProperties||Exhibit.Database.defaultIgnoredProperties;
  936. var type=this.getObject(id,"type");
  937. var label=this.getObject(id,"label")||id;
  938. var item={id:id,label:label,type:type,vals:{}};
  939. if(id in this._newItems){item.changeType="added";
  940. var properties=this.getAllProperties();
  941. for(var i in properties){var prop=properties[i];
  942. if(ignoredProperties.indexOf(prop)!=-1){continue;
  943. }var val=this.getObject(id,prop);
  944. if(val){item.vals[prop]={newVal:val};
  945. }}}else{if(id in this._originalValues&&!this.isSubmission(id)){item.changeType="modified";
  946. var vals=this._originalValues[id];
  947. var hasModification=false;
  948. for(var prop in vals){if(ignoredProperties.indexOf(prop)!=-1){continue;
  949. }hasModification=true;
  950. var oldVal=this._originalValues[id][prop];
  951. var newVal=this.getObject(id,prop);
  952. if(!newVal){SimileAjax.Debug.warn("empty value for "+id+", "+prop);
  953. }else{item.vals[prop]={oldVal:oldVal,newVal:newVal};
  954. }}if(!hasModification){return null;
  955. }}else{return null;
  956. }}if(!item[Exhibit.Database.TimestampPropertyName]){item[Exhibit.Database.TimestampPropertyName]=Exhibit.Database.makeISO8601DateString();
  957. }return item;
  958. };
  959. Exhibit.Database._Impl.prototype.collectAllChanges=function(ignoredProperties){var ret=[];
  960. var items=this._items.toArray();
  961. for(var i in items){var id=items[i];
  962. var item=this.collectChangesForItem(id,ignoredProperties);
  963. if(item){ret.push(item);
  964. }}return ret;
  965. };
  966. Exhibit.Database._Impl.prototype.mergeSubmissionIntoItem=function(submissionID){var db=this;
  967. if(!this.isSubmission(submissionID)){throw submissionID+" is not a submission!";
  968. }var change=this.getObject(submissionID,"change");
  969. if(change=="modification"){var itemID=this.getObject(submissionID,"changedItem");
  970. var vals=this._spo[submissionID];
  971. SimileAjax.jQuery.each(vals,function(attr,val){if(Exhibit.Database.defaultIgnoredSubmissionProperties.indexOf(attr)!=-1){return ;
  972. }if(val.length==1){db.editItem(itemID,attr,val[0]);
  973. }else{SimileAjax.Debug.warn("Exhibit.Database._Impl.prototype.commitChangeToItem cannot handle multiple values for attribute "+attr+": "+val);
  974. }});
  975. delete this._submissionRegistry[submissionID];
  976. }else{if(change=="addition"){delete this._submissionRegistry[submissionID];
  977. this._newItems[submissionID]=true;
  978. }else{throw"unknown change type "+change;
  979. }}this._listeners.fire("onAfterLoadingItems",[]);
  980. };
  981. /* bibtex-exporter.js */
  982. Exhibit.BibtexExporter={getLabel:function(){return"Bibtex";
  983. },_excludeProperties:{"pub-type":true,"type":true,"uri":true,"key":true}};
  984. Exhibit.BibtexExporter.exportOne=function(itemID,database){return Exhibit.BibtexExporter._wrap(Exhibit.BibtexExporter._exportOne(itemID,database));
  985. };
  986. Exhibit.BibtexExporter.exportMany=function(set,database){var s="";
  987. set.visit(function(itemID){s+=Exhibit.BibtexExporter._exportOne(itemID,database)+"\n";
  988. });
  989. return Exhibit.BibtexExporter._wrap(s);
  990. };
  991. Exhibit.BibtexExporter._exportOne=function(itemID,database){var s="";
  992. var type=database.getObject(itemID,"pub-type");
  993. var key=database.getObject(itemID,"key");
  994. key=(key!=null?key:itemID);
  995. key=key.replace(/[\s,]/g,"-");
  996. s+="@"+type+"{"+key+",\n";
  997. var allProperties=database.getAllProperties();
  998. for(var i=0;
  999. i<allProperties.length;
  1000. i++){var propertyID=allProperties[i];
  1001. var property=database.getProperty(propertyID);
  1002. var values=database.getObjects(itemID,propertyID);
  1003. var valueType=property.getValueType();
  1004. if(values.size()>0&&!(propertyID in Exhibit.BibtexExporter._excludeProperties)){s+="\t"+(propertyID=="label"?"title":propertyID)+' = "';
  1005. var strings;
  1006. if(valueType=="item"){strings=[];
  1007. values.visit(function(value){strings.push(database.getObject(value,"label"));
  1008. });
  1009. }else{if(valueType=="url"){strings=[];
  1010. values.visit(function(value){strings.push(Exhibit.Persistence.resolveURL(value));
  1011. });
  1012. }else{strings=values.toArray();
  1013. }}s+=strings.join(" and ")+'",\n';
  1014. }}s+='\torigin = "'+Exhibit.Persistence.getItemLink(itemID)+'"\n';
  1015. s+="}\n";
  1016. return s;
  1017. };
  1018. Exhibit.BibtexExporter._wrap=function(s){return s;
  1019. };
  1020. /* exhibit-json-exporter.js */
  1021. Exhibit.ExhibitJsonExporter={getLabel:function(){return Exhibit.l10n.exhibitJsonExporterLabel;
  1022. }};
  1023. Exhibit.ExhibitJsonExporter.exportOne=function(itemID,database){return Exhibit.ExhibitJsonExporter._wrap(Exhibit.ExhibitJsonExporter._exportOne(itemID,database)+"\n");
  1024. };
  1025. Exhibit.ExhibitJsonExporter.exportMany=function(set,database){var s="";
  1026. var size=set.size();
  1027. var count=0;
  1028. set.visit(function(itemID){s+=Exhibit.ExhibitJsonExporter._exportOne(itemID,database)+((count++<size-1)?",\n":"\n");
  1029. });
  1030. return Exhibit.ExhibitJsonExporter._wrap(s);
  1031. };
  1032. Exhibit.ExhibitJsonExporter._exportOne=function(itemID,database){function quote(s){if(/[\\\x00-\x1F\x22]/.test(s)){return'"'+s.replace(/([\\\x00-\x1f\x22])/g,function(a,b){var c={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"}[b];
  1033. if(c){return c;
  1034. }c=b.charCodeAt();
  1035. return"\\x"+Math.floor(c/16).toString(16)+(c%16).toString(16);
  1036. })+'"';
  1037. }return'"'+s+'"';
  1038. }var s="";
  1039. var uri=database.getObject(itemID,"uri");
  1040. s+=' {"id":'+quote(itemID)+",\n";
  1041. var allProperties=database.getAllProperties();
  1042. for(var i=0;
  1043. i<allProperties.length;
  1044. i++){var propertyID=allProperties[i];
  1045. var property=database.getProperty(propertyID);
  1046. var values=database.getObjects(itemID,propertyID);
  1047. var valueType=property.getValueType();
  1048. if(values.size()>0){var array;
  1049. if(valueType=="url"){array=[];
  1050. values.visit(function(value){array.push(Exhibit.Persistence.resolveURL(value));
  1051. });
  1052. }else{array=values.toArray();
  1053. }s+=" "+quote(propertyID)+":";
  1054. if(array.length==1){s+=quote(array[0]);
  1055. }else{s+="[";
  1056. for(var j=0;
  1057. j<array.length;
  1058. j++){s+=(j>0?",":"")+quote(array[j]);
  1059. }s+="]";
  1060. }s+=",\n";
  1061. }}s+=' "origin":'+quote(Exhibit.Persistence.getItemLink(itemID))+"\n";
  1062. s+=" }";
  1063. return s;
  1064. };
  1065. Exhibit.ExhibitJsonExporter._wrap=function(s){return'{\n "items":[\n'+s+" ]\n}";
  1066. };
  1067. /* facet-selection-exporter.js */
  1068. Exhibit.FacetSelectionExporter={getLabel:function(){return"Facet Selections";
  1069. },exportOne:function(itemID,database){return Exhibit.FacetSelectionExporter._exportUrl();
  1070. },exportMany:function(set,database){return Exhibit.FacetSelectionExporter._exportUrl();
  1071. }};
  1072. Exhibit.FacetSelectionExporter._exportUrl=function(){var currentSettings=window.exhibit.exportSettings();
  1073. var url=window.location.href.split("?")[0]+"?";
  1074. var sep="";
  1075. for(id in currentSettings){url+=sep+id+"="+escape(currentSettings[id]);
  1076. if(sep===""){sep="&";
  1077. }}return url;
  1078. };
  1079. /* rdf-xml-exporter.js */
  1080. Exhibit.RdfXmlExporter={getLabel:function(){return Exhibit.l10n.rdfXmlExporterLabel;
  1081. }};
  1082. Exhibit.RdfXmlExporter.exportOne=function(itemID,database){var propertyIDToQualifiedName={};
  1083. var prefixToBase={};
  1084. database.getNamespaces(propertyIDToQualifiedName,prefixToBase);
  1085. return Exhibit.RdfXmlExporter._wrapRdf(Exhibit.RdfXmlExporter._exportOne(itemID,database,propertyIDToQualifiedName,prefixToBase),prefixToBase);
  1086. };
  1087. Exhibit.RdfXmlExporter.exportMany=function(set,database){var s="";
  1088. var propertyIDToQualifiedName={};
  1089. var prefixToBase={};
  1090. database.getNamespaces(propertyIDToQualifiedName,prefixToBase);
  1091. set.visit(function(itemID){s+=Exhibit.RdfXmlExporter._exportOne(itemID,database,propertyIDToQualifiedName,prefixToBase)+"\n";
  1092. });
  1093. return Exhibit.RdfXmlExporter._wrapRdf(s,prefixToBase);
  1094. };
  1095. Exhibit.RdfXmlExporter._exportOne=function(itemID,database,propertyIDToQualifiedName,prefixToBase){var s="";
  1096. var uri=database.getObject(itemID,"uri");
  1097. s+="<rdf:Description rdf:about='"+uri+"'>\n";
  1098. var allProperties=database.getAllProperties();
  1099. for(var i=0;
  1100. i<allProperties.length;
  1101. i++){var propertyID=allProperties[i];
  1102. var property=database.getProperty(propertyID);
  1103. var values=database.getObjects(itemID,propertyID);
  1104. var valueType=property.getValueType();
  1105. var propertyString;
  1106. if(propertyID in propertyIDToQualifiedName){var qname=propertyIDToQualifiedName[propertyID];
  1107. propertyString=qname.prefix+":"+qname.localName;
  1108. }else{propertyString=property.getURI();
  1109. }if(valueType=="item"){values.visit(function(value){s+="\t<"+propertyString+" rdf:resource='"+value+"' />\n";
  1110. });
  1111. }else{if(propertyID!="uri"){if(valueType=="url"){values.visit(function(value){s+="\t<"+propertyString+">"+Exhibit.Persistence.resolveURL(value)+"</"+propertyString+">\n";
  1112. });
  1113. }else{values.visit(function(value){s+="\t<"+propertyString+">"+value+"</"+propertyString+">\n";
  1114. });
  1115. }}}}s+="\t<exhibit:origin>"+Exhibit.Persistence.getItemLink(itemID)+"</exhibit:origin>\n";
  1116. s+="</rdf:Description>";
  1117. return s;
  1118. };
  1119. Exhibit.RdfXmlExporter._wrapRdf=function(s,prefixToBase){var s2="<?xml version='1.0'?>\n<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'\n\txmlns:exhibit='http://simile.mit.edu/2006/11/exhibit#'";
  1120. for(prefix in prefixToBase){s2+="\n\txmlns:"+prefix+"='"+prefixToBase[prefix]+"'";
  1121. }s2+=">\n"+s+"\n</rdf:RDF>";
  1122. return s2;
  1123. };
  1124. /* semantic-wikitext-exporter.js */
  1125. Exhibit.SemanticWikitextExporter={getLabel:function(){return Exhibit.l10n.smwExporterLabel;
  1126. }};
  1127. Exhibit.SemanticWikitextExporter.exportOne=function(itemID,database){return Exhibit.SemanticWikitextExporter._wrap(Exhibit.SemanticWikitextExporter._exportOne(itemID,database));
  1128. };
  1129. Exhibit.SemanticWikitextExporter.exportMany=function(set,database){var s="";
  1130. set.visit(function(itemID){s+=Exhibit.SemanticWikitextExporter._exportOne(itemID,database)+"\n";
  1131. });
  1132. return Exhibit.SemanticWikitextExporter._wrap(s);
  1133. };
  1134. Exhibit.SemanticWikitextExporter._exportOne=function(itemID,database){var s="";
  1135. var uri=database.getObject(itemID,"uri");
  1136. s+=uri+"\n";
  1137. var allProperties=database.getAllProperties();
  1138. for(var i=0;
  1139. i<allProperties.length;
  1140. i++){var propertyID=allProperties[i];
  1141. var property=database.getProperty(propertyID);
  1142. var values=database.getObjects(itemID,propertyID);
  1143. var valueType=property.getValueType();
  1144. if(valueType=="item"){values.visit(function(value){s+="[["+propertyID+"::"+value+"]]\n";
  1145. });
  1146. }else{if(valueType=="url"){values.visit(function(value){s+="[["+propertyID+":="+Exhibit.Persistence.resolveURL(value)+"]]\n";
  1147. });
  1148. }else{values.visit(function(value){s+="[["+propertyID+":="+value+"]]\n";
  1149. });
  1150. }}}s+="[[origin:="+Exhibit.Persistence.getItemLink(itemID)+"]]\n";
  1151. s+="\n";
  1152. return s;
  1153. };
  1154. Exhibit.SemanticWikitextExporter._wrap=function(s){return s;
  1155. };
  1156. /* tsv-exporter.js */
  1157. Exhibit.TSVExporter={getLabel:function(){return Exhibit.l10n.tsvExporterLabel;
  1158. }};
  1159. Exhibit.TSVExporter.exportOne=function(itemID,database){return Exhibit.TSVExporter._wrap(Exhibit.TSVExporter._exportOne(itemID,database),database);
  1160. };
  1161. Exhibit.TSVExporter.exportMany=function(set,database){var s="";
  1162. set.visit(function(itemID){s+=Exhibit.TSVExporter._exportOne(itemID,database)+"\n";
  1163. });
  1164. return Exhibit.TSVExporter._wrap(s,database);
  1165. };
  1166. Exhibit.TSVExporter._exportOne=function(itemID,database){var s="";
  1167. var allProperties=database.getAllProperties();
  1168. for(var i=0;
  1169. i<allProperties.length;
  1170. i++){var propertyID=allProperties[i];
  1171. var property=database.getProperty(propertyID);
  1172. var values=database.getObjects(itemID,propertyID);
  1173. var valueType=property.getValueType();
  1174. s+=values.toArray().join("; ")+"\t";
  1175. }return s;
  1176. };
  1177. Exhibit.TSVExporter._wrap=function(s,database){var header="";
  1178. var allProperties=database.getAllProperties();
  1179. for(var i=0;
  1180. i<allProperties.length;
  1181. i++){var propertyID=allProperties[i];
  1182. var property=database.getProperty(propertyID);
  1183. var valueType=property.getValueType();
  1184. header+=propertyID+":"+valueType+"\t";
  1185. }return header+"\n"+s;
  1186. };
  1187. /* expression-parser.js */
  1188. Exhibit.ExpressionParser=new Object();
  1189. Exhibit.ExpressionParser.parse=function(s,startIndex,results){startIndex=startIndex||0;
  1190. results=results||{};
  1191. var scanner=new Exhibit.ExpressionScanner(s,startIndex);
  1192. try{return Exhibit.ExpressionParser._internalParse(scanner,false);
  1193. }finally{results.index=scanner.token()!=null?scanner.token().start:scanner.index();
  1194. }};
  1195. Exhibit.ExpressionParser.parseSeveral=function(s,startIndex,results){startIndex=startIndex||0;
  1196. results=results||{};
  1197. var scanner=new Exhibit.ExpressionScanner(s,startIndex);
  1198. try{return Exhibit.ExpressionParser._internalParse(scanner,true);
  1199. }finally{results.index=scanner.token()!=null?scanner.token().start:scanner.index();
  1200. }};
  1201. Exhibit.ExpressionParser._internalParse=function(scanner,several){var Scanner=Exhibit.ExpressionScanner;
  1202. var token=scanner.token();
  1203. var next=function(){scanner.next();
  1204. token=scanner.token();
  1205. };
  1206. var makePosition=function(){return token!=null?token.start:scanner.index();
  1207. };
  1208. var parsePath=function(){var path=new Exhibit.Expression.Path();
  1209. while(token!=null&&token.type==Scanner.PATH_OPERATOR){var hopOperator=token.value;
  1210. next();
  1211. if(token!=null&&token.type==Scanner.IDENTIFIER){path.appendSegment(token.value,hopOperator);
  1212. next();
  1213. }else{throw new Error("Missing property ID at position "+makePosition());
  1214. }}return path;
  1215. };
  1216. var parseFactor=function(){if(token==null){throw new Error("Missing factor at end of expression");
  1217. }var result=null;
  1218. switch(token.type){case Scanner.NUMBER:result=new Exhibit.Expression._Constant(token.value,"number");
  1219. next();
  1220. break;
  1221. case Scanner.STRING:result=new Exhibit.Expression._Constant(token.value,"text");
  1222. next();
  1223. break;
  1224. case Scanner.PATH_OPERATOR:result=parsePath();
  1225. break;
  1226. case Scanner.IDENTIFIER:var identifier=token.value;
  1227. next();
  1228. if(identifier in Exhibit.Controls){if(token!=null&&token.type==Scanner.DELIMITER&&token.value=="("){next();
  1229. var args=(token!=null&&token.type==Scanner.DELIMITER&&token.value==")")?[]:parseExpressionList();
  1230. result=new Exhibit.Expression._ControlCall(identifier,args);
  1231. if(token!=null&&token.type==Scanner.DELIMITER&&token.value==")"){next();
  1232. }else{throw new Error("Missing ) to end "+identifier+" at position "+makePosition());
  1233. }}else{throw new Error("Missing ( to start "+identifier+" at position "+makePosition());
  1234. }}else{if(token!=null&&token.type==Scanner.DELIMITER&&token.value=="("){next();
  1235. var args=(token!=null&&token.type==Scanner.DELIMITER&&token.value==")")?[]:parseExpressionList();
  1236. result=new Exhibit.Expression._FunctionCall(identifier,args);
  1237. if(token!=null&&token.type==Scanner.DELIMITER&&token.value==")"){next();
  1238. }else{throw new Error("Missing ) after function call "+identifier+" at position "+makePosition());
  1239. }}else{result=parsePath();
  1240. result.setRootName(identifier);
  1241. }}break;
  1242. case Scanner.DELIMITER:if(token.value=="("){next();
  1243. result=parseExpression();
  1244. if(token!=null&&token.type==Scanner.DELIMITER&&token.value==")"){next();
  1245. break;
  1246. }else{throw new Error("Missing ) at position "+makePosition());
  1247. }}default:throw new Error("Unexpected text "+token.value+" at position "+makePosition());
  1248. }return result;
  1249. };
  1250. var parseTerm=function(){var term=parseFactor();
  1251. while(token!=null&&token.type==Scanner.OPERATOR&&(token.value=="*"||token.value=="/")){var operator=token.value;
  1252. next();
  1253. term=new Exhibit.Expression._Operator(operator,[term,parseFactor()]);
  1254. }return term;
  1255. };
  1256. var parseSubExpression=function(){var subExpression=parseTerm();
  1257. while(token!=null&&token.type==Scanner.OPERATOR&&(token.value=="+"||token.value=="-")){var operator=token.value;
  1258. next();
  1259. subExpression=new Exhibit.Expression._Operator(operator,[subExpression,parseTerm()]);
  1260. }return subExpression;
  1261. };
  1262. var parseExpression=function(){var expression=parseSubExpression();
  1263. while(token!=null&&token.type==Scanner.OPERATOR&&(token.value=="="||token.value=="<>"||token.value=="<"||token.value=="<="||token.value==">"||token.value==">=")){var operator=token.value;
  1264. next();
  1265. expression=new Exhibit.Expression._Operator(operator,[expression,parseSubExpression()]);
  1266. }return expression;
  1267. };
  1268. var parseExpressionList=function(){var expressions=[parseExpression()];
  1269. while(token!=null&&token.type==Scanner.DELIMITER&&token.value==","){next();
  1270. expressions.push(parseExpression());
  1271. }return expressions;
  1272. };
  1273. if(several){var roots=parseExpressionList();
  1274. var expressions=[];
  1275. for(var r=0;
  1276. r<roots.length;
  1277. r++){expressions.push(new Exhibit.Expression._Impl(roots[r]));
  1278. }return expressions;
  1279. }else{return new Exhibit.Expression._Impl(parseExpression());
  1280. }};
  1281. Exhibit.ExpressionScanner=function(text,startIndex){this._text=text+" ";
  1282. this._maxIndex=text.length;
  1283. this._index=startIndex;
  1284. this.next();
  1285. };
  1286. Exhibit.ExpressionScanner.DELIMITER=0;
  1287. Exhibit.ExpressionScanner.NUMBER=1;
  1288. Exhibit.ExpressionScanner.STRING=2;
  1289. Exhibit.ExpressionScanner.IDENTIFIER=3;
  1290. Exhibit.ExpressionScanner.OPERATOR=4;
  1291. Exhibit.ExpressionScanner.PATH_OPERATOR=5;
  1292. Exhibit.ExpressionScanner.prototype.token=function(){return this._token;
  1293. };
  1294. Exhibit.ExpressionScanner.prototype.index=function(){return this._index;
  1295. };
  1296. Exhibit.ExpressionScanner.prototype.next=function(){this._token=null;
  1297. while(this._index<this._maxIndex&&" \t\r\n".indexOf(this._text.charAt(this._index))>=0){this._index++;
  1298. }if(this._index<this._maxIndex){var c1=this._text.charAt(this._index);
  1299. var c2=this._text.charAt(this._index+1);
  1300. if(".!".indexOf(c1)>=0){if(c2=="@"){this._token={type:Exhibit.ExpressionScanner.PATH_OPERATOR,value:c1+c2,start:this._index,end:this._index+2};
  1301. this._index+=2;
  1302. }else{this._token={type:Exhibit.ExpressionScanner.PATH_OPERATOR,value:c1,start:this._index,end:this._index+1};
  1303. this._index++;
  1304. }}else{if("<>".indexOf(c1)>=0){if((c2=="=")||("<>".indexOf(c2)>=0&&c1!=c2)){this._token={type:Exhibit.ExpressionScanner.OPERATOR,value:c1+c2,start:this._index,end:this._index+2};
  1305. this._index+=2;
  1306. }else{this._token={type:Exhibit.ExpressionScanner.OPERATOR,value:c1,start:this._index,end:this._index+1};
  1307. this._index++;
  1308. }}else{if("+-*/=".indexOf(c1)>=0){this._token={type:Exhibit.ExpressionScanner.OPERATOR,value:c1,start:this._index,end:this._index+1};
  1309. this._index++;
  1310. }else{if("(),".indexOf(c1)>=0){this._token={type:Exhibit.ExpressionScanner.DELIMITER,value:c1,start:this._index,end:this._index+1};
  1311. this._index++;
  1312. }else{if("\"'".indexOf(c1)>=0){var i=this._index+1;
  1313. while(i<this._maxIndex){if(this._text.charAt(i)==c1&&this._text.charAt(i-1)!="\\"){break;
  1314. }i++;
  1315. }if(i<this._maxIndex){this._token={type:Exhibit.ExpressionScanner.STRING,value:this._text.substring(this._index+1,i).replace(/\\'/g,"'").replace(/\\"/g,'"'),start:this._index,end:i+1};
  1316. this._index=i+1;
  1317. }else{throw new Error("Unterminated string starting at "+this._index);
  1318. }}else{if(this._isDigit(c1)){var i=this._index;
  1319. while(i<this._maxIndex&&this._isDigit(this._text.charAt(i))){i++;
  1320. }if(i<this._maxIndex&&this._text.charAt(i)=="."){i++;
  1321. while(i<this._maxIndex&&this._isDigit(this._text.charAt(i))){i++;
  1322. }}this._token={type:Exhibit.ExpressionScanner.NUMBER,value:parseFloat(this._text.substring(this._index,i)),start:this._index,end:i};
  1323. this._index=i;
  1324. }else{var i=this._index;
  1325. while(i<this._maxIndex){var c=this._text.charAt(i);
  1326. if("(),.!@ \t".indexOf(c)<0){i++;
  1327. }else{break;
  1328. }}this._token={type:Exhibit.ExpressionScanner.IDENTIFIER,value:this._text.substring(this._index,i),start:this._index,end:i};
  1329. this._index=i;
  1330. }}}}}}}};
  1331. Exhibit.ExpressionScanner.prototype._isDigit=function(c){return"0123456789".indexOf(c)>=0;
  1332. };
  1333. /* expression.js */
  1334. Exhibit.Expression=new Object();
  1335. Exhibit.Expression._Impl=function(rootNode){this._rootNode=rootNode;
  1336. };
  1337. Exhibit.Expression._Impl.prototype.evaluate=function(roots,rootValueTypes,defaultRootName,database){var collection=this._rootNode.evaluate(roots,rootValueTypes,defaultRootName,database);
  1338. return{values:collection.getSet(),valueType:collection.valueType,size:collection.size};
  1339. };
  1340. Exhibit.Expression._Impl.prototype.evaluateOnItem=function(itemID,database){return this.evaluate({"value":itemID},{"value":"item"},"value",database);
  1341. };
  1342. Exhibit.Expression._Impl.prototype.evaluateSingle=function(roots,rootValueTypes,defaultRootName,database){var collection=this._rootNode.evaluate(roots,rootValueTypes,defaultRootName,database);
  1343. var result={value:null,valueType:collection.valueType};
  1344. collection.forEachValue(function(v){result.value=v;
  1345. return true;
  1346. });
  1347. return result;
  1348. };
  1349. Exhibit.Expression._Impl.prototype.evaluateSingleOnItem=function(itemID,database){return this.evaluateSingle({"value":itemID},{"value":"item"},"value",database);
  1350. };
  1351. Exhibit.Expression._Impl.prototype.testExists=function(roots,rootValueTypes,defaultRootName,database){return this.isPath()?this._rootNode.testExists(roots,rootValueTypes,defaultRootName,database):this.evaluate(roots,rootValueTypes,defaultRootName,database).values.size()>0;
  1352. };
  1353. Exhibit.Expression._Impl.prototype.isPath=function(){return this._rootNode instanceof Exhibit.Expression.Path;
  1354. };
  1355. Exhibit.Expression._Impl.prototype.getPath=function(){return this.isPath()?this._rootNode:null;
  1356. };
  1357. Exhibit.Expression._Collection=function(values,valueType){this._values=values;
  1358. this.valueType=valueType;
  1359. if(values instanceof Array){this.forEachValue=Exhibit.Expression._Collection._forEachValueInArray;
  1360. this.getSet=Exhibit.Expression._Collection._getSetFromArray;
  1361. this.contains=Exhibit.Expression._Collection._containsInArray;
  1362. this.size=values.length;
  1363. }else{this.forEachValue=Exhibit.Expression._Collection._forEachValueInSet;
  1364. this.getSet=Exhibit.Expression._Collection._getSetFromSet;
  1365. this.contains=Exhibit.Expression._Collection._containsInSet;
  1366. this.size=values.size();
  1367. }};
  1368. Exhibit.Expression._Collection._forEachValueInSet=function(f){this._values.visit(f);
  1369. };
  1370. Exhibit.Expression._Collection._forEachValueInArray=function(f){var a=this._values;
  1371. for(var i=0;
  1372. i<a.length;
  1373. i++){if(f(a[i])){break;
  1374. }}};
  1375. Exhibit.Expression._Collection._getSetFromSet=function(){return this._values;
  1376. };
  1377. Exhibit.Expression._Collection._getSetFromArray=function(){return new Exhibit.Set(this._values);
  1378. };
  1379. Exhibit.Expression._Collection._containsInSet=function(v){this._values.contains(v);
  1380. };
  1381. Exhibit.Expression._Collection._containsInArray=function(v){var a=this._values;
  1382. for(var i=0;
  1383. i<a.length;
  1384. i++){if(a[i]==v){return true;
  1385. }}return false;
  1386. };
  1387. Exhibit.Expression.Path=function(){this._rootName=null;
  1388. this._segments=[];
  1389. };
  1390. Exhibit.Expression.Path.create=function(property,forward){var path=new Exhibit.Expression.Path();
  1391. path._segments.push({property:property,forward:forward,isArray:false});
  1392. return path;
  1393. };
  1394. Exhibit.Expression.Path.prototype.setRootName=function(rootName){this._rootName=rootName;
  1395. };
  1396. Exhibit.Expression.Path.prototype.appendSegment=function(property,hopOperator){this._segments.push({property:property,forward:hopOperator.charAt(0)==".",isArray:hopOperator.length>1});
  1397. };
  1398. Exhibit.Expression.Path.prototype.getSegment=function(index){if(index<this._segments.length){var segment=this._segments[index];
  1399. return{property:segment.property,forward:segment.forward,isArray:segment.isArray};
  1400. }else{return null;
  1401. }};
  1402. Exhibit.Expression.Path.prototype.getLastSegment=function(){return this.getSegment(this._segments.length-1);
  1403. };
  1404. Exhibit.Expression.Path.prototype.getSegmentCount=function(){return this._segments.length;
  1405. };
  1406. Exhibit.Expression.Path.prototype.evaluate=function(roots,rootValueTypes,defaultRootName,database){var rootName=this._rootName!=null?this._rootName:defaultRootName;
  1407. var valueType=rootName in rootValueTypes?rootValueTypes[rootName]:"text";
  1408. var collection=null;
  1409. if(rootName in roots){var root=roots[rootName];
  1410. if(root instanceof Exhibit.Set||root instanceof Array){collection=new Exhibit.Expression._Collection(root,valueType);
  1411. }else{collection=new Exhibit.Expression._Collection([root],valueType);
  1412. }return this._walkForward(collection,database);
  1413. }else{throw new Error("No such variable called "+rootName);
  1414. }};
  1415. Exhibit.Expression.Path.prototype.evaluateBackward=function(value,valueType,filter,database){var collection=new Exhibit.Expression._Collection([value],valueType);
  1416. return this._walkBackward(collection,filter,database);
  1417. };
  1418. Exhibit.Expression.Path.prototype.walkForward=function(values,valueType,database){return this._walkForward(new Exhibit.Expression._Collection(values,valueType),database);
  1419. };
  1420. Exhibit.Expression.Path.prototype.walkBackward=function(values,valueType,filter,database){return this._walkBackward(new Exhibit.Expression._Collection(values,valueType),filter,database);
  1421. };
  1422. Exhibit.Expression.Path.prototype._walkForward=function(collection,database){for(var i=0;
  1423. i<this._segments.length;
  1424. i++){var segment=this._segments[i];
  1425. if(segment.isArray){var a=[];
  1426. var valueType;
  1427. if(segment.forward){collection.forEachValue(function(v){database.getObjects(v,segment.property).visit(function(v2){a.push(v2);
  1428. });
  1429. });
  1430. var property=database.getProperty(segment.property);
  1431. valueType=property!=null?property.getValueType():"text";
  1432. }else{collection.forEachValue(function(v){database.getSubjects(v,segment.property).visit(function(v2){a.push(v2);
  1433. });
  1434. });
  1435. valueType="item";
  1436. }collection=new Exhibit.Expression._Collection(a,valueType);
  1437. }else{if(segment.forward){var values=database.getObjectsUnion(collection.getSet(),segment.property);
  1438. var property=database.getProperty(segment.property);
  1439. var valueType=property!=null?property.getValueType():"text";
  1440. collection=new Exhibit.Expression._Collection(values,valueType);
  1441. }else{var values=database.getSubjectsUnion(collection.getSet(),segment.property);
  1442. collection=new Exhibit.Expression._Collection(values,"item");
  1443. }}}return collection;
  1444. };
  1445. Exhibit.Expression.Path.prototype._walkBackward=function(collection,filter,database){for(var i=this._segments.length-1;
  1446. i>=0;
  1447. i--){var segment=this._segments[i];
  1448. if(segment.isArray){var a=[];
  1449. var valueType;
  1450. if(segment.forward){collection.forEachValue(function(v){database.getSubjects(v,segment.property).visit(function(v2){if(i>0||filter==null||filter.contains(v2)){a.push(v2);
  1451. }});
  1452. });
  1453. var property=database.getProperty(segment.property);
  1454. valueType=property!=null?property.getValueType():"text";
  1455. }else{collection.forEachValue(function(v){database.getObjects(v,segment.property).visit(function(v2){if(i>0||filter==null||filter.contains(v2)){a.push(v2);
  1456. }});
  1457. });
  1458. valueType="item";
  1459. }collection=new Exhibit.Expression._Collection(a,valueType);
  1460. }else{if(segment.forward){var values=database.getSubjectsUnion(collection.getSet(),segment.property,null,i==0?filter:null);
  1461. collection=new Exhibit.Expression._Collection(values,"item");
  1462. }else{var values=database.getObjectsUnion(collection.getSet(),segment.property,null,i==0?filter:null);
  1463. var property=database.getProperty(segment.property);
  1464. var valueType=property!=null?property.getValueType():"text";
  1465. collection=new Exhibit.Expression._Collection(values,valueType);
  1466. }}}return collection;
  1467. };
  1468. Exhibit.Expression.Path.prototype.rangeBackward=function(from,to,inclusive,filter,database){var set=new Exhibit.Set();
  1469. var valueType="item";
  1470. if(this._segments.length>0){var segment=this._segments[this._segments.length-1];
  1471. if(segment.forward){database.getSubjectsInRange(segment.property,from,to,inclusive,set,this._segments.length==1?filter:null);
  1472. }else{throw new Error("Last path of segment must be forward");
  1473. }for(var i=this._segments.length-2;
  1474. i>=0;
  1475. i--){segment=this._segments[i];
  1476. if(segment.forward){set=database.getSubjectsUnion(set,segment.property,null,i==0?filter:null);
  1477. valueType="item";
  1478. }else{set=database.getObjectsUnion(set,segment.property,null,i==0?filter:null);
  1479. var property=database.getProperty(segment.property);
  1480. valueType=property!=null?property.getValueType():"text";
  1481. }}}return{valueType:valueType,values:set,count:set.size()};
  1482. };
  1483. Exhibit.Expression.Path.prototype.testExists=function(roots,rootValueTypes,defaultRootName,database){return this.evaluate(roots,rootValueTypes,defaultRootName,database).size>0;
  1484. };
  1485. Exhibit.Expression._Constant=function(value,valueType){this._value=value;
  1486. this._valueType=valueType;
  1487. };
  1488. Exhibit.Expression._Constant.prototype.evaluate=function(roots,rootValueTypes,defaultRootName,database){return new Exhibit.Expression._Collection([this._value],this._valueType);
  1489. };
  1490. Exhibit.Expression._Operator=function(operator,args){this._operator=operator;
  1491. this._args=args;
  1492. };
  1493. Exhibit.Expression._Operator.prototype.evaluate=function(roots,rootValueTypes,defaultRootName,database){var values=[];
  1494. var args=[];
  1495. for(var i=0;
  1496. i<this._args.length;
  1497. i++){args.push(this._args[i].evaluate(roots,rootValueTypes,defaultRootName,database));
  1498. }var operator=Exhibit.Expression._operators[this._operator];
  1499. var f=operator.f;
  1500. if(operator.argumentType=="number"){args[0].forEachValue(function(v1){if(!(typeof v1=="number")){v1=parseFloat(v1);
  1501. }args[1].forEachValue(function(v2){if(!(typeof v2=="number")){v2=parseFloat(v2);
  1502. }values.push(f(v1,v2));
  1503. });
  1504. });
  1505. }else{args[0].forEachValue(function(v1){args[1].forEachValue(function(v2){values.push(f(v1,v2));
  1506. });
  1507. });
  1508. }return new Exhibit.Expression._Collection(values,operator.valueType);
  1509. };
  1510. Exhibit.Expression._operators={"+":{argumentType:"number",valueType:"number",f:function(a,b){return a+b;
  1511. }},"-":{argumentType:"number",valueType:"number",f:function(a,b){return a-b;
  1512. }},"*":{argumentType:"number",valueType:"number",f:function(a,b){return a*b;
  1513. }},"/":{argumentType:"number",valueType:"number",f:function(a,b){return a/b;
  1514. }},"=":{valueType:"boolean",f:function(a,b){return a==b;
  1515. }},"<>":{valueType:"boolean",f:function(a,b){return a!=b;
  1516. }},"><":{valueType:"boolean",f:function(a,b){return a!=b;
  1517. }},"<":{argumentType:"number",valueType:"boolean",f:function(a,b){return a<b;
  1518. }},">":{argumentType:"number",valueType:"boolean",f:function(a,b){return a>b;
  1519. }},"<=":{argumentType:"number",valueType:"boolean",f:function(a,b){return a<=b;
  1520. }},">=":{argumentType:"number",valueType:"boolean",f:function(a,b){return a>=b;
  1521. }}};
  1522. Exhibit.Expression._FunctionCall=function(name,args){this._name=name;
  1523. this._args=args;
  1524. };
  1525. Exhibit.Expression._FunctionCall.prototype.evaluate=function(roots,rootValueTypes,defaultRootName,database){var args=[];
  1526. for(var i=0;
  1527. i<this._args.length;
  1528. i++){args.push(this._args[i].evaluate(roots,rootValueTypes,defaultRootName,database));
  1529. }if(this._name in Exhibit.Functions){return Exhibit.Functions[this._name].f(args);
  1530. }else{throw new Error("No such function named "+this._name);
  1531. }};
  1532. Exhibit.Expression._ControlCall=function(name,args){this._name=name;
  1533. this._args=args;
  1534. };
  1535. Exhibit.Expression._ControlCall.prototype.evaluate=function(roots,rootValueTypes,defaultRootName,database){return Exhibit.Controls[this._name].f(this._args,roots,rootValueTypes,defaultRootName,database);
  1536. };
  1537. /* functions.js */
  1538. Exhibit.Functions={};
  1539. Exhibit.FunctionUtilities={};
  1540. Exhibit.FunctionUtilities.registerSimpleMappingFunction=function(name,f,valueType){Exhibit.Functions[name]={f:function(args){var set=new Exhibit.Set();
  1541. for(var i=0;
  1542. i<args.length;
  1543. i++){args[i].forEachValue(function(v){var v2=f(v);
  1544. if(v2!=undefined){set.add(v2);
  1545. }});
  1546. }return new Exhibit.Expression._Collection(set,valueType);
  1547. }};
  1548. };
  1549. Exhibit.Functions["union"]={f:function(args){var set=new Exhibit.Set();
  1550. var valueType=null;
  1551. if(args.length>0){var valueType=args[0].valueType;
  1552. for(var i=0;
  1553. i<args.length;
  1554. i++){var arg=args[i];
  1555. if(arg.size>0){if(valueType==null){valueType=arg.valueType;
  1556. }set.addSet(arg.getSet());
  1557. }}}return new Exhibit.Expression._Collection(set,valueType!=null?valueType:"text");
  1558. }};
  1559. Exhibit.Functions["contains"]={f:function(args){var result=args[0].size>0;
  1560. var set=args[0].getSet();
  1561. args[1].forEachValue(function(v){if(!set.contains(v)){result=false;
  1562. return true;
  1563. }});
  1564. return new Exhibit.Expression._Collection([result],"boolean");
  1565. }};
  1566. Exhibit.Functions["exists"]={f:function(args){return new Exhibit.Expression._Collection([args[0].size>0],"boolean");
  1567. }};
  1568. Exhibit.Functions["count"]={f:function(args){return new Exhibit.Expression._Collection([args[0].size],"number");
  1569. }};
  1570. Exhibit.Functions["not"]={f:function(args){return new Exhibit.Expression._Collection([!args[0].contains(true)],"boolean");
  1571. }};
  1572. Exhibit.Functions["and"]={f:function(args){var r=true;
  1573. for(var i=0;
  1574. r&&i<args.length;
  1575. i++){r=r&&args[i].contains(true);
  1576. }return new Exhibit.Expression._Collection([r],"boolean");
  1577. }};
  1578. Exhibit.Functions["or"]={f:function(args){var r=false;
  1579. for(var i=0;
  1580. !r&&i<args.length;
  1581. i++){r=r||args[i].contains(true);
  1582. }return new Exhibit.Expression._Collection([r],"boolean");
  1583. }};
  1584. Exhibit.Functions["add"]={f:function(args){var total=0;
  1585. for(var i=0;
  1586. i<args.length;
  1587. i++){args[i].forEachValue(function(v){if(v!=null){if(typeof v=="number"){total+=v;
  1588. }else{var n=parseFloat(v);
  1589. if(!isNaN(n)){total+=n;
  1590. }}}});
  1591. }return new Exhibit.Expression._Collection([total],"number");
  1592. }};
  1593. Exhibit.Functions["concat"]={f:function(args){var result=[];
  1594. for(var i=0;
  1595. i<args.length;
  1596. i++){args[i].forEachValue(function(v){if(v!=null){result.push(v);
  1597. }});
  1598. }return new Exhibit.Expression._Collection([result.join("")],"text");
  1599. }};
  1600. Exhibit.Functions["multiply"]={f:function(args){var product=1;
  1601. for(var i=0;
  1602. i<args.length;
  1603. i++){args[i].forEachValue(function(v){if(v!=null){if(typeof v=="number"){product*=v;
  1604. }else{var n=parseFloat(v);
  1605. if(!isNaN(n)){product*=n;
  1606. }}}});
  1607. }return new Exhibit.Expression._Collection([product],"number");
  1608. }};
  1609. Exhibit.Functions["date-range"]={_parseDate:function(v){if(v==null){return Number.NEGATIVE_INFINITY;
  1610. }else{if(v instanceof Date){return v.getTime();
  1611. }else{try{return SimileAjax.DateTime.parseIso8601DateTime(v).getTime();
  1612. }catch(e){return Number.NEGATIVE_INFINITY;
  1613. }}}},_factors:{second:1000,minute:60*1000,hour:60*60*1000,day:24*60*60*1000,week:7*24*60*60*1000,month:30*24*60*60*1000,quarter:3*30*24*60*60*1000,year:365*24*60*60*1000,decade:10*365*24*60*60*1000,century:100*365*24*60*60*1000},_computeRange:function(from,to,interval){var range=to-from;
  1614. if(isFinite(range)){if(interval in this._factors){range=Math.round(range/this._factors[interval]);
  1615. }return range;
  1616. }return null;
  1617. },f:function(args){var self=this;
  1618. var from=Number.POSITIVE_INFINITY;
  1619. args[0].forEachValue(function(v){from=Math.min(from,self._parseDate(v));
  1620. });
  1621. var to=Number.NEGATIVE_INFINITY;
  1622. args[1].forEachValue(function(v){to=Math.max(to,self._parseDate(v));
  1623. });
  1624. var interval="day";
  1625. args[2].forEachValue(function(v){interval=v;
  1626. });
  1627. var range=this._computeRange(from,to,interval);
  1628. return new Exhibit.Expression._Collection(range!=null?[range]:[],"number");
  1629. }};
  1630. Exhibit.Functions["distance"]={_units:{km:1000,mile:1609.344},_computeDistance:function(from,to,unit,roundTo){var range=from.distanceFrom(to);
  1631. if(!roundTo){roundTo=1;
  1632. }if(isFinite(range)){if(this._units.hasOwnProperty(unit)){range=range/this._units[unit];
  1633. }return Exhibit.Util.round(range,roundTo);
  1634. }return null;
  1635. },f:function(args){var self=this;
  1636. var data={};
  1637. var name=["origo","lat","lng","unit","round"];
  1638. for(var i=0,n;
  1639. n=name[i];
  1640. i++){args[i].forEachValue(function(v){data[n]=v;
  1641. });
  1642. }var latlng=data.origo.split(",");
  1643. var from=new GLatLng(latlng[0],latlng[1]);
  1644. var to=new GLatLng(data.lat,data.lng);
  1645. var range=this._computeDistance(from,to,data.unit,data.round);
  1646. return new Exhibit.Expression._Collection(range!=null?[range]:[],"number");
  1647. }};
  1648. Exhibit.Functions["min"]={f:function(args){var returnMe=function(val){return val;
  1649. };
  1650. var min=Number.POSITIVE_INFINITY;
  1651. var valueType=null;
  1652. for(var i=0;
  1653. i<args.length;
  1654. i++){var arg=args[i];
  1655. var currentValueType=arg.valueType?arg.valueType:"text";
  1656. var parser=Exhibit.SettingsUtilities._typeToParser(currentValueType);
  1657. arg.forEachValue(function(v){parsedV=parser(v,returnMe);
  1658. if(parsedV<min||min==Number.POSITIVE_INFINITY){min=parsedV;
  1659. valueType=(valueType==null)?currentValueType:(valueType==currentValueType?valueType:"text");
  1660. }});
  1661. }return new Exhibit.Expression._Collection([min],valueType!=null?valueType:"text");
  1662. }};
  1663. Exhibit.Functions["max"]={f:function(args){var returnMe=function(val){return val;
  1664. };
  1665. var max=Number.NEGATIVE_INFINITY;
  1666. var valueType=null;
  1667. for(var i=0;
  1668. i<args.length;
  1669. i++){var arg=args[i];
  1670. var currentValueType=arg.valueType?arg.valueType:"text";
  1671. var parser=Exhibit.SettingsUtilities._typeToParser(currentValueType);
  1672. arg.forEachValue(function(v){parsedV=parser(v,returnMe);
  1673. if(parsedV>max||max==Number.NEGATIVE_INFINITY){max=parsedV;
  1674. valueType=(valueType==null)?currentValueType:(valueType==currentValueType?valueType:"text");
  1675. }});
  1676. }return new Exhibit.Expression._Collection([max],valueType!=null?valueType:"text");
  1677. }};
  1678. Exhibit.Functions["remove"]={f:function(args){var set=args[0].getSet();
  1679. var valueType=args[0].valueType;
  1680. for(var i=1;
  1681. i<args.length;
  1682. i++){var arg=args[i];
  1683. if(arg.size>0){set.removeSet(arg.getSet());
  1684. }}return new Exhibit.Expression._Collection(set,valueType);
  1685. }};
  1686. Exhibit.Functions["now"]={f:function(args){return new Exhibit.Expression._Collection([new Date()],"date");
  1687. }};
  1688. /* authenticated-importer.js */
  1689. Exhibit.AuthenticatedImporter={_callbacks:{}};
  1690. Exhibit.importers["application/authenticated"]=Exhibit.AuthenticatedImporter;
  1691. Exhibit.AuthenticatedImporter.constructURL=function(){return"https://www.google.com/accounts/AuthSubRequest?scope=http%3A%2F%2Fspreadsheets.google.com%2Ffeeds%2F&session=1&secure=0&next="+window.location;
  1692. };
  1693. Exhibit.AuthenticatedImporter.load=function(link,database,cont){var url=typeof link=="string"?link:link.href;
  1694. url=Exhibit.Persistence.resolveURL(url);
  1695. var fError=function(statusText,status,xmlhttp){Exhibit.UI.hideBusyIndicator();
  1696. Exhibit.UI.showHelp(Exhibit.l10n.failedToLoadDataFileMessage(url));
  1697. if(cont){cont();
  1698. }};
  1699. var fDone=function(xmlhttp){Exhibit.UI.hideBusyIndicator();
  1700. try{var o=null;
  1701. try{o=eval("("+xmlhttp.responseText+")");
  1702. }catch(e){Exhibit.UI.showJsonFileValidation(Exhibit.l10n.badJsonMessage(url,e),url);
  1703. }if(o!=null){database.loadData(o,Exhibit.Persistence.getBaseURL(url));
  1704. }}catch(e){SimileAjax.Debug.exception(e,"Error loading Exhibit JSON data from "+url);
  1705. }finally{if(cont){cont();
  1706. }}};
  1707. Exhibit.UI.showBusyIndicator();
  1708. SimileAjax.XmlHttp.get(url,fError,fDone);
  1709. };
  1710. /* babel-based-importer.js */
  1711. Exhibit.BabelBasedImporter={mimetypeToReader:{"application/rdf+xml":"rdf-xml","application/n3":"n3","application/msexcel":"xls","application/x-msexcel":"xls","application/x-ms-excel":"xls","application/vnd.ms-excel":"xls","application/x-excel":"xls","application/xls":"xls","application/x-xls":"xls","application/x-bibtex":"bibtex"},babelTranslatorURL:"http://service.simile-widgets.org/babel/translator",_initialize:function(){var links=[];
  1712. var heads=document.documentElement.getElementsByTagName("head");
  1713. for(var h=0;
  1714. h<heads.length;
  1715. h++){var linkElmts=heads[h].getElementsByTagName("link");
  1716. for(var l=0;
  1717. l<linkElmts.length;
  1718. l++){var link=linkElmts[l];
  1719. if(link.rel.match(/\bexhibit\/babel-translator\b/)){Exhibit.BabelBasedImporter.babelTranslatorURL=link.href;
  1720. }}}Exhibit.BabelBasedImporter._initialize=function(){};
  1721. }};
  1722. Exhibit.importers["application/rdf+xml"]=Exhibit.BabelBasedImporter;
  1723. Exhibit.importers["application/n3"]=Exhibit.BabelBasedImporter;
  1724. Exhibit.importers["application/msexcel"]=Exhibit.BabelBasedImporter;
  1725. Exhibit.importers["application/x-msexcel"]=Exhibit.BabelBasedImporter;
  1726. Exhibit.importers["application/vnd.ms-excel"]=Exhibit.BabelBasedImporter;
  1727. Exhibit.importers["application/x-excel"]=Exhibit.BabelBasedImporter;
  1728. Exhibit.importers["application/xls"]=Exhibit.BabelBasedImporter;
  1729. Exhibit.importers["application/x-xls"]=Exhibit.BabelBasedImporter;
  1730. Exhibit.importers["application/x-bibtex"]=Exhibit.BabelBasedImporter;
  1731. Exhibit.BabelBasedImporter.load=function(link,database,cont){Exhibit.BabelBasedImporter._initialize();
  1732. var url=(typeof link=="string")?Exhibit.Persistence.resolveURL(link):Exhibit.Persistence.resolveURL(link.href);
  1733. var reader="rdf-xml";
  1734. var writer="exhibit-jsonp";
  1735. if(typeof link!="string"){var mimetype=link.type;
  1736. if(mimetype in Exhibit.BabelBasedImporter.mimetypeToReader){reader=Exhibit.BabelBasedImporter.mimetypeToReader[mimetype];
  1737. }}if(reader=="bibtex"){writer="bibtex-exhibit-jsonp";
  1738. }var babelURL=Exhibit.BabelBasedImporter.babelTranslatorURL+"?"+["reader="+reader,"writer="+writer,"url="+encodeURIComponent(url)].join("&");
  1739. return Exhibit.JSONPImporter.load(babelURL,database,cont);
  1740. };
  1741. /* exhibit-json-importer.js */
  1742. Exhibit.ExhibitJSONImporter={};
  1743. Exhibit.importers["application/json"]=Exhibit.ExhibitJSONImporter;
  1744. Exhibit.ExhibitJSONImporter.parse=function(content,link,url){var o=null;
  1745. try{o=eval("("+content+")");
  1746. }catch(e){Exhibit.UI.showJsonFileValidation(Exhibit.l10n.badJsonMessage(url,e),url);
  1747. }return o;
  1748. };
  1749. Exhibit.ExhibitJSONImporter.load=function(link,database,cont){var url=typeof link=="string"?link:link.href;
  1750. url=Exhibit.Persistence.resolveURL(url);
  1751. var fError=function(statusText,status,xmlhttp){Exhibit.UI.hideBusyIndicator();
  1752. Exhibit.UI.showHelp(Exhibit.l10n.failedToLoadDataFileMessage(url));
  1753. if(cont){cont();
  1754. }};
  1755. var fDone=function(xmlhttp){Exhibit.UI.hideBusyIndicator();
  1756. var o=Exhibit.JSONImporter.parse(xmlhttp.responseText,link,url);
  1757. if(o!=null){try{database.loadData(o,Exhibit.Persistence.getBaseURL(url));
  1758. }catch(e){SimileAjax.Debug.exception(e,"Error loading Exhibit JSON data from "+url);
  1759. }}if(cont){cont();
  1760. }};
  1761. Exhibit.UI.showBusyIndicator();
  1762. SimileAjax.XmlHttp.get(url,fError,fDone);
  1763. };
  1764. /* html-table-importer.js */
  1765. Exhibit.HtmlTableImporter={};
  1766. Exhibit.importers["text/html"]=Exhibit.HtmlTableImporter;
  1767. Exhibit.ProxyGetter=function(link,database,parser,cont){var url=typeof link=="string"?link:link.href;
  1768. if(typeof link!="string"){var xpath=link.getAttribute("ex:xpath");
  1769. }var babelURL="http://service.simile-widgets.org/babel/html-extractor?url="+encodeURIComponent(url);
  1770. if(xpath){babelURL+="xpath="+xpath;
  1771. }var fConvert=function(string){var div=document.createElement("div");
  1772. div.innerHTML=string;
  1773. var e=div.firstChild;
  1774. var string=string.slice(string.search(/<BODY>/)+6,string.search(/<\/BODY>/));
  1775. return parser(string,link);
  1776. };
  1777. return Exhibit.JSONPImporter.load(babelURL,database,cont,fConvert);
  1778. };
  1779. Exhibit.HtmlTableImporter.parse=function(table,link,url){var $=SimileAjax.jQuery;
  1780. var jq=$(table);
  1781. table=jq.get(0);
  1782. var readAttributes=function(node,attributes){var result={},found=false,attr,value,i;
  1783. for(i=0;
  1784. attr=attributes[i];
  1785. i++){value=Exhibit.getAttribute(node,attr);
  1786. if(value){result[attr]=value;
  1787. found=true;
  1788. }}return found&&result;
  1789. };
  1790. var typelist=["uri","label","pluralLabel"];
  1791. var proplist=["uri","valueType","label","reverseLabel","pluralLabel","reversePluralLabel","groupingLabel","reverseGroupingLabel"];
  1792. var columnProplist=["valueParser","arity","hrefProperty","srcProperty"];
  1793. var types={},properties={};
  1794. var type=Exhibit.getAttribute(link,"itemType");
  1795. var typeSchema=type&&readAttributes(link,typelist);
  1796. var separator=Exhibit.getAttribute(link,"separator")||";";
  1797. if(typeSchema){types[type]=types;
  1798. }var columns=Exhibit.getAttribute(link,"property");
  1799. var columnAttrs=[];
  1800. var headerRow=Exhibit.getAttribute(link,"headerRow");
  1801. if(columns){columns=columns.split(",");
  1802. }else{var hasProps=function(){return Exhibit.getAttribute(this,"property");
  1803. };
  1804. if(jq.find("col").filter(hasProps).length>0){columns=jq.find("col");
  1805. }else{headerRow=true;
  1806. columns=jq.find("tr").eq(0).children();
  1807. }columns=columns.map(function(i){var property=Exhibit.getAttribute(this,"property")||$(this).text();
  1808. var propSchema=readAttributes(this,proplist);
  1809. if(propSchema&&property){properties[property]=propSchema;
  1810. }columnAttrs[i]=readAttributes(this,columnProplist)||{};
  1811. return property;
  1812. }).get();
  1813. }var rows=jq.find("tr");
  1814. if(headerRow){rows=rows.slice(1);
  1815. }rows=rows.filter(":has(td)");
  1816. var parseRow=function(){var item={};
  1817. var fields=$("td",this);
  1818. fields.each(function(i){var prop=columns[i];
  1819. if(prop){var attrs=columnAttrs[i];
  1820. if(attrs.valueParser){item[prop]=attrs.valueParser(this);
  1821. }else{if(attrs.hrefProperty||attrs.srcProperty){item[prop]=$(this).text();
  1822. }else{item[prop]=$(this).html();
  1823. }if(attrs.arity!="single"){item[prop]=item[prop].split(separator);
  1824. }}}if(attrs.hrefProperty){item[attrs.hrefProperty]=$("[href]",this).attr("href");
  1825. }if(attrs.srcProperty){item[attrs.srcProperty]=$("[src]",this).attr("src");
  1826. }if(type){item.type=type;
  1827. }});
  1828. return item;
  1829. };
  1830. var items=rows.map(parseRow).get();
  1831. return({types:types,properties:properties,items:items});
  1832. };
  1833. /* json-importer.js */
  1834. Exhibit.JSONImporter={};
  1835. Exhibit.importers["application/general-json"]=Exhibit.JSONImporter;
  1836. Exhibit.JSONImporter.getjsonDocument=function(docURL){var jsonDoc=null;
  1837. $.ajax({url:docURL,type:"GET",dataType:"json",async:false,success:function(data){jsonDoc=data;
  1838. }});
  1839. if(jsonDoc){return jsonDoc;
  1840. }else{alert("ERROR FINDING JSON DOC");
  1841. return null;
  1842. }};
  1843. Exhibit.JSONImporter.findFirstItems=function(json,configuration){if(json instanceof Array){return json.length>0?Exhibit.JSONImporter.findFirstItems(json[0],configuration):null;
  1844. }else{var visited=[];
  1845. var listOfItems=[];
  1846. for(child in json){visited.push(json[child]);
  1847. if(configuration.itemTag.indexOf(child)>=0){for(var i=0;
  1848. i<json[child].length;
  1849. i++){var subChild=json[child][i];
  1850. subChild.index=configuration.itemTag.indexOf(child);
  1851. listOfItems.push(subChild);
  1852. }}}if(listOfItems.length){return listOfItems;
  1853. }else{return Exhibit.JSONImporter.findFirstItems(visited,configuration);
  1854. }}};
  1855. Exhibit.JSONImporter.getItems=function(json,exhibitJSON,configuration){var itemQueue;
  1856. var root=json;
  1857. if(root instanceof Array){itemQueue=root;
  1858. }else{itemQueue=[root];
  1859. }while(itemQueue.length>0){var myObject=itemQueue.shift();
  1860. var index=myObject.index;
  1861. var objectToAppend={};
  1862. var propertyQueue=[];
  1863. for(propertyKey in myObject){propertyQueue.push(propertyKey);
  1864. }while(propertyQueue.length>0){var key=propertyQueue.shift();
  1865. var keyID=key.split(".").pop();
  1866. if(configuration.itemTag.indexOf(keyID)==-1){var propertyValue=eval("myObject."+key);
  1867. if(keyID=="index"){}else{if(propertyValue instanceof Array){objectToAppend[keyID]=propertyValue;
  1868. }else{if(propertyValue instanceof Object){for(newProperty in propertyValue){propertyQueue.push(key+"."+newProperty);
  1869. }}else{if(keyID==configuration.propertyTags[index]){var referenceIndex=configuration.propertyTags.indexOf(keyID);
  1870. var newKey=configuration.propertyNames[referenceIndex];
  1871. objectToAppend[newKey]=propertyValue;
  1872. }else{if(keyID==configuration.propertyLabel[index]){objectToAppend.label=propertyValue;
  1873. }else{objectToAppend[keyID]=propertyValue;
  1874. }}}}}if(configuration.itemType[index]){objectToAppend.type=configuration.itemType[index];
  1875. }else{objectToAppend.type="Item";
  1876. }}else{newObject=eval("myObject."+key);
  1877. if(newObject instanceof Array){for(var i=0;
  1878. i<newObject.length;
  1879. i++){var object=newObject[i];
  1880. object.index=configuration.itemTag.indexOf(keyID);
  1881. if(configuration.parentRelation[object.index]){object[configuration.parentRelation[object.index]]=objectToAppend.label;
  1882. }else{object["is a child of"]=objectToAppend.label;
  1883. }itemQueue.push(object);
  1884. }}else{newObject.index=configuration.itemTag.indexOf(keyID);
  1885. if(configuration.parentRelation[newObject.index]){newObject[configuration.parentRelation[newObject.index]]=objectToAppend.label;
  1886. }else{newObject["isChildOf"]=objectToAppend.label;
  1887. }itemQueue.push(newObject);
  1888. }}}exhibitJSON.items.push(objectToAppend);
  1889. }return exhibitJSON;
  1890. };
  1891. Exhibit.JSONImporter.configure=function(){var configuration={"itemTag":[],"propertyLabel":[],"itemType":[],"parentRelation":[],"propertyTags":[],"propertyNames":[]};
  1892. $("link").each(function(){if(this.hasAttribute("ex:itemTags")){configuration.itemTag=Exhibit.getAttribute(this,"ex:itemTags",",");
  1893. }if(this.hasAttribute("ex:propertyLabels")){configuration.propertyLabel=Exhibit.getAttribute(this,"ex:propertyLabels",",");
  1894. }if(this.hasAttribute("ex:itemTypes")){configuration.itemType=Exhibit.getAttribute(this,"ex:itemTypes",",");
  1895. }if(this.hasAttribute("ex:parentRelations")){configuration.parentRelation=Exhibit.getAttribute(this,"ex:parentRelations",",");
  1896. }if(this.hasAttribute("ex:propertyNames")){configuration.propertyNames=Exhibit.getAttribute(this,"ex:propertyNames",",");
  1897. }if(this.hasAttribute("ex:propertyTags")){configuration.propertyTags=Exhibit.getAttribute(this,"ex:propertyTags",",");
  1898. }});
  1899. return configuration;
  1900. };
  1901. Exhibit.JSONImporter.load=function(link,database,cont){var self=this;
  1902. var url=typeof link=="string"?link:link.href;
  1903. url=Exhibit.Persistence.resolveURL(url);
  1904. var fError=function(statusText,status,xmlhttp){Exhibit.UI.hideBusyIndicator();
  1905. Exhibit.UI.showHelp(Exhibit.l10n.failedToLoadDataFileMessage(url));
  1906. if(cont){cont();
  1907. }};
  1908. var fDone=function(){Exhibit.UI.hideBusyIndicator();
  1909. try{var o=null;
  1910. try{jsonDoc=Exhibit.JSONImporter.getjsonDocument(url);
  1911. var configuration=self.configure();
  1912. o={"items":[]};
  1913. var root=self.findFirstItems(jsonDoc,configuration);
  1914. o=Exhibit.JSONImporter.getItems(root,o,configuration);
  1915. }catch(e){Exhibit.UI.showJsonFileValidation(Exhibit.l10n.badJsonMessage(url,e),url);
  1916. }if(o!=null){database.loadData(o,Exhibit.Persistence.getBaseURL(url));
  1917. }}catch(e){SimileAjax.Debug.exception(e,"Error loading Exhibit JSON data from "+url);
  1918. }finally{if(cont){cont();
  1919. }}};
  1920. Exhibit.UI.showBusyIndicator();
  1921. SimileAjax.XmlHttp.get(url,fError,fDone);
  1922. };
  1923. /* jsonp-importer.js */
  1924. Exhibit.JSONPImporter={_callbacks:{}};
  1925. Exhibit.importers["application/jsonp"]=Exhibit.JSONPImporter;
  1926. Exhibit.JSONPImporter.getter=function(link,database,parser,cont){var fConvert=function(json,url,link){parser(json,link,url);
  1927. };
  1928. Exhibit.JSONPImporter.load(link,database,cont,fConvert);
  1929. };
  1930. Exhibit.JSONPImporter.load=function(link,database,cont,fConvert,staticJSONPCallback,charset){var url=link;
  1931. if(typeof link!="string"){url=Exhibit.Persistence.resolveURL(link.href);
  1932. fConvert=Exhibit.getAttribute(link,"converter");
  1933. staticJSONPCallback=Exhibit.getAttribute(link,"jsonp-callback");
  1934. charset=Exhibit.getAttribute(link,"charset");
  1935. }if(typeof fConvert=="string"){var name=fConvert;
  1936. name=name.charAt(0).toLowerCase()+name.substring(1)+"Converter";
  1937. if(name in Exhibit.JSONPImporter){fConvert=Exhibit.JSONPImporter[name];
  1938. }else{try{fConvert=eval(fConvert);
  1939. }catch(e){fConvert=null;
  1940. }}}if(fConvert!=null&&"preprocessURL" in fConvert){url=fConvert.preprocessURL(url);
  1941. }var next=Exhibit.JSONPImporter._callbacks.next||1;
  1942. Exhibit.JSONPImporter._callbacks.next=next+1;
  1943. var callbackName="cb"+next.toString(36);
  1944. var callbackURL=url;
  1945. if(callbackURL.indexOf("?")==-1){callbackURL+="?";
  1946. }var lastChar=callbackURL.charAt(callbackURL.length-1);
  1947. if(lastChar!="="){if(lastChar!="&"&&lastChar!="?"){callbackURL+="&";
  1948. }callbackURL+="callback=";
  1949. }var callbackFull="Exhibit.JSONPImporter._callbacks."+callbackName;
  1950. callbackURL+=callbackFull;
  1951. var cleanup=function(failedURL){try{Exhibit.UI.hideBusyIndicator();
  1952. delete Exhibit.JSONPImporter._callbacks[callbackName+"_fail"];
  1953. delete Exhibit.JSONPImporter._callbacks[callbackName];
  1954. if(script&&script.parentNode){script.parentNode.removeChild(script);
  1955. }}finally{if(failedURL){prompt("Failed to load javascript file:",failedURL);
  1956. cont&&cont(undefined);
  1957. }}};
  1958. Exhibit.JSONPImporter._callbacks[callbackName+"_fail"]=cleanup;
  1959. Exhibit.JSONPImporter._callbacks[callbackName]=function(json){try{cleanup(null);
  1960. database.loadData(fConvert?fConvert(json,url,link):json,Exhibit.Persistence.getBaseURL(url));
  1961. }finally{if(cont){cont(json);
  1962. }}};
  1963. if(staticJSONPCallback){callbackURL=url;
  1964. eval(staticJSONPCallback+"="+callbackFull);
  1965. }var fail=callbackFull+"_fail('"+callbackURL+"');";
  1966. var script=SimileAjax.includeJavascriptFile(document,callbackURL,fail,charset);
  1967. Exhibit.UI.showBusyIndicator();
  1968. return Exhibit.JSONPImporter._callbacks[callbackName];
  1969. };
  1970. Exhibit.JSONPImporter.transformJSON=function(json,index,mapping,converters){var objects=json,items=[];
  1971. if(index){index=index.split(".");
  1972. while(index.length){objects=objects[index.shift()];
  1973. }}for(var i=0,object;
  1974. object=objects[i];
  1975. i++){var item={};
  1976. for(var name in mapping){if(mapping.hasOwnProperty(name)){var index=mapping[name].split(".");
  1977. for(var property=object;
  1978. index.length&&property;
  1979. property=property[index.shift()]){}if(property&&converters&&converters.hasOwnProperty(name)){property=converters[name](property,object,i,objects,json);
  1980. }if(typeof property!="undefined"){item[name]=property;
  1981. }}}items.push(item);
  1982. }return items;
  1983. };
  1984. Exhibit.JSONPImporter.deliciousConverter=function(json,url){var items=Exhibit.JSONPImporter.transformJSON(json,null,{label:"u",note:"n",description:"d",tags:"t"});
  1985. return{items:items,properties:{url:{valueType:"url"}}};
  1986. };
  1987. Exhibit.JSONPImporter.googleSpreadsheetsConverter=function(json,url,link){var separator=";";
  1988. if((link)&&(typeof link!="string")){var s=Exhibit.getAttribute(link,"separator");
  1989. if(s!=null&&s.length>0){separator=s;
  1990. }}var items=[];
  1991. var properties={};
  1992. var types={};
  1993. var valueTypes={"text":true,"number":true,"item":true,"url":true,"boolean":true,"date":true};
  1994. var entries=json.feed.entry||[];
  1995. for(var i=0;
  1996. i<entries.length;
  1997. i++){var entry=entries[i];
  1998. var id=entry.id.$t;
  1999. var c=id.lastIndexOf("C");
  2000. var r=id.lastIndexOf("R");
  2001. entries[i]={row:parseInt(id.substring(r+1,c))-1,col:parseInt(id.substring(c+1))-1,val:entry.content.$t};
  2002. }var cellIndex=0;
  2003. var getNextRow=function(){if(cellIndex<entries.length){var firstEntry=entries[cellIndex++];
  2004. var row=[firstEntry];
  2005. while(cellIndex<entries.length){var nextEntry=entries[cellIndex];
  2006. if(nextEntry.row==firstEntry.row){row.push(nextEntry);
  2007. cellIndex++;
  2008. }else{break;
  2009. }}return row;
  2010. }return null;
  2011. };
  2012. var propertyRow=getNextRow();
  2013. if(propertyRow!=null){var propertiesByColumn=[];
  2014. for(var i=0;
  2015. i<propertyRow.length;
  2016. i++){var cell=propertyRow[i];
  2017. var fieldSpec=cell.val.trim().replace(/^\{/g,"").replace(/\}$/g,"").split(":");
  2018. var fieldName=fieldSpec[0].trim();
  2019. var fieldDetails=fieldSpec.length>1?fieldSpec[1].split(","):[];
  2020. var property={single:false};
  2021. for(var d=0;
  2022. d<fieldDetails.length;
  2023. d++){var detail=fieldDetails[d].trim();
  2024. if(detail in valueTypes){property.valueType=detail;
  2025. }else{if(detail=="single"){property.single=true;
  2026. }}}propertiesByColumn[cell.col]=fieldName;
  2027. properties[fieldName]=property;
  2028. }var row=null;
  2029. while((row=getNextRow())!=null){var item={};
  2030. for(var i=0;
  2031. i<row.length;
  2032. i++){var cell=row[i];
  2033. var fieldName=propertiesByColumn[cell.col];
  2034. if(typeof fieldName=="string"){var googleDocsDateRegex=/^\d{1,2}\/\d{1,2}\/\d{4}$/;
  2035. if(googleDocsDateRegex.exec(cell.val)){cell.val=Exhibit.Database.makeISO8601DateString(new Date(cell.val));
  2036. }item[fieldName]=cell.val;
  2037. var property=properties[fieldName];
  2038. if(!property.single){var fieldValues=cell.val.split(separator);
  2039. for(var v=0;
  2040. v<fieldValues.length;
  2041. v++){fieldValues[v]=fieldValues[v].trim();
  2042. }item[fieldName]=fieldValues;
  2043. }else{item[fieldName]=cell.val.trim();
  2044. }}}items.push(item);
  2045. }}return{types:types,properties:properties,items:items};
  2046. };
  2047. Exhibit.JSONPImporter.googleSpreadsheetsConverter.preprocessURL=function(url){return url.replace(/\/list\//g,"/cells/");
  2048. };
  2049. /* rdfa-importer.js */
  2050. var RDFA=new Object();
  2051. RDFA.url="http://www.w3.org/2006/07/SWD/RDFa/impl/js/20070301/rdfa.js";
  2052. Exhibit.RDFaImporter={};
  2053. Exhibit.importers["application/RDFa"]=Exhibit.RDFaImporter;
  2054. Exhibit.RDFaImporter.load=function(link,database,cont){try{if((link.getAttribute("href")||"").length==0){Exhibit.RDFaImporter.loadRDFa(null,document,database);
  2055. }else{iframe=document.createElement("iframe");
  2056. iframe.style.display="none";
  2057. iframe.setAttribute("onLoad","Exhibit.RDFaImporter.loadRDFa(this, this.contentDocument, database)");
  2058. iframe.src=link.href;
  2059. document.body.appendChild(iframe);
  2060. }}catch(e){SimileAjax.Debug.exception(e);
  2061. }finally{if(cont){cont();
  2062. }}};
  2063. Exhibit.RDFaImporter.loadRDFa=function(iframe,rdfa,database){var textOf=function(n){return n.textContent||n.innerText||"";
  2064. };
  2065. var readAttributes=function(node,attributes){var result={},found=false,attr,value,i;
  2066. for(i=0;
  2067. attr=attributes[i];
  2068. i++){value=Exhibit.getAttribute(node,attr);
  2069. if(value){result[attr]=value;
  2070. found=true;
  2071. }}return found&&result;
  2072. };
  2073. RDFA.CALLBACK_DONE_PARSING=function(){if(iframe!=null){document.body.removeChild(iframe);
  2074. }this.cloneObject=function(what){for(var i in what){this[i]=what[i];
  2075. }};
  2076. var triples=this.triples;
  2077. var parsed={"classes":{},"properties":{},"items":[]};
  2078. for(var i in triples){var item={};
  2079. item["id"],item["uri"],item["label"]=i;
  2080. var tri=triples[i];
  2081. for(var j in tri){for(var k=0;
  2082. k<tri[j].length;
  2083. k++){if(tri[j][k].predicate.ns){var p_label=tri[j][k].predicate.ns.prefix+":"+tri[j][k].predicate.suffix;
  2084. if(j=="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"){try{var type_uri=tri[j][k]["object"];
  2085. var matches=type_uri.match(/(.+?)(#|\/)([a-zA-Z_]+)?$/);
  2086. var type_label=matches[3]+"("+matches[1]+")";
  2087. parsed["classes"][type_label]={"label":type_label,"uri":type_uri};
  2088. item["type"]=type_label;
  2089. }catch(e){}}else{parsed["properties"][p_label]={"uri":j,"label":tri[j][k]["predicate"]["suffix"]};
  2090. try{if(!item[p_label]){item[p_label]=[];
  2091. }item[p_label].push(tri[j][k]["object"]);
  2092. }catch(e){SimileAjax.Debug.log("problem adding property value: "+e);
  2093. }if(j=="http://purl.org/dc/elements/1.1/title"||j=="http://www.w3.org/2000/01/rdf-schema#"||j=="http://xmlns.com/foaf/0.1/name"){item.label=item[p_label];
  2094. }}}else{item[j]=tri[j][k]["object"];
  2095. }}}parsed["items"].push(new this.cloneObject(item));
  2096. }database.loadData(parsed,Exhibit.Persistence.getBaseURL(document.location.href));
  2097. };
  2098. RDFA.CALLBACK_DONE_LOADING=function(){RDFA.parse(rdfa);
  2099. };
  2100. SimileAjax.includeJavascriptFile(document,RDFA.url);
  2101. };
  2102. /* tsv-csv-importer.js */
  2103. Exhibit.TsvImporter={};
  2104. Exhibit.CsvImporter={};
  2105. Exhibit.TsvCsvImporter={};
  2106. Exhibit.importers["text/comma-separated-values"]=Exhibit.CsvImporter;
  2107. Exhibit.importers["text/csv"]=Exhibit.CsvImporter;
  2108. Exhibit.importers["text/tab-separated-values"]=Exhibit.TsvImporter;
  2109. Exhibit.importers["text/tsv"]=Exhibit.TsvImporter;
  2110. Exhibit.TsvImporter.parse=function(content,link,url){return Exhibit.TsvCsvImporter.parse(content,link,url,"\t");
  2111. };
  2112. Exhibit.CsvImporter.parse=function(content,link,url){return Exhibit.TsvCsvImporter.parse(content,link,url,",");
  2113. };
  2114. Exhibit.TsvCsvImporter.parse=function(content,link,url,separator){var url=link;
  2115. var hasColumnTitles=true;
  2116. var expressionString=null;
  2117. if(typeof link!="string"){url=link.href;
  2118. expressionString=Exhibit.getAttribute(link,"properties");
  2119. if(expressionString){hasColumnTitles=Exhibit.getAttribute(link,"hasColumnTitles");
  2120. if(hasColumnTitles){hasColumnTitles=(hasColumnTitles.toLowerCase()=="true");
  2121. }}}var valueSeparator=Exhibit.getAttribute(link,"valueSeparator");
  2122. var o=null;
  2123. try{o=Exhibit.TsvCsvImporter._parseInternal(content,separator,expressionString,hasColumnTitles,valueSeparator);
  2124. }catch(e){SimileAjax.Debug.exception(e,"Error parsing tsv/csv from "+url);
  2125. }return o;
  2126. };
  2127. Exhibit.TsvCsvImporter._parseInternal=function(text,separator,expressionString,hasColumnTitles,valueSeparator){var data=Exhibit.TsvCsvImporter.CsvToArray(text,separator);
  2128. var exprs=null;
  2129. var propNames=[];
  2130. var properties=[];
  2131. if(hasColumnTitles){exprs=data.shift();
  2132. }if(expressionString){exprs=expressionString.split(",");
  2133. }if(!exprs){SimileAjax.Debug.exception(new Error("No property names defined for tsv/csv file"));
  2134. }for(i=0;
  2135. i<exprs.length;
  2136. i++){var expr=exprs[i].split(":");
  2137. propNames[i]=expr[0];
  2138. if(expr.length>1){properties[propNames[i]]={valueType:expr[1]};
  2139. }}var items=[];
  2140. for(i=0;
  2141. i<data.length;
  2142. i++){var row=data[i];
  2143. var item={};
  2144. var len=row.length<exprs.length?row.length:exprs.length;
  2145. for(j=0;
  2146. j<len;
  2147. j++){if(row[j].length>0){if(valueSeparator&&(row[j].indexOf(valueSeparator)>=0)){row[j]=row[j].split(valueSeparator);
  2148. }item[propNames[j]]=row[j];
  2149. }}items.push(item);
  2150. }return{items:items,properties:properties};
  2151. };
  2152. Exhibit.TsvCsvImporter.CsvToArray=function(text,separator){var i;
  2153. if(text.indexOf('"')<0){var lines=text.split(/\r?\n/);
  2154. var items=[];
  2155. for(i=0;
  2156. i<lines.length;
  2157. i++){if(lines[i].length>0){items.push(lines[i].split(separator));
  2158. }}return items;
  2159. }text=text.replace(/\r?\n/g,"\n");
  2160. var lines=text.match(/([^"\n]|("[^"]*"))+?(?=\r?\n|$)/g);
  2161. var records=[];
  2162. for(i=0;
  2163. i<lines.length;
  2164. i++){if(lines[i].length>0){records.push(lines[i].replace(new RegExp(separator,"g"),"\uFFFF").replace(/"([^"]*"")*[^"]*"/g,function(quoted){return quoted.slice(1,-1).replace(/\uFFFF/g,separator).replace(/""/,'"');
  2165. }).split("\uFFFF"));
  2166. }}return records;
  2167. };
  2168. /* xml-importer.js */
  2169. Exhibit.XMLImporter={};
  2170. Exhibit.importers["application/xml"]=Exhibit.XMLImporter;
  2171. Exhibit.XMLImporter.getItems=function(xmlDoc,configuration){var items=[];
  2172. function maybeAdd(item,property,value){if(item&&property&&property.length>0&&value&&value.length>0){if(item[property]){item[property].push(value);
  2173. }else{item[property]=[value];
  2174. }}}function visit(node,parentItem,parentProperty){var tag=node.tagName;
  2175. var jQ=SimileAjax.jQuery(node);
  2176. var children=jQ.children();
  2177. var oldParentItem=parentItem;
  2178. if(tag in configuration.itemType){var item={type:[configuration.itemType[tag]]};
  2179. items.push(item);
  2180. parentItem=item;
  2181. }if(children.length==0){var property=configuration.propertyNames[tag]||tag;
  2182. maybeAdd(parentItem,property,jQ.text().trim());
  2183. }else{children.each(function(){visit(this,parentItem,tag);
  2184. });
  2185. }var attrMap=node.attributes;
  2186. if(attrMap){for(i=0;
  2187. i<attrMap.length;
  2188. i++){var attr=attrMap[i].nodeName;
  2189. maybeAdd(parentItem,configuration.propertyNames[attr]||attr,jQ.attr(attr));
  2190. }}if(tag in configuration.itemType){if(configuration.labelProperty[tag]!="label"){var label=item[configuration.labelProperty[tag]]||[];
  2191. if(label.length>0){item.label=label[0];
  2192. }}parentProperty=configuration.parentRelation[tag]||parentProperty;
  2193. maybeAdd(oldParentItem,parentProperty,item.label);
  2194. }}visit(xmlDoc,null,null);
  2195. return items;
  2196. };
  2197. Exhibit.XMLImporter.configure=function(link){var configuration={"labelProperty":[],"itemType":[],"parentRelation":[],"propertyNames":{}};
  2198. var itemTag=Exhibit.getAttribute(link,"ex:itemTags",",")||["item"];
  2199. var labelProperty=Exhibit.getAttribute(link,"ex:labelProperties",",")||[];
  2200. var itemType=Exhibit.getAttribute(link,"ex:itemTypes",",")||[];
  2201. var parentRelation=Exhibit.getAttribute(link,"ex:parentRelations",",")||[];
  2202. for(i=0;
  2203. i<itemTag.length;
  2204. i++){var tag=itemTag[i];
  2205. configuration.itemType[tag]=itemType[i]||tag;
  2206. configuration.labelProperty[tag]=labelProperty[i]||"label";
  2207. configuration.parentRelation[tag]=parentRelation[i]||tag;
  2208. }var propertyNames=Exhibit.getAttribute(link,"ex:propertyNames",",")||[];
  2209. var propertyTags=Exhibit.getAttribute(link,"ex:propertyTags",",")||[];
  2210. for(i=0;
  2211. i<propertyTags.length;
  2212. i++){configuration.propertyNames[propertyTags[i]]=(i<propertyNames.length)?propertyNames[i]:propertyTags[i];
  2213. }return configuration;
  2214. };
  2215. Exhibit.XMLImporter.parse=function(content,link,url){var self=this;
  2216. var configuration;
  2217. try{configuration=Exhibit.XMLImporter.configure(link);
  2218. url=Exhibit.Persistence.resolveURL(url);
  2219. }catch(e){SimileAjax.Debug.exception(e,"Error configuring XML importer for "+url);
  2220. return ;
  2221. }try{var xmlDoc=SimileAjax.jQuery.parseXML(content);
  2222. var o=Exhibit.XMLImporter.getItems(xmlDoc,configuration);
  2223. return{items:o};
  2224. }catch(e){SimileAjax.Debug.exception(e,"Error parsing XML data from "+url);
  2225. return null;
  2226. }};
  2227. /* exhibit.js */
  2228. Exhibit.create=function(database){return new Exhibit._Impl(database);
  2229. };
  2230. Exhibit.getAttribute=function(elmt,name,splitOn){try{var value=elmt.getAttribute(name);
  2231. if(value==null||value.length==0){value=elmt.getAttribute("ex:"+name);
  2232. if(value==null||value.length==0){value=elmt.getAttribute("data-ex-"+name);
  2233. if(value==null||value.length==0){return null;
  2234. }}}if(splitOn==null){return value;
  2235. }var values=value.split(splitOn);
  2236. for(var i=0;
  2237. value=values[i];
  2238. i++){values[i]=value.trim();
  2239. }return values;
  2240. }catch(e){return null;
  2241. }};
  2242. Exhibit.getRoleAttribute=function(elmt){var role=Exhibit.getAttribute(elmt,"role")||"";
  2243. role=role.replace(/^exhibit-/,"");
  2244. return role;
  2245. };
  2246. Exhibit.getConfigurationFromDOM=function(elmt){var c=Exhibit.getAttribute(elmt,"configuration");
  2247. if(c!=null&&c.length>0){try{var o=eval(c);
  2248. if(typeof o=="object"){return o;
  2249. }}catch(e){}}return{};
  2250. };
  2251. Exhibit.extractOptionsFromElement=function(elmt){var opts={};
  2252. var attrs=elmt.attributes;
  2253. for(var i in attrs){if(attrs.hasOwnProperty(i)){var name=attrs[i].nodeName;
  2254. var value=attrs[i].nodeValue;
  2255. if(name.indexOf("ex:")==0){name=name.substring(3);
  2256. }opts[name]=value;
  2257. }}return opts;
  2258. };
  2259. Exhibit.getExporters=function(){Exhibit._initializeExporters();
  2260. return[].concat(Exhibit._exporters);
  2261. };
  2262. Exhibit.addExporter=function(exporter){Exhibit._initializeExporters();
  2263. Exhibit._exporters.push(exporter);
  2264. };
  2265. Exhibit._initializeExporters=function(){if(!("_exporters" in Exhibit)){Exhibit._exporters=[Exhibit.RdfXmlExporter,Exhibit.SemanticWikitextExporter,Exhibit.TSVExporter,Exhibit.ExhibitJsonExporter,Exhibit.FacetSelectionExporter];
  2266. }};
  2267. Exhibit._Impl=function(database){this._database=database!=null?database:("database" in window?window.database:Exhibit.Database.create());
  2268. this._uiContext=Exhibit.UIContext.createRootContext({},this);
  2269. this._collectionMap={};
  2270. this._componentMap={};
  2271. this._historyListener={onBeforePerform:function(action){if(action.lengthy){Exhibit.UI.showBusyIndicator();
  2272. }},onAfterPerform:function(action){if(action.lengthy){Exhibit.UI.hideBusyIndicator();
  2273. }},onBeforeUndoSeveral:function(){Exhibit.UI.showBusyIndicator();
  2274. },onAfterUndoSeveral:function(){Exhibit.UI.hideBusyIndicator();
  2275. },onBeforeRedoSeveral:function(){Exhibit.UI.showBusyIndicator();
  2276. },onAfterRedoSeveral:function(){Exhibit.UI.hideBusyIndicator();
  2277. }};
  2278. SimileAjax.History.addListener(this._historyListener);
  2279. };
  2280. Exhibit._Impl.prototype.dispose=function(){SimileAjax.History.removeListener(this._historyListener);
  2281. for(var id in this._componentMap){try{this._componentMap[id].dispose();
  2282. }catch(e){SimileAjax.Debug.exception(e,"Failed to dispose component");
  2283. }}for(var id in this._collectionMap){try{this._collectionMap[id].dispose();
  2284. }catch(e){SimileAjax.Debug.exception(e,"Failed to dispose collection");
  2285. }}this._uiContext.dispose();
  2286. this._componentMap=null;
  2287. this._collectionMap=null;
  2288. this._uiContext=null;
  2289. this._database=null;
  2290. };
  2291. Exhibit._Impl.prototype.getDatabase=function(){return this._database;
  2292. };
  2293. Exhibit._Impl.prototype.getUIContext=function(){return this._uiContext;
  2294. };
  2295. Exhibit._Impl.prototype.getCollection=function(id){var collection=this._collectionMap[id];
  2296. if(collection==null&&id=="default"){collection=Exhibit.Collection.createAllItemsCollection(id,this._database);
  2297. this.setDefaultCollection(collection);
  2298. }return collection;
  2299. };
  2300. Exhibit._Impl.prototype.getDefaultCollection=function(){return this.getCollection("default");
  2301. };
  2302. Exhibit._Impl.prototype.setCollection=function(id,c){if(id in this._collectionMap){try{this._collectionMap[id].dispose();
  2303. }catch(e){SimileAjax.Debug.exception(e);
  2304. }}this._collectionMap[id]=c;
  2305. };
  2306. Exhibit._Impl.prototype.setDefaultCollection=function(c){this.setCollection("default",c);
  2307. };
  2308. Exhibit._Impl.prototype.getComponent=function(id){return this._componentMap[id];
  2309. };
  2310. Exhibit._Impl.prototype.setComponent=function(id,c){if(id in this._componentMap){try{this._componentMap[id].dispose();
  2311. }catch(e){SimileAjax.Debug.exception(e);
  2312. }}this._componentMap[id]=c;
  2313. };
  2314. Exhibit._Impl.prototype.disposeComponent=function(id){if(id in this._componentMap){try{this._componentMap[id].dispose();
  2315. }catch(e){SimileAjax.Debug.exception(e);
  2316. }delete this._componentMap[id];
  2317. }};
  2318. Exhibit._Impl.prototype.configure=function(configuration){if("collections" in configuration){for(var i=0;
  2319. i<configuration.collections.length;
  2320. i++){var config=configuration.collections[i];
  2321. var id=config.id;
  2322. if(id==null||id.length==0){id="default";
  2323. }this.setCollection(id,Exhibit.Collection.create2(id,config,this._uiContext));
  2324. }}if("components" in configuration){for(var i=0;
  2325. i<configuration.components.length;
  2326. i++){var config=configuration.components[i];
  2327. var component=Exhibit.UI.create(config,config.elmt,this._uiContext);
  2328. if(component!=null){var id=elmt.id;
  2329. if(id==null||id.length==0){id="component"+Math.floor(Math.random()*1000000);
  2330. }this.setComponent(id,component);
  2331. }}}};
  2332. Exhibit._Impl.prototype.configureFromDOM=function(root){var collectionElmts=[];
  2333. var coderElmts=[];
  2334. var coordinatorElmts=[];
  2335. var lensElmts=[];
  2336. var facetElmts=[];
  2337. var otherElmts=[];
  2338. var f=function(elmt){var role=Exhibit.getRoleAttribute(elmt);
  2339. if(role.length>0){switch(role){case"collection":collectionElmts.push(elmt);
  2340. break;
  2341. case"coder":coderElmts.push(elmt);
  2342. break;
  2343. case"coordinator":coordinatorElmts.push(elmt);
  2344. break;
  2345. case"lens":case"submission-lens":case"edit-lens":lensElmts.push(elmt);
  2346. break;
  2347. case"facet":facetElmts.push(elmt);
  2348. break;
  2349. default:otherElmts.push(elmt);
  2350. }}else{var node=elmt.firstChild;
  2351. while(node!=null){if(node.nodeType==1){f(node);
  2352. }node=node.nextSibling;
  2353. }}};
  2354. f(root||document.body);
  2355. var uiContext=this._uiContext;
  2356. for(var i=0;
  2357. i<collectionElmts.length;
  2358. i++){var elmt=collectionElmts[i];
  2359. var id=elmt.id;
  2360. if(id==null||id.length==0){id="default";
  2361. }this.setCollection(id,Exhibit.Collection.createFromDOM2(id,elmt,uiContext));
  2362. }var self=this;
  2363. var processElmts=function(elmts){for(var i=0;
  2364. i<elmts.length;
  2365. i++){var elmt=elmts[i];
  2366. try{var component=Exhibit.UI.createFromDOM(elmt,uiContext);
  2367. if(component!=null){var id=elmt.id;
  2368. if(id==null||id.length==0){id="component"+Math.floor(Math.random()*1000000);
  2369. }self.setComponent(id,component);
  2370. }}catch(e){SimileAjax.Debug.exception(e);
  2371. }}};
  2372. processElmts(coordinatorElmts);
  2373. processElmts(coderElmts);
  2374. processElmts(lensElmts);
  2375. processElmts(facetElmts);
  2376. processElmts(otherElmts);
  2377. this.importSettings();
  2378. var exporters=Exhibit.getAttribute(document.body,"exporters");
  2379. if(exporters!=null){exporters=exporters.split(";");
  2380. for(var i=0;
  2381. i<exporters.length;
  2382. i++){var expr=exporters[i];
  2383. var exporter=null;
  2384. try{exporter=eval(expr);
  2385. }catch(e){}if(exporter==null){try{exporter=eval(expr+"Exporter");
  2386. }catch(e){}}if(exporter==null){try{exporter=eval("Exhibit."+expr+"Exporter");
  2387. }catch(e){}}if(typeof exporter=="object"){Exhibit.addExporter(exporter);
  2388. }}}var hash=document.location.hash;
  2389. if(hash.length>1){var itemID=decodeURIComponent(hash.substr(1));
  2390. if(this._database.containsItem(itemID)){this._showFocusDialogOnItem(itemID);
  2391. }}};
  2392. Exhibit._Impl.prototype._showFocusDialogOnItem=function(itemID){var dom=SimileAjax.DOM.createDOMFromString("div","<div class='exhibit-focusDialog-viewContainer' id='lensContainer'></div><div class='exhibit-focusDialog-controls'><button id='closeButton'>"+Exhibit.l10n.focusDialogBoxCloseButtonLabel+"</button></div>");
  2393. dom.elmt.className="exhibit-focusDialog exhibit-ui-protection";
  2394. dom.close=function(){document.body.removeChild(dom.elmt);
  2395. };
  2396. dom.layer=SimileAjax.WindowManager.pushLayer(function(){dom.close();
  2397. },false);
  2398. var itemLens=this._uiContext.getLensRegistry().createLens(itemID,dom.lensContainer,this._uiContext);
  2399. dom.elmt.style.top=(document.body.scrollTop+100)+"px";
  2400. document.body.appendChild(dom.elmt);
  2401. SimileAjax.WindowManager.registerEvent(dom.closeButton,"click",function(elmt,evt,target){SimileAjax.WindowManager.popLayer(dom.layer);
  2402. },dom.layer);
  2403. };
  2404. Exhibit._Impl.prototype.exportSettings=function(){var facetSelections={},facetSettings="";
  2405. for(var id in this._componentMap){if(typeof this._componentMap[id].exportFacetSelection!=="undefined"){facetSettings=this._componentMap[id].exportFacetSelection()||false;
  2406. if(facetSettings){facetSelections[id]=facetSettings;
  2407. }}}return facetSelections;
  2408. };
  2409. Exhibit._Impl.prototype.importSettings=function(){if(window.location.search.length>0){searchComponents=window.location.search.substr(1,window.location.search.length-1).split("&");
  2410. for(var x=0;
  2411. x<searchComponents.length;
  2412. x++){var component=searchComponents[x].split("=");
  2413. var componentId=component[0];
  2414. var componentSelection=unescape(component[1]);
  2415. if(this._componentMap[componentId]&&(typeof this._componentMap[componentId].importFacetSelection!=="undefined")){this._componentMap[componentId].importFacetSelection(componentSelection);
  2416. }}}};
  2417. /* persistence.js */
  2418. Exhibit.Persistence={};
  2419. Exhibit.Persistence.getBaseURL=function(url){try{if(url.indexOf("://")<0){var url2=Exhibit.Persistence.getBaseURL(document.location.href);
  2420. if(url.substr(0,1)=="/"){url=url2.substr(0,url2.indexOf("/",url2.indexOf("://")+3))+url;
  2421. }else{url=url2+url;
  2422. }}var i=url.lastIndexOf("/");
  2423. if(i<0){return"";
  2424. }else{return url.substr(0,i+1);
  2425. }}catch(e){return url;
  2426. }};
  2427. Exhibit.Persistence.resolveURL=function(url){if(url.indexOf("://")<0){var url2=Exhibit.Persistence.getBaseURL(document.location.href);
  2428. if(url.substr(0,1)=="/"){url=url2.substr(0,url2.indexOf("/",url2.indexOf("://")+3))+url;
  2429. }else{if(url.substr(0,1)=="#"){url2=document.location.href;
  2430. index=(url2+"#").indexOf("#");
  2431. url=url2.substr(0,index)+url;
  2432. }else{url=url2+url;
  2433. }}}return url;
  2434. };
  2435. Exhibit.Persistence.getURLWithoutQueryAndHash=function(){var url;
  2436. if("_urlWithoutQueryAndHash" in Exhibit){url=Exhibit.Persistence._urlWithoutQueryAndHash;
  2437. }else{url=document.location.href;
  2438. var hash=url.indexOf("#");
  2439. var question=url.indexOf("?");
  2440. if(question>=0){url=url.substr(0,question);
  2441. }else{if(hash>=0){url=url.substr(0,hash);
  2442. }}Exhibit.Persistence._urlWithoutQueryAndHash=url;
  2443. }return url;
  2444. };
  2445. Exhibit.Persistence.getURLWithoutQuery=function(){var url;
  2446. if("_urlWithoutQuery" in Exhibit.Persistence){url=Exhibit.Persistence._urlWithoutQuery;
  2447. }else{url=document.location.href;
  2448. var question=url.indexOf("?");
  2449. if(question>=0){url=url.substr(0,question);
  2450. }Exhibit.Persistence._urlWithoutQuery=url;
  2451. }return url;
  2452. };
  2453. Exhibit.Persistence.getItemLink=function(itemID){return Exhibit.Persistence.getURLWithoutQueryAndHash()+"#"+encodeURIComponent(itemID);
  2454. };
  2455. /* color-coder.js */
  2456. Exhibit.ColorCoder=function(uiContext){this._uiContext=uiContext;
  2457. this._settings={};
  2458. this._map={};
  2459. this._mixedCase={label:Exhibit.Coders.l10n.mixedCaseLabel,color:Exhibit.Coders.mixedCaseColor};
  2460. this._missingCase={label:Exhibit.Coders.l10n.missingCaseLabel,color:Exhibit.Coders.missingCaseColor};
  2461. this._othersCase={label:Exhibit.Coders.l10n.othersCaseLabel,color:Exhibit.Coders.othersCaseColor};
  2462. };
  2463. Exhibit.ColorCoder._settingSpecs={};
  2464. Exhibit.ColorCoder.create=function(configuration,uiContext){var coder=new Exhibit.ColorCoder(Exhibit.UIContext.create(configuration,uiContext));
  2465. Exhibit.ColorCoder._configure(coder,configuration);
  2466. return coder;
  2467. };
  2468. Exhibit.ColorCoder.createFromDOM=function(configElmt,uiContext){configElmt.style.display="none";
  2469. var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  2470. var coder=new Exhibit.ColorCoder(Exhibit.UIContext.create(configuration,uiContext));
  2471. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.ColorCoder._settingSpecs,coder._settings);
  2472. try{var node=configElmt.firstChild;
  2473. while(node!=null){if(node.nodeType==1){coder._addEntry(Exhibit.getAttribute(node,"case"),node.firstChild.nodeValue.trim(),Exhibit.getAttribute(node,"color"));
  2474. }node=node.nextSibling;
  2475. }}catch(e){SimileAjax.Debug.exception(e,"ColorCoder: Error processing configuration of coder");
  2476. }Exhibit.ColorCoder._configure(coder,configuration);
  2477. return coder;
  2478. };
  2479. Exhibit.ColorCoder._configure=function(coder,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.ColorCoder._settingSpecs,coder._settings);
  2480. if("entries" in configuration){var entries=configuration.entries;
  2481. for(var i=0;
  2482. i<entries.length;
  2483. i++){coder._addEntry(entries[i].kase,entries[i].key,entries[i].color);
  2484. }}};
  2485. Exhibit.ColorCoder.prototype.dispose=function(){this._uiContext=null;
  2486. this._settings=null;
  2487. };
  2488. Exhibit.ColorCoder._colorTable={"red":"#ff0000","green":"#00ff00","blue":"#0000ff","white":"#ffffff","black":"#000000","gray":"#888888"};
  2489. Exhibit.ColorCoder.prototype._addEntry=function(kase,key,color){if(color in Exhibit.ColorCoder._colorTable){color=Exhibit.ColorCoder._colorTable[color];
  2490. }var entry=null;
  2491. switch(kase){case"others":entry=this._othersCase;
  2492. break;
  2493. case"mixed":entry=this._mixedCase;
  2494. break;
  2495. case"missing":entry=this._missingCase;
  2496. break;
  2497. }if(entry!=null){entry.label=key;
  2498. entry.color=color;
  2499. }else{this._map[key]={color:color};
  2500. }};
  2501. Exhibit.ColorCoder.prototype.translate=function(key,flags){if(key in this._map){if(flags){flags.keys.add(key);
  2502. }return this._map[key].color;
  2503. }else{if(key==null){if(flags){flags.missing=true;
  2504. }return this._missingCase.color;
  2505. }else{if(flags){flags.others=true;
  2506. }return this._othersCase.color;
  2507. }}};
  2508. Exhibit.ColorCoder.prototype.translateSet=function(keys,flags){var color=null;
  2509. var self=this;
  2510. keys.visit(function(key){var color2=self.translate(key,flags);
  2511. if(color==null){color=color2;
  2512. }else{if(color!=color2){if(flags){flags.mixed=true;
  2513. }color=self._mixedCase.color;
  2514. return true;
  2515. }}return false;
  2516. });
  2517. if(color!=null){return color;
  2518. }else{if(flags){flags.missing=true;
  2519. }return this._missingCase.color;
  2520. }};
  2521. Exhibit.ColorCoder.prototype.getOthersLabel=function(){return this._othersCase.label;
  2522. };
  2523. Exhibit.ColorCoder.prototype.getOthersColor=function(){return this._othersCase.color;
  2524. };
  2525. Exhibit.ColorCoder.prototype.getMissingLabel=function(){return this._missingCase.label;
  2526. };
  2527. Exhibit.ColorCoder.prototype.getMissingColor=function(){return this._missingCase.color;
  2528. };
  2529. Exhibit.ColorCoder.prototype.getMixedLabel=function(){return this._mixedCase.label;
  2530. };
  2531. Exhibit.ColorCoder.prototype.getMixedColor=function(){return this._mixedCase.color;
  2532. };
  2533. /* color-gradient-coder.js */
  2534. Exhibit.ColorGradientCoder=function(uiContext){this._uiContext=uiContext;
  2535. this._settings={};
  2536. this._gradientPoints=[];
  2537. this._mixedCase={label:Exhibit.Coders.l10n.mixedCaseLabel,color:Exhibit.Coders.mixedCaseColor};
  2538. this._missingCase={label:Exhibit.Coders.l10n.missingCaseLabel,color:Exhibit.Coders.missingCaseColor};
  2539. this._othersCase={label:Exhibit.Coders.l10n.othersCaseLabel,color:Exhibit.Coders.othersCaseColor};
  2540. };
  2541. Exhibit.ColorGradientCoder._settingSpecs={};
  2542. Exhibit.ColorGradientCoder.create=function(configuration,uiContext){var coder=new Exhibit.ColorGradientCoder(Exhibit.UIContext.create(configuration,uiContext));
  2543. Exhibit.ColorGradientCoder._configure(coder,configuration);
  2544. return coder;
  2545. };
  2546. Exhibit.ColorGradientCoder.createFromDOM=function(configElmt,uiContext){configElmt.style.display="none";
  2547. var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  2548. var coder=new Exhibit.ColorGradientCoder(Exhibit.UIContext.create(configuration,uiContext));
  2549. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.ColorGradientCoder._settingSpecs,coder._settings);
  2550. try{var gradientPoints=Exhibit.getAttribute(configElmt,"gradientPoints",";");
  2551. for(var i=0;
  2552. i<gradientPoints.length;
  2553. i++){var point=gradientPoints[i];
  2554. var value=parseFloat(point);
  2555. var colorIndex=point.indexOf("#")+1;
  2556. var red=parseInt(point.slice(colorIndex,colorIndex+2),16);
  2557. var green=parseInt(point.slice(colorIndex+2,colorIndex+4),16);
  2558. var blue=parseInt(point.slice(colorIndex+4),16);
  2559. coder._gradientPoints.push({value:value,red:red,green:green,blue:blue});
  2560. }var node=configElmt.firstChild;
  2561. while(node!=null){if(node.nodeType==1){coder._addEntry(Exhibit.getAttribute(node,"case"),node.firstChild.nodeValue.trim(),Exhibit.getAttribute(node,"color"));
  2562. }node=node.nextSibling;
  2563. }}catch(e){SimileAjax.Debug.exception(e,"ColorGradientCoder: Error processing configuration of coder");
  2564. }Exhibit.ColorGradientCoder._configure(coder,configuration);
  2565. return coder;
  2566. };
  2567. Exhibit.ColorGradientCoder._configure=function(coder,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.ColorGradientCoder._settingSpecs,coder._settings);
  2568. if("entries" in configuration){var entries=configuration.entries;
  2569. for(var i=0;
  2570. i<entries.length;
  2571. i++){coder._addEntry(entries[i].kase,entries[i].key,entries[i].color);
  2572. }}};
  2573. Exhibit.ColorGradientCoder.prototype.dispose=function(){this._uiContext=null;
  2574. this._settings=null;
  2575. };
  2576. Exhibit.ColorGradientCoder.prototype._addEntry=function(kase,key,color){var entry=null;
  2577. switch(kase){case"others":entry=this._othersCase;
  2578. break;
  2579. case"mixed":entry=this._mixedCase;
  2580. break;
  2581. case"missing":entry=this._missingCase;
  2582. break;
  2583. }if(entry!=null){entry.label=key;
  2584. entry.color=color;
  2585. }};
  2586. Exhibit.ColorGradientCoder.prototype.translate=function(key,flags){var gradientPoints=this._gradientPoints;
  2587. var getColor=function(key){for(var j=0;
  2588. j<gradientPoints.length;
  2589. j++){if(key==gradientPoints[j].value){return rgbToHex(gradientPoints[j].red,gradientPoints[j].green,gradientPoints[j].blue);
  2590. }else{if(gradientPoints[j+1]!=null){if(key<gradientPoints[j+1].value){var fraction=(key-gradientPoints[j].value)/(gradientPoints[j+1].value-gradientPoints[j].value);
  2591. var newRed=Math.floor(gradientPoints[j].red+fraction*(gradientPoints[j+1].red-gradientPoints[j].red));
  2592. var newGreen=Math.floor(gradientPoints[j].green+fraction*(gradientPoints[j+1].green-gradientPoints[j].green));
  2593. var newBlue=Math.floor(gradientPoints[j].blue+fraction*(gradientPoints[j+1].blue-gradientPoints[j].blue));
  2594. return rgbToHex(newRed,newGreen,newBlue);
  2595. }}}}};
  2596. var rgbToHex=function(r,g,b){var decToHex=function(n){if(n==0){return"00";
  2597. }else{if(n<16){return"0"+n.toString(16);
  2598. }else{return n.toString(16);
  2599. }}};
  2600. return"#"+decToHex(r)+decToHex(g)+decToHex(b);
  2601. };
  2602. if(key.constructor!=Number){key=parseFloat(key);
  2603. }if(key>=gradientPoints[0].value&key<=gradientPoints[gradientPoints.length-1].value){if(flags){flags.keys.add(key);
  2604. }return getColor(key);
  2605. }else{if(key==null){if(flags){flags.missing=true;
  2606. }return this._missingCase.color;
  2607. }else{if(flags){flags.others=true;
  2608. }return this._othersCase.color;
  2609. }}};
  2610. Exhibit.ColorGradientCoder.prototype.translateSet=function(keys,flags){var color=null;
  2611. var self=this;
  2612. keys.visit(function(key){var color2=self.translate(key,flags);
  2613. if(color==null){color=color2;
  2614. }else{if(color!=color2){if(flags){flags.mixed=true;
  2615. }color=self._mixedCase.color;
  2616. return true;
  2617. }}return false;
  2618. });
  2619. if(color!=null){return color;
  2620. }else{if(flags){flags.missing=true;
  2621. }return this._missingCase.color;
  2622. }};
  2623. Exhibit.ColorGradientCoder.prototype.getOthersLabel=function(){return this._othersCase.label;
  2624. };
  2625. Exhibit.ColorGradientCoder.prototype.getOthersColor=function(){return this._othersCase.color;
  2626. };
  2627. Exhibit.ColorGradientCoder.prototype.getMissingLabel=function(){return this._missingCase.label;
  2628. };
  2629. Exhibit.ColorGradientCoder.prototype.getMissingColor=function(){return this._missingCase.color;
  2630. };
  2631. Exhibit.ColorGradientCoder.prototype.getMixedLabel=function(){return this._mixedCase.label;
  2632. };
  2633. Exhibit.ColorGradientCoder.prototype.getMixedColor=function(){return this._mixedCase.color;
  2634. };
  2635. /* default-color-coder.js */
  2636. Exhibit.DefaultColorCoder=function(uiContext){};
  2637. Exhibit.DefaultColorCoder.colors=["#FF9000","#5D7CBA","#A97838","#8B9BBA","#FFC77F","#003EBA","#29447B","#543C1C"];
  2638. Exhibit.DefaultColorCoder._map={};
  2639. Exhibit.DefaultColorCoder._nextColor=0;
  2640. Exhibit.DefaultColorCoder.prototype.translate=function(key,flags){if(key==null){if(flags){flags.missing=true;
  2641. }return Exhibit.Coders.missingCaseColor;
  2642. }else{if(flags){flags.keys.add(key);
  2643. }if(key in Exhibit.DefaultColorCoder._map){return Exhibit.DefaultColorCoder._map[key];
  2644. }else{var color=Exhibit.DefaultColorCoder.colors[Exhibit.DefaultColorCoder._nextColor];
  2645. Exhibit.DefaultColorCoder._nextColor=(Exhibit.DefaultColorCoder._nextColor+1)%Exhibit.DefaultColorCoder.colors.length;
  2646. Exhibit.DefaultColorCoder._map[key]=color;
  2647. return color;
  2648. }}};
  2649. Exhibit.DefaultColorCoder.prototype.translateSet=function(keys,flags){var color=null;
  2650. var self=this;
  2651. keys.visit(function(key){var color2=self.translate(key,flags);
  2652. if(color==null){color=color2;
  2653. }else{if(color!=color2){color=Exhibit.Coders.mixedCaseColor;
  2654. flags.mixed=true;
  2655. return true;
  2656. }}return false;
  2657. });
  2658. if(color!=null){return color;
  2659. }else{flags.missing=true;
  2660. return Exhibit.Coders.missingCaseColor;
  2661. }};
  2662. Exhibit.DefaultColorCoder.prototype.getOthersLabel=function(){return Exhibit.Coders.l10n.othersCaseLabel;
  2663. };
  2664. Exhibit.DefaultColorCoder.prototype.getOthersColor=function(){return Exhibit.Coders.othersCaseColor;
  2665. };
  2666. Exhibit.DefaultColorCoder.prototype.getMissingLabel=function(){return Exhibit.Coders.l10n.missingCaseLabel;
  2667. };
  2668. Exhibit.DefaultColorCoder.prototype.getMissingColor=function(){return Exhibit.Coders.missingCaseColor;
  2669. };
  2670. Exhibit.DefaultColorCoder.prototype.getMixedLabel=function(){return Exhibit.Coders.l10n.mixedCaseLabel;
  2671. };
  2672. Exhibit.DefaultColorCoder.prototype.getMixedColor=function(){return Exhibit.Coders.mixedCaseColor;
  2673. };
  2674. /* icon-coder.js */
  2675. Exhibit.IconCoder=function(uiContext){this._uiContext=uiContext;
  2676. this._settings={};
  2677. this._map={};
  2678. this._mixedCase={label:"mixed",icon:null};
  2679. this._missingCase={label:"missing",icon:null};
  2680. this._othersCase={label:"others",icon:null};
  2681. };
  2682. Exhibit.IconCoder._settingSpecs={};
  2683. Exhibit.IconCoder.create=function(configuration,uiContext){var coder=new Exhibit.IconCoder(Exhibit.UIContext.create(configuration,uiContext));
  2684. Exhibit.IconCoder._configure(coder,configuration);
  2685. return coder;
  2686. };
  2687. Exhibit.IconCoder.createFromDOM=function(configElmt,uiContext){configElmt.style.display="none";
  2688. var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  2689. var coder=new Exhibit.IconCoder(Exhibit.UIContext.create(configuration,uiContext));
  2690. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.IconCoder._settingSpecs,coder._settings);
  2691. try{var node=configElmt.firstChild;
  2692. while(node!=null){if(node.nodeType==1){coder._addEntry(Exhibit.getAttribute(node,"case"),node.firstChild.nodeValue.trim(),Exhibit.getAttribute(node,"icon"));
  2693. }node=node.nextSibling;
  2694. }}catch(e){SimileAjax.Debug.exception(e,"IconCoder: Error processing configuration of coder");
  2695. }Exhibit.IconCoder._configure(coder,configuration);
  2696. return coder;
  2697. };
  2698. Exhibit.IconCoder._configure=function(coder,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.IconCoder._settingSpecs,coder._settings);
  2699. if("entries" in configuration){var entries=configuration.entries;
  2700. for(var i=0;
  2701. i<entries.length;
  2702. i++){coder._addEntry(entries[i].kase,entries[i].key,entries[i].icon);
  2703. }}};
  2704. Exhibit.IconCoder.prototype.dispose=function(){this._uiContext=null;
  2705. this._settings=null;
  2706. };
  2707. Exhibit.IconCoder._iconTable={};
  2708. Exhibit.IconCoder.prototype._addEntry=function(kase,key,icon){if(icon in Exhibit.IconCoder._iconTable){icon=Exhibit.IconCoder._iconTable[icon];
  2709. }var entry=null;
  2710. switch(kase){case"others":entry=this._othersCase;
  2711. break;
  2712. case"mixed":entry=this._mixedCase;
  2713. break;
  2714. case"missing":entry=this._missingCase;
  2715. break;
  2716. }if(entry!=null){entry.label=key;
  2717. entry.icon=icon;
  2718. }else{this._map[key]={icon:icon};
  2719. }};
  2720. Exhibit.IconCoder.prototype.translate=function(key,flags){if(key in this._map){if(flags){flags.keys.add(key);
  2721. }return this._map[key].icon;
  2722. }else{if(key==null){if(flags){flags.missing=true;
  2723. }return this._missingCase.icon;
  2724. }else{if(flags){flags.others=true;
  2725. }return this._othersCase.icon;
  2726. }}};
  2727. Exhibit.IconCoder.prototype.translateSet=function(keys,flags){var icon=null;
  2728. var self=this;
  2729. keys.visit(function(key){var icon2=self.translate(key,flags);
  2730. if(icon==null){icon=icon2;
  2731. }else{if(icon!=icon2){if(flags){flags.mixed=true;
  2732. }icon=self._mixedCase.icon;
  2733. return true;
  2734. }}return false;
  2735. });
  2736. if(icon!=null){return icon;
  2737. }else{if(flags){flags.missing=true;
  2738. }return this._missingCase.icon;
  2739. }};
  2740. Exhibit.IconCoder.prototype.getOthersLabel=function(){return this._othersCase.label;
  2741. };
  2742. Exhibit.IconCoder.prototype.getOthersIcon=function(){return this._othersCase.icon;
  2743. };
  2744. Exhibit.IconCoder.prototype.getMissingLabel=function(){return this._missingCase.label;
  2745. };
  2746. Exhibit.IconCoder.prototype.getMissingIcon=function(){return this._missingCase.icon;
  2747. };
  2748. Exhibit.IconCoder.prototype.getMixedLabel=function(){return this._mixedCase.label;
  2749. };
  2750. Exhibit.IconCoder.prototype.getMixedIcon=function(){return this._mixedCase.icon;
  2751. };
  2752. /* ordered-color-coder.js */
  2753. Exhibit.OrderedColorCoder=function(uiContext){this._uiContext=uiContext;
  2754. this._settings={};
  2755. this._map={};
  2756. this._order=new Exhibit.OrderedColorCoder._OrderedHash();
  2757. this._usePriority="highest";
  2758. this._mixedCase={label:null,color:null,isDefault:true};
  2759. this._missingCase={label:Exhibit.Coders.l10n.missingCaseLabel,color:Exhibit.Coders.missingCaseColor,isDefault:true};
  2760. this._othersCase={label:Exhibit.Coders.l10n.othersCaseLabel,color:Exhibit.Coders.othersCaseColor,isDefault:true};
  2761. };
  2762. Exhibit.OrderedColorCoder._OrderedHash=function(){this.size=0;
  2763. this.hash={};
  2764. };
  2765. Exhibit.OrderedColorCoder._OrderedHash.prototype.add=function(key){this.hash[key]=this.size++;
  2766. };
  2767. Exhibit.OrderedColorCoder._OrderedHash.prototype.size=function(){return this.size;
  2768. };
  2769. Exhibit.OrderedColorCoder._OrderedHash.prototype.get=function(key){return this.hash[key];
  2770. };
  2771. Exhibit.OrderedColorCoder._settingSpecs={};
  2772. Exhibit.OrderedColorCoder.create=function(configuration,uiContext){var coder=new Exhibit.OrderedColorCoder(Exhibit.UIContext.create(configuration,uiContext));
  2773. Exhibit.OrderedColorCoder._configure(coder,configuration);
  2774. return coder;
  2775. };
  2776. Exhibit.OrderedColorCoder.createFromDOM=function(configElmt,uiContext){configElmt.style.display="none";
  2777. var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  2778. var coder=new Exhibit.OrderedColorCoder(Exhibit.UIContext.create(configuration,uiContext));
  2779. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.OrderedColorCoder._settingSpecs,coder._settings);
  2780. try{this._usePriority=coder._settings.usePriority;
  2781. var node=configElmt.firstChild;
  2782. while(node!=null){if(node.nodeType==1){coder._addEntry(Exhibit.getAttribute(node,"case"),node.firstChild.nodeValue.trim(),Exhibit.getAttribute(node,"color"));
  2783. }node=node.nextSibling;
  2784. }if(coder.getOthersIsDefault()){coder._addEntry("other",coder.getOthersLabel(),coder.getOthersColor());
  2785. }if(coder.getMissingIsDefault()){coder._addEntry("missing",coder.getMissingLabel(),coder.getMissingColor());
  2786. }}catch(e){SimileAjax.Debug.exception(e,"OrderedColorCoder: Error processing configuration of coder");
  2787. }Exhibit.OrderedColorCoder._configure(coder,configuration);
  2788. return coder;
  2789. };
  2790. Exhibit.OrderedColorCoder._configure=function(coder,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.OrderedColorCoder._settingSpecs,coder._settings);
  2791. if("entries" in configuration){var entries=configuration.entries;
  2792. for(var i=0;
  2793. i<entries.length;
  2794. i++){coder._addEntry(entries[i].kase,entries[i].key,entries[i].color);
  2795. }if(this.getOthersIsDefault()){coder._addEntry("other",this.getOthersLabel(),this.getOthersColor());
  2796. }if(this.getMissingIsDefault()){coder._addEntry("missing",this.getMissingLabel(),this.getMissingColor());
  2797. }}};
  2798. Exhibit.OrderedColorCoder.prototype.dispose=function(){this._uiContext=null;
  2799. this._settings=null;
  2800. };
  2801. Exhibit.OrderedColorCoder._colorTable={"red":"#ff0000","green":"#00ff00","blue":"#0000ff","white":"#ffffff","black":"#000000","gray":"#888888"};
  2802. Exhibit.OrderedColorCoder.prototype._addEntry=function(kase,key,color){if(color in Exhibit.OrderedColorCoder._colorTable){color=Exhibit.OrderedColorCoder._colorTable[color];
  2803. }var entry=null;
  2804. var mixed=false;
  2805. switch(kase){case"others":entry=this._othersCase;
  2806. break;
  2807. case"missing":entry=this._missingCase;
  2808. break;
  2809. case"mixed":mixed=true;
  2810. break;
  2811. }if(entry!=null){entry.label=key;
  2812. entry.color=color;
  2813. entry.isDefault=false;
  2814. this._order.add(key);
  2815. }else{if(!mixed){this._map[key]={color:color};
  2816. this._order.add(key);
  2817. }}};
  2818. Exhibit.OrderedColorCoder.prototype.translate=function(key,flags){if(key in this._map){if(flags){flags.keys.add(key);
  2819. }return this._map[key].color;
  2820. }else{if(key==null){if(flags){flags.missing=true;
  2821. }return this._missingCase.color;
  2822. }else{if(flags){flags.others=true;
  2823. }return this._othersCase.color;
  2824. }}};
  2825. Exhibit.OrderedColorCoder.prototype.translateSet=function(keys,flags){var color=null;
  2826. var lastKey=null;
  2827. var self=this;
  2828. keys.visit(function(key){var color2=self.translate(key,flags);
  2829. if(color==null){color=color2;
  2830. lastKey=key;
  2831. }else{if(color!=color2){if(key==null){key=self.getMissingLabel();
  2832. }else{if(!(key in self._map)){key=self.getOthersLabel();
  2833. }}var keyOrder=self._order.get(key);
  2834. var lastKeyOrder=self._order.get(lastKey);
  2835. if(self._usePriority=="highest"){if(keyOrder<lastKeyOrder){color=color2;
  2836. lastKey=key;
  2837. }}else{if(self._usePriority=="lowest"){if(keyOrder>lastKeyOrder){color=color2;
  2838. lastKey=key;
  2839. }}else{return false;
  2840. }}return true;
  2841. }}return false;
  2842. });
  2843. if(color!=null){return color;
  2844. }else{if(flags){flags.missing=true;
  2845. }return this._missingCase.color;
  2846. }};
  2847. Exhibit.OrderedColorCoder.prototype.getOthersLabel=function(){return this._othersCase.label;
  2848. };
  2849. Exhibit.OrderedColorCoder.prototype.getOthersColor=function(){return this._othersCase.color;
  2850. };
  2851. Exhibit.OrderedColorCoder.prototype.getOthersIsDefault=function(){return this._othersCase.isDefault;
  2852. };
  2853. Exhibit.OrderedColorCoder.prototype.getMissingLabel=function(){return this._missingCase.label;
  2854. };
  2855. Exhibit.OrderedColorCoder.prototype.getMissingColor=function(){return this._missingCase.color;
  2856. };
  2857. Exhibit.OrderedColorCoder.prototype.getMissingIsDefault=function(){return this._missingCase.isDefault;
  2858. };
  2859. Exhibit.OrderedColorCoder.prototype.getMixedLabel=function(){return this._mixedCase.label;
  2860. };
  2861. Exhibit.OrderedColorCoder.prototype.getMixedColor=function(){return this._mixedCase.color;
  2862. };
  2863. Exhibit.OrderedColorCoder.prototype.getMixedIsDefault=function(){return this._mixedCase.isDefault;
  2864. };
  2865. /* size-coder.js */
  2866. Exhibit.SizeCoder=function(uiContext){this._uiContext=uiContext;
  2867. this._settings={};
  2868. this._map={};
  2869. this._mixedCase={label:"mixed",size:10};
  2870. this._missingCase={label:"missing",size:10};
  2871. this._othersCase={label:"others",size:10};
  2872. };
  2873. Exhibit.SizeCoder._settingSpecs={};
  2874. Exhibit.SizeCoder.create=function(configuration,uiContext){var coder=new Exhibit.SizeCoder(Exhibit.UIContext.create(configuration,uiContext));
  2875. Exhibit.SizeCoder._configure(coder,configuration);
  2876. return coder;
  2877. };
  2878. Exhibit.SizeCoder.createFromDOM=function(configElmt,uiContext){configElmt.style.display="none";
  2879. var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  2880. var coder=new Exhibit.SizeCoder(Exhibit.UIContext.create(configuration,uiContext));
  2881. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.SizeCoder._settingSpecs,coder._settings);
  2882. try{var node=configElmt.firstChild;
  2883. while(node!=null){if(node.nodeType==1){coder._addEntry(Exhibit.getAttribute(node,"case"),node.firstChild.nodeValue.trim(),Exhibit.getAttribute(node,"size"));
  2884. }node=node.nextSibling;
  2885. }}catch(e){SimileAjax.Debug.exception(e,"SizeCoder: Error processing configuration of coder");
  2886. }Exhibit.SizeCoder._configure(coder,configuration);
  2887. return coder;
  2888. };
  2889. Exhibit.SizeCoder._configure=function(coder,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.SizeCoder._settingSpecs,coder._settings);
  2890. if("entries" in configuration){var entries=configuration.entries;
  2891. for(var i=0;
  2892. i<entries.length;
  2893. i++){coder._addEntry(entries[i].kase,entries[i].key,entries[i].size);
  2894. }}};
  2895. Exhibit.SizeCoder.prototype.dispose=function(){this._uiContext=null;
  2896. this._settings=null;
  2897. };
  2898. Exhibit.SizeCoder.prototype._addEntry=function(kase,key,size){var entry=null;
  2899. switch(kase){case"others":entry=this._othersCase;
  2900. break;
  2901. case"mixed":entry=this._mixedCase;
  2902. break;
  2903. case"missing":entry=this._missingCase;
  2904. break;
  2905. }if(entry!=null){entry.label=key;
  2906. entry.size=size;
  2907. }else{this._map[key]={size:size};
  2908. }};
  2909. Exhibit.SizeCoder.prototype.translate=function(key,flags){if(key in this._map){if(flags){flags.keys.add(key);
  2910. }return this._map[key].size;
  2911. }else{if(key==null){if(flags){flags.missing=true;
  2912. }return this._missingCase.size;
  2913. }else{if(flags){flags.others=true;
  2914. }return this._othersCase.size;
  2915. }}};
  2916. Exhibit.SizeCoder.prototype.translateSet=function(keys,flags){var size=null;
  2917. var self=this;
  2918. keys.visit(function(key){var size2=self.translate(key,flags);
  2919. if(size==null){size=size2;
  2920. }else{if(size!=size2){if(flags){flags.mixed=true;
  2921. }size=self._mixedCase.size;
  2922. return true;
  2923. }}return false;
  2924. });
  2925. if(size!=null){return size;
  2926. }else{if(flags){flags.missing=true;
  2927. }return this._missingCase.size;
  2928. }};
  2929. Exhibit.SizeCoder.prototype.getOthersLabel=function(){return this._othersCase.label;
  2930. };
  2931. Exhibit.SizeCoder.prototype.getOthersSize=function(){return this._othersCase.size;
  2932. };
  2933. Exhibit.SizeCoder.prototype.getMissingLabel=function(){return this._missingCase.label;
  2934. };
  2935. Exhibit.SizeCoder.prototype.getMissingSize=function(){return this._missingCase.size;
  2936. };
  2937. Exhibit.SizeCoder.prototype.getMixedLabel=function(){return this._mixedCase.label;
  2938. };
  2939. Exhibit.SizeCoder.prototype.getMixedSize=function(){return this._mixedCase.size;
  2940. };
  2941. /* size-gradient-coder.js */
  2942. Exhibit.SizeGradientCoder=function(uiContext){this._uiContext=uiContext;
  2943. this._settings={};
  2944. this._log={func:function(size){return Math.ceil(Math.log(size));
  2945. },invFunc:function(size){return Math.ceil(Math.exp(size));
  2946. }};
  2947. this._linear={func:function(size){return Math.ceil(size);
  2948. },invFunc:function(size){return Math.ceil(size);
  2949. }};
  2950. this._quad={func:function(size){return Math.ceil(Math.pow((size/100),2));
  2951. },invFunc:function(size){return Math.sqrt(size)*100;
  2952. }};
  2953. this._exp={func:function(size){return Math.ceil(Math.exp(size));
  2954. },invFunc:function(size){return Math.ceil(Math.log(size));
  2955. }};
  2956. this._markerScale=this._quad;
  2957. this._valueScale=this._linear;
  2958. this._gradientPoints=[];
  2959. this._mixedCase={label:"mixed",size:20};
  2960. this._missingCase={label:"missing",size:20};
  2961. this._othersCase={label:"others",size:20};
  2962. };
  2963. Exhibit.SizeGradientCoder._settingSpecs={};
  2964. Exhibit.SizeGradientCoder.create=function(configuration,uiContext){var coder=new Exhibit.SizeGradientCoder(Exhibit.UIContext.create(configuration,uiContext));
  2965. Exhibit.SizeGradientCoder._configure(coder,configuration);
  2966. return coder;
  2967. };
  2968. Exhibit.SizeGradientCoder.createFromDOM=function(configElmt,uiContext){configElmt.style.display="none";
  2969. var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  2970. var coder=new Exhibit.SizeGradientCoder(Exhibit.UIContext.create(configuration,uiContext));
  2971. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.SizeGradientCoder._settingSpecs,coder._settings);
  2972. try{var markerScale=coder._settings.markerScale;
  2973. if(markerScale=="log"){coder._markerScale=coder._log;
  2974. }if(markerScale=="linear"){coder._markerScale=coder._linear;
  2975. }if(markerScale=="exp"){coder._markerScale=coder._exp;
  2976. }var gradientPoints=Exhibit.getAttribute(configElmt,"gradientPoints",";");
  2977. for(var i=0;
  2978. i<gradientPoints.length;
  2979. i++){var point=gradientPoints[i].split(",");
  2980. var value=parseFloat(point[0]);
  2981. var size=coder._markerScale.invFunc(parseFloat(point[1]));
  2982. coder._gradientPoints.push({value:value,size:size});
  2983. }var node=configElmt.firstChild;
  2984. while(node!=null){if(node.nodeType==1){coder._addEntry(Exhibit.getAttribute(node,"case"),node.firstChild.nodeValue.trim(),Exhibit.getAttribute(node,"size"));
  2985. }node=node.nextSibling;
  2986. }}catch(e){SimileAjax.Debug.exception(e,"SizeGradientCoder: Error processing configuration of coder");
  2987. }Exhibit.SizeGradientCoder._configure(coder,configuration);
  2988. return coder;
  2989. };
  2990. Exhibit.SizeGradientCoder._configure=function(coder,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.SizeGradientCoder._settingSpecs,coder._settings);
  2991. if("entries" in configuration){var entries=configuration.entries;
  2992. for(var i=0;
  2993. i<entries.length;
  2994. i++){coder._addEntry(entries[i].kase,entries[i].key,entries[i].size);
  2995. }}};
  2996. Exhibit.SizeGradientCoder.prototype.dispose=function(){this._uiContext=null;
  2997. this._settings=null;
  2998. };
  2999. Exhibit.SizeGradientCoder.prototype._addEntry=function(kase,key,size){var entry=null;
  3000. switch(kase){case"others":entry=this._othersCase;
  3001. break;
  3002. case"mixed":entry=this._mixedCase;
  3003. break;
  3004. case"missing":entry=this._missingCase;
  3005. break;
  3006. }if(entry!=null){entry.label=key;
  3007. entry.size=size;
  3008. }};
  3009. Exhibit.SizeGradientCoder.prototype.translate=function(key,flags){var self=this;
  3010. var gradientPoints=this._gradientPoints;
  3011. var getSize=function(key){if(key.constructor!=Number){key=parseFloat(key);
  3012. }for(j=0;
  3013. j<gradientPoints.length;
  3014. j++){if(key==gradientPoints[j].value){return self._markerScale.func(gradientPoints[j].size);
  3015. }else{if(gradientPoints[j+1]!=null){if(key<gradientPoints[j+1].value){var fraction=(key-gradientPoints[j].value)/(gradientPoints[j+1].value-gradientPoints[j].value);
  3016. var newSize=Math.floor(gradientPoints[j].size+fraction*(gradientPoints[j+1].size-gradientPoints[j].size));
  3017. return self._markerScale.func(newSize);
  3018. }}}}};
  3019. if(key>=gradientPoints[0].value&key<=gradientPoints[gradientPoints.length-1].value){if(flags){flags.keys.add(key);
  3020. }return getSize(key);
  3021. }else{if(key==null){if(flags){flags.missing=true;
  3022. }return this._missingCase.size;
  3023. }else{if(flags){flags.others=true;
  3024. }return this._othersCase.size;
  3025. }}};
  3026. Exhibit.SizeGradientCoder.prototype.translateSet=function(keys,flags){var size=null;
  3027. var self=this;
  3028. keys.visit(function(key){var size2=self.translate(key,flags);
  3029. if(size==null){size=size2;
  3030. }else{if(size!=size2){if(flags){flags.mixed=true;
  3031. }size=self._mixedCase.size;
  3032. return true;
  3033. }}return false;
  3034. });
  3035. if(size!=null){return size;
  3036. }else{if(flags){flags.missing=true;
  3037. }return this._missingCase.size;
  3038. }};
  3039. Exhibit.SizeGradientCoder.prototype.getOthersLabel=function(){return this._othersCase.label;
  3040. };
  3041. Exhibit.SizeGradientCoder.prototype.getOthersSize=function(){return this._othersCase.size;
  3042. };
  3043. Exhibit.SizeGradientCoder.prototype.getMissingLabel=function(){return this._missingCase.label;
  3044. };
  3045. Exhibit.SizeGradientCoder.prototype.getMissingSize=function(){return this._missingCase.size;
  3046. };
  3047. Exhibit.SizeGradientCoder.prototype.getMixedLabel=function(){return this._mixedCase.label;
  3048. };
  3049. Exhibit.SizeGradientCoder.prototype.getMixedSize=function(){return this._mixedCase.size;
  3050. };
  3051. /* coordinator.js */
  3052. Exhibit.Coordinator=function(uiContext){this._uiContext=uiContext;
  3053. this._listeners=[];
  3054. };
  3055. Exhibit.Coordinator.create=function(configuration,uiContext){var coordinator=new Exhibit.Coordinator(uiContext);
  3056. return coordinator;
  3057. };
  3058. Exhibit.Coordinator.createFromDOM=function(div,uiContext){var coordinator=new Exhibit.Coordinator(Exhibit.UIContext.createFromDOM(div,uiContext,false));
  3059. return coordinator;
  3060. };
  3061. Exhibit.Coordinator.prototype.dispose=function(){this._uiContext.dispose();
  3062. this._uiContext=null;
  3063. };
  3064. Exhibit.Coordinator.prototype.addListener=function(callback){var listener=new Exhibit.Coordinator._Listener(this,callback);
  3065. this._listeners.push(listener);
  3066. return listener;
  3067. };
  3068. Exhibit.Coordinator.prototype._removeListener=function(listener){for(var i=0;
  3069. i<this._listeners.length;
  3070. i++){if(this._listeners[i]==listener){this._listeners.splice(i,1);
  3071. return ;
  3072. }}};
  3073. Exhibit.Coordinator.prototype._fire=function(listener,o){for(var i=0;
  3074. i<this._listeners.length;
  3075. i++){var listener2=this._listeners[i];
  3076. if(listener2!=listener){listener2._callback(o);
  3077. }}};
  3078. Exhibit.Coordinator._Listener=function(coordinator,callback){this._coordinator=coordinator;
  3079. this._callback=callback;
  3080. };
  3081. Exhibit.Coordinator._Listener.prototype.dispose=function(){this._coordinator._removeListener(this);
  3082. };
  3083. Exhibit.Coordinator._Listener.prototype.fire=function(o){this._coordinator._fire(this,o);
  3084. };
  3085. /* alpha-range-facet.js */
  3086. Exhibit.AlphaRangeFacet=function(containerElmt,uiContext){this._div=containerElmt;
  3087. this._uiContext=uiContext;
  3088. this._expression=null;
  3089. this._settings={};
  3090. this._dom=null;
  3091. this._ranges=[];
  3092. var self=this;
  3093. this._listener={onRootItemsChanged:function(){if("_rangeIndex" in self){delete self._rangeIndex;
  3094. }}};
  3095. uiContext.getCollection().addListener(this._listener);
  3096. };
  3097. Exhibit.AlphaRangeFacet._settingSpecs={"facetLabel":{type:"text"},"scroll":{type:"boolean",defaultValue:true},"height":{type:"text"},"interval":{type:"int",defaultValue:7},"collapsible":{type:"boolean",defaultValue:false},"collapsed":{type:"boolean",defaultValue:false}};
  3098. Exhibit.AlphaRangeFacet.create=function(configuration,containerElmt,uiContext){var uiContext=Exhibit.UIContext.create(configuration,uiContext);
  3099. var facet=new Exhibit.AlphaRangeFacet(containerElmt,uiContext);
  3100. Exhibit.AlphaRangeFacet._configure(facet,configuration);
  3101. facet._initializeUI();
  3102. uiContext.getCollection().addFacet(facet);
  3103. return facet;
  3104. };
  3105. Exhibit.AlphaRangeFacet.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  3106. var uiContext=Exhibit.UIContext.createFromDOM(configElmt,uiContext);
  3107. var facet=new Exhibit.AlphaRangeFacet(containerElmt!=null?containerElmt:configElmt,uiContext);
  3108. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.AlphaRangeFacet._settingSpecs,facet._settings);
  3109. try{var expressionString=Exhibit.getAttribute(configElmt,"expression");
  3110. if(expressionString!=null&&expressionString.length>0){facet._expression=Exhibit.ExpressionParser.parse(expressionString);
  3111. }}catch(e){SimileAjax.Debug.exception(e,"AlphaRangeFacet: Error processing configuration of alpha range facet");
  3112. }Exhibit.AlphaRangeFacet._configure(facet,configuration);
  3113. facet._initializeUI();
  3114. uiContext.getCollection().addFacet(facet);
  3115. return facet;
  3116. };
  3117. Exhibit.AlphaRangeFacet._configure=function(facet,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.AlphaRangeFacet._settingSpecs,facet._settings);
  3118. if("expression" in configuration){facet._expression=Exhibit.ExpressionParser.parse(configuration.expression);
  3119. }if(!("facetLabel" in facet._settings)){facet._settings.facetLabel="missing ex:facetLabel";
  3120. if(facet._expression!=null&&facet._expression.isPath()){var segment=facet._expression.getPath().getLastSegment();
  3121. var property=facet._uiContext.getDatabase().getProperty(segment.property);
  3122. if(property!=null){facet._settings.facetLabel=segment.forward?property.getLabel():property.getReverseLabel();
  3123. }}}if(facet._settings.collapsed){facet._settings.collapsible=true;
  3124. }};
  3125. Exhibit.AlphaRangeFacet.prototype.dispose=function(){this._uiContext.getCollection().removeFacet(this);
  3126. this._uiContext.getCollection().removeListener(this._listener);
  3127. this._uiContext=null;
  3128. this._div.innerHTML="";
  3129. this._div=null;
  3130. this._dom=null;
  3131. this._expression=null;
  3132. this._settings=null;
  3133. this._ranges=[];
  3134. };
  3135. Exhibit.AlphaRangeFacet.prototype.hasRestrictions=function(){return this._ranges.length>0;
  3136. };
  3137. Exhibit.AlphaRangeFacet.prototype.clearAllRestrictions=function(){var restrictions=[];
  3138. if(this._ranges.length>0){restrictions=restrictions.concat(this._ranges);
  3139. this._ranges=[];
  3140. this._notifyCollection();
  3141. }return restrictions;
  3142. };
  3143. Exhibit.AlphaRangeFacet.prototype.applyRestrictions=function(restrictions){this._ranges=restrictions;
  3144. this._notifyCollection();
  3145. };
  3146. Exhibit.AlphaRangeFacet.prototype.setRange=function(from,to,selected){if(selected){for(var i=0;
  3147. i<this._ranges.length;
  3148. i++){var range=this._ranges[i];
  3149. if(range.from==from&&range.to==to){return ;
  3150. }}this._ranges.push({from:from,to:to});
  3151. }else{for(var i=0;
  3152. i<this._ranges.length;
  3153. i++){var range=this._ranges[i];
  3154. if(range.from==from&&range.to==to){this._ranges.splice(i,1);
  3155. break;
  3156. }}}this._notifyCollection();
  3157. };
  3158. Exhibit.AlphaRangeFacet.prototype.restrict=function(items){if(this._ranges.length==0){return items;
  3159. }else{this._buildRangeIndex();
  3160. var set=new Exhibit.Set();
  3161. for(var i=0;
  3162. i<this._ranges.length;
  3163. i++){var range=this._ranges[i];
  3164. this._rangeIndex.getSubjectsInRange(range.from,String.fromCharCode(range.to.charCodeAt(0)+1),true,set,items);
  3165. }return set;
  3166. }};
  3167. Exhibit.AlphaRangeFacet.prototype.update=function(items){this._dom.valuesContainer.style.display="none";
  3168. this._dom.valuesContainer.innerHTML="";
  3169. this._reconstruct(items);
  3170. this._dom.valuesContainer.style.display="block";
  3171. };
  3172. Exhibit.AlphaRangeFacet.prototype._reconstruct=function(items){var self=this;
  3173. var ranges=[];
  3174. var rangeIndex;
  3175. var computeItems;
  3176. this._buildRangeIndex();
  3177. rangeIndex=this._rangeIndex;
  3178. countItems=function(range){return rangeIndex.getSubjectsInRange(range.from,String.fromCharCode(range.to.charCodeAt(0)+1),true,null,items).size();
  3179. };
  3180. var alphaList=[];
  3181. var alphaInList=function(a){for(x in alphaList){if(alphaList[x]==a){return true;
  3182. }}return false;
  3183. };
  3184. for(var y=0;
  3185. y<rangeIndex.getCount();
  3186. y+=1){var alphaChar=rangeIndex._pairs[y].value.substr(0,1).toUpperCase();
  3187. if(!alphaInList(alphaChar)){alphaList.push(alphaChar);
  3188. }}for(var x=0;
  3189. x<alphaList.length;
  3190. x+=this._settings.interval){var range={from:alphaList[x],to:alphaList[(x+this._settings.interval>=alphaList.length?alphaList.length-1:x+this._settings.interval-1)],selected:false};
  3191. range.count=countItems(range);
  3192. for(var i=0;
  3193. i<this._ranges.length;
  3194. i++){var range2=this._ranges[i];
  3195. if(range2.from==range.from&&range2.to==range.to){range.selected=true;
  3196. facetHasSelection=true;
  3197. break;
  3198. }}ranges.push(range);
  3199. }var facetHasSelection=this._ranges.length>0;
  3200. var containerDiv=this._dom.valuesContainer;
  3201. containerDiv.style.display="none";
  3202. var constructFacetItemFunction=Exhibit.FacetUtilities[this._settings.scroll?"constructFacetItem":"constructFlowingFacetItem"];
  3203. var makeFacetValue=function(from,to,count,selected){var onSelect=function(elmt,evt,target){self._toggleRange(from,to,selected,false);
  3204. SimileAjax.DOM.cancelEvent(evt);
  3205. return false;
  3206. };
  3207. var onSelectOnly=function(elmt,evt,target){self._toggleRange(from,to,selected,!(evt.ctrlKey||evt.metaKey));
  3208. SimileAjax.DOM.cancelEvent(evt);
  3209. return false;
  3210. };
  3211. var elmt=constructFacetItemFunction(from.substr(0,1)+" - "+to.substr(0,1),count,null,selected,facetHasSelection,onSelect,onSelectOnly,self._uiContext);
  3212. containerDiv.appendChild(elmt);
  3213. };
  3214. for(var i=0;
  3215. i<ranges.length;
  3216. i++){var range=ranges[i];
  3217. if(range.selected||range.count>0){makeFacetValue(range.from,range.to,range.count,range.selected);
  3218. }}containerDiv.style.display="block";
  3219. this._dom.setSelectionCount(this._ranges.length);
  3220. };
  3221. Exhibit.AlphaRangeFacet.prototype._notifyCollection=function(){this._uiContext.getCollection().onFacetUpdated(this);
  3222. };
  3223. Exhibit.AlphaRangeFacet.prototype._initializeUI=function(){var self=this;
  3224. this._dom=Exhibit.FacetUtilities[this._settings.scroll?"constructFacetFrame":"constructFlowingFacetFrame"](this,this._div,this._settings.facetLabel,function(elmt,evt,target){self._clearSelections();
  3225. },this._uiContext,this._settings.collapsible,this._settings.collapsed);
  3226. if("height" in this._settings){this._dom.valuesContainer.style.height=this._settings.height;
  3227. }};
  3228. Exhibit.AlphaRangeFacet.prototype._toggleRange=function(from,to,wasSelected,singleSelection){var self=this;
  3229. var label=from+" to "+to;
  3230. var wasOnlyThingSelected=(this._ranges.length==1&&wasSelected);
  3231. if(singleSelection&&!wasOnlyThingSelected){var newRestrictions=[{from:from,to:to}];
  3232. var oldRestrictions=[].concat(this._ranges);
  3233. SimileAjax.History.addLengthyAction(function(){self.applyRestrictions(newRestrictions);
  3234. },function(){self.applyRestrictions(oldRestrictions);
  3235. },String.substitute(Exhibit.FacetUtilities.l10n["facetSelectOnlyActionTitle"],[label,this._settings.facetLabel]));
  3236. }else{SimileAjax.History.addLengthyAction(function(){self.setRange(from,to,!wasSelected);
  3237. },function(){self.setRange(from,to,wasSelected);
  3238. },String.substitute(Exhibit.FacetUtilities.l10n[wasSelected?"facetUnselectActionTitle":"facetSelectActionTitle"],[label,this._settings.facetLabel]));
  3239. }};
  3240. Exhibit.AlphaRangeFacet.prototype._clearSelections=function(){var state={};
  3241. var self=this;
  3242. SimileAjax.History.addLengthyAction(function(){state.restrictions=self.clearAllRestrictions();
  3243. },function(){self.applyRestrictions(state.restrictions);
  3244. },String.substitute(Exhibit.FacetUtilities.l10n["facetClearSelectionsActionTitle"],[this._settings.facetLabel]));
  3245. };
  3246. Exhibit.AlphaRangeFacet.prototype._buildRangeIndex=function(){if(!("_rangeIndex" in this)){var expression=this._expression;
  3247. var database=this._uiContext.getDatabase();
  3248. var segment=expression.getPath().getLastSegment();
  3249. var property=database.getProperty(segment.property);
  3250. var getter=function(item,f){database.getObjects(item,property.getID(),null,null).visit(function(value){f(value.toUpperCase());
  3251. });
  3252. };
  3253. this._rangeIndex=new Exhibit.Database._RangeIndex(this._uiContext.getCollection().getAllItems(),getter);
  3254. }};
  3255. Exhibit.AlphaRangeFacet.prototype.exportFacetSelection=function(){var exportedSettings=[];
  3256. for(var i=0;
  3257. i<this._ranges.length;
  3258. i++){var range=this._ranges[i];
  3259. exportedSettings.push(range.from+"|"+range.to);
  3260. }return exportedSettings.join(",");
  3261. };
  3262. Exhibit.AlphaRangeFacet.prototype.importFacetSelection=function(settings){if(settings.length>0){var ranges=settings.split(",");
  3263. for(var i=0;
  3264. i<ranges.length;
  3265. i++){var range=ranges[i].split("|");
  3266. this._ranges.push({from:range[0],to:range[1]});
  3267. }}if(ranges&&ranges.length>0){this.update();
  3268. this._notifyCollection();
  3269. }};
  3270. /* cloud-facet.js */
  3271. Exhibit.CloudFacet=function(containerElmt,uiContext){this._div=containerElmt;
  3272. this._uiContext=uiContext;
  3273. this._colorCoder=null;
  3274. this._expression=null;
  3275. this._valueSet=new Exhibit.Set();
  3276. this._selectMissing=false;
  3277. this._settings={};
  3278. this._dom=null;
  3279. var self=this;
  3280. this._listener={onRootItemsChanged:function(){if("_itemToValue" in self){delete self._itemToValue;
  3281. }if("_valueToItem" in self){delete self._valueToItem;
  3282. }if("_missingItems" in self){delete self._missingItems;
  3283. }}};
  3284. uiContext.getCollection().addListener(this._listener);
  3285. };
  3286. Exhibit.CloudFacet._settingSpecs={"facetLabel":{type:"text"},"minimumCount":{type:"int",defaultValue:1},"showMissing":{type:"boolean",defaultValue:true},"missingLabel":{type:"text"}};
  3287. Exhibit.CloudFacet.create=function(configuration,containerElmt,uiContext){var uiContext=Exhibit.UIContext.create(configuration,uiContext);
  3288. var facet=new Exhibit.CloudFacet(containerElmt,uiContext);
  3289. Exhibit.CloudFacet._configure(facet,configuration);
  3290. facet._initializeUI();
  3291. uiContext.getCollection().addFacet(facet);
  3292. return facet;
  3293. };
  3294. Exhibit.CloudFacet.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  3295. var uiContext=Exhibit.UIContext.createFromDOM(configElmt,uiContext);
  3296. var facet=new Exhibit.CloudFacet(containerElmt!=null?containerElmt:configElmt,uiContext);
  3297. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.CloudFacet._settingSpecs,facet._settings);
  3298. try{var expressionString=Exhibit.getAttribute(configElmt,"expression");
  3299. if(expressionString!=null&&expressionString.length>0){facet._expression=Exhibit.ExpressionParser.parse(expressionString);
  3300. }var selection=Exhibit.getAttribute(configElmt,"selection",";");
  3301. if(selection!=null&&selection.length>0){for(var i=0,s;
  3302. s=selection[i];
  3303. i++){facet._valueSet.add(s);
  3304. }}var selectMissing=Exhibit.getAttribute(configElmt,"selectMissing");
  3305. if(selectMissing!=null&&selectMissing.length>0){facet._selectMissing=(selectMissing=="true");
  3306. }}catch(e){SimileAjax.Debug.exception(e,"CloudFacet: Error processing configuration of cloud facet");
  3307. }Exhibit.CloudFacet._configure(facet,configuration);
  3308. facet._initializeUI();
  3309. uiContext.getCollection().addFacet(facet);
  3310. return facet;
  3311. };
  3312. Exhibit.CloudFacet._configure=function(facet,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.CloudFacet._settingSpecs,facet._settings);
  3313. if("expression" in configuration){facet._expression=Exhibit.ExpressionParser.parse(configuration.expression);
  3314. }if("selection" in configuration){var selection=configuration.selection;
  3315. for(var i=0;
  3316. i<selection.length;
  3317. i++){facet._valueSet.add(selection[i]);
  3318. }}if("selectMissing" in configuration){facet._selectMissing=configuration.selectMissing;
  3319. }};
  3320. Exhibit.CloudFacet.prototype.dispose=function(){this._uiContext.getCollection().removeFacet(this);
  3321. this._uiContext.getCollection().removeListener(this._listener);
  3322. this._uiContext=null;
  3323. this._div.innerHTML="";
  3324. this._div=null;
  3325. this._dom=null;
  3326. this._expression=null;
  3327. this._valueSet=null;
  3328. this._settings=null;
  3329. this._itemToValue=null;
  3330. this._valueToItem=null;
  3331. this._missingItems=null;
  3332. };
  3333. Exhibit.CloudFacet.prototype.hasRestrictions=function(){return this._valueSet.size()>0||this._selectMissing;
  3334. };
  3335. Exhibit.CloudFacet.prototype.clearAllRestrictions=function(){var restrictions={selection:[],selectMissing:false};
  3336. if(this.hasRestrictions()){this._valueSet.visit(function(v){restrictions.selection.push(v);
  3337. });
  3338. this._valueSet=new Exhibit.Set();
  3339. restrictions.selectMissing=this._selectMissing;
  3340. this._selectMissing=false;
  3341. var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  3342. this._notifyCollection();
  3343. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  3344. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  3345. SimileAjax.RemoteLog.possiblyLog({facetType:"Cloud",facetLabel:this._settings.facetLabel,operation:"clearAllRestrictions",exhibitSize:totalSize,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize});
  3346. }return restrictions;
  3347. };
  3348. Exhibit.CloudFacet.prototype.applyRestrictions=function(restrictions){this._valueSet=new Exhibit.Set();
  3349. for(var i=0;
  3350. i<restrictions.selection.length;
  3351. i++){this._valueSet.add(restrictions.selection[i]);
  3352. }this._selectMissing=restrictions.selectMissing;
  3353. var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  3354. this._notifyCollection();
  3355. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  3356. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  3357. SimileAjax.RemoteLog.possiblyLog({facetType:"Cloud",facetLabel:this._settings.facetLabel,operation:"applyRestrictions",exhibitSize:totalSize,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize});
  3358. };
  3359. Exhibit.CloudFacet.prototype.setSelection=function(value,selected){if(selected){this._valueSet.add(value);
  3360. }else{this._valueSet.remove(value);
  3361. }var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  3362. this._notifyCollection();
  3363. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  3364. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  3365. SimileAjax.RemoteLog.possiblyLog({facetType:"Cloud",facetLabel:this._settings.facetLabel,operation:"setSelection",value:value,selected:selected,exhibitSize:totalSize,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize});
  3366. };
  3367. Exhibit.CloudFacet.prototype.setSelectMissing=function(selected){if(selected!=this._selectMissing){this._selectMissing=selected;
  3368. this._notifyCollection();
  3369. }};
  3370. Exhibit.CloudFacet.prototype.restrict=function(items){if(this._valueSet.size()==0&&!this._selectMissing){return items;
  3371. }var set;
  3372. if(this._expression.isPath()){set=this._expression.getPath().walkBackward(this._valueSet,"item",items,this._uiContext.getDatabase()).getSet();
  3373. }else{this._buildMaps();
  3374. set=new Exhibit.Set();
  3375. var valueToItem=this._valueToItem;
  3376. this._valueSet.visit(function(value){if(value in valueToItem){var itemA=valueToItem[value];
  3377. for(var i=0;
  3378. i<itemA.length;
  3379. i++){var item=itemA[i];
  3380. if(items.contains(item)){set.add(item);
  3381. }}}});
  3382. }if(this._selectMissing){this._buildMaps();
  3383. var missingItems=this._missingItems;
  3384. items.visit(function(item){if(item in missingItems){set.add(item);
  3385. }});
  3386. }return set;
  3387. };
  3388. Exhibit.CloudFacet.prototype.update=function(items){this._constructBody(this._computeFacet(items));
  3389. };
  3390. Exhibit.CloudFacet.prototype._computeFacet=function(items){var database=this._uiContext.getDatabase();
  3391. var entries=[];
  3392. var valueType="text";
  3393. var self=this;
  3394. if(this._expression.isPath()){var path=this._expression.getPath();
  3395. var facetValueResult=path.walkForward(items,"item",database);
  3396. valueType=facetValueResult.valueType;
  3397. if(facetValueResult.size>0){facetValueResult.forEachValue(function(facetValue){var itemSubcollection=path.evaluateBackward(facetValue,valueType,items,database);
  3398. if(itemSubcollection.size>=self._settings.minimumCount||self._valueSet.contains(facetValue)){entries.push({value:facetValue,count:itemSubcollection.size});
  3399. }});
  3400. }}else{this._buildMaps();
  3401. valueType=this._valueType;
  3402. for(var value in this._valueToItem){var itemA=this._valueToItem[value];
  3403. var count=0;
  3404. for(var i=0;
  3405. i<itemA.length;
  3406. i++){if(items.contains(itemA[i])){count++;
  3407. }}if(count>=this._settings.minimumCount||this._valueSet.contains(value)){entries.push({value:value,count:count});
  3408. }}}if(entries.length>0){var selection=this._valueSet;
  3409. var labeler=valueType=="item"?function(v){var l=database.getObject(v,"label");
  3410. return l!=null?l:v;
  3411. }:function(v){return v;
  3412. };
  3413. for(var i=0;
  3414. i<entries.length;
  3415. i++){var entry=entries[i];
  3416. entry.actionLabel=entry.selectionLabel=labeler(entry.value);
  3417. entry.selected=selection.contains(entry.value);
  3418. }var sortValueFunction=function(a,b){return a.selectionLabel.localeCompare(b.selectionLabel);
  3419. };
  3420. if("_orderMap" in this){var orderMap=this._orderMap;
  3421. sortValueFunction=function(a,b){if(a.selectionLabel in orderMap){if(b.selectionLabel in orderMap){return orderMap[a.selectionLabel]-orderMap[b.selectionLabel];
  3422. }else{return -1;
  3423. }}else{if(b.selectionLabel in orderMap){return 1;
  3424. }else{return a.selectionLabel.localeCompare(b.selectionLabel);
  3425. }}};
  3426. }else{if(valueType=="number"){sortValueFunction=function(a,b){a=parseFloat(a.value);
  3427. b=parseFloat(b.value);
  3428. return a<b?-1:a>b?1:0;
  3429. };
  3430. }}var sortFunction=sortValueFunction;
  3431. if(this._settings.sortMode=="count"){sortFunction=function(a,b){var c=b.count-a.count;
  3432. return c!=0?c:sortValueFunction(a,b);
  3433. };
  3434. }var sortDirectionFunction=sortFunction;
  3435. if(this._settings.sortDirection=="reverse"){sortDirectionFunction=function(a,b){return sortFunction(b,a);
  3436. };
  3437. }entries.sort(sortDirectionFunction);
  3438. }if(this._settings.showMissing||this._selectMissing){this._buildMaps();
  3439. var count=0;
  3440. for(var item in this._missingItems){if(items.contains(item)){count++;
  3441. }}if(count>0||this._selectMissing){var span=document.createElement("span");
  3442. span.innerHTML=("missingLabel" in this._settings)?this._settings.missingLabel:Exhibit.FacetUtilities.l10n.missingThisField;
  3443. span.className="exhibit-facet-value-missingThisField";
  3444. entries.unshift({value:null,count:count,selected:this._selectMissing,selectionLabel:span,actionLabel:Exhibit.FacetUtilities.l10n.missingThisField});
  3445. }}return entries;
  3446. };
  3447. Exhibit.CloudFacet.prototype._notifyCollection=function(){this._uiContext.getCollection().onFacetUpdated(this);
  3448. };
  3449. Exhibit.CloudFacet.prototype._initializeUI=function(){this._div.innerHTML="";
  3450. this._div.className="exhibit-cloudFacet";
  3451. var dom=SimileAjax.DOM.createDOMFromString(this._div,(("facetLabel" in this._settings)?("<div class='exhibit-cloudFacet-header'><span class='exhibit-cloudFacet-header-title'>"+this._settings.facetLabel+"</span></div>"):"")+"<div class='exhibit-cloudFacet-body' id='valuesContainer'></div>");
  3452. this._dom=dom;
  3453. };
  3454. Exhibit.CloudFacet.prototype._constructBody=function(entries){var self=this;
  3455. var div=this._dom.valuesContainer;
  3456. div.style.display="none";
  3457. div.innerHTML="";
  3458. if(entries.length>0){var min=Number.POSITIVE_INFINITY;
  3459. var max=Number.NEGATIVE_INFINITY;
  3460. for(var j=0;
  3461. j<entries.length;
  3462. j++){var entry=entries[j];
  3463. min=Math.min(min,entry.count);
  3464. max=Math.max(max,entry.count);
  3465. }var range=max-min;
  3466. var constructValue=function(entry){var onSelect=function(elmt,evt,target){self._filter(entry.value,entry.actionLabel,!(evt.ctrlKey||evt.metaKey));
  3467. SimileAjax.DOM.cancelEvent(evt);
  3468. return false;
  3469. };
  3470. var elmt=document.createElement("span");
  3471. elmt.appendChild(document.createTextNode("\u00A0"));
  3472. if(typeof entry.selectionLabel=="string"){elmt.appendChild(document.createTextNode(entry.selectionLabel));
  3473. }else{elmt.appendChild(entry.selectionLabel);
  3474. }elmt.appendChild(document.createTextNode("\u00A0"));
  3475. elmt.className=entry.selected?"exhibit-cloudFacet-value exhibit-cloudFacet-value-selected":"exhibit-cloudFacet-value";
  3476. if(entry.count>min){elmt.style.fontSize=Math.ceil(100+100*Math.log(1+1.5*(entry.count-min)/range))+"%";
  3477. }SimileAjax.WindowManager.registerEvent(elmt,"click",onSelect,SimileAjax.WindowManager.getBaseLayer());
  3478. div.appendChild(elmt);
  3479. div.appendChild(document.createTextNode(" "));
  3480. };
  3481. for(var j=0;
  3482. j<entries.length;
  3483. j++){constructValue(entries[j]);
  3484. }}div.style.display="block";
  3485. };
  3486. Exhibit.CloudFacet.prototype._filter=function(value,label,selectOnly){var self=this;
  3487. var selected,select,deselect;
  3488. var oldValues=new Exhibit.Set(this._valueSet);
  3489. var oldSelectMissing=this._selectMissing;
  3490. var newValues;
  3491. var newSelectMissing;
  3492. var actionLabel;
  3493. var wasSelected;
  3494. var wasOnlyThingSelected;
  3495. if(value==null){wasSelected=oldSelectMissing;
  3496. wasOnlyThingSelected=wasSelected&&(oldValues.size()==0);
  3497. if(selectOnly){if(oldValues.size()==0){newSelectMissing=!oldSelectMissing;
  3498. }else{newSelectMissing=true;
  3499. }newValues=new Exhibit.Set();
  3500. }else{newSelectMissing=!oldSelectMissing;
  3501. newValues=new Exhibit.Set(oldValues);
  3502. }}else{wasSelected=oldValues.contains(value);
  3503. wasOnlyThingSelected=wasSelected&&(oldValues.size()==1)&&!oldSelectMissing;
  3504. if(selectOnly){newSelectMissing=false;
  3505. newValues=new Exhibit.Set();
  3506. if(!oldValues.contains(value)){newValues.add(value);
  3507. }else{if(oldValues.size()>1||oldSelectMissing){newValues.add(value);
  3508. }}}else{newSelectMissing=oldSelectMissing;
  3509. newValues=new Exhibit.Set(oldValues);
  3510. if(newValues.contains(value)){newValues.remove(value);
  3511. }else{newValues.add(value);
  3512. }}}var newRestrictions={selection:newValues.toArray(),selectMissing:newSelectMissing};
  3513. var oldRestrictions={selection:oldValues.toArray(),selectMissing:oldSelectMissing};
  3514. var facetLabel=("facetLabel" in this._settings)?this._settings.facetLabel:"";
  3515. SimileAjax.History.addLengthyAction(function(){self.applyRestrictions(newRestrictions);
  3516. },function(){self.applyRestrictions(oldRestrictions);
  3517. },(selectOnly&&!wasOnlyThingSelected)?String.substitute(Exhibit.FacetUtilities.l10n["facetSelectOnlyActionTitle"],[label,facetLabel]):String.substitute(Exhibit.FacetUtilities.l10n[wasSelected?"facetUnselectActionTitle":"facetSelectActionTitle"],[label,facetLabel]));
  3518. };
  3519. Exhibit.CloudFacet.prototype._clearSelections=function(){var state={};
  3520. var self=this;
  3521. SimileAjax.History.addLengthyAction(function(){state.restrictions=self.clearAllRestrictions();
  3522. },function(){self.applyRestrictions(state.restrictions);
  3523. },String.substitute(Exhibit.FacetUtilities.l10n["facetClearSelectionsActionTitle"],[this._settings.facetLabel]));
  3524. };
  3525. Exhibit.CloudFacet.prototype._buildMaps=function(){if(!("_itemToValue" in this)){var itemToValue={};
  3526. var valueToItem={};
  3527. var missingItems={};
  3528. var valueType="text";
  3529. var insert=function(x,y,map){if(x in map){map[x].push(y);
  3530. }else{map[x]=[y];
  3531. }};
  3532. var expression=this._expression;
  3533. var database=this._uiContext.getDatabase();
  3534. this._uiContext.getCollection().getAllItems().visit(function(item){var results=expression.evaluateOnItem(item,database);
  3535. if(results.values.size()>0){valueType=results.valueType;
  3536. results.values.visit(function(value){insert(item,value,itemToValue);
  3537. insert(value,item,valueToItem);
  3538. });
  3539. }else{missingItems[item]=true;
  3540. }});
  3541. this._itemToValue=itemToValue;
  3542. this._valueToItem=valueToItem;
  3543. this._missingItems=missingItems;
  3544. this._valueType=valueType;
  3545. }};
  3546. /* hierarchical-facet.js */
  3547. Exhibit.HierarchicalFacet=function(containerElmt,uiContext){this._div=containerElmt;
  3548. this._uiContext=uiContext;
  3549. this._colorCoder=null;
  3550. this._expression=null;
  3551. this._uniformGroupingExpression=null;
  3552. this._selections=[];
  3553. this._expanded={};
  3554. this._settings={};
  3555. this._dom=null;
  3556. var self=this;
  3557. this._listener={onRootItemsChanged:function(){if("_cache" in self){delete self._cache;
  3558. }}};
  3559. uiContext.getCollection().addListener(this._listener);
  3560. };
  3561. Exhibit.HierarchicalFacet._settingSpecs={"facetLabel":{type:"text"},"fixedOrder":{type:"text"},"sortMode":{type:"text",defaultValue:"value"},"sortDirection":{type:"text",defaultValue:"forward"},"othersLabel":{type:"text"},"scroll":{type:"boolean",defaultValue:true},"height":{type:"text"},"colorCoder":{type:"text",defaultValue:null},"collapsible":{type:"boolean",defaultValue:false},"collapsed":{type:"boolean",defaultValue:false}};
  3562. Exhibit.HierarchicalFacet.create=function(configuration,containerElmt,uiContext){var uiContext=Exhibit.UIContext.create(configuration,uiContext);
  3563. var facet=new Exhibit.HierarchicalFacet(containerElmt,uiContext);
  3564. Exhibit.HierarchicalFacet._configure(facet,configuration);
  3565. facet._initializeUI();
  3566. uiContext.getCollection().addFacet(facet);
  3567. return facet;
  3568. };
  3569. Exhibit.HierarchicalFacet.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  3570. var uiContext=Exhibit.UIContext.createFromDOM(configElmt,uiContext);
  3571. var facet=new Exhibit.HierarchicalFacet(containerElmt!=null?containerElmt:configElmt,uiContext);
  3572. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.HierarchicalFacet._settingSpecs,facet._settings);
  3573. try{var expressionString=Exhibit.getAttribute(configElmt,"expression");
  3574. if(expressionString!=null&&expressionString.length>0){facet._expression=Exhibit.ExpressionParser.parse(expressionString);
  3575. }var uniformGroupingString=Exhibit.getAttribute(configElmt,"uniformGrouping");
  3576. if(uniformGroupingString!=null&&uniformGroupingString.length>0){facet._uniformGroupingExpression=Exhibit.ExpressionParser.parse(uniformGroupingString);
  3577. }var selection=Exhibit.getAttribute(configElmt,"selection",";");
  3578. if(selection!=null&&selection.length>0){for(var i=0,s;
  3579. s=selection[i];
  3580. i++){facet._selections=facet._internalAddSelection({value:s,selectOthers:false});
  3581. }}}catch(e){SimileAjax.Debug.exception(e,"HierarchicalFacet: Error processing configuration of hierarchical facet");
  3582. }Exhibit.HierarchicalFacet._configure(facet,configuration);
  3583. facet._initializeUI();
  3584. uiContext.getCollection().addFacet(facet);
  3585. return facet;
  3586. };
  3587. Exhibit.HierarchicalFacet._configure=function(facet,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.HierarchicalFacet._settingSpecs,facet._settings);
  3588. if("expression" in configuration){facet._expression=Exhibit.ExpressionParser.parse(configuration.expression);
  3589. }if("uniformGrouping" in configuration){facet._uniformGroupingExpression=Exhibit.ExpressionParser.parse(configuration.uniformGrouping);
  3590. }if("selection" in configuration){var selection=configuration.selection;
  3591. for(var i=0;
  3592. i<selection.length;
  3593. i++){facet._selections.push({value:selection[i],selectOthers:false});
  3594. }}if(!("facetLabel" in facet._settings)){facet._settings.facetLabel="missing ex:facetLabel";
  3595. if(facet._expression!=null&&facet._expression.isPath()){var segment=facet._expression.getPath().getLastSegment();
  3596. var property=facet._uiContext.getDatabase().getProperty(segment.property);
  3597. if(property!=null){facet._settings.facetLabel=segment.forward?property.getLabel():property.getReverseLabel();
  3598. }}}if("fixedOrder" in facet._settings){var values=facet._settings.fixedOrder.split(";");
  3599. var orderMap={};
  3600. for(var i=0;
  3601. i<values.length;
  3602. i++){orderMap[values[i].trim()]=i;
  3603. }facet._orderMap=orderMap;
  3604. }if("colorCoder" in facet._settings){facet._colorCoder=facet._uiContext.getExhibit().getComponent(facet._settings.colorCoder);
  3605. }if(facet._settings.collapsed){facet._settings.collapsible=true;
  3606. }};
  3607. Exhibit.HierarchicalFacet.prototype.dispose=function(){this._uiContext.getCollection().removeFacet(this);
  3608. this._uiContext.getCollection().removeListener(this._listener);
  3609. this._uiContext=null;
  3610. this._colorCoder=null;
  3611. this._div.innerHTML="";
  3612. this._div=null;
  3613. this._dom=null;
  3614. this._expression=null;
  3615. this._uniformGroupingExpression=null;
  3616. this._selections=null;
  3617. this._settings=null;
  3618. this._cache=null;
  3619. };
  3620. Exhibit.HierarchicalFacet.prototype.hasRestrictions=function(){return this._selections.length>0;
  3621. };
  3622. Exhibit.HierarchicalFacet.prototype.clearAllRestrictions=function(){var selections=this._selections;
  3623. this._selections=[];
  3624. if(selections.length>0){this._notifyCollection();
  3625. }return selections;
  3626. };
  3627. Exhibit.HierarchicalFacet.prototype.applyRestrictions=function(restrictions){this._selections=[].concat(restrictions);
  3628. this._notifyCollection();
  3629. };
  3630. Exhibit.HierarchicalFacet.prototype.setSelection=function(value,selected){var selection={value:value,selectOthers:false};
  3631. if(selected){this._selections=this._internalAddSelection(selection);
  3632. }else{this._selections=this._internalRemoveSelection(selection);
  3633. }this._notifyCollection();
  3634. };
  3635. Exhibit.HierarchicalFacet.prototype.setselectOthers=function(value,selected){var selection={value:value,selectOthers:true};
  3636. if(selected){this._selections=this._internalAddSelection(selection);
  3637. }else{this._selections=this._internalRemoveSelection(selection);
  3638. }this._notifyCollection();
  3639. };
  3640. Exhibit.HierarchicalFacet.prototype.restrict=function(items){if(this._selections.length==0){return items;
  3641. }this._buildCache();
  3642. var set=new Exhibit.Set();
  3643. var includeNode=function(node){if("children" in node){includeChildNodes(node.children);
  3644. Exhibit.Set.createIntersection(node.others,items,set);
  3645. }else{Exhibit.Set.createIntersection(node.items,items,set);
  3646. }};
  3647. var includeChildNodes=function(childNodes){for(var i=0;
  3648. i<childNodes.length;
  3649. i++){includeNode(childNodes[i]);
  3650. }};
  3651. for(var i=0;
  3652. i<this._selections.length;
  3653. i++){var selection=this._selections[i];
  3654. var node=this._getTreeNode(selection.value);
  3655. if(node){if(selection.selectOthers){Exhibit.Set.createIntersection(node.others,items,set);
  3656. }else{includeNode(node);
  3657. }}}return set;
  3658. };
  3659. Exhibit.HierarchicalFacet.prototype._internalAddSelection=function(selection){var parentToClear={};
  3660. var childrenToClear={};
  3661. this._buildCache();
  3662. var cache=this._cache;
  3663. var markClearAncestors=function(value){if(value in cache.valueToParent){var parents=cache.valueToParent[value];
  3664. for(var i=0;
  3665. i<parents.length;
  3666. i++){var parent=parents[i];
  3667. parentToClear[parent]=true;
  3668. markClearAncestors(parent);
  3669. }}};
  3670. var markClearDescendants=function(value){if(value in cache.valueToChildren){var children=cache.valueToChildren[value];
  3671. for(var i=0;
  3672. i<children.length;
  3673. i++){var child=children[i];
  3674. childrenToClear[child]=true;
  3675. markClearDescendants(child);
  3676. }}};
  3677. if(selection.value!=null){markClearAncestors(selection.value);
  3678. if(selection.selectOthers){parentToClear[selection.value]=true;
  3679. }else{childrenToClear[selection.value]=true;
  3680. markClearDescendants(selection.value);
  3681. }}var oldSelections=this._selections;
  3682. var newSelections=[selection];
  3683. for(var i=0;
  3684. i<oldSelections.length;
  3685. i++){var s=oldSelections[i];
  3686. if((!(s.value in parentToClear)||s.selectOthers)&&(!(s.value in childrenToClear))){newSelections.push(s);
  3687. }}return newSelections;
  3688. };
  3689. Exhibit.HierarchicalFacet.prototype._internalRemoveSelection=function(selection){var oldSelections=this._selections;
  3690. var newSelections=[];
  3691. for(var i=0;
  3692. i<oldSelections.length;
  3693. i++){var s=oldSelections[i];
  3694. if(s.value!=selection.value||s.selectOthers!=selection.selectOthers){newSelections.push(s);
  3695. }}return newSelections;
  3696. };
  3697. Exhibit.HierarchicalFacet.prototype.update=function(items){this._dom.valuesContainer.style.display="none";
  3698. this._dom.valuesContainer.innerHTML="";
  3699. var tree=this._computeFacet(items);
  3700. if(tree){this._constructBody(tree);
  3701. }this._dom.valuesContainer.style.display="block";
  3702. };
  3703. Exhibit.HierarchicalFacet.prototype._computeFacet=function(items){this._buildCache();
  3704. var database=this._uiContext.getDatabase();
  3705. var sorter=this._getValueSorter();
  3706. var othersLabel="othersLabel" in this._settings?this._settings.othersLabel:"(others)";
  3707. var selectionMap={};
  3708. for(var i=0;
  3709. i<this._selections.length;
  3710. i++){var s=this._selections[i];
  3711. selectionMap[s.value]=s.selectOthers;
  3712. }var processNode=function(node,resultNodes,superset){var selected=(node.value in selectionMap&&!selectionMap[node.value]);
  3713. if("children" in node){var resultNode={value:node.value,label:node.label,children:[],selected:selected,areOthers:false};
  3714. var superset2=new Exhibit.Set();
  3715. for(var i=0;
  3716. i<node.children.length;
  3717. i++){var childNode=node.children[i];
  3718. processNode(childNode,resultNode.children,superset2);
  3719. }resultNode.children.sort(sorter);
  3720. if(node.others.size()>0){var othersSelected=(node.value in selectionMap&&selectionMap[node.value]);
  3721. var subset=Exhibit.Set.createIntersection(items,node.others);
  3722. if(subset.size()>0||othersSelected){resultNode.children.push({value:node.value,label:othersLabel,count:subset.size(),selected:othersSelected,areOthers:true});
  3723. superset2.addSet(subset);
  3724. }}resultNode.count=superset2.size();
  3725. if(selected||resultNode.count>0||resultNode.children.length>0){resultNodes.push(resultNode);
  3726. if(superset!=null&&superset2.size()>0){superset.addSet(superset2);
  3727. }}}else{var subset=Exhibit.Set.createIntersection(items,node.items);
  3728. if(subset.size()>0||selected){resultNodes.push({value:node.value,label:node.label,count:subset.size(),selected:selected,areOthers:false});
  3729. if(superset!=null&&subset.size()>0){superset.addSet(subset);
  3730. }}}};
  3731. var nodes=[];
  3732. processNode(this._cache.tree,nodes,null);
  3733. return nodes[0];
  3734. };
  3735. Exhibit.HierarchicalFacet.prototype._getValueSorter=function(){var sortValueFunction=function(a,b){return a.label.localeCompare(b.label);
  3736. };
  3737. if("_orderMap" in this){var orderMap=this._orderMap;
  3738. sortValueFunction=function(a,b){if(a.label in orderMap){if(b.label in orderMap){return orderMap[a.label]-orderMap[b.label];
  3739. }else{return -1;
  3740. }}else{if(b.label in orderMap){return 1;
  3741. }else{return a.label.localeCompare(b.label);
  3742. }}};
  3743. }else{if(this._cache.valueType=="number"){sortValueFunction=function(a,b){a=parseFloat(a.value);
  3744. b=parseFloat(b.value);
  3745. return a<b?-1:a>b?1:0;
  3746. };
  3747. }}var sortFunction=sortValueFunction;
  3748. if(this._settings.sortMode=="count"){sortFunction=function(a,b){var c=b.count-a.count;
  3749. return c!=0?c:sortValueFunction(a,b);
  3750. };
  3751. }var sortDirectionFunction=sortFunction;
  3752. if(this._settings.sortDirection=="reverse"){sortDirectionFunction=function(a,b){return sortFunction(b,a);
  3753. };
  3754. }return sortDirectionFunction;
  3755. };
  3756. Exhibit.HierarchicalFacet.prototype._notifyCollection=function(){this._uiContext.getCollection().onFacetUpdated(this);
  3757. };
  3758. Exhibit.HierarchicalFacet.prototype._initializeUI=function(){var self=this;
  3759. this._dom=Exhibit.FacetUtilities[this._settings.scroll?"constructFacetFrame":"constructFlowingFacetFrame"](this,this._div,this._settings.facetLabel,function(elmt,evt,target){self._clearSelections();
  3760. },this._uiContext,this._settings.collapsible,this._settings.collapsed);
  3761. if("height" in this._settings&&this._settings.scroll){this._dom.valuesContainer.style.height=this._settings.height;
  3762. }};
  3763. Exhibit.HierarchicalFacet.prototype._constructBody=function(tree){var self=this;
  3764. var containerDiv=this._dom.valuesContainer;
  3765. containerDiv.style.display="none";
  3766. var constructFacetItemFunction=Exhibit.FacetUtilities[this._settings.scroll?"constructHierarchicalFacetItem":"constructFlowingHierarchicalFacetItem"];
  3767. var facetHasSelection=this._selections.length>0;
  3768. var processNode=function(node,div){var hasChildren=("children" in node);
  3769. var onSelect=function(elmt,evt,target){self._filter(node.value,node.areOthers,node.label,node.selected,false);
  3770. SimileAjax.DOM.cancelEvent(evt);
  3771. return false;
  3772. };
  3773. var onSelectOnly=function(elmt,evt,target){self._filter(node.value,node.areOthers,node.label,node.selected,!(evt.ctrlKey||evt.metaKey));
  3774. SimileAjax.DOM.cancelEvent(evt);
  3775. return false;
  3776. };
  3777. var onToggleChildren=function(elmt,evt,target){var show;
  3778. if(node.value in self._expanded){delete self._expanded[node.value];
  3779. show=false;
  3780. }else{self._expanded[node.value]=true;
  3781. show=true;
  3782. }dom.showChildren(show);
  3783. SimileAjax.DOM.cancelEvent(evt);
  3784. return false;
  3785. };
  3786. var dom=constructFacetItemFunction(node.label,node.count,(self._colorCoder!=null)?self._colorCoder.translate(node.value):null,node.selected,hasChildren,(node.value in self._expanded),facetHasSelection,onSelect,onSelectOnly,onToggleChildren,self._uiContext);
  3787. div.appendChild(dom.elmt);
  3788. if(hasChildren){processChildNodes(node.children,dom.childrenContainer);
  3789. }};
  3790. var processChildNodes=function(childNodes,div){for(var i=0;
  3791. i<childNodes.length;
  3792. i++){processNode(childNodes[i],div);
  3793. }};
  3794. processChildNodes(tree.children,containerDiv);
  3795. containerDiv.style.display="block";
  3796. this._dom.setSelectionCount(this._selections.length);
  3797. };
  3798. Exhibit.HierarchicalFacet.prototype._filter=function(value,areOthers,label,wasSelected,selectOnly){var self=this;
  3799. var wasSelectedAlone=wasSelected&&this._selections.length==1;
  3800. var selection={value:value,selectOthers:areOthers};
  3801. var oldRestrictions=this._selections;
  3802. var newRestrictions;
  3803. if(wasSelected){if(selectOnly){if(wasSelectedAlone){newRestrictions=[];
  3804. }else{newRestrictions=[selection];
  3805. }}else{newRestrictions=this._internalRemoveSelection(selection);
  3806. }}else{if(selectOnly){newRestrictions=[selection];
  3807. }else{newRestrictions=this._internalAddSelection(selection);
  3808. }}SimileAjax.History.addLengthyAction(function(){self.applyRestrictions(newRestrictions);
  3809. },function(){self.applyRestrictions(oldRestrictions);
  3810. },(selectOnly&&!wasSelectedAlone)?String.substitute(Exhibit.FacetUtilities.l10n["facetSelectOnlyActionTitle"],[label,this._settings.facetLabel]):String.substitute(Exhibit.FacetUtilities.l10n[wasSelected?"facetUnselectActionTitle":"facetSelectActionTitle"],[label,this._settings.facetLabel]));
  3811. };
  3812. Exhibit.HierarchicalFacet.prototype._clearSelections=function(){var state={};
  3813. var self=this;
  3814. SimileAjax.History.addLengthyAction(function(){state.restrictions=self.clearAllRestrictions();
  3815. },function(){self.applyRestrictions(state.restrictions);
  3816. },String.substitute(Exhibit.FacetUtilities.l10n["facetClearSelectionsActionTitle"],[this._settings.facetLabel]));
  3817. };
  3818. Exhibit.HierarchicalFacet.prototype._buildCache=function(){if(!("_cache" in this)){var valueToItem={};
  3819. var valueType="text";
  3820. var valueToChildren={};
  3821. var valueToParent={};
  3822. var valueToPath={};
  3823. var values=new Exhibit.Set();
  3824. var insert=function(x,y,map){if(x in map){map[x].push(y);
  3825. }else{map[x]=[y];
  3826. }};
  3827. var database=this._uiContext.getDatabase();
  3828. var tree={value:null,label:"(root)",others:new Exhibit.Set(),children:[]};
  3829. var expression=this._expression;
  3830. this._uiContext.getCollection().getAllItems().visit(function(item){var results=expression.evaluateOnItem(item,database);
  3831. if(results.values.size()>0){valueType=results.valueType;
  3832. results.values.visit(function(value){values.add(value);
  3833. insert(value,item,valueToItem);
  3834. });
  3835. }else{tree.others.add(item);
  3836. }});
  3837. var groupingExpression=this._uniformGroupingExpression;
  3838. var rootValues=new Exhibit.Set();
  3839. var getParentChildRelationships=function(valueSet){var newValueSet=new Exhibit.Set();
  3840. valueSet.visit(function(value){var results=groupingExpression.evaluateOnItem(value,database);
  3841. if(results.values.size()>0){results.values.visit(function(parentValue){insert(value,parentValue,valueToParent);
  3842. insert(parentValue,value,valueToChildren);
  3843. if(!valueSet.contains(parentValue)){newValueSet.add(parentValue);
  3844. }return true;
  3845. });
  3846. }else{rootValues.add(value);
  3847. }});
  3848. if(newValueSet.size()>0){getParentChildRelationships(newValueSet);
  3849. }};
  3850. getParentChildRelationships(values);
  3851. var processValue=function(value,nodes,valueSet,path){var label=database.getObject(value,"label");
  3852. var node={value:value,label:label!=null?label:value};
  3853. nodes.push(node);
  3854. valueToPath[value]=path;
  3855. if(value in valueToChildren){node.children=[];
  3856. var valueSet2=new Exhibit.Set();
  3857. var childrenValue=valueToChildren[value];
  3858. for(var i=0;
  3859. i<childrenValue.length;
  3860. i++){processValue(childrenValue[i],node.children,valueSet2,path.concat(i));
  3861. }node.others=new Exhibit.Set();
  3862. if(value in valueToItem){var items=valueToItem[value];
  3863. for(var i=0;
  3864. i<items.length;
  3865. i++){var item=items[i];
  3866. if(!valueSet2.contains(item)){node.others.add(item);
  3867. valueSet.add(item);
  3868. }}}valueSet.addSet(valueSet2);
  3869. }else{node.items=new Exhibit.Set();
  3870. if(value in valueToItem){var items=valueToItem[value];
  3871. for(var i=0;
  3872. i<items.length;
  3873. i++){var item=items[i];
  3874. node.items.add(item);
  3875. valueSet.add(item);
  3876. }}}};
  3877. var index=0;
  3878. rootValues.visit(function(value){processValue(value,tree.children,new Exhibit.Set(),[index++]);
  3879. });
  3880. this._cache={tree:tree,valueToChildren:valueToChildren,valueToParent:valueToParent,valueToPath:valueToPath,valueType:valueType};
  3881. }};
  3882. Exhibit.HierarchicalFacet.prototype._getTreeNode=function(value){if(value==null){return this._cache.tree;
  3883. }var path=this._cache.valueToPath[value];
  3884. var trace=function(node,path,index){var node2=node.children[path[index]];
  3885. if(++index<path.length){return trace(node2,path,index);
  3886. }else{return node2;
  3887. }};
  3888. return(path)?trace(this._cache.tree,path,0):null;
  3889. };
  3890. /* image-facet.js */
  3891. Exhibit.ImageFacet=function(containerElmt,uiContext){this._div=containerElmt;
  3892. this._uiContext=uiContext;
  3893. this._colorCoder=null;
  3894. this._expression=null;
  3895. this._valueSet=new Exhibit.Set();
  3896. this._selectMissing=false;
  3897. this._settings={};
  3898. this._dom=null;
  3899. };
  3900. Exhibit.ImageFacet._settingSpecs={"facetLabel":{type:"text"},"thumbNail":{type:"uri"},"overlayCounts":{type:"boolean",defaultValue:true},"fixedOrder":{type:"text"},"sortMode":{type:"text",defaultValue:"value"},"sortDirection":{type:"text",defaultValue:"forward"},"showMissing":{type:"boolean",defaultValue:true},"missingLabel":{type:"text"},"scroll":{type:"boolean",defaultValue:true},"height":{type:"text"},"colorCoder":{type:"text",defaultValue:null},"collapsible":{type:"boolean",defaultValue:false},"collapsed":{type:"boolean",defaultValue:false}};
  3901. Exhibit.ImageFacet.create=function(configuration,containerElmt,uiContext){var uiContext=Exhibit.UIContext.create(configuration,uiContext);
  3902. var facet=new Exhibit.ImageFacet(containerElmt,uiContext);
  3903. Exhibit.ImageFacet._configure(facet,configuration);
  3904. facet._initializeUI();
  3905. uiContext.getCollection().addFacet(facet);
  3906. return facet;
  3907. };
  3908. Exhibit.ImageFacet.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  3909. var uiContext=Exhibit.UIContext.createFromDOM(configElmt,uiContext);
  3910. var facet=new Exhibit.ImageFacet(containerElmt!=null?containerElmt:configElmt,uiContext);
  3911. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.ImageFacet._settingSpecs,facet._settings);
  3912. try{var expressionString=Exhibit.getAttribute(configElmt,"expression");
  3913. if(expressionString!=null&&expressionString.length>0){facet._expression=Exhibit.ExpressionParser.parse(expressionString);
  3914. }var imageString=Exhibit.getAttribute(configElmt,"image");
  3915. if(imageString!=null&&imageString.length>0){facet._imageExpression=Exhibit.ExpressionParser.parse(imageString);
  3916. }var tooltipString=Exhibit.getAttribute(configElmt,"tooltip");
  3917. if(tooltipString!=null&&tooltipString.length>0){facet._tooltipExpression=Exhibit.ExpressionParser.parse(tooltipString);
  3918. }var selection=Exhibit.getAttribute(configElmt,"selection",";");
  3919. if(selection!=null&&selection.length>0){for(var i=0,s;
  3920. s=selection[i];
  3921. i++){facet._valueSet.add(s);
  3922. }}var selectMissing=Exhibit.getAttribute(configElmt,"selectMissing");
  3923. if(selectMissing!=null&&selectMissing.length>0){facet._selectMissing=(selectMissing=="true");
  3924. }}catch(e){SimileAjax.Debug.exception(e,"ImageFacet: Error processing configuration of list facet");
  3925. }Exhibit.ImageFacet._configure(facet,configuration);
  3926. facet._initializeUI();
  3927. uiContext.getCollection().addFacet(facet);
  3928. return facet;
  3929. };
  3930. Exhibit.ImageFacet._configure=function(facet,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.ImageFacet._settingSpecs,facet._settings);
  3931. if("expression" in configuration){facet._expression=Exhibit.ExpressionParser.parse(configuration.expression);
  3932. }if("image" in configuration){facet._imageExpression=Exhibit.ExpressionParser.parse(configuration.image);
  3933. }if("tooltip" in configuration){facet._tooltipExpression=Exhibit.ExpressionParser.parse(configuration.tooltip);
  3934. }if(!(facet._imageExpression)){facet._imageExpression=Exhibit.ExpressionParser.parse("value");
  3935. }if(!(facet._tooltipExpression)){facet._tooltipExpression=Exhibit.ExpressionParser.parse("value");
  3936. }if("selection" in configuration){var selection=configuration.selection;
  3937. for(var i=0;
  3938. i<selection.length;
  3939. i++){facet._valueSet.add(selection[i]);
  3940. }}if("selectMissing" in configuration){facet._selectMissing=configuration.selectMissing;
  3941. }if(!("facetLabel" in facet._settings)){facet._settings.facetLabel="missing ex:facetLabel";
  3942. if(facet._expression!=null&&facet._expression.isPath()){var segment=facet._expression.getPath().getLastSegment();
  3943. var property=facet._uiContext.getDatabase().getProperty(segment.property);
  3944. if(property!=null){facet._settings.facetLabel=segment.forward?property.getLabel():property.getReverseLabel();
  3945. }}}if("fixedOrder" in facet._settings){var values=facet._settings.fixedOrder.split(";");
  3946. var orderMap={};
  3947. for(var i=0;
  3948. i<values.length;
  3949. i++){orderMap[values[i].trim()]=i;
  3950. }facet._orderMap=orderMap;
  3951. }if("colorCoder" in facet._settings){facet._colorCoder=facet._uiContext.getExhibit().getComponent(facet._settings.colorCoder);
  3952. }if(facet._settings.collapsed){facet._settings.collapsible=true;
  3953. }facet._cache=new Exhibit.FacetUtilities.Cache(facet._uiContext.getDatabase(),facet._uiContext.getCollection(),facet._expression);
  3954. };
  3955. Exhibit.ImageFacet.prototype.dispose=function(){this._cache.dispose();
  3956. this._cache=null;
  3957. this._uiContext.getCollection().removeFacet(this);
  3958. this._uiContext=null;
  3959. this._colorCoder=null;
  3960. this._div.innerHTML="";
  3961. this._div=null;
  3962. this._dom=null;
  3963. this._expression=null;
  3964. this._valueSet=null;
  3965. this._settings=null;
  3966. };
  3967. Exhibit.ImageFacet.prototype.hasRestrictions=function(){return this._valueSet.size()>0||this._selectMissing;
  3968. };
  3969. Exhibit.ImageFacet.prototype.clearAllRestrictions=function(){var restrictions={selection:[],selectMissing:false};
  3970. if(this.hasRestrictions()){this._valueSet.visit(function(v){restrictions.selection.push(v);
  3971. });
  3972. this._valueSet=new Exhibit.Set();
  3973. restrictions.selectMissing=this._selectMissing;
  3974. this._selectMissing=false;
  3975. this._notifyCollection();
  3976. }return restrictions;
  3977. };
  3978. Exhibit.ImageFacet.prototype.applyRestrictions=function(restrictions){this._valueSet=new Exhibit.Set();
  3979. for(var i=0;
  3980. i<restrictions.selection.length;
  3981. i++){this._valueSet.add(restrictions.selection[i]);
  3982. }this._selectMissing=restrictions.selectMissing;
  3983. this._notifyCollection();
  3984. };
  3985. Exhibit.ImageFacet.prototype.setSelection=function(value,selected){if(selected){this._valueSet.add(value);
  3986. }else{this._valueSet.remove(value);
  3987. }this._notifyCollection();
  3988. };
  3989. Exhibit.ImageFacet.prototype.setSelectMissing=function(selected){if(selected!=this._selectMissing){this._selectMissing=selected;
  3990. this._notifyCollection();
  3991. }};
  3992. Exhibit.ImageFacet.prototype.restrict=function(items){if(this._valueSet.size()==0&&!this._selectMissing){return items;
  3993. }var set=this._cache.getItemsFromValues(this._valueSet,items);
  3994. if(this._selectMissing){this._cache.getItemsMissingValue(items,set);
  3995. }return set;
  3996. };
  3997. Exhibit.ImageFacet.prototype.update=function(items){this._dom.valuesContainer.style.display="none";
  3998. this._dom.valuesContainer.innerHTML="";
  3999. this._constructBody(this._computeFacet(items));
  4000. this._dom.valuesContainer.style.display="block";
  4001. };
  4002. Exhibit.ImageFacet.prototype._computeFacet=function(items){var database=this._uiContext.getDatabase();
  4003. var r=this._cache.getValueCountsFromItems(items);
  4004. var entries=r.entries;
  4005. var valueType=r.valueType;
  4006. if(entries.length>0){var selection=this._valueSet;
  4007. var labeler=valueType=="item"?function(v){var l=database.getObject(v,"label");
  4008. return l!=null?l:v;
  4009. }:function(v){return v;
  4010. };
  4011. for(var i=0;
  4012. i<entries.length;
  4013. i++){var entry=entries[i];
  4014. entry.actionLabel=entry.selectionLabel=labeler(entry.value);
  4015. entry.image=this._imageExpression.evaluateSingleOnItem(entry.value,database).value;
  4016. entry.tooltip=this._tooltipExpression.evaluateSingleOnItem(entry.value,database).value;
  4017. entry.selected=selection.contains(entry.value);
  4018. }entries.sort(this._createSortFunction(valueType));
  4019. }return entries;
  4020. };
  4021. Exhibit.ImageFacet.prototype._notifyCollection=function(){this._uiContext.getCollection().onFacetUpdated(this);
  4022. };
  4023. Exhibit.ImageFacet.prototype._initializeUI=function(){var self=this;
  4024. this._dom=Exhibit.FacetUtilities[this._settings.scroll?"constructFacetFrame":"constructFlowingFacetFrame"](this,this._div,this._settings.facetLabel,function(elmt,evt,target){self._clearSelections();
  4025. },this._uiContext,this._settings.collapsible,this._settings.collapsed);
  4026. if("height" in this._settings&&this._settings.scroll){this._dom.valuesContainer.style.height=this._settings.height;
  4027. }};
  4028. Exhibit.ImageFacet.prototype._constructBody=function(entries){var self=this;
  4029. var shouldOverlayCounts=this._settings.overlayCounts;
  4030. var containerDiv=this._dom.valuesContainer;
  4031. containerDiv.style.display="none";
  4032. var facetHasSelection=this._valueSet.size()>0||this._selectMissing;
  4033. var constructValue=function(entry){var onSelectOnly=function(elmt,evt,target){self._filter(entry.value,entry.actionLabel,!(evt.ctrlKey||evt.metaKey));
  4034. SimileAjax.DOM.cancelEvent(evt);
  4035. return false;
  4036. };
  4037. var elmt=document.createElement("span");
  4038. var wrapper=document.createElement("div");
  4039. wrapper.className="wrapper";
  4040. var image=document.createElement("img");
  4041. image.src=entry.image;
  4042. wrapper.appendChild(image);
  4043. if(shouldOverlayCounts==true){var countDiv=document.createElement("div");
  4044. countDiv.className="countDiv";
  4045. var countBackground=document.createElement("div");
  4046. countBackground.className="countBackground";
  4047. countDiv.appendChild(countBackground);
  4048. var innerCount=document.createElement("div");
  4049. innerCount.className="text";
  4050. innerCount.innerHTML=entry.count;
  4051. countDiv.appendChild(innerCount);
  4052. wrapper.appendChild(countDiv);
  4053. }elmt.appendChild(wrapper);
  4054. elmt.className=entry.selected?"inline-block exhibit-imageFacet-value exhibit-imageFacet-value-selected":"inline-block exhibit-imageFacet-value";
  4055. elmt.title=entry.count+" "+entry.tooltip;
  4056. SimileAjax.WindowManager.registerEvent(elmt,"click",onSelectOnly,SimileAjax.WindowManager.getBaseLayer());
  4057. containerDiv.appendChild(elmt);
  4058. };
  4059. for(var j=0;
  4060. j<entries.length;
  4061. j++){constructValue(entries[j]);
  4062. }containerDiv.style.display="block";
  4063. this._dom.setSelectionCount(this._valueSet.size()+(this._selectMissing?1:0));
  4064. };
  4065. Exhibit.ImageFacet.prototype._filter=function(value,label,selectOnly){var self=this;
  4066. var selected,select,deselect;
  4067. var oldValues=new Exhibit.Set(this._valueSet);
  4068. var oldSelectMissing=this._selectMissing;
  4069. var newValues;
  4070. var newSelectMissing;
  4071. var actionLabel;
  4072. var wasSelected;
  4073. var wasOnlyThingSelected;
  4074. if(value==null){wasSelected=oldSelectMissing;
  4075. wasOnlyThingSelected=wasSelected&&(oldValues.size()==0);
  4076. if(selectOnly){if(oldValues.size()==0){newSelectMissing=!oldSelectMissing;
  4077. }else{newSelectMissing=true;
  4078. }newValues=new Exhibit.Set();
  4079. }else{newSelectMissing=!oldSelectMissing;
  4080. newValues=new Exhibit.Set(oldValues);
  4081. }}else{wasSelected=oldValues.contains(value);
  4082. wasOnlyThingSelected=wasSelected&&(oldValues.size()==1)&&!oldSelectMissing;
  4083. if(selectOnly){newSelectMissing=false;
  4084. newValues=new Exhibit.Set();
  4085. if(!oldValues.contains(value)){newValues.add(value);
  4086. }else{if(oldValues.size()>1||oldSelectMissing){newValues.add(value);
  4087. }}}else{newSelectMissing=oldSelectMissing;
  4088. newValues=new Exhibit.Set(oldValues);
  4089. if(newValues.contains(value)){newValues.remove(value);
  4090. }else{newValues.add(value);
  4091. }}}var newRestrictions={selection:newValues.toArray(),selectMissing:newSelectMissing};
  4092. var oldRestrictions={selection:oldValues.toArray(),selectMissing:oldSelectMissing};
  4093. SimileAjax.History.addLengthyAction(function(){self.applyRestrictions(newRestrictions);
  4094. },function(){self.applyRestrictions(oldRestrictions);
  4095. },(selectOnly&&!wasOnlyThingSelected)?String.substitute(Exhibit.FacetUtilities.l10n["facetSelectOnlyActionTitle"],[label,this._settings.facetLabel]):String.substitute(Exhibit.FacetUtilities.l10n[wasSelected?"facetUnselectActionTitle":"facetSelectActionTitle"],[label,this._settings.facetLabel]));
  4096. };
  4097. Exhibit.ImageFacet.prototype._clearSelections=function(){var state={};
  4098. var self=this;
  4099. SimileAjax.History.addLengthyAction(function(){state.restrictions=self.clearAllRestrictions();
  4100. },function(){self.applyRestrictions(state.restrictions);
  4101. },String.substitute(Exhibit.FacetUtilities.l10n["facetClearSelectionsActionTitle"],[this._settings.facetLabel]));
  4102. };
  4103. Exhibit.ImageFacet.prototype._createSortFunction=function(valueType){var sortValueFunction=function(a,b){return a.selectionLabel.localeCompare(b.selectionLabel);
  4104. };
  4105. if("_orderMap" in this){var orderMap=this._orderMap;
  4106. sortValueFunction=function(a,b){if(a.selectionLabel in orderMap){if(b.selectionLabel in orderMap){return orderMap[a.selectionLabel]-orderMap[b.selectionLabel];
  4107. }else{return -1;
  4108. }}else{if(b.selectionLabel in orderMap){return 1;
  4109. }else{return a.selectionLabel.localeCompare(b.selectionLabel);
  4110. }}};
  4111. }else{if(valueType=="number"){sortValueFunction=function(a,b){a=parseFloat(a.value);
  4112. b=parseFloat(b.value);
  4113. return a<b?-1:a>b?1:0;
  4114. };
  4115. }}var sortFunction=sortValueFunction;
  4116. if(this._settings.sortMode=="count"){sortFunction=function(a,b){var c=b.count-a.count;
  4117. return c!=0?c:sortValueFunction(a,b);
  4118. };
  4119. }var sortDirectionFunction=sortFunction;
  4120. if(this._settings.sortDirection=="reverse"){sortDirectionFunction=function(a,b){return sortFunction(b,a);
  4121. };
  4122. }return sortDirectionFunction;
  4123. };
  4124. /* list-facet.js */
  4125. Exhibit.ListFacet=function(containerElmt,uiContext){this._div=containerElmt;
  4126. this._uiContext=uiContext;
  4127. this._colorCoder=null;
  4128. this._expression=null;
  4129. this._valueSet=new Exhibit.Set();
  4130. this._selectMissing=false;
  4131. this._delayedUpdateItems=null;
  4132. this._settings={};
  4133. this._dom=null;
  4134. };
  4135. Exhibit.ListFacet._settingSpecs={"facetLabel":{type:"text"},"fixedOrder":{type:"text"},"sortMode":{type:"text",defaultValue:"value"},"sortDirection":{type:"text",defaultValue:"forward"},"showMissing":{type:"boolean",defaultValue:true},"missingLabel":{type:"text"},"scroll":{type:"boolean",defaultValue:true},"height":{type:"text"},"colorCoder":{type:"text",defaultValue:null},"collapsible":{type:"boolean",defaultValue:false},"collapsed":{type:"boolean",defaultValue:false},"formatter":{type:"text",defaultValue:null}};
  4136. Exhibit.ListFacet.create=function(configuration,containerElmt,uiContext){var uiContext=Exhibit.UIContext.create(configuration,uiContext);
  4137. var facet=new Exhibit.ListFacet(containerElmt,uiContext);
  4138. Exhibit.ListFacet._configure(facet,configuration);
  4139. facet._initializeUI();
  4140. uiContext.getCollection().addFacet(facet);
  4141. return facet;
  4142. };
  4143. Exhibit.ListFacet.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  4144. var uiContext=Exhibit.UIContext.createFromDOM(configElmt,uiContext);
  4145. var facet=new Exhibit.ListFacet(containerElmt!=null?containerElmt:configElmt,uiContext);
  4146. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.ListFacet._settingSpecs,facet._settings);
  4147. try{var expressionString=Exhibit.getAttribute(configElmt,"expression");
  4148. if(expressionString!=null&&expressionString.length>0){facet._expression=Exhibit.ExpressionParser.parse(expressionString);
  4149. }var selection=Exhibit.getAttribute(configElmt,"selection",";");
  4150. if(selection!=null&&selection.length>0){for(var i=0,s;
  4151. s=selection[i];
  4152. i++){facet._valueSet.add(s);
  4153. }}var selectMissing=Exhibit.getAttribute(configElmt,"selectMissing");
  4154. if(selectMissing!=null&&selectMissing.length>0){facet._selectMissing=(selectMissing=="true");
  4155. }}catch(e){SimileAjax.Debug.exception(e,"ListFacet: Error processing configuration of list facet");
  4156. }Exhibit.ListFacet._configure(facet,configuration);
  4157. facet._initializeUI();
  4158. uiContext.getCollection().addFacet(facet);
  4159. return facet;
  4160. };
  4161. Exhibit.ListFacet._configure=function(facet,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.ListFacet._settingSpecs,facet._settings);
  4162. if("expression" in configuration){facet._expression=Exhibit.ExpressionParser.parse(configuration.expression);
  4163. }if("selection" in configuration){var selection=configuration.selection;
  4164. for(var i=0;
  4165. i<selection.length;
  4166. i++){facet._valueSet.add(selection[i]);
  4167. }}if("selectMissing" in configuration){facet._selectMissing=configuration.selectMissing;
  4168. }if(!("facetLabel" in facet._settings)){facet._settings.facetLabel="missing ex:facetLabel";
  4169. if(facet._expression!=null&&facet._expression.isPath()){var segment=facet._expression.getPath().getLastSegment();
  4170. var property=facet._uiContext.getDatabase().getProperty(segment.property);
  4171. if(property!=null){facet._settings.facetLabel=segment.forward?property.getLabel():property.getReverseLabel();
  4172. }}}if("fixedOrder" in facet._settings){var values=facet._settings.fixedOrder.split(";");
  4173. var orderMap={};
  4174. for(var i=0;
  4175. i<values.length;
  4176. i++){orderMap[values[i].trim()]=i;
  4177. }facet._orderMap=orderMap;
  4178. }if("colorCoder" in facet._settings){facet._colorCoder=facet._uiContext.getExhibit().getComponent(facet._settings.colorCoder);
  4179. }if(facet._settings.collapsed){facet._settings.collapsible=true;
  4180. }if("formatter" in facet._settings){var formatter=facet._settings.formatter;
  4181. if(formatter!=null&&formatter.length>0){try{facet._formatter=eval(formatter);
  4182. }catch(e){SimileAjax.Debug.log(e);
  4183. }}}facet._cache=new Exhibit.FacetUtilities.Cache(facet._uiContext.getDatabase(),facet._uiContext.getCollection(),facet._expression);
  4184. };
  4185. Exhibit.ListFacet.prototype.dispose=function(){this._cache.dispose();
  4186. this._cache=null;
  4187. this._uiContext.getCollection().removeFacet(this);
  4188. this._uiContext=null;
  4189. this._colorCoder=null;
  4190. this._div.innerHTML="";
  4191. this._div=null;
  4192. this._dom=null;
  4193. this._expression=null;
  4194. this._valueSet=null;
  4195. this._settings=null;
  4196. };
  4197. Exhibit.ListFacet.prototype.hasRestrictions=function(){return this._valueSet.size()>0||this._selectMissing;
  4198. };
  4199. Exhibit.ListFacet.prototype.clearAllRestrictions=function(){var oldRestrictionSize=SimileAjax.RemoteLog.logActive?this._valueSet.size():0;
  4200. var restrictions={selection:[],selectMissing:false};
  4201. if(this.hasRestrictions()){this._valueSet.visit(function(v){restrictions.selection.push(v);
  4202. });
  4203. this._valueSet=new Exhibit.Set();
  4204. restrictions.selectMissing=this._selectMissing;
  4205. this._selectMissing=false;
  4206. var newRestrictionSize=SimileAjax.RemoteLog.logActive?this._valueSet.size():0;
  4207. var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4208. this._notifyCollection();
  4209. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4210. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  4211. var restricted="";
  4212. if(newRestrictionSize>0){arr=Array();
  4213. for(k in this._valueSet._hash){arr.push(k);
  4214. }restricted=arr.join("##");
  4215. }SimileAjax.RemoteLog.possiblyLog({facetType:"ListFacet",facetLabel:this._settings.facetLabel,operation:"clearAllRestrictions",exhibitSize:totalSize,selectedValues:restricted,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize,oldRestrictionSize:oldRestrictionSize,newRestrictionSize:newRestrictionSize});
  4216. }return restrictions;
  4217. };
  4218. Exhibit.ListFacet.prototype.applyRestrictions=function(restrictions){var oldRestrictionSize=SimileAjax.RemoteLog.logActive?this._valueSet.size():0;
  4219. this._valueSet=new Exhibit.Set();
  4220. for(var i=0;
  4221. i<restrictions.selection.length;
  4222. i++){this._valueSet.add(restrictions.selection[i]);
  4223. }this._selectMissing=restrictions.selectMissing;
  4224. var newRestrictionSize=SimileAjax.RemoteLog.logActive?this._valueSet.size():0;
  4225. var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4226. this._notifyCollection();
  4227. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4228. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  4229. var restricted="";
  4230. if(newRestrictionSize>0){arr=Array();
  4231. for(k in this._valueSet._hash){arr.push(k);
  4232. }restricted=arr.join("##");
  4233. }SimileAjax.RemoteLog.possiblyLog({facetType:"ListFacet",facetLabel:this._settings.facetLabel,operation:"applyRestrictions",exhibitSize:totalSize,selectedValues:restricted,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize,oldRestrictionSize:oldRestrictionSize,newRestrictionSize:newRestrictionSize});
  4234. };
  4235. Exhibit.ListFacet.prototype.setSelection=function(value,selected){var oldRestrictionSize=SimileAjax.RemoteLog.logActive?this._valueSet.size():0;
  4236. if(selected){this._valueSet.add(value);
  4237. }else{this._valueSet.remove(value);
  4238. }var newRestrictionSize=SimileAjax.RemoteLog.logActive?this._valueSet.size():0;
  4239. var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4240. this._notifyCollection();
  4241. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4242. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  4243. var restricted="";
  4244. if(newRestrictionSize>0){arr=Array();
  4245. for(k in this._valueSet._hash){arr.push(k);
  4246. }restricted=arr.join("##");
  4247. }SimileAjax.RemoteLog.possiblyLog({facetType:"ListFacet",facetLabel:this._settings.facetLabel,operation:"setSelection",value:value,selected:selected,exhibitSize:totalSize,selectedValues:restricted,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize,oldRestrictionSize:oldRestrictionSize,newRestrictionSize:newRestrictionSize});
  4248. };
  4249. Exhibit.ListFacet.prototype.setSelectMissing=function(selected){if(selected!=this._selectMissing){this._selectMissing=selected;
  4250. this._notifyCollection();
  4251. }};
  4252. Exhibit.ListFacet.prototype.restrict=function(items){if(this._valueSet.size()==0&&!this._selectMissing){return items;
  4253. }var set=this._cache.getItemsFromValues(this._valueSet,items);
  4254. if(this._selectMissing){this._cache.getItemsMissingValue(items,set);
  4255. }return set;
  4256. };
  4257. Exhibit.ListFacet.prototype.onUncollapse=function(){if(this._delayedUpdateItems!=null){this.update(this._delayedUpdateItems);
  4258. this._delayedUpdateItems=null;
  4259. }};
  4260. Exhibit.ListFacet.prototype.update=function(items){if(Exhibit.FacetUtilities.isCollapsed(this)){this._delayedUpdateItems=items;
  4261. return ;
  4262. }this._dom.valuesContainer.style.display="none";
  4263. this._dom.valuesContainer.innerHTML="";
  4264. this._constructBody(this._computeFacet(items));
  4265. this._dom.valuesContainer.style.display="block";
  4266. };
  4267. Exhibit.ListFacet.prototype._computeFacet=function(items){var database=this._uiContext.getDatabase();
  4268. var r=this._cache.getValueCountsFromItems(items);
  4269. var entries=r.entries;
  4270. var valueType=r.valueType;
  4271. if(entries.length>0){var selection=this._valueSet;
  4272. var labeler=valueType=="item"?function(v){var l=database.getObject(v,"label");
  4273. return l!=null?l:v;
  4274. }:function(v){return v;
  4275. };
  4276. for(var i=0;
  4277. i<entries.length;
  4278. i++){var entry=entries[i];
  4279. entry.actionLabel=entry.selectionLabel=labeler(entry.value);
  4280. entry.selected=selection.contains(entry.value);
  4281. }entries.sort(this._createSortFunction(valueType));
  4282. }if(this._settings.showMissing||this._selectMissing){var count=this._cache.countItemsMissingValue(items);
  4283. if(count>0||this._selectMissing){var span=document.createElement("span");
  4284. span.innerHTML=("missingLabel" in this._settings)?this._settings.missingLabel:Exhibit.FacetUtilities.l10n.missingThisField;
  4285. span.className="exhibit-facet-value-missingThisField";
  4286. entries.unshift({value:null,count:count,selected:this._selectMissing,selectionLabel:span,actionLabel:Exhibit.FacetUtilities.l10n.missingThisField});
  4287. }}return entries;
  4288. };
  4289. Exhibit.ListFacet.prototype._notifyCollection=function(){this._uiContext.getCollection().onFacetUpdated(this);
  4290. };
  4291. Exhibit.ListFacet.prototype._initializeUI=function(){var self=this;
  4292. this._dom=Exhibit.FacetUtilities[this._settings.scroll?"constructFacetFrame":"constructFlowingFacetFrame"](this,this._div,this._settings.facetLabel,function(elmt,evt,target){self._clearSelections();
  4293. },this._uiContext,this._settings.collapsible,this._settings.collapsed);
  4294. if("height" in this._settings&&this._settings.scroll){this._dom.valuesContainer.style.height=this._settings.height;
  4295. }};
  4296. Exhibit.ListFacet.prototype._constructBody=function(entries){var self=this;
  4297. var containerDiv=this._dom.valuesContainer;
  4298. containerDiv.style.display="none";
  4299. var constructFacetItemFunction=Exhibit.FacetUtilities[this._settings.scroll?"constructFacetItem":"constructFlowingFacetItem"];
  4300. var facetHasSelection=this._valueSet.size()>0||this._selectMissing;
  4301. var constructValue=function(entry){var onSelect=function(elmt,evt,target){self._filter(entry.value,entry.actionLabel,false);
  4302. SimileAjax.DOM.cancelEvent(evt);
  4303. return false;
  4304. };
  4305. var onSelectOnly=function(elmt,evt,target){self._filter(entry.value,entry.actionLabel,!(evt.ctrlKey||evt.metaKey));
  4306. SimileAjax.DOM.cancelEvent(evt);
  4307. return false;
  4308. };
  4309. var elmt=constructFacetItemFunction(entry.selectionLabel,entry.count,(self._colorCoder!=null)?self._colorCoder.translate(entry.value):null,entry.selected,facetHasSelection,onSelect,onSelectOnly,self._uiContext);
  4310. if(self._formatter){self._formatter(elmt);
  4311. }containerDiv.appendChild(elmt);
  4312. };
  4313. for(var j=0;
  4314. j<entries.length;
  4315. j++){constructValue(entries[j]);
  4316. }containerDiv.style.display="block";
  4317. this._dom.setSelectionCount(this._valueSet.size()+(this._selectMissing?1:0));
  4318. };
  4319. Exhibit.ListFacet.prototype._filter=function(value,label,selectOnly){var self=this;
  4320. var selected,select,deselect;
  4321. var oldValues=new Exhibit.Set(this._valueSet);
  4322. var oldSelectMissing=this._selectMissing;
  4323. var newValues;
  4324. var newSelectMissing;
  4325. var actionLabel;
  4326. var wasSelected;
  4327. var wasOnlyThingSelected;
  4328. if(value==null){wasSelected=oldSelectMissing;
  4329. wasOnlyThingSelected=wasSelected&&(oldValues.size()==0);
  4330. if(selectOnly){if(oldValues.size()==0){newSelectMissing=!oldSelectMissing;
  4331. }else{newSelectMissing=true;
  4332. }newValues=new Exhibit.Set();
  4333. }else{newSelectMissing=!oldSelectMissing;
  4334. newValues=new Exhibit.Set(oldValues);
  4335. }}else{wasSelected=oldValues.contains(value);
  4336. wasOnlyThingSelected=wasSelected&&(oldValues.size()==1)&&!oldSelectMissing;
  4337. if(selectOnly){newSelectMissing=false;
  4338. newValues=new Exhibit.Set();
  4339. if(!oldValues.contains(value)){newValues.add(value);
  4340. }else{if(oldValues.size()>1||oldSelectMissing){newValues.add(value);
  4341. }}}else{newSelectMissing=oldSelectMissing;
  4342. newValues=new Exhibit.Set(oldValues);
  4343. if(newValues.contains(value)){newValues.remove(value);
  4344. }else{newValues.add(value);
  4345. }}}var newRestrictions={selection:newValues.toArray(),selectMissing:newSelectMissing};
  4346. var oldRestrictions={selection:oldValues.toArray(),selectMissing:oldSelectMissing};
  4347. SimileAjax.History.addLengthyAction(function(){self.applyRestrictions(newRestrictions);
  4348. },function(){self.applyRestrictions(oldRestrictions);
  4349. },(selectOnly&&!wasOnlyThingSelected)?String.substitute(Exhibit.FacetUtilities.l10n["facetSelectOnlyActionTitle"],[label,this._settings.facetLabel]):String.substitute(Exhibit.FacetUtilities.l10n[wasSelected?"facetUnselectActionTitle":"facetSelectActionTitle"],[label,this._settings.facetLabel]));
  4350. };
  4351. Exhibit.ListFacet.prototype._clearSelections=function(){var state={};
  4352. var self=this;
  4353. SimileAjax.History.addLengthyAction(function(){state.restrictions=self.clearAllRestrictions();
  4354. },function(){self.applyRestrictions(state.restrictions);
  4355. },String.substitute(Exhibit.FacetUtilities.l10n["facetClearSelectionsActionTitle"],[this._settings.facetLabel]));
  4356. };
  4357. Exhibit.ListFacet.prototype._createSortFunction=function(valueType){var sortValueFunction=function(a,b){return a.selectionLabel.localeCompare(b.selectionLabel);
  4358. };
  4359. if("_orderMap" in this){var orderMap=this._orderMap;
  4360. sortValueFunction=function(a,b){if(a.selectionLabel in orderMap){if(b.selectionLabel in orderMap){return orderMap[a.selectionLabel]-orderMap[b.selectionLabel];
  4361. }else{return -1;
  4362. }}else{if(b.selectionLabel in orderMap){return 1;
  4363. }else{return a.selectionLabel.localeCompare(b.selectionLabel);
  4364. }}};
  4365. }else{if(valueType=="number"){sortValueFunction=function(a,b){a=parseFloat(a.value);
  4366. b=parseFloat(b.value);
  4367. return a<b?-1:a>b?1:0;
  4368. };
  4369. }}var sortFunction=sortValueFunction;
  4370. if(this._settings.sortMode=="count"){sortFunction=function(a,b){var c=b.count-a.count;
  4371. return c!=0?c:sortValueFunction(a,b);
  4372. };
  4373. }var sortDirectionFunction=sortFunction;
  4374. if(this._settings.sortDirection=="reverse"){sortDirectionFunction=function(a,b){return sortFunction(b,a);
  4375. };
  4376. }return sortDirectionFunction;
  4377. };
  4378. Exhibit.ListFacet.prototype.exportFacetSelection=function(){var s=[];
  4379. this._valueSet.visit(function(v){s.push(v);
  4380. });
  4381. if(s.length>0){return s.join(",");
  4382. }};
  4383. Exhibit.ListFacet.prototype.importFacetSelection=function(settings){var self=this;
  4384. self.applyRestrictions({selection:settings.split(","),selectMissing:self._selectMissing});
  4385. };
  4386. /* numeric-range-facet.js */
  4387. Exhibit.NumericRangeFacet=function(containerElmt,uiContext){this._div=containerElmt;
  4388. this._uiContext=uiContext;
  4389. this._expression=null;
  4390. this._settings={};
  4391. this._dom=null;
  4392. this._ranges=[];
  4393. var self=this;
  4394. this._listener={onRootItemsChanged:function(){if("_rangeIndex" in self){delete self._rangeIndex;
  4395. }}};
  4396. uiContext.getCollection().addListener(this._listener);
  4397. };
  4398. Exhibit.NumericRangeFacet._settingSpecs={"facetLabel":{type:"text"},"scroll":{type:"boolean",defaultValue:true},"height":{type:"text"},"interval":{type:"float",defaultValue:10},"collapsible":{type:"boolean",defaultValue:false},"collapsed":{type:"boolean",defaultValue:false}};
  4399. Exhibit.NumericRangeFacet.create=function(configuration,containerElmt,uiContext){var uiContext=Exhibit.UIContext.create(configuration,uiContext);
  4400. var facet=new Exhibit.NumericRangeFacet(containerElmt,uiContext);
  4401. Exhibit.NumericRangeFacet._configure(facet,configuration);
  4402. facet._initializeUI();
  4403. uiContext.getCollection().addFacet(facet);
  4404. return facet;
  4405. };
  4406. Exhibit.NumericRangeFacet.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  4407. var uiContext=Exhibit.UIContext.createFromDOM(configElmt,uiContext);
  4408. var facet=new Exhibit.NumericRangeFacet(containerElmt!=null?containerElmt:configElmt,uiContext);
  4409. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.NumericRangeFacet._settingSpecs,facet._settings);
  4410. try{var expressionString=Exhibit.getAttribute(configElmt,"expression");
  4411. if(expressionString!=null&&expressionString.length>0){facet._expression=Exhibit.ExpressionParser.parse(expressionString);
  4412. }}catch(e){SimileAjax.Debug.exception(e,"NumericRangeFacet: Error processing configuration of numeric range facet");
  4413. }Exhibit.NumericRangeFacet._configure(facet,configuration);
  4414. facet._initializeUI();
  4415. uiContext.getCollection().addFacet(facet);
  4416. return facet;
  4417. };
  4418. Exhibit.NumericRangeFacet._configure=function(facet,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.NumericRangeFacet._settingSpecs,facet._settings);
  4419. if("expression" in configuration){facet._expression=Exhibit.ExpressionParser.parse(configuration.expression);
  4420. }if(!("facetLabel" in facet._settings)){facet._settings.facetLabel="missing ex:facetLabel";
  4421. if(facet._expression!=null&&facet._expression.isPath()){var segment=facet._expression.getPath().getLastSegment();
  4422. var property=facet._uiContext.getDatabase().getProperty(segment.property);
  4423. if(property!=null){facet._settings.facetLabel=segment.forward?property.getLabel():property.getReverseLabel();
  4424. }}}if(facet._settings.collapsed){facet._settings.collapsible=true;
  4425. }};
  4426. Exhibit.NumericRangeFacet.prototype.dispose=function(){this._uiContext.getCollection().removeFacet(this);
  4427. this._uiContext.getCollection().removeListener(this._listener);
  4428. this._uiContext=null;
  4429. this._div.innerHTML="";
  4430. this._div=null;
  4431. this._dom=null;
  4432. this._expression=null;
  4433. this._settings=null;
  4434. this._ranges=null;
  4435. };
  4436. Exhibit.NumericRangeFacet.prototype.hasRestrictions=function(){return this._ranges.length>0;
  4437. };
  4438. Exhibit.NumericRangeFacet.prototype.clearAllRestrictions=function(){var restrictions=[];
  4439. if(this._ranges.length>0){restrictions=restrictions.concat(this._ranges);
  4440. this._ranges=[];
  4441. var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4442. this._notifyCollection();
  4443. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4444. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  4445. SimileAjax.RemoteLog.possiblyLog({facetType:"NumericRange",facetLabel:this._settings.facetLabel,operation:"clearAllRestrictions",exhibitSize:totalSize,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize});
  4446. }return restrictions;
  4447. };
  4448. Exhibit.NumericRangeFacet.prototype.applyRestrictions=function(restrictions){this._ranges=restrictions;
  4449. var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4450. this._notifyCollection();
  4451. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4452. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  4453. SimileAjax.RemoteLog.possiblyLog({facetType:"NumericRange",facetLabel:this._settings.facetLabel,operation:"applyRestrictions",exhibitSize:totalSize,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize});
  4454. };
  4455. Exhibit.NumericRangeFacet.prototype.setRange=function(from,to,selected){if(selected){for(var i=0;
  4456. i<this._ranges.length;
  4457. i++){var range=this._ranges[i];
  4458. if(range.from==from&&range.to==to){return ;
  4459. }}this._ranges.push({from:from,to:to});
  4460. }else{for(var i=0;
  4461. i<this._ranges.length;
  4462. i++){var range=this._ranges[i];
  4463. if(range.from==from&&range.to==to){this._ranges.splice(i,1);
  4464. break;
  4465. }}}var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4466. this._notifyCollection();
  4467. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4468. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  4469. SimileAjax.RemoteLog.possiblyLog({facetType:"NumericRange",facetLabel:this._settings.facetLabel,operation:"setRange",from:from,to:to,selected:selected,exhibitSize:totalSize,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize});
  4470. };
  4471. Exhibit.NumericRangeFacet.prototype.restrict=function(items){if(this._ranges.length==0){return items;
  4472. }else{if(this._expression.isPath()){var path=this._expression.getPath();
  4473. var database=this._uiContext.getDatabase();
  4474. var set=new Exhibit.Set();
  4475. for(var i=0;
  4476. i<this._ranges.length;
  4477. i++){var range=this._ranges[i];
  4478. set.addSet(path.rangeBackward(range.from,range.to,false,items,database).values);
  4479. }return set;
  4480. }else{this._buildRangeIndex();
  4481. var set=new Exhibit.Set();
  4482. for(var i=0;
  4483. i<this._ranges.length;
  4484. i++){var range=this._ranges[i];
  4485. this._rangeIndex.getSubjectsInRange(range.from,range.to,false,set,items);
  4486. }return set;
  4487. }}};
  4488. Exhibit.NumericRangeFacet.prototype.update=function(items){this._dom.valuesContainer.style.display="none";
  4489. this._dom.valuesContainer.innerHTML="";
  4490. this._reconstruct(items);
  4491. this._dom.valuesContainer.style.display="block";
  4492. };
  4493. Exhibit.NumericRangeFacet.prototype._reconstruct=function(items){var self=this;
  4494. var ranges=[];
  4495. var rangeIndex;
  4496. var computeItems;
  4497. if(this._expression.isPath()){var database=this._uiContext.getDatabase();
  4498. var path=this._expression.getPath();
  4499. var propertyID=path.getLastSegment().property;
  4500. var property=database.getProperty(propertyID);
  4501. if(property==null){return null;
  4502. }rangeIndex=property.getRangeIndex();
  4503. countItems=function(range){return path.rangeBackward(range.from,range.to,false,items,database).values.size();
  4504. };
  4505. }else{this._buildRangeIndex();
  4506. rangeIndex=this._rangeIndex;
  4507. countItems=function(range){return rangeIndex.getSubjectsInRange(range.from,range.to,false,null,items).size();
  4508. };
  4509. }var min=rangeIndex.getMin();
  4510. var max=rangeIndex.getMax();
  4511. min=Math.floor(min/this._settings.interval)*this._settings.interval;
  4512. max=Math.ceil((max+this._settings.interval)/this._settings.interval)*this._settings.interval;
  4513. for(var x=min;
  4514. x<max;
  4515. x+=this._settings.interval){var range={from:x,to:x+this._settings.interval,selected:false};
  4516. range.count=countItems(range);
  4517. for(var i=0;
  4518. i<this._ranges.length;
  4519. i++){var range2=this._ranges[i];
  4520. if(range2.from==range.from&&range2.to==range.to){range.selected=true;
  4521. facetHasSelection=true;
  4522. break;
  4523. }}ranges.push(range);
  4524. }var facetHasSelection=this._ranges.length>0;
  4525. var containerDiv=this._dom.valuesContainer;
  4526. containerDiv.style.display="none";
  4527. var constructFacetItemFunction=Exhibit.FacetUtilities[this._settings.scroll?"constructFacetItem":"constructFlowingFacetItem"];
  4528. var makeFacetValue=function(from,to,count,selected){var onSelect=function(elmt,evt,target){self._toggleRange(from,to,selected,false);
  4529. SimileAjax.DOM.cancelEvent(evt);
  4530. return false;
  4531. };
  4532. var onSelectOnly=function(elmt,evt,target){self._toggleRange(from,to,selected,!(evt.ctrlKey||evt.metaKey));
  4533. SimileAjax.DOM.cancelEvent(evt);
  4534. return false;
  4535. };
  4536. var elmt=constructFacetItemFunction(from+" - "+to,count,null,selected,facetHasSelection,onSelect,onSelectOnly,self._uiContext);
  4537. containerDiv.appendChild(elmt);
  4538. };
  4539. for(var i=0;
  4540. i<ranges.length;
  4541. i++){var range=ranges[i];
  4542. if(range.selected||range.count>0){makeFacetValue(range.from,range.to,range.count,range.selected);
  4543. }}containerDiv.style.display="block";
  4544. this._dom.setSelectionCount(this._ranges.length);
  4545. };
  4546. Exhibit.NumericRangeFacet.prototype._notifyCollection=function(){this._uiContext.getCollection().onFacetUpdated(this);
  4547. };
  4548. Exhibit.NumericRangeFacet.prototype._initializeUI=function(){var self=this;
  4549. this._dom=Exhibit.FacetUtilities[this._settings.scroll?"constructFacetFrame":"constructFlowingFacetFrame"](this,this._div,this._settings.facetLabel,function(elmt,evt,target){self._clearSelections();
  4550. },this._uiContext,this._settings.collapsible,this._settings.collapsed);
  4551. if("height" in this._settings){this._dom.valuesContainer.style.height=this._settings.height;
  4552. }};
  4553. Exhibit.NumericRangeFacet.prototype._toggleRange=function(from,to,wasSelected,singleSelection){var self=this;
  4554. var label=from+" to "+to;
  4555. var wasOnlyThingSelected=(this._ranges.length==1&&wasSelected);
  4556. if(singleSelection&&!wasOnlyThingSelected){var newRestrictions=[{from:from,to:to}];
  4557. var oldRestrictions=[].concat(this._ranges);
  4558. SimileAjax.History.addLengthyAction(function(){self.applyRestrictions(newRestrictions);
  4559. },function(){self.applyRestrictions(oldRestrictions);
  4560. },String.substitute(Exhibit.FacetUtilities.l10n["facetSelectOnlyActionTitle"],[label,this._settings.facetLabel]));
  4561. }else{SimileAjax.History.addLengthyAction(function(){self.setRange(from,to,!wasSelected);
  4562. },function(){self.setRange(from,to,wasSelected);
  4563. },String.substitute(Exhibit.FacetUtilities.l10n[wasSelected?"facetUnselectActionTitle":"facetSelectActionTitle"],[label,this._settings.facetLabel]));
  4564. }};
  4565. Exhibit.NumericRangeFacet.prototype._clearSelections=function(){var state={};
  4566. var self=this;
  4567. SimileAjax.History.addLengthyAction(function(){state.restrictions=self.clearAllRestrictions();
  4568. },function(){self.applyRestrictions(state.restrictions);
  4569. },String.substitute(Exhibit.FacetUtilities.l10n["facetClearSelectionsActionTitle"],[this._settings.facetLabel]));
  4570. };
  4571. Exhibit.NumericRangeFacet.prototype._buildRangeIndex=function(){if(!("_rangeIndex" in this)){var expression=this._expression;
  4572. var database=this._uiContext.getDatabase();
  4573. var getter=function(item,f){expression.evaluateOnItem(item,database).values.visit(function(value){if(typeof value!="number"){value=parseFloat(value);
  4574. }if(!isNaN(value)){f(value);
  4575. }});
  4576. };
  4577. this._rangeIndex=new Exhibit.Database._RangeIndex(this._uiContext.getCollection().getAllItems(),getter);
  4578. }};
  4579. /* slider-facet.js */
  4580. Exhibit.SliderFacet=function(containerElmt,uiContext){this._div=containerElmt;
  4581. this._uiContext=uiContext;
  4582. this._expression=null;
  4583. this._settings={};
  4584. this._range={min:null,max:null};
  4585. this._maxRange={min:null,max:null};
  4586. };
  4587. Exhibit.SliderFacet._settingsSpecs={"facetLabel":{type:"text"},"scroll":{type:"boolean",defaultValue:true},"height":{type:"text"},"precision":{type:"float",defaultValue:1},"histogram":{type:"boolean",defaultValue:true},"height":{type:"int",defaultValue:false},"width":{type:"int",defaultValue:false},"horizontal":{type:"boolean",defaultValue:true},"inputText":{type:"boolean",defaultValue:true},"showMissing":{type:"boolean",defaultValue:true},"selection":{type:"float",dimensions:2}};
  4588. Exhibit.SliderFacet.create=function(configuration,containerElmt,uiContext){var uiContext=Exhibit.UIContext.create(configuration,uiContext);
  4589. var facet=new Exhibit.SliderFacet(containerElmt,uiContext);
  4590. Exhibit.SliderFacet._configure(facet,configuration);
  4591. facet._initializeUI();
  4592. uiContext.getCollection().addFacet(facet);
  4593. return facet;
  4594. };
  4595. Exhibit.SliderFacet.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  4596. var uiContext=Exhibit.UIContext.createFromDOM(configElmt,uiContext);
  4597. var facet=new Exhibit.SliderFacet(containerElmt!=null?containerElmt:configElmt,uiContext);
  4598. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.SliderFacet._settingsSpecs,facet._settings);
  4599. try{var expressionString=Exhibit.getAttribute(configElmt,"expression");
  4600. if(expressionString!=null&&expressionString.length>0){facet._expression=Exhibit.ExpressionParser.parse(expressionString);
  4601. }var showMissing=Exhibit.getAttribute(configElmt,"showMissing");
  4602. if(showMissing!=null&&showMissing.length>0){facet._showMissing=(showMissing=="true");
  4603. }else{facet._showMissing=true;
  4604. }if("selection" in facet._settings){var selection=facet._settings.selection;
  4605. facet._range={min:selection[0],max:selection[1]};
  4606. }}catch(e){SimileAjax.Debug.exception(e,"SliderFacet: Error processing configuration of slider facet");
  4607. }Exhibit.SliderFacet._configure(facet,configuration);
  4608. facet._initializeUI();
  4609. uiContext.getCollection().addFacet(facet);
  4610. return facet;
  4611. };
  4612. Exhibit.SliderFacet._configure=function(facet,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.SliderFacet._settingsSpecs,facet._settings);
  4613. if("expression" in configuration){facet._expression=Exhibit.ExpressionParser.parse(configuration.expression);
  4614. }if("selection" in configuration){var selection=configuration.selection;
  4615. facet._range={min:selection[0],max:selection[1]};
  4616. }if("showMissing" in configuration){facet._showMissing=configuration.showMissing;
  4617. }if(!("facetLabel" in facet._settings)){facet._settings.facetLabel="missing ex:facetLabel";
  4618. if(facet._expression!=null&&facet._expression.isPath()){var segment=facet._expression.getPath().getLastSegment();
  4619. var property=facet._uiContext.getDatabase().getProperty(segment.property);
  4620. if(property!=null){facet._settings.facetLabel=segment.forward?property.getLabel():property.getReverseLabel();
  4621. }}}facet._cache=new Exhibit.FacetUtilities.Cache(facet._uiContext.getDatabase(),facet._uiContext.getCollection(),facet._expression);
  4622. facet._maxRange=facet._getMaxRange();
  4623. };
  4624. Exhibit.SliderFacet.prototype._initializeUI=function(){this._dom=SimileAjax.DOM.createDOMFromString(this._div,"<div class='exhibit-facet-header'><span class='exhibit-facet-header-title'>"+this._settings.facetLabel+"</span></div><div class='exhibit-slider' id='slider'></div>");
  4625. this._slider=new Exhibit.SliderFacet.slider(this._dom.slider,this,this._settings.precision,this._settings.horizontal);
  4626. };
  4627. Exhibit.SliderFacet.prototype.hasRestrictions=function(){return(this._range.min&&this._range.min!=this._maxRange.min)||(this._range.max&&this._range.max!=this._maxRange.max);
  4628. };
  4629. Exhibit.SliderFacet.prototype.update=function(items){if(this._settings.histogram){var data=[];
  4630. var n=75;
  4631. var range=(this._maxRange.max-this._maxRange.min)/n;
  4632. var missingCount=0;
  4633. var database=this._uiContext.getDatabase();
  4634. if(this._selectMissing){missingCount=this._cache.getItemsMissingValue(items).size();
  4635. }if(this._expression.isPath()){var path=this._expression.getPath();
  4636. for(var i=0;
  4637. i<n;
  4638. i++){data[i]=path.rangeBackward(this._maxRange.min+i*range,this._maxRange.min+(i+1)*range,false,items,database).values.size()+missingCount;
  4639. }}else{this._buildRangeIndex();
  4640. var rangeIndex=this._rangeIndex;
  4641. for(var i=0;
  4642. i<n;
  4643. i++){data[i]=rangeIndex.getSubjectsInRange(this._maxRange.min+i*range,this._maxRange.min+(i+1)*range,false,null,items).size()+missingCount;
  4644. }}this._slider.updateHistogram(data);
  4645. }this._slider._setMin(this._range.min);
  4646. this._slider._setMax(this._range.max);
  4647. };
  4648. Exhibit.SliderFacet.prototype.restrict=function(items){if(!this.hasRestrictions()){return items;
  4649. }set=new Exhibit.Set();
  4650. if(this._expression.isPath()){var path=this._expression.getPath();
  4651. var database=this._uiContext.getDatabase();
  4652. set=path.rangeBackward(this._range.min,this._range.max,false,items,database).values;
  4653. }else{this._buildRangeIndex();
  4654. var rangeIndex=this._rangeIndex;
  4655. set=rangeIndex.getSubjectsInRange(this._range.min,this._range.max,false,null,items);
  4656. }if(this._showMissing){this._cache.getItemsMissingValue(items,set);
  4657. }return set;
  4658. };
  4659. Exhibit.SliderFacet.prototype._getMaxRange=function(){if(this._expression.getPath()){var path=this._expression.getPath();
  4660. var database=this._uiContext.getDatabase();
  4661. var propertyID=path.getLastSegment().property;
  4662. var property=database.getProperty(propertyID);
  4663. var rangeIndex=property.getRangeIndex();
  4664. }else{this._buildRangeIndex();
  4665. var rangeIndex=this._rangeIndex;
  4666. }return{min:rangeIndex.getMin(),max:rangeIndex.getMax()};
  4667. };
  4668. Exhibit.SliderFacet.prototype._buildRangeIndex=function(){if(!("_rangeIndex" in this)){var expression=this._expression;
  4669. var database=this._uiContext.getDatabase();
  4670. var getter=function(item,f){expression.evaluateOnItem(item,database).values.visit(function(value){if(typeof value!="number"){value=parseFloat(value);
  4671. }if(!isNaN(value)){f(value);
  4672. }});
  4673. };
  4674. this._rangeIndex=new Exhibit.Database._RangeIndex(this._uiContext.getCollection().getAllItems(),getter);
  4675. }};
  4676. Exhibit.SliderFacet.prototype.changeRange=function(range){this._range=range;
  4677. var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4678. this._notifyCollection();
  4679. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4680. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  4681. SimileAjax.RemoteLog.possiblyLog({facetType:"Slider",facetLabel:this._settings.facetLabel,operation:"changeRange",max:range.max,min:range.min,exhibitSize:totalSize,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize});
  4682. };
  4683. Exhibit.SliderFacet.prototype._notifyCollection=function(){this._uiContext.getCollection().onFacetUpdated(this);
  4684. };
  4685. Exhibit.SliderFacet.prototype.clearAllRestrictions=function(){var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4686. this._slider.resetSliders();
  4687. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4688. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  4689. SimileAjax.RemoteLog.possiblyLog({facetType:"Slider",facetLabel:this._settings.facetLabel,operation:"clearAllRestrictions",exhibitSize:totalSize,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize});
  4690. this._range=this._maxRange;
  4691. };
  4692. Exhibit.SliderFacet.prototype.dispose=function(){this._uiContext.getCollection().removeFacet(this);
  4693. this._uiContext=null;
  4694. this._colorCoder=null;
  4695. this._div.innerHTML="";
  4696. this._div=null;
  4697. this._dom=null;
  4698. this._expression=null;
  4699. this._settings=null;
  4700. this._range=null;
  4701. this._maxRange=null;
  4702. };
  4703. /* slider.js */
  4704. Exhibit.SliderFacet.slider=function(div,facet,precision){this._div=div;
  4705. this._facet=facet;
  4706. this._prec=precision||0.1;
  4707. this._maxRange={min:parseFloat(Exhibit.Util.round(facet._maxRange.min-precision/2,this._prec)),max:parseFloat(Exhibit.Util.round(facet._maxRange.max+precision/2,this._prec))};
  4708. this._horizontal=this._facet._settings.horizontal;
  4709. this._scaleFactor=null;
  4710. this._slider1={};
  4711. this._slider2={};
  4712. this._dom=SimileAjax.DOM.createDOMFromString(div,'<div class="exhibit-slider-bar" id="bar"><div id="slider1"></div><div id="slider2"></div>'+(this._facet._settings.histogram?'<div class="exhibit-slider-histogram" id="histogram"></div>':"")+'</div><div class="exhibit-slider-display">'+(this._facet._settings.inputText?'<input type="text" id="minDisplay"></input> - <input type="text" id="maxDisplay"></input> ':'<span id="minDisplay"></span> - <span id="maxDisplay"></span>')+"</div>");
  4713. var horizontal=this._horizontal;
  4714. var histogram=this._dom.histogram;
  4715. if(horizontal&&histogram){this._dom.bar.style.height="14px";
  4716. this._dom.bar.style.width="150px";
  4717. }else{if(horizontal&&!histogram){this._dom.bar.style.height="1px";
  4718. this._dom.bar.style.width="150px";
  4719. }else{if(!horizontal&&histogram){this._dom.bar.style.height="150px";
  4720. this._dom.bar.style.width="14px";
  4721. }else{this._dom.bar.style.height="150px";
  4722. this._dom.bar.style.width="1px";
  4723. }}}if(this._facet._settings.height){this._dom.bar.style.height=this._facet._settings.height+"px";
  4724. }if(this._facet._settings.width){this._dom.bar.style.width=this._facet._settings.width+"px";
  4725. }if(histogram){this._dom.histogram.style.height=this._dom.bar.offsetHeight+"px";
  4726. this._dom.histogram.style.width=this._dom.bar.offsetWidth+"px";
  4727. }if(horizontal){this._scaleFactor=(this._maxRange.max-this._maxRange.min)/this._dom.bar.offsetWidth;
  4728. }else{this._scaleFactor=(this._maxRange.max-this._maxRange.min)/this._dom.bar.offsetHeight;
  4729. }this._slider1=new Exhibit.SliderFacet.slider.slider(this._dom.slider1,this);
  4730. this._slider2=new Exhibit.SliderFacet.slider.slider(this._dom.slider2,this);
  4731. this._setSlider(this._slider1,this._maxRange.min);
  4732. this._setSlider(this._slider2,this._maxRange.max);
  4733. this._registerDragging();
  4734. if(this._facet._settings.inputText){this._registerInputs();
  4735. }};
  4736. Exhibit.SliderFacet.slider.prototype.resetSliders=function(){this._setSlider(this._slider1,this._maxRange.min);
  4737. this._setSlider(this._slider2,this._maxRange.max);
  4738. };
  4739. Exhibit.SliderFacet.slider.prototype._setSlider=function(slider,value){if(value>this._maxRange.max){value=this._maxRange.max;
  4740. }else{if(value<this._maxRange.min){value=this._maxRange.min;
  4741. }}value=parseFloat(Exhibit.Util.round(value,this._prec));
  4742. slider.value=value;
  4743. if(this._horizontal){slider.div.style.left=((value-this._maxRange.min)/this._scaleFactor-slider.offset)+"px";
  4744. }else{slider.div.style.top=((value-this._maxRange.min)/this._scaleFactor-slider.offset)+"px";
  4745. }this._setDisplays(slider);
  4746. };
  4747. Exhibit.SliderFacet.slider.prototype._setMin=function(value){var slider=this._slider1.value<this._slider2.value?this._slider1:this._slider2;
  4748. var other=(slider==this._slider1)?this._slider2:this._slider1;
  4749. value=parseFloat(value);
  4750. if(isNaN(value)){return ;
  4751. }if(value>other.value){value=other.value;
  4752. }this._setSlider(slider,value);
  4753. };
  4754. Exhibit.SliderFacet.slider.prototype._setMax=function(value){var slider=this._slider1.value>this._slider2.value?this._slider1:this._slider2;
  4755. var other=(slider==this._slider1)?this._slider2:this._slider1;
  4756. value=parseFloat(value);
  4757. if(isNaN(value)){return ;
  4758. }if(value<other.value){value=other.value;
  4759. }this._setSlider(slider,value);
  4760. };
  4761. Exhibit.SliderFacet.slider.prototype._setDisplays=function(slider){var other=(slider==this._slider1)?this._slider2:this._slider1;
  4762. var min=Math.min(slider.value,other.value);
  4763. var max=Math.max(slider.value,other.value);
  4764. if(this._facet._settings.inputText){this._dom.minDisplay.value=min;
  4765. this._dom.maxDisplay.value=max;
  4766. }else{this._dom.minDisplay.innerHTML=min;
  4767. this._dom.maxDisplay.innerHTML=max;
  4768. }};
  4769. Exhibit.SliderFacet.slider.slider=function(div,self){var barEl=self._dom.bar;
  4770. this.div=div;
  4771. if(self._horizontal){this.div.className="exhibit-slider-handle";
  4772. this.div.style.backgroundImage='url("'+Exhibit.urlPrefix+'images/slider-handle.png")';
  4773. this.offset=this.div.offsetWidth/2;
  4774. this.min=-this.offset;
  4775. this.max=barEl.offsetWidth-this.offset;
  4776. }else{this.div.className="exhibit-slider-handle2";
  4777. this.div.style.backgroundImage='url("'+Exhibit.urlPrefix+'images/slider-handle2.png")';
  4778. this.offset=this.div.offsetHeight/2;
  4779. this.min=-this.offset;
  4780. this.max=barEl.offsetHeight-this.offset;
  4781. }if(self._facet._settings.histogram){this.div.style.top=(barEl.offsetHeight-4)+"px";
  4782. }};
  4783. Exhibit.SliderFacet.slider.prototype._registerDragging=function(){var self=this;
  4784. var startDrag=function(slider){return function(e){e=e||window.event;
  4785. var onMove=self._horizontal?onDragH(e,slider):onDragV(e,slider);
  4786. if(document.attachEvent){document.attachEvent("onmousemove",onMove);
  4787. document.attachEvent("onmouseup",endDrag(slider,onMove));
  4788. }else{document.addEventListener("mousemove",onMove,false);
  4789. document.addEventListener("mouseup",endDrag(slider,onMove),false);
  4790. }SimileAjax.DOM.cancelEvent(e);
  4791. return false;
  4792. };
  4793. };
  4794. var onDragH=function(e,slider){var origX=e.screenX;
  4795. var origLeft=parseInt(slider.div.style.left);
  4796. var min=slider.min;
  4797. var max=slider.max;
  4798. return function(e){e=e||window.event;
  4799. var dx=e.screenX-origX;
  4800. var newLeft=origLeft+dx;
  4801. if(newLeft<min){newLeft=min;
  4802. }if(newLeft>max){newLeft=max;
  4803. }slider.div.style.left=newLeft+"px";
  4804. setTimeout(function(){var position=parseInt(slider.div.style.left)+slider.offset;
  4805. slider.value=parseFloat(Exhibit.Util.round(position*self._scaleFactor+self._maxRange.min,self._prec));
  4806. self._setDisplays(slider);
  4807. },0);
  4808. };
  4809. };
  4810. var onDragV=function(e,slider){var origY=e.screenY;
  4811. var origTop=parseInt(slider.div.style.top);
  4812. var min=slider.min;
  4813. var max=slider.max;
  4814. return function(e){e=e||window.event;
  4815. var dy=e.screenY-origY;
  4816. var newTop=origTop+dy;
  4817. if(newTop<min){newTop=min;
  4818. }if(newTop>max){newTop=max;
  4819. }slider.div.style.top=newTop+"px";
  4820. setTimeout(function(){var position=parseInt(slider.div.style.top)+slider.offset;
  4821. slider.value=parseFloat(Exhibit.Util.round(position*self._scaleFactor+self._maxRange.min,self._prec));
  4822. self._setDisplays(slider);
  4823. },0);
  4824. };
  4825. };
  4826. var endDrag=function(slider,moveListener){return function(e){if(document.detachEvent){document.detachEvent("onmousemove",moveListener);
  4827. document.detachEvent("onmouseup",arguments.callee);
  4828. }else{document.removeEventListener("mousemove",moveListener,false);
  4829. document.removeEventListener("mouseup",arguments.callee,false);
  4830. }self._notifyFacet();
  4831. };
  4832. };
  4833. var attachListeners=function(slider){if(document.attachEvent){slider.div.attachEvent("onmousedown",startDrag(slider));
  4834. }else{slider.div.addEventListener("mousedown",startDrag(slider),false);
  4835. }};
  4836. attachListeners(this._slider1);
  4837. attachListeners(this._slider2);
  4838. };
  4839. Exhibit.SliderFacet.slider.prototype._notifyFacet=function(){var val1=this._slider1.value;
  4840. var val2=this._slider2.value;
  4841. this._facet.changeRange({min:Math.min(val1,val2),max:Math.max(val1,val2)});
  4842. };
  4843. Exhibit.SliderFacet.slider.prototype.updateHistogram=function(data){var n=data.length;
  4844. var histogram=this._dom.histogram;
  4845. var maxVal=Math.max.apply(Math,data);
  4846. if(!maxVal){return ;
  4847. }if(this._horizontal){var width=histogram.offsetWidth/n;
  4848. var maxHeight=histogram.offsetHeight;
  4849. var ratio=maxHeight/maxVal;
  4850. histogram.innerHTML="";
  4851. for(var i=0;
  4852. i<n;
  4853. i++){var height=Math.ceil(data[i]*ratio);
  4854. var bar=document.createElement("div");
  4855. histogram.appendChild(bar);
  4856. bar.style.width=width+"px";
  4857. bar.style.height=height+"px";
  4858. bar.style.display=height?"":"none";
  4859. bar.style.position="absolute";
  4860. bar.style.top=(maxHeight-height)+"px";
  4861. bar.style.left=i*width+"px";
  4862. }}else{var width=histogram.offsetHeight/n;
  4863. var maxHeight=histogram.offsetWidth;
  4864. var ratio=maxHeight/maxVal;
  4865. histogram.innerHTML="";
  4866. for(var i=0;
  4867. i<n;
  4868. i++){var height=Math.round(data[i]*ratio);
  4869. var bar=document.createElement("div");
  4870. bar.style.height=width;
  4871. bar.style.width=height;
  4872. bar.style.position="absolute";
  4873. bar.style.left=0;
  4874. bar.style.top=i*width;
  4875. histogram.appendChild(bar);
  4876. }}};
  4877. Exhibit.SliderFacet.slider.prototype._registerInputs=function(){var self=this;
  4878. if(document.attachEvent){this._dom.minDisplay.attachEvent("onchange",function(e){self._setMin(this.value);
  4879. self._notifyFacet();
  4880. });
  4881. this._dom.maxDisplay.attachEvent("onchange",function(e){self._setMax(this.value);
  4882. self._notifyFacet();
  4883. });
  4884. }else{this._dom.minDisplay.addEventListener("change",function(e){self._setMin(this.value);
  4885. self._notifyFacet();
  4886. },false);
  4887. this._dom.maxDisplay.addEventListener("change",function(e){self._setMax(this.value);
  4888. self._notifyFacet();
  4889. },false);
  4890. }};
  4891. /* text-search-facet.js */
  4892. Exhibit.TextSearchFacet=function(containerElmt,uiContext){this._div=containerElmt;
  4893. this._uiContext=uiContext;
  4894. this._expressions=[];
  4895. this._text=null;
  4896. this._settings={};
  4897. this._dom=null;
  4898. this._timerID=null;
  4899. var self=this;
  4900. this._listener={onRootItemsChanged:function(){if("_itemToValue" in self){delete self._itemToValue;
  4901. }}};
  4902. uiContext.getCollection().addListener(this._listener);
  4903. };
  4904. Exhibit.TextSearchFacet._settingSpecs={"facetLabel":{type:"text"},"queryParamName":{type:"text"},"requiresEnter":{type:"boolean",defaultValue:false}};
  4905. Exhibit.TextSearchFacet.create=function(configuration,containerElmt,uiContext){var uiContext=Exhibit.UIContext.create(configuration,uiContext);
  4906. var facet=new Exhibit.TextSearchFacet(containerElmt,uiContext);
  4907. Exhibit.TextSearchFacet._configure(facet,configuration);
  4908. facet._initializeUI();
  4909. uiContext.getCollection().addFacet(facet);
  4910. return facet;
  4911. };
  4912. Exhibit.TextSearchFacet.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  4913. var uiContext=Exhibit.UIContext.createFromDOM(configElmt,uiContext);
  4914. var facet=new Exhibit.TextSearchFacet(containerElmt!=null?containerElmt:configElmt,uiContext);
  4915. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.TextSearchFacet._settingSpecs,facet._settings);
  4916. try{var s=Exhibit.getAttribute(configElmt,"expressions");
  4917. if(s!=null&&s.length>0){facet._expressions=Exhibit.ExpressionParser.parseSeveral(s);
  4918. }var query=Exhibit.getAttribute(configElmt,"query");
  4919. if(query!=null&&query.length>0){facet._text=query;
  4920. }}catch(e){SimileAjax.Debug.exception(e,"TextSearchFacet: Error processing configuration of list facet");
  4921. }Exhibit.TextSearchFacet._configure(facet,configuration);
  4922. facet._initializeUI();
  4923. uiContext.getCollection().addFacet(facet);
  4924. return facet;
  4925. };
  4926. Exhibit.TextSearchFacet._configure=function(facet,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.TextSearchFacet._settingSpecs,facet._settings);
  4927. if("expressions" in configuration){for(var i=0;
  4928. i<configuration.expressions.length;
  4929. i++){facet._expressions.push(Exhibit.ExpressionParser.parse(configuration.expressions[i]));
  4930. }}if("selection" in configuration){var selection=configuration.selection;
  4931. for(var i=0;
  4932. i<selection.length;
  4933. i++){facet._valueSet.add(selection[i]);
  4934. }}if("query" in configuration){facet._text=configuration.query;
  4935. }if("queryParamName" in facet._settings){var params=SimileAjax.parseURLParameters();
  4936. if(facet._settings["queryParamName"] in params){facet._text=params[facet._settings["queryParamName"]];
  4937. }}if(!("facetLabel" in facet._settings)){facet._settings.facetLabel="";
  4938. }};
  4939. Exhibit.TextSearchFacet.prototype.dispose=function(){this._uiContext.getCollection().removeFacet(this);
  4940. this._uiContext.getCollection().removeListener(this._listener);
  4941. this._uiContext=null;
  4942. this._div.innerHTML="";
  4943. this._div=null;
  4944. this._dom=null;
  4945. this._expressions=null;
  4946. this._itemToValue=null;
  4947. this._settings=null;
  4948. };
  4949. Exhibit.TextSearchFacet.prototype.hasRestrictions=function(){return this._text!=null;
  4950. };
  4951. Exhibit.TextSearchFacet.prototype.clearAllRestrictions=function(){var restrictions=this._text;
  4952. if(this._text!=null){this._text=null;
  4953. var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4954. this._notifyCollection();
  4955. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4956. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  4957. SimileAjax.RemoteLog.possiblyLog({facetType:"TextSearch",facetLabel:this._settings.facetLabel,operation:"clearAllRestrictions",exhibitSize:totalSize,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize});
  4958. }this._dom.input.value="";
  4959. return restrictions;
  4960. };
  4961. Exhibit.TextSearchFacet.prototype.applyRestrictions=function(restrictions){this.setText(restrictions);
  4962. };
  4963. Exhibit.TextSearchFacet.prototype.setText=function(text){if(text!=null){text=text.trim();
  4964. this._dom.input.value=text;
  4965. text=text.length>0?text:null;
  4966. }else{this._dom.input.value="";
  4967. }if(text!=this._text){this._text=text;
  4968. var preUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4969. this._notifyCollection();
  4970. var postUpdateSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countRestrictedItems():0;
  4971. var totalSize=SimileAjax.RemoteLog.logActive?this._uiContext.getCollection().countAllItems():0;
  4972. SimileAjax.RemoteLog.possiblyLog({facetType:"TextSearch",facetLabel:this._settings.facetLabel,operation:"setText",text:text,exhibitSize:totalSize,preUpdateSize:preUpdateSize,postUpdateSize:postUpdateSize});
  4973. }};
  4974. Exhibit.TextSearchFacet.prototype.restrict=function(items){if(this._text==null){return items;
  4975. }else{this._buildMaps();
  4976. var set=new Exhibit.Set();
  4977. var itemToValue=this._itemToValue;
  4978. var text=this._text.toLowerCase();
  4979. items.visit(function(item){if(item in itemToValue){var values=itemToValue[item];
  4980. for(var v=0;
  4981. v<values.length;
  4982. v++){if(values[v].indexOf(text)>=0){set.add(item);
  4983. break;
  4984. }}}});
  4985. return set;
  4986. }};
  4987. Exhibit.TextSearchFacet.prototype.update=function(items){};
  4988. Exhibit.TextSearchFacet.prototype._notifyCollection=function(){this._uiContext.getCollection().onFacetUpdated(this);
  4989. };
  4990. Exhibit.TextSearchFacet.prototype._initializeUI=function(){var self=this;
  4991. this._dom=Exhibit.TextSearchFacet.constructFacetFrame(this._div,this._settings.facetLabel);
  4992. if(this._text!=null){this._dom.input.value=this._text;
  4993. }SimileAjax.WindowManager.registerEvent(this._dom.input,"keyup",function(elmt,evt,target){self._onTextInputKeyUp(evt);
  4994. });
  4995. };
  4996. Exhibit.TextSearchFacet.constructFacetFrame=function(div,facetLabel){if(facetLabel!==""&&facetLabel!==null){return SimileAjax.DOM.createDOMFromString(div,"<div class='exhibit-facet-header'><span class='exhibit-facet-header-title'>"+facetLabel+"</span></div><div class='exhibit-text-facet'><input type='text' id='input'></div>");
  4997. }else{return SimileAjax.DOM.createDOMFromString(div,"<div class='exhibit-text-facet'><input type='text' id='input'></div>");
  4998. }};
  4999. Exhibit.TextSearchFacet.prototype._onTextInputKeyUp=function(evt){if(this._timerID!=null){window.clearTimeout(this._timerID);
  5000. }var self=this;
  5001. if(this._settings.requiresEnter==false){this._timerID=window.setTimeout(function(){self._onTimeout();
  5002. },500);
  5003. }else{var newText=this._dom.input.value.trim();
  5004. if(newText.length==0||evt.keyCode==13){this._timerID=window.setTimeout(function(){self._onTimeout();
  5005. },0);
  5006. }}};
  5007. Exhibit.TextSearchFacet.prototype._onTimeout=function(){this._timerID=null;
  5008. var newText=this._dom.input.value.trim();
  5009. if(newText.length==0){newText=null;
  5010. }if(newText!=this._text){var self=this;
  5011. var oldText=this._text;
  5012. SimileAjax.History.addLengthyAction(function(){self.setText(newText);
  5013. },function(){self.setText(oldText);
  5014. },newText!=null?String.substitute(Exhibit.FacetUtilities.l10n["facetTextSearchActionTitle"],[newText]):Exhibit.FacetUtilities.l10n["facetClearTextSearchActionTitle"]);
  5015. }};
  5016. Exhibit.TextSearchFacet.prototype._buildMaps=function(){if(!("_itemToValue" in this)){var itemToValue={};
  5017. var allItems=this._uiContext.getCollection().getAllItems();
  5018. var database=this._uiContext.getDatabase();
  5019. if(this._expressions.length>0){var expressions=this._expressions;
  5020. allItems.visit(function(item){var values=[];
  5021. for(var x=0;
  5022. x<expressions.length;
  5023. x++){var expression=expressions[x];
  5024. expression.evaluateOnItem(item,database).values.visit(function(v){values.push(v.toLowerCase());
  5025. });
  5026. }itemToValue[item]=values;
  5027. });
  5028. }else{var propertyIDs=database.getAllProperties();
  5029. allItems.visit(function(item){var values=[];
  5030. for(var p=0;
  5031. p<propertyIDs.length;
  5032. p++){database.getObjects(item,propertyIDs[p]).visit(function(v){values.push(v.toLowerCase());
  5033. });
  5034. }itemToValue[item]=values;
  5035. });
  5036. }this._itemToValue=itemToValue;
  5037. }};
  5038. Exhibit.TextSearchFacet.prototype.exportFacetSelection=function(){return this._text;
  5039. };
  5040. Exhibit.TextSearchFacet.prototype.importFacetSelection=function(settings){this.setText(settings);
  5041. };
  5042. /* format-parser.js */
  5043. Exhibit.FormatParser=new Object();
  5044. Exhibit.FormatParser.parse=function(uiContext,s,startIndex,results){startIndex=startIndex||0;
  5045. results=results||{};
  5046. var scanner=new Exhibit.FormatScanner(s,startIndex);
  5047. try{return Exhibit.FormatParser._internalParse(uiContext,scanner,results,false);
  5048. }finally{results.index=scanner.token()!=null?scanner.token().start:scanner.index();
  5049. }};
  5050. Exhibit.FormatParser.parseSeveral=function(uiContext,s,startIndex,results){startIndex=startIndex||0;
  5051. results=results||{};
  5052. var scanner=new Exhibit.FormatScanner(s,startIndex);
  5053. try{return Exhibit.FormatParser._internalParse(uiContext,scanner,results,true);
  5054. }finally{results.index=scanner.token()!=null?scanner.token().start:scanner.index();
  5055. }};
  5056. Exhibit.FormatParser._valueTypes={"list":true,"number":true,"date":true,"item":true,"text":true,"url":true,"image":true,"currency":true};
  5057. Exhibit.FormatParser._internalParse=function(uiContext,scanner,results,several){var Scanner=Exhibit.FormatScanner;
  5058. var token=scanner.token();
  5059. var next=function(){scanner.next();
  5060. token=scanner.token();
  5061. };
  5062. var makePosition=function(){return token!=null?token.start:scanner.index();
  5063. };
  5064. var enterSetting=function(valueType,settingName,value){uiContext.putSetting("format/"+valueType+"/"+settingName,value);
  5065. };
  5066. var checkKeywords=function(valueType,settingName,keywords){if(token!=null&&token.type!=Scanner.IDENTIFIER&&token.value in keywords){enterSetting(valueType,settingName,keywords[token.value]);
  5067. next();
  5068. return false;
  5069. }return true;
  5070. };
  5071. var parseNumber=function(valueType,settingName,keywords){if(checkKeywords(valueType,settingName,keywords)){if(token==null||token.type!=Scanner.NUMBER){throw new Error("Missing number at position "+makePosition());
  5072. }enterSetting(valueType,settingName,token.value);
  5073. next();
  5074. }};
  5075. var parseInteger=function(valueType,settingName,keywords){if(checkKeywords(valueType,settingName,keywords)){if(token==null||token.type!=Scanner.NUMBER){throw new Error("Missing integer at position "+makePosition());
  5076. }enterSetting(valueType,settingName,Math.round(token.value));
  5077. next();
  5078. }};
  5079. var parseNonnegativeInteger=function(valueType,settingName,keywords){if(checkKeywords(valueType,settingName,keywords)){if(token==null||token.type!=Scanner.NUMBER||token.value<0){throw new Error("Missing non-negative integer at position "+makePosition());
  5080. }enterSetting(valueType,settingName,Math.round(token.value));
  5081. next();
  5082. }};
  5083. var parseString=function(valueType,settingName,keywords){if(checkKeywords(valueType,settingName,keywords)){if(token==null||token.type!=Scanner.STRING){throw new Error("Missing string at position "+makePosition());
  5084. }enterSetting(valueType,settingName,token.value);
  5085. next();
  5086. }};
  5087. var parseURL=function(valueType,settingName,keywords){if(checkKeywords(valueType,settingName,keywords)){if(token==null||token.type!=Scanner.URL){throw new Error("Missing url at position "+makePosition());
  5088. }enterSetting(valueType,settingName,token.value);
  5089. next();
  5090. }};
  5091. var parseExpression=function(valueType,settingName,keywords){if(checkKeywords(valueType,settingName,keywords)){if(token==null||token.type!=Scanner.EXPRESSION){throw new Error("Missing expression at position "+makePosition());
  5092. }enterSetting(valueType,settingName,token.value);
  5093. next();
  5094. }};
  5095. var parseExpressionOrString=function(valueType,settingName,keywords){if(checkKeywords(valueType,settingName,keywords)){if(token==null||(token.type!=Scanner.EXPRESSION&&token.type!=Scanner.STRING)){throw new Error("Missing expression or string at position "+makePosition());
  5096. }enterSetting(valueType,settingName,token.value);
  5097. next();
  5098. }};
  5099. var parseChoices=function(valueType,settingName,choices){if(token==null||token.type!=Scanner.IDENTIFIER){throw new Error("Missing option at position "+makePosition());
  5100. }for(var i=0;
  5101. i<choices.length;
  5102. i++){if(token.value==choices[i]){enterSetting(valueType,settingName,token.value);
  5103. next();
  5104. return ;
  5105. }}throw new Error("Unsupported option "+token.value+" for setting "+settingName+" on value type "+valueType+" found at position "+makePosition());
  5106. };
  5107. var parseFlags=function(valueType,settingName,flags,counterFlags){outer:while(token!=null&&token.type==Scanner.IDENTIFIER){for(var i=0;
  5108. i<flags.length;
  5109. i++){if(token.value==flags[i]){enterSetting(valueType,settingName+"/"+token.value,true);
  5110. next();
  5111. continue outer;
  5112. }}if(token.value in counterFlags){enterSetting(valueType,settingName+"/"+counterFlags[token.value],false);
  5113. next();
  5114. continue outer;
  5115. }throw new Error("Unsupported flag "+token.value+" for setting "+settingName+" on value type "+valueType+" found at position "+makePosition());
  5116. }};
  5117. var parseSetting=function(valueType,settingName){switch(valueType){case"number":switch(settingName){case"decimal-digits":parseNonnegativeInteger(valueType,settingName,{"default":-1});
  5118. return ;
  5119. }break;
  5120. case"date":switch(settingName){case"time-zone":parseNumber(valueType,settingName,{"default":null});
  5121. return ;
  5122. case"show":parseChoices(valueType,settingName,["date","time","date-time"]);
  5123. return ;
  5124. case"mode":parseChoices(valueType,settingName,["short","medium","long","full"]);
  5125. enterSetting(valueType,"template",null);
  5126. return ;
  5127. case"template":parseString(valueType,settingName,{});
  5128. enterSetting(valueType,"mode",null);
  5129. return ;
  5130. }break;
  5131. case"boolean":switch(settingName){}break;
  5132. case"text":switch(settingName){case"max-length":parseInteger(valueType,settingName,{"none":0});
  5133. return ;
  5134. }break;
  5135. case"image":switch(settingName){case"tooltip":parseExpressionOrString(valueType,settingName,{"none":null});
  5136. return ;
  5137. case"max-width":case"max-height":parseInteger(valueType,settingName,{"none":-1});
  5138. return ;
  5139. }break;
  5140. case"url":switch(settingName){case"target":parseString(valueType,settingName,{"none":null});
  5141. return ;
  5142. case"external-icon":parseURL(valueType,settingName,{"none":null});
  5143. return ;
  5144. }break;
  5145. case"item":switch(settingName){case"title":parseExpression(valueType,settingName,{"default":null});
  5146. return ;
  5147. }break;
  5148. case"currency":switch(settingName){case"negative-format":parseFlags(valueType,settingName,["red","parentheses","signed"],{"unsigned":"signed","no-parenthesis":"parentheses","black":"red"});
  5149. return ;
  5150. case"symbol":parseString(valueType,settingName,{"default":"$","none":null});
  5151. return ;
  5152. case"symbol-placement":parseChoices(valueType,settingName,["first","last","after-sign"]);
  5153. return ;
  5154. case"decimal-digits":parseNonnegativeInteger(valueType,settingName,{"default":-1});
  5155. return ;
  5156. }break;
  5157. case"list":switch(settingName){case"separator":case"last-separator":case"pair-separator":case"empty-text":parseString(valueType,settingName,{});
  5158. return ;
  5159. }break;
  5160. }throw new Error("Unsupported setting called "+settingName+" for value type "+valueType+" found at position "+makePosition());
  5161. };
  5162. var parseSettingList=function(valueType){while(token!=null&&token.type==Scanner.IDENTIFIER){var settingName=token.value;
  5163. next();
  5164. if(token==null||token.type!=Scanner.DELIMITER||token.value!=":"){throw new Error("Missing : at position "+makePosition());
  5165. }next();
  5166. parseSetting(valueType,settingName);
  5167. if(token==null||token.type!=Scanner.DELIMITER||token.value!=";"){break;
  5168. }else{next();
  5169. }}};
  5170. var parseRule=function(){if(token==null||token.type!=Scanner.IDENTIFIER){throw new Error("Missing value type at position "+makePosition());
  5171. }var valueType=token.value;
  5172. if(!(valueType in Exhibit.FormatParser._valueTypes)){throw new Error("Unsupported value type "+valueType+" at position "+makePosition());
  5173. }next();
  5174. if(token!=null&&token.type==Scanner.DELIMITER&&token.value=="{"){next();
  5175. parseSettingList(valueType);
  5176. if(token==null||token.type!=Scanner.DELIMITER||token.value!="}"){throw new Error("Missing } at position "+makePosition());
  5177. }next();
  5178. }return valueType;
  5179. };
  5180. var parseRuleList=function(){var valueType="text";
  5181. while(token!=null&&token.type==Scanner.IDENTIFIER){valueType=parseRule();
  5182. }return valueType;
  5183. };
  5184. if(several){return parseRuleList();
  5185. }else{return parseRule();
  5186. }};
  5187. Exhibit.FormatScanner=function(text,startIndex){this._text=text+" ";
  5188. this._maxIndex=text.length;
  5189. this._index=startIndex;
  5190. this.next();
  5191. };
  5192. Exhibit.FormatScanner.DELIMITER=0;
  5193. Exhibit.FormatScanner.NUMBER=1;
  5194. Exhibit.FormatScanner.STRING=2;
  5195. Exhibit.FormatScanner.IDENTIFIER=3;
  5196. Exhibit.FormatScanner.URL=4;
  5197. Exhibit.FormatScanner.EXPRESSION=5;
  5198. Exhibit.FormatScanner.COLOR=6;
  5199. Exhibit.FormatScanner.prototype.token=function(){return this._token;
  5200. };
  5201. Exhibit.FormatScanner.prototype.index=function(){return this._index;
  5202. };
  5203. Exhibit.FormatScanner.prototype.next=function(){this._token=null;
  5204. var self=this;
  5205. var skipSpaces=function(x){while(x<self._maxIndex&&" \t\r\n".indexOf(self._text.charAt(x))>=0){x++;
  5206. }return x;
  5207. };
  5208. this._index=skipSpaces(this._index);
  5209. if(this._index<this._maxIndex){var c1=this._text.charAt(this._index);
  5210. var c2=this._text.charAt(this._index+1);
  5211. if("{}(),:;".indexOf(c1)>=0){this._token={type:Exhibit.FormatScanner.DELIMITER,value:c1,start:this._index,end:this._index+1};
  5212. this._index++;
  5213. }else{if("\"'".indexOf(c1)>=0){var i=this._index+1;
  5214. while(i<this._maxIndex){if(this._text.charAt(i)==c1&&this._text.charAt(i-1)!="\\"){break;
  5215. }i++;
  5216. }if(i<this._maxIndex){this._token={type:Exhibit.FormatScanner.STRING,value:this._text.substring(this._index+1,i).replace(/\\'/g,"'").replace(/\\"/g,'"'),start:this._index,end:i+1};
  5217. this._index=i+1;
  5218. }else{throw new Error("Unterminated string starting at "+this._index);
  5219. }}else{if(c1=="#"){var i=this._index+1;
  5220. while(i<this._maxIndex&&this._isHexDigit(this._text.charAt(i))){i++;
  5221. }this._token={type:Exhibit.FormatScanner.COLOR,value:this._text.substring(this._index,i),start:this._index,end:i};
  5222. this._index=i;
  5223. }else{if(this._isDigit(c1)){var i=this._index;
  5224. while(i<this._maxIndex&&this._isDigit(this._text.charAt(i))){i++;
  5225. }if(i<this._maxIndex&&this._text.charAt(i)=="."){i++;
  5226. while(i<this._maxIndex&&this._isDigit(this._text.charAt(i))){i++;
  5227. }}this._token={type:Exhibit.FormatScanner.NUMBER,value:parseFloat(this._text.substring(this._index,i)),start:this._index,end:i};
  5228. this._index=i;
  5229. }else{var i=this._index;
  5230. while(i<this._maxIndex){var j=this._text.substr(i).search(/\W/);
  5231. if(j>0){i+=j;
  5232. }else{if("-".indexOf(this._text.charAt(i))>=0){i++;
  5233. }else{break;
  5234. }}}var identifier=this._text.substring(this._index,i);
  5235. while(true){if(identifier=="url"){var openParen=skipSpaces(i);
  5236. if(this._text.charAt(openParen)=="("){var closeParen=this._text.indexOf(")",openParen);
  5237. if(closeParen>0){this._token={type:Exhibit.FormatScanner.URL,value:this._text.substring(openParen+1,closeParen),start:this._index,end:closeParen+1};
  5238. this._index=closeParen+1;
  5239. break;
  5240. }else{throw new Error("Missing ) to close url at "+this._index);
  5241. }}}else{if(identifier=="expression"){var openParen=skipSpaces(i);
  5242. if(this._text.charAt(openParen)=="("){var o={};
  5243. var expression=Exhibit.ExpressionParser.parse(this._text,openParen+1,o);
  5244. var closeParen=skipSpaces(o.index);
  5245. if(this._text.charAt(closeParen)==")"){this._token={type:Exhibit.FormatScanner.EXPRESSION,value:expression,start:this._index,end:closeParen+1};
  5246. this._index=closeParen+1;
  5247. break;
  5248. }else{throw new Error("Missing ) to close expression at "+o.index);
  5249. }}}}this._token={type:Exhibit.FormatScanner.IDENTIFIER,value:identifier,start:this._index,end:i};
  5250. this._index=i;
  5251. break;
  5252. }}}}}}};
  5253. Exhibit.FormatScanner.prototype._isDigit=function(c){return"0123456789".indexOf(c)>=0;
  5254. };
  5255. Exhibit.FormatScanner.prototype._isHexDigit=function(c){return"0123456789abcdefABCDEF".indexOf(c)>=0;
  5256. };
  5257. /* formatter.js */
  5258. Exhibit.Formatter=new Object();
  5259. Exhibit.Formatter.createListDelimiter=function(parentElmt,count,uiContext){var separator=uiContext.getSetting("format/list/separator");
  5260. var lastSeparator=uiContext.getSetting("format/list/last-separator");
  5261. var pairSeparator=uiContext.getSetting("format/list/pair-separator");
  5262. if(typeof separator!="string"){separator=Exhibit.Formatter.l10n.listSeparator;
  5263. }if(typeof lastSeparator!="string"){lastSeparator=Exhibit.Formatter.l10n.listLastSeparator;
  5264. }if(typeof pairSeparator!="string"){pairSeparator=Exhibit.Formatter.l10n.listPairSeparator;
  5265. }var f=function(){if(f.index>0&&f.index<count){if(count>2){parentElmt.appendChild(document.createTextNode((f.index==count-1)?lastSeparator:separator));
  5266. }else{parentElmt.appendChild(document.createTextNode(pairSeparator));
  5267. }}f.index++;
  5268. };
  5269. f.index=0;
  5270. return f;
  5271. };
  5272. Exhibit.Formatter._lessThanRegex=/</g;
  5273. Exhibit.Formatter._greaterThanRegex=/>/g;
  5274. Exhibit.Formatter.encodeAngleBrackets=function(s){return s.replace(Exhibit.Formatter._lessThanRegex,"&lt;").replace(Exhibit.Formatter._greaterThanRegex,"&gt;");
  5275. };
  5276. Exhibit.Formatter._ListFormatter=function(uiContext){this._uiContext=uiContext;
  5277. this._separator=uiContext.getSetting("format/list/separator");
  5278. this._lastSeparator=uiContext.getSetting("format/list/last-separator");
  5279. this._pairSeparator=uiContext.getSetting("format/list/pair-separator");
  5280. this._emptyText=uiContext.getSetting("format/list/empty-text");
  5281. if(typeof this._separator!="string"){this._separator=Exhibit.Formatter.l10n.listSeparator;
  5282. }if(typeof this._lastSeparator!="string"){this._lastSeparator=Exhibit.Formatter.l10n.listLastSeparator;
  5283. }if(typeof this._pairSeparator!="string"){this._pairSeparator=Exhibit.Formatter.l10n.listPairSeparator;
  5284. }};
  5285. Exhibit.Formatter._ListFormatter.prototype.formatList=function(values,count,valueType,appender){var uiContext=this._uiContext;
  5286. var self=this;
  5287. if(count==0){if(this._emptyText!=null&&this._emptyText.length>0){appender(document.createTextNode(this._emptyText));
  5288. }}else{if(count==1){values.visit(function(v){uiContext.format(v,valueType,appender);
  5289. });
  5290. }else{var index=0;
  5291. if(count==2){values.visit(function(v){uiContext.format(v,valueType,appender);
  5292. index++;
  5293. if(index==1){appender(document.createTextNode(self._pairSeparator));
  5294. }});
  5295. }else{values.visit(function(v){uiContext.format(v,valueType,appender);
  5296. index++;
  5297. if(index<count){appender(document.createTextNode((index==count-1)?self._lastSeparator:self._separator));
  5298. }});
  5299. }}}};
  5300. Exhibit.Formatter._TextFormatter=function(uiContext){this._maxLength=uiContext.getSetting("format/text/max-length");
  5301. if(typeof this._maxLength=="number"){this._maxLength=Math.max(3,Math.round(this._maxLength));
  5302. }else{this._maxLength=0;
  5303. }};
  5304. Exhibit.Formatter._TextFormatter.prototype.format=function(value,appender){var span=document.createElement("span");
  5305. span.innerHTML=this.formatText(value);
  5306. appender(span);
  5307. };
  5308. Exhibit.Formatter._TextFormatter.prototype.formatText=function(value){if(Exhibit.params.safe){value=Exhibit.Formatter.encodeAngleBrackets(value);
  5309. }if(this._maxLength==0||value.length<=this._maxLength){return value;
  5310. }else{return value.substr(0,this._maxLength)+Exhibit.Formatter.l10n.textEllipsis;
  5311. }};
  5312. Exhibit.Formatter._BooleanFormatter=function(uiContext){};
  5313. Exhibit.Formatter._BooleanFormatter.prototype.format=function(value,appender){var span=document.createElement("span");
  5314. span.innerHTML=this.formatText(value);
  5315. appender(span);
  5316. };
  5317. Exhibit.Formatter._BooleanFormatter.prototype.formatText=function(value){return(typeof value=="boolean"?value:(typeof value=="string"?(value=="true"):false))?Exhibit.Formatter.l10n.booleanTrue:Exhibit.Formatter.l10n.booleanFalse;
  5318. };
  5319. Exhibit.Formatter._NumberFormatter=function(uiContext){this._decimalDigits=uiContext.getSetting("format/number/decimal-digits");
  5320. if(typeof this._decimalDigits=="number"){this._decimalDigits=Math.max(-1,Math.round(this._decimalDigits));
  5321. }else{this._decimalDigits=-1;
  5322. }};
  5323. Exhibit.Formatter._NumberFormatter.prototype.format=function(value,appender){appender(document.createTextNode(this.formatText(value)));
  5324. };
  5325. Exhibit.Formatter._NumberFormatter.prototype.formatText=function(value){if(this._decimalDigits==-1){return value.toString();
  5326. }else{return new Number(value).toFixed(this._decimalDigits);
  5327. }};
  5328. Exhibit.Formatter._ImageFormatter=function(uiContext){this._uiContext=uiContext;
  5329. this._maxWidth=uiContext.getSetting("format/image/max-width");
  5330. if(typeof this._maxWidth=="number"){this._maxWidth=Math.max(-1,Math.round(this._maxWidth));
  5331. }else{this._maxWidth=-1;
  5332. }this._maxHeight=uiContext.getSetting("format/image/max-height");
  5333. if(typeof this._maxHeight=="number"){this._maxHeight=Math.max(-1,Math.round(this._maxHeight));
  5334. }else{this._maxHeight=-1;
  5335. }this._tooltip=uiContext.getSetting("format/image/tooltip");
  5336. };
  5337. Exhibit.Formatter._ImageFormatter.prototype.format=function(value,appender){if(Exhibit.params.safe){value=value.trim().startsWith("javascript:")?"":value;
  5338. }var img=document.createElement("img");
  5339. img.src=value;
  5340. if(this._tooltip!=null){if(typeof this._tooltip=="string"){img.title=this._tootlip;
  5341. }else{img.title=this._tooltip.evaluateSingleOnItem(this._uiContext.getSetting("itemID"),this._uiContext.getDatabase()).value;
  5342. }}appender(img);
  5343. };
  5344. Exhibit.Formatter._ImageFormatter.prototype.formatText=function(value){return value;
  5345. };
  5346. Exhibit.Formatter._URLFormatter=function(uiContext){this._target=uiContext.getSetting("format/url/target");
  5347. this._externalIcon=uiContext.getSetting("format/url/external-icon");
  5348. };
  5349. Exhibit.Formatter._URLFormatter.prototype.format=function(value,appender){var a=document.createElement("a");
  5350. a.href=value;
  5351. a.innerHTML=value;
  5352. if(this._target!=null){a.target=this._target;
  5353. }if(this._externalIcon!=null){}appender(a);
  5354. };
  5355. Exhibit.Formatter._URLFormatter.prototype.formatText=function(value){if(Exhibit.params.safe){value=value.trim().startsWith("javascript:")?"":value;
  5356. }return value;
  5357. };
  5358. Exhibit.Formatter._CurrencyFormatter=function(uiContext){this._decimalDigits=uiContext.getSetting("format/currency/decimal-digits");
  5359. if(typeof this._decimalDigits=="number"){this._decimalDigits=Math.max(-1,Math.round(this._decimalDigits));
  5360. }else{this._decimalDigits=2;
  5361. }this._symbol=uiContext.getSetting("format/currency/symbol");
  5362. if(this._symbol==null){this._symbol=Exhibit.Formatter.l10n.currencySymbol;
  5363. }this._symbolPlacement=uiContext.getSetting("format/currency/symbol-placement");
  5364. if(this._symbolPlacement==null){this._symbol=Exhibit.Formatter.l10n.currencySymbolPlacement;
  5365. }this._negativeFormat={signed:uiContext.getBooleanSetting("format/currency/negative-format/signed",Exhibit.Formatter.l10n.currencyShowSign),red:uiContext.getBooleanSetting("format/currency/negative-format/red",Exhibit.Formatter.l10n.currencyShowRed),parentheses:uiContext.getBooleanSetting("format/currency/negative-format/parentheses",Exhibit.Formatter.l10n.currencyShowParentheses)};
  5366. };
  5367. Exhibit.Formatter._CurrencyFormatter.prototype.format=function(value,appender){var text=this.formatText(value);
  5368. if(value<0&&this._negativeFormat.red){var span=document.createElement("span");
  5369. span.innerHTML=text;
  5370. span.style.color="red";
  5371. appender(span);
  5372. }else{appender(document.createTextNode(text));
  5373. }};
  5374. Exhibit.Formatter._CurrencyFormatter.prototype.formatText=function(value){var negative=value<0;
  5375. var text;
  5376. if(this._decimalDigits==-1){text=Math.abs(value);
  5377. }else{text=new Number(Math.abs(value)).toFixed(this._decimalDigits);
  5378. }var sign=(negative&&this._negativeFormat.signed)?"-":"";
  5379. if(negative&&this._negativeFormat.parentheses){text="("+text+")";
  5380. }switch(this._negativeFormat){case"first":text=this._symbol+sign+text;
  5381. break;
  5382. case"after-sign":text=sign+this._symbol+text;
  5383. break;
  5384. case"last":text=sign+text+this._symbol;
  5385. break;
  5386. }return text;
  5387. };
  5388. Exhibit.Formatter._ItemFormatter=function(uiContext){this._uiContext=uiContext;
  5389. this._title=uiContext.getSetting("format/item/title");
  5390. };
  5391. Exhibit.Formatter._ItemFormatter.prototype.format=function(value,appender){var self=this;
  5392. var title=this.formatText(value);
  5393. var a=SimileAjax.DOM.createElementFromString('<a href="'+Exhibit.Persistence.getItemLink(value)+"\" class='exhibit-item'>"+title+"</a>");
  5394. var handler=function(elmt,evt,target){Exhibit.UI.showItemInPopup(value,elmt,self._uiContext);
  5395. };
  5396. SimileAjax.WindowManager.registerEvent(a,"click",handler,this._uiContext.getSetting("layer"));
  5397. appender(a);
  5398. };
  5399. Exhibit.Formatter._ItemFormatter.prototype.formatText=function(value){var database=this._uiContext.getDatabase();
  5400. var title=null;
  5401. if(this._title==null){title=database.getObject(value,"label");
  5402. }else{title=this._title.evaluateSingleOnItem(value,database).value;
  5403. }if(title==null){title=value;
  5404. }return title;
  5405. };
  5406. Exhibit.Formatter._DateFormatter=function(uiContext){this._timeZone=uiContext.getSetting("format/date/time-zone");
  5407. if(!(typeof this._timeZone=="number")){this._timeZone=-(new Date().getTimezoneOffset())/60;
  5408. }this._timeZoneOffset=this._timeZone*3600000;
  5409. var mode=uiContext.getSetting("format/date/mode");
  5410. var show=uiContext.getSetting("format/date/show");
  5411. var template=null;
  5412. switch(mode){case"short":template=show=="date"?Exhibit.Formatter.l10n.dateShortFormat:(show=="time"?Exhibit.Formatter.l10n.timeShortFormat:Exhibit.Formatter.l10n.dateTimeShortFormat);
  5413. break;
  5414. case"medium":template=show=="date"?Exhibit.Formatter.l10n.dateMediumFormat:(show=="time"?Exhibit.Formatter.l10n.timeMediumFormat:Exhibit.Formatter.l10n.dateTimeMediumFormat);
  5415. break;
  5416. case"long":template=show=="date"?Exhibit.Formatter.l10n.dateLongFormat:(show=="time"?Exhibit.Formatter.l10n.timeLongFormat:Exhibit.Formatter.l10n.dateTimeLongFormat);
  5417. break;
  5418. case"full":template=show=="date"?Exhibit.Formatter.l10n.dateFullFormat:(show=="time"?Exhibit.Formatter.l10n.timeFullFormat:Exhibit.Formatter.l10n.dateTimeFullFormat);
  5419. break;
  5420. default:template=uiContext.getSetting("format/date/template");
  5421. }if(typeof template!="string"){template=Exhibit.Formatter.l10n.dateTimeDefaultFormat;
  5422. }var segments=[];
  5423. var placeholders=template.match(/\b\w+\b/g);
  5424. var startIndex=0;
  5425. for(var p=0;
  5426. p<placeholders.length;
  5427. p++){var placeholder=placeholders[p];
  5428. var index=template.indexOf(placeholder,startIndex);
  5429. if(index>startIndex){segments.push(template.substring(startIndex,index));
  5430. }var retriever=Exhibit.Formatter._DateFormatter._retrievers[placeholder];
  5431. if(typeof retriever=="function"){segments.push(retriever);
  5432. }else{segments.push(placeholder);
  5433. }startIndex=index+placeholder.length;
  5434. }if(startIndex<template.length){segments.push(template.substr(startIndex));
  5435. }this._segments=segments;
  5436. };
  5437. Exhibit.Formatter._DateFormatter.prototype.format=function(value,appender){appender(document.createTextNode(this.formatText(value)));
  5438. };
  5439. Exhibit.Formatter._DateFormatter.prototype.formatText=function(value){var date=(value instanceof Date)?value:SimileAjax.DateTime.parseIso8601DateTime(value);
  5440. if(date==null){return value;
  5441. }date.setTime(date.getTime()+this._timeZoneOffset);
  5442. var text="";
  5443. var segments=this._segments;
  5444. for(var i=0;
  5445. i<segments.length;
  5446. i++){var segment=segments[i];
  5447. if(typeof segment=="string"){text+=segment;
  5448. }else{text+=segment(date);
  5449. }}return text;
  5450. };
  5451. Exhibit.Formatter._DateFormatter._pad=function(n){return n<10?("0"+n):n.toString();
  5452. };
  5453. Exhibit.Formatter._DateFormatter._pad3=function(n){return n<10?("00"+n):(n<100?("0"+n):n.toString());
  5454. };
  5455. Exhibit.Formatter._DateFormatter._retrievers={"d":function(date){return date.getUTCDate().toString();
  5456. },"dd":function(date){return Exhibit.Formatter._DateFormatter._pad(date.getUTCDate());
  5457. },"EEE":function(date){return Exhibit.Formatter.l10n.shortDaysOfWeek[date.getUTCDay()];
  5458. },"EEEE":function(date){return Exhibit.Formatter.l10n.daysOfWeek[date.getUTCDay()];
  5459. },"MM":function(date){return Exhibit.Formatter._DateFormatter._pad(date.getUTCMonth()+1);
  5460. },"MMM":function(date){return Exhibit.Formatter.l10n.shortMonths[date.getUTCMonth()];
  5461. },"MMMM":function(date){return Exhibit.Formatter.l10n.months[date.getUTCMonth()];
  5462. },"yy":function(date){return Exhibit.Formatter._DateFormatter._pad(date.getUTCFullYear()%100);
  5463. },"yyyy":function(date){var y=date.getUTCFullYear();
  5464. return y>0?y.toString():(1-y);
  5465. },"G":function(date){var y=date.getUTCYear();
  5466. return y>0?Exhibit.Formatter.l10n.commonEra:Exhibit.Formatter.l10n.beforeCommonEra;
  5467. },"HH":function(date){return Exhibit.Formatter._DateFormatter._pad(date.getUTCHours());
  5468. },"hh":function(date){var h=date.getUTCHours();
  5469. return Exhibit.Formatter._DateFormatter._pad(h==0?12:(h>12?h-12:h));
  5470. },"h":function(date){var h=date.getUTCHours();
  5471. return(h==0?12:(h>12?h-12:h)).toString();
  5472. },"a":function(date){return date.getUTCHours()<12?Exhibit.Formatter.l10n.beforeNoon:Exhibit.Formatter.l10n.afterNoon;
  5473. },"A":function(date){return date.getUTCHours()<12?Exhibit.Formatter.l10n.BeforeNoon:Exhibit.Formatter.l10n.AfterNoon;
  5474. },"mm":function(date){return Exhibit.Formatter._DateFormatter._pad(date.getUTCMinutes());
  5475. },"ss":function(date){return Exhibit.Formatter._DateFormatter._pad(date.getUTCSeconds());
  5476. },"S":function(date){return Exhibit.Formatter._DateFormatter._pad3(date.getUTCMilliseconds());
  5477. }};
  5478. Exhibit.Formatter._constructors={"number":Exhibit.Formatter._NumberFormatter,"date":Exhibit.Formatter._DateFormatter,"text":Exhibit.Formatter._TextFormatter,"boolean":Exhibit.Formatter._BooleanFormatter,"image":Exhibit.Formatter._ImageFormatter,"url":Exhibit.Formatter._URLFormatter,"item":Exhibit.Formatter._ItemFormatter,"currency":Exhibit.Formatter._CurrencyFormatter};
  5479. /* lens.js */
  5480. Exhibit.LensRegistry=function(parentRegistry){this._parentRegistry=parentRegistry;
  5481. this._defaultLens=null;
  5482. this._typeToLens={};
  5483. this._editLensTemplates={};
  5484. this._submissionLensTemplates={};
  5485. this._lensSelectors=[];
  5486. };
  5487. Exhibit.LensRegistry.prototype.registerDefaultLens=function(elmtOrURL){this._defaultLens=(typeof elmtOrURL=="string")?elmtOrURL:elmtOrURL.cloneNode(true);
  5488. };
  5489. Exhibit.LensRegistry.prototype.registerLensForType=function(elmtOrURL,type){if(typeof elmtOrURL=="string"){this._typeToLens[type]=elmtOrURL;
  5490. }var role=Exhibit.getRoleAttribute(elmtOrURL);
  5491. if(role=="lens"){this._typeToLens[type]=elmtOrURL.cloneNode(true);
  5492. }else{if(role=="edit-lens"){this._editLensTemplates[type]=elmtOrURL.cloneNode(true);
  5493. }else{if(role=="submission-lens"){this._submissionLensTemplates[type]=elmtOrURL.cloneNode(true);
  5494. }else{SimileAjax.Debug.warn("Unknown lens type "+elmtOrURL);
  5495. }}}};
  5496. Exhibit.LensRegistry.prototype.addLensSelector=function(lensSelector){this._lensSelectors.unshift(lensSelector);
  5497. };
  5498. Exhibit.LensRegistry.prototype.getLens=function(itemID,uiContext){return uiContext.isBeingEdited(itemID)?this.getEditLens(itemID,uiContext):this.getNormalLens(itemID,uiContext);
  5499. };
  5500. Exhibit.LensRegistry.prototype.getNormalLens=function(itemID,uiContext){var db=uiContext.getDatabase();
  5501. for(var i=0;
  5502. i<this._lensSelectors.length;
  5503. i++){var lens=this._lensSelectors[i](itemID,db);
  5504. if(lens!=null){return lens;
  5505. }}var type=db.getObject(itemID,"type");
  5506. if(type in this._typeToLens){return this._typeToLens[type];
  5507. }if(this._defaultLens!=null){return this._defaultLens;
  5508. }if(this._parentRegistry){return this._parentRegistry.getLens(itemID,uiContext);
  5509. }return null;
  5510. };
  5511. Exhibit.LensRegistry.prototype.getEditLens=function(itemID,uiContext){var type=uiContext.getDatabase().getObject(itemID,"type");
  5512. if(type in this._editLensTemplates){return this._editLensTemplates[type];
  5513. }else{return this._parentRegistry&&this._parentRegistry.getEditLens(itemID,uiContext);
  5514. }};
  5515. Exhibit.LensRegistry.prototype.createLens=function(itemID,div,uiContext,opts){var lens=new Exhibit.Lens();
  5516. if(uiContext.getDatabase().isNewItem(itemID)){SimileAjax.jQuery(div).addClass("newItem");
  5517. }opts=opts||{};
  5518. var lensTemplate=opts.lensTemplate||this.getLens(itemID,uiContext);
  5519. if(lensTemplate==null){lens._constructDefaultUI(itemID,div,uiContext);
  5520. }else{if(typeof lensTemplate=="string"){lens._constructFromLensTemplateURL(itemID,div,uiContext,lensTemplate,opts);
  5521. }else{lens._constructFromLensTemplateDOM(itemID,div,uiContext,lensTemplate,opts);
  5522. }}return lens;
  5523. };
  5524. Exhibit.LensRegistry.prototype.createEditLens=function(itemID,div,uiContext,opts){opts=opts||{};
  5525. opts.lensTemplate=this.getEditLens(itemID,uiContext);
  5526. return this.createLens(itemID,div,uiContext,opts);
  5527. };
  5528. Exhibit.LensRegistry.prototype.createNormalLens=function(itemID,div,uiContext,opts){opts=opts||{};
  5529. opts.lensTemplate=this.getNormalLens(itemID,uiContext);
  5530. return this.createLens(itemID,div,uiContext,opts);
  5531. };
  5532. Exhibit.Lens=function(){};
  5533. Exhibit.Lens._commonProperties=null;
  5534. Exhibit.Lens.prototype._constructDefaultUI=function(itemID,div,uiContext){var database=uiContext.getDatabase();
  5535. if(Exhibit.Lens._commonProperties==null){Exhibit.Lens._commonProperties=database.getAllProperties();
  5536. }var properties=Exhibit.Lens._commonProperties;
  5537. var label=database.getObject(itemID,"label");
  5538. label=label!=null?label:itemID;
  5539. if(Exhibit.params.safe){label=Exhibit.Formatter.encodeAngleBrackets(label);
  5540. }var template={elmt:div,className:"exhibit-lens",children:[{tag:"div",className:"exhibit-lens-title",title:label,children:[label+" (",{tag:"a",href:Exhibit.Persistence.getItemLink(itemID),target:"_blank",children:[Exhibit.l10n.itemLinkLabel]},")"]},{tag:"div",className:"exhibit-lens-body",children:[{tag:"table",className:"exhibit-lens-properties",field:"propertiesTable"}]}]};
  5541. var dom=SimileAjax.DOM.createDOMFromTemplate(template);
  5542. div.setAttribute("ex:itemID",itemID);
  5543. var pairs=Exhibit.ViewPanel.getPropertyValuesPairs(itemID,properties,database);
  5544. for(var j=0;
  5545. j<pairs.length;
  5546. j++){var pair=pairs[j];
  5547. var tr=dom.propertiesTable.insertRow(j);
  5548. tr.className="exhibit-lens-property";
  5549. var tdName=tr.insertCell(0);
  5550. tdName.className="exhibit-lens-property-name";
  5551. tdName.innerHTML=pair.propertyLabel+": ";
  5552. var tdValues=tr.insertCell(1);
  5553. tdValues.className="exhibit-lens-property-values";
  5554. if(pair.valueType=="item"){for(var m=0;
  5555. m<pair.values.length;
  5556. m++){if(m>0){tdValues.appendChild(document.createTextNode(", "));
  5557. }tdValues.appendChild(Exhibit.UI.makeItemSpan(pair.values[m],null,uiContext));
  5558. }}else{for(var m=0;
  5559. m<pair.values.length;
  5560. m++){if(m>0){tdValues.appendChild(document.createTextNode(", "));
  5561. }tdValues.appendChild(Exhibit.UI.makeValueSpan(pair.values[m],pair.valueType));
  5562. }}}};
  5563. Exhibit.Lens.prototype._constructDefaultEditingUI=function(itemID,div,uiContext){};
  5564. Exhibit.Lens._compiledTemplates={};
  5565. Exhibit.Lens._handlers=["onblur","onfocus","onkeydown","onkeypress","onkeyup","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onclick","onresize","onscroll"];
  5566. Exhibit.Lens.prototype._constructFromLensTemplateURL=function(itemID,div,uiContext,lensTemplateURL){var job={lens:this,itemID:itemID,div:div,uiContext:uiContext,opts:opts};
  5567. var compiledTemplate=Exhibit.Lens._compiledTemplates[lensTemplateURL];
  5568. if(compiledTemplate==null){Exhibit.Lens._startCompilingTemplate(lensTemplateURL,job);
  5569. }else{if(!compiledTemplate.compiled){compiledTemplate.jobs.push(job);
  5570. }else{job.template=compiledTemplate;
  5571. Exhibit.Lens._performConstructFromLensTemplateJob(job);
  5572. }}};
  5573. Exhibit.Lens.prototype._constructFromLensTemplateDOM=function(itemID,div,uiContext,lensTemplateNode,opts){var job={lens:this,itemID:itemID,div:div,uiContext:uiContext,opts:opts};
  5574. var id=lensTemplateNode.id;
  5575. if(id==null||id.length==0){id="exhibitLensTemplate"+Math.floor(Math.random()*10000);
  5576. lensTemplateNode.id=id;
  5577. }var compiledTemplate=Exhibit.Lens._compiledTemplates[id];
  5578. if(compiledTemplate==null){compiledTemplate={url:id,template:Exhibit.Lens.compileTemplate(lensTemplateNode,false,uiContext),compiled:true,jobs:[]};
  5579. Exhibit.Lens._compiledTemplates[id]=compiledTemplate;
  5580. }job.template=compiledTemplate;
  5581. Exhibit.Lens._performConstructFromLensTemplateJob(job);
  5582. };
  5583. Exhibit.Lens._startCompilingTemplate=function(lensTemplateURL,job){var compiledTemplate={url:lensTemplateURL,template:null,compiled:false,jobs:[job]};
  5584. Exhibit.Lens._compiledTemplates[lensTemplateURL]=compiledTemplate;
  5585. var fError=function(statusText,status,xmlhttp){SimileAjax.Debug.log("Failed to load view template from "+lensTemplateURL+"\n"+statusText);
  5586. };
  5587. var fDone=function(xmlhttp){try{compiledTemplate.template=Exhibit.Lens.compileTemplate(xmlhttp.responseXML.documentElement,true,job.uiContext);
  5588. compiledTemplate.compiled=true;
  5589. for(var i=0;
  5590. i<compiledTemplate.jobs.length;
  5591. i++){try{var job2=compiledTemplate.jobs[i];
  5592. job2.template=compiledTemplate;
  5593. Exhibit.Lens._performConstructFromLensTemplateJob(job2);
  5594. }catch(e){SimileAjax.Debug.exception(e,"Lens: Error constructing lens template in job queue");
  5595. }}compiledTemplate.jobs=null;
  5596. }catch(e){SimileAjax.Debug.exception(e,"Lens: Error compiling lens template and processing template job queue");
  5597. }};
  5598. SimileAjax.XmlHttp.get(lensTemplateURL,fError,fDone);
  5599. return compiledTemplate;
  5600. };
  5601. Exhibit.Lens.compileTemplate=function(rootNode,isXML,uiContext){return Exhibit.Lens._processTemplateNode(rootNode,isXML,uiContext);
  5602. };
  5603. Exhibit.Lens._processTemplateNode=function(node,isXML,uiContext){if(node.nodeType==1){return Exhibit.Lens._processTemplateElement(node,isXML,uiContext);
  5604. }else{return node.nodeValue||"";
  5605. }};
  5606. Exhibit.Lens._processTemplateElement=function(elmt,isXML,uiContext){var templateNode={tag:elmt.tagName.toLowerCase()||"span",uiContext:uiContext,control:null,condition:null,content:null,contentAttributes:null,subcontentAttributes:null,attributes:[],styles:[],handlers:[],children:null};
  5607. var settings={parseChildTextNodes:true};
  5608. var attributes=elmt.attributes;
  5609. for(var i=0;
  5610. i<attributes.length;
  5611. i++){var attribute=attributes[i];
  5612. var name=attribute.nodeName;
  5613. var value=attribute.nodeValue;
  5614. Exhibit.Lens._processTemplateAttribute(uiContext,templateNode,settings,name,value);
  5615. }if(!isXML&&SimileAjax.Platform.browser.isIE){var handlers=Exhibit.Lens._handlers;
  5616. for(var h=0;
  5617. h<handlers.length;
  5618. h++){var handler=handlers[h];
  5619. var code=elmt[handler];
  5620. if(code!=null){templateNode.handlers.push({name:handler,code:code});
  5621. }}}var childNode=elmt.firstChild;
  5622. if(childNode!=null){templateNode.children=[];
  5623. while(childNode!=null){if((settings.parseChildTextNodes&&childNode.nodeType==3)||childNode.nodeType==1){templateNode.children.push(Exhibit.Lens._processTemplateNode(childNode,isXML,templateNode.uiContext));
  5624. }childNode=childNode.nextSibling;
  5625. }}return templateNode;
  5626. };
  5627. Exhibit.Lens._processTemplateAttribute=function(uiContext,templateNode,settings,name,value){if(value==null||typeof value!="string"||value.length==0||name=="contentEditable"){return ;
  5628. }if(name.length>3&&name.substr(0,3)=="ex:"){name=name.substr(3);
  5629. if(name=="formats"){templateNode.uiContext=Exhibit.UIContext._createWithParent(uiContext);
  5630. Exhibit.FormatParser.parseSeveral(templateNode.uiContext,value,0,{});
  5631. }else{if(name=="onshow"){templateNode.attributes.push({name:name,value:value});
  5632. }else{if(name=="control"){templateNode.control=value;
  5633. }else{if(name=="content"){templateNode.content=Exhibit.ExpressionParser.parse(value);
  5634. templateNode.attributes.push({name:"ex:content",value:value});
  5635. }else{if(name=="editor"){templateNode.attributes.push({name:"ex:editor",value:value});
  5636. }else{if(name=="edit"){templateNode.edit=value;
  5637. }else{if(name=="options"){templateNode.options=value;
  5638. }else{if(name=="editvalues"){templateNode.editValues=value;
  5639. }else{if(name=="tag"){templateNode.tag=value;
  5640. }else{if(name=="if-exists"){templateNode.condition={test:"if-exists",expression:Exhibit.ExpressionParser.parse(value)};
  5641. }else{if(name=="if"){templateNode.condition={test:"if",expression:Exhibit.ExpressionParser.parse(value)};
  5642. settings.parseChildTextNodes=false;
  5643. }else{if(name=="select"){templateNode.condition={test:"select",expression:Exhibit.ExpressionParser.parse(value)};
  5644. }else{if(name=="case"){templateNode.condition={test:"case",value:value};
  5645. settings.parseChildTextNodes=false;
  5646. }else{var isStyle=false;
  5647. var x=name.indexOf("-style-content");
  5648. if(x>0){isStyle=true;
  5649. }else{x=name.indexOf("-content");
  5650. }if(x>0){if(templateNode.contentAttributes==null){templateNode.contentAttributes=[];
  5651. }templateNode.contentAttributes.push({name:name.substr(0,x),expression:Exhibit.ExpressionParser.parse(value),isStyle:isStyle,isSingle:name.substr(0,x) in {href:1,src:1}});
  5652. }else{x=name.indexOf("-style-subcontent");
  5653. if(x>0){isStyle=true;
  5654. }else{x=name.indexOf("-subcontent");
  5655. }if(x>0){if(templateNode.subcontentAttributes==null){templateNode.subcontentAttributes=[];
  5656. }templateNode.subcontentAttributes.push({name:name.substr(0,x),fragments:Exhibit.Lens._parseSubcontentAttribute(value),isStyle:isStyle});
  5657. }}}}}}}}}}}}}}}}else{if(name=="style"){Exhibit.Lens._processStyle(templateNode,value);
  5658. }else{if(name!="id"){if(name=="class"){if(SimileAjax.Platform.browser.isIE&&SimileAjax.Platform.browser.majorVersion<8){name="className";
  5659. }}else{if(name=="cellspacing"){name="cellSpacing";
  5660. }else{if(name=="cellpadding"){name="cellPadding";
  5661. }else{if(name=="bgcolor"){name="bgColor";
  5662. }}}}templateNode.attributes.push({name:name,value:value});
  5663. }}}};
  5664. Exhibit.Lens._processStyle=function(templateNode,styleValue){var styles=styleValue.split(";");
  5665. for(var s=0;
  5666. s<styles.length;
  5667. s++){var pair=styles[s].split(":");
  5668. if(pair.length>1){var n=pair[0].trim();
  5669. var v=pair[1].trim();
  5670. if(n=="float"){n=SimileAjax.Platform.browser.isIE?"styleFloat":"cssFloat";
  5671. }else{if(n=="-moz-opacity"){n="MozOpacity";
  5672. }else{if(n.indexOf("-")>0){var segments=n.split("-");
  5673. n=segments[0];
  5674. for(var x=1;
  5675. x<segments.length;
  5676. x++){n+=segments[x].substr(0,1).toUpperCase()+segments[x].substr(1);
  5677. }}}}templateNode.styles.push({name:n,value:v});
  5678. }}};
  5679. Exhibit.Lens._parseSubcontentAttribute=function(value){var fragments=[];
  5680. var current=0;
  5681. var open;
  5682. while(current<value.length&&(open=value.indexOf("{{",current))>=0){var close=value.indexOf("}}",open);
  5683. if(close<0){break;
  5684. }fragments.push(value.substring(current,open));
  5685. fragments.push(Exhibit.ExpressionParser.parse(value.substring(open+2,close)));
  5686. current=close+2;
  5687. }if(current<value.length){fragments.push(value.substr(current));
  5688. }return fragments;
  5689. };
  5690. Exhibit.Lens.constructFromLensTemplate=function(itemID,templateNode,parentElmt,uiContext,opts){return Exhibit.Lens._performConstructFromLensTemplateJob({itemID:itemID,template:{template:templateNode},div:parentElmt,uiContext:uiContext,opts:opts});
  5691. };
  5692. Exhibit.Lens._performConstructFromLensTemplateJob=function(job){Exhibit.Lens._constructFromLensTemplateNode({"value":job.itemID},{"value":"item"},job.template.template,job.div,job.opts);
  5693. var node=job.div.tagName.toLowerCase()=="table"?job.div.rows[job.div.rows.length-1]:job.div.lastChild;
  5694. SimileAjax.jQuery(node).show();
  5695. node.setAttribute("ex:itemID",job.itemID);
  5696. if(!Exhibit.params.safe){var onshow=Exhibit.getAttribute(node,"onshow");
  5697. if(onshow!=null&&onshow.length>0){try{(new Function(onshow)).call(node);
  5698. }catch(e){SimileAjax.Debug.log(e);
  5699. }}}return node;
  5700. };
  5701. Exhibit.Lens._constructFromLensTemplateNode=function(roots,rootValueTypes,templateNode,parentElmt,opts){if(typeof templateNode=="string"){parentElmt.appendChild(document.createTextNode(templateNode));
  5702. return ;
  5703. }var uiContext=templateNode.uiContext;
  5704. var database=uiContext.getDatabase();
  5705. var children=templateNode.children;
  5706. function processChildren(){if(children!=null){for(var i=0;
  5707. i<children.length;
  5708. i++){Exhibit.Lens._constructFromLensTemplateNode(roots,rootValueTypes,children[i],elmt,opts);
  5709. }}}if(templateNode.condition!=null){if(templateNode.condition.test=="if-exists"){if(!templateNode.condition.expression.testExists(roots,rootValueTypes,"value",database)){return ;
  5710. }}else{if(templateNode.condition.test=="if"){if(templateNode.condition.expression.evaluate(roots,rootValueTypes,"value",database).values.contains(true)){if(children!=null&&children.length>0){Exhibit.Lens._constructFromLensTemplateNode(roots,rootValueTypes,children[0],parentElmt,opts);
  5711. }}else{if(children!=null&&children.length>1){Exhibit.Lens._constructFromLensTemplateNode(roots,rootValueTypes,children[1],parentElmt,opts);
  5712. }}return ;
  5713. }else{if(templateNode.condition.test=="select"){var values=templateNode.condition.expression.evaluate(roots,rootValueTypes,"value",database).values;
  5714. if(children!=null){var lastChildTemplateNode=null;
  5715. for(var c=0;
  5716. c<children.length;
  5717. c++){var childTemplateNode=children[c];
  5718. if(childTemplateNode.condition!=null&&childTemplateNode.condition.test=="case"){if(values.contains(childTemplateNode.condition.value)){Exhibit.Lens._constructFromLensTemplateNode(roots,rootValueTypes,childTemplateNode,parentElmt,opts);
  5719. return ;
  5720. }}else{if(typeof childTemplateNode!="string"){lastChildTemplateNode=childTemplateNode;
  5721. }}}}if(lastChildTemplateNode!=null){Exhibit.Lens._constructFromLensTemplateNode(roots,rootValueTypes,lastChildTemplateNode,parentElmt,opts);
  5722. }return ;
  5723. }}}}var elmt=Exhibit.Lens._constructElmtWithAttributes(templateNode,parentElmt,database);
  5724. if(templateNode.contentAttributes!=null){var contentAttributes=templateNode.contentAttributes;
  5725. for(var i=0;
  5726. i<contentAttributes.length;
  5727. i++){var attribute=contentAttributes[i];
  5728. var values=[];
  5729. attribute.expression.evaluate(roots,rootValueTypes,"value",database).values.visit(function(v){values.push(v);
  5730. });
  5731. var value=attribute.isSingle?values[0]||"":values.join(";");
  5732. if(attribute.isStyle){elmt.style[attribute.name]=value;
  5733. }else{if("class"==attribute.name){elmt.className=value;
  5734. }else{if(Exhibit.Lens._attributeValueIsSafe(attribute.name,value)){elmt.setAttribute(attribute.name,value);
  5735. }}}}}if(templateNode.subcontentAttributes!=null){var subcontentAttributes=templateNode.subcontentAttributes;
  5736. for(var i=0;
  5737. i<subcontentAttributes.length;
  5738. i++){var attribute=subcontentAttributes[i];
  5739. var fragments=attribute.fragments;
  5740. var results="";
  5741. for(var r=0;
  5742. r<fragments.length;
  5743. r++){var fragment=fragments[r];
  5744. if(typeof fragment=="string"){results+=fragment;
  5745. }else{results+=fragment.evaluateSingle(roots,rootValueTypes,"value",database).value;
  5746. }}if(attribute.isStyle){elmt.style[attribute.name]=results;
  5747. }else{if("class"==attribute.name){elmt.className=results;
  5748. }else{if(Exhibit.Lens._attributeValueIsSafe(attribute.name,results)){elmt.setAttribute(attribute.name,results);
  5749. }}}}}if(!Exhibit.params.safe){var handlers=templateNode.handlers;
  5750. for(var h=0;
  5751. h<handlers.length;
  5752. h++){var handler=handlers[h];
  5753. elmt[handler.name]=handler.code;
  5754. }}var itemID=roots["value"];
  5755. if(templateNode.control!=null){switch(templateNode.control){case"item-link":var a=document.createElement("a");
  5756. a.innerHTML=Exhibit.l10n.itemLinkLabel;
  5757. a.href=Exhibit.Persistence.getItemLink(itemID);
  5758. a.target="_blank";
  5759. elmt.appendChild(a);
  5760. break;
  5761. case"remove-item":if(!opts.disableEditWidgets&&database.isNewItem(itemID)){if(templateNode.tag=="a"){elmt.href="javascript:";
  5762. }SimileAjax.jQuery(elmt).click(function(){database.removeItem(itemID);
  5763. });
  5764. processChildren();
  5765. }else{parentElmt.removeChild(elmt);
  5766. }break;
  5767. case"start-editing":if(templateNode.tag=="a"){elmt.href="javascript:";
  5768. }if(opts.disableEditWidgets){parentElmt.removeChild(elmt);
  5769. }else{if(opts.inPopup){SimileAjax.jQuery(elmt).click(function(){Exhibit.UI.showItemInPopup(itemID,null,uiContext,{lensType:"edit",coords:opts.coords});
  5770. });
  5771. processChildren();
  5772. }else{SimileAjax.jQuery(elmt).click(function(){uiContext.setEditMode(itemID,true);
  5773. uiContext.getCollection()._listeners.fire("onItemsChanged",[]);
  5774. });
  5775. processChildren();
  5776. }}break;
  5777. case"stop-editing":if(templateNode.tag=="a"){elmt.href="javascript:";
  5778. }if(opts.disableEditWidgets){parentElmt.removeChild(elmt);
  5779. }else{if(opts.inPopup){SimileAjax.jQuery(elmt).click(function(){Exhibit.UI.showItemInPopup(itemID,null,uiContext,{lensType:"normal",coords:opts.coords});
  5780. });
  5781. processChildren();
  5782. }else{SimileAjax.jQuery(elmt).click(function(){uiContext.setEditMode(itemID,false);
  5783. uiContext.getCollection()._listeners.fire("onItemsChanged",[]);
  5784. });
  5785. processChildren();
  5786. }}break;
  5787. case"accept-changes":if(database.isSubmission(itemID)){if(templateNode.tag=="a"){elmt.href="javascript:";
  5788. }SimileAjax.jQuery(elmt).click(function(){database.mergeSubmissionIntoItem(itemID);
  5789. });
  5790. processChildren();
  5791. }else{SimileAjax.Debug.warn("accept-changes element in non-submission item");
  5792. parentElmt.removeChild(elmt);
  5793. }break;
  5794. }}else{if(templateNode.content!=null){var results=templateNode.content.evaluate(roots,rootValueTypes,"value",database);
  5795. if(children!=null){var rootValueTypes2={"value":results.valueType,"index":"number"};
  5796. var index=1;
  5797. var processOneValue=function(childValue){var roots2={"value":childValue,"index":index++};
  5798. for(var i=0;
  5799. i<children.length;
  5800. i++){Exhibit.Lens._constructFromLensTemplateNode(roots2,rootValueTypes2,children[i],elmt,opts);
  5801. }};
  5802. if(results.values instanceof Array){for(var i=0;
  5803. i<results.values.length;
  5804. i++){processOneValue(results.values[i]);
  5805. }}else{results.values.visit(processOneValue);
  5806. }}else{Exhibit.Lens._constructDefaultValueList(results.values,results.valueType,elmt,templateNode.uiContext);
  5807. }}else{if(templateNode.edit!=null){processChildren();
  5808. Exhibit.Lens._constructEditableContent(templateNode,elmt,itemID,uiContext);
  5809. }else{if(children!=null){for(var i=0;
  5810. i<children.length;
  5811. i++){Exhibit.Lens._constructFromLensTemplateNode(roots,rootValueTypes,children[i],elmt,opts);
  5812. }}}}}};
  5813. Exhibit.Lens._constructElmtWithAttributes=function(templateNode,parentElmt,database){var elmt;
  5814. if(templateNode.tag=="input"&&SimileAjax.Platform.browser.isIE){var a=["<input"];
  5815. var attributes=templateNode.attributes;
  5816. for(var i=0;
  5817. i<attributes.length;
  5818. i++){var attribute=attributes[i];
  5819. if(Exhibit.Lens._attributeValueIsSafe(attribute.name,attribute.value)){a.push(attribute.name+'="'+attribute.value+'"');
  5820. }}a.push("></input>");
  5821. elmt=SimileAjax.DOM.createElementFromString(a.join(" "));
  5822. parentElmt.appendChild(elmt);
  5823. }else{switch(templateNode.tag){case"tr":elmt=parentElmt.insertRow(parentElmt.rows.length);
  5824. break;
  5825. case"td":elmt=parentElmt.insertCell(parentElmt.cells.length);
  5826. break;
  5827. default:elmt=document.createElement(templateNode.tag);
  5828. parentElmt.appendChild(elmt);
  5829. }var attributes=templateNode.attributes;
  5830. for(var i=0;
  5831. i<attributes.length;
  5832. i++){var attribute=attributes[i];
  5833. if(Exhibit.Lens._attributeValueIsSafe(attribute.name,attribute.value)){try{elmt.setAttribute(attribute.name,attribute.value);
  5834. }catch(e){}}}}var styles=templateNode.styles;
  5835. for(var i=0;
  5836. i<styles.length;
  5837. i++){var style=styles[i];
  5838. elmt.style[style.name]=style.value;
  5839. }return elmt;
  5840. };
  5841. Exhibit.Lens._constructEditableContent=function(templateNode,elmt,itemID,uiContext){var db=uiContext.getDatabase();
  5842. var attr=templateNode.edit.replace(".","");
  5843. var itemValue=db.getObject(itemID,attr);
  5844. var changeHandler=function(){if(this.value&&this.value!=itemValue){db.editItem(itemID,attr,this.value);
  5845. }};
  5846. if(templateNode.tag=="select"){Exhibit.Lens._constructEditableSelect(templateNode,elmt,itemID,uiContext,itemValue);
  5847. SimileAjax.jQuery(elmt).blur(changeHandler);
  5848. }else{elmt.value=itemValue;
  5849. SimileAjax.jQuery(elmt).change(changeHandler);
  5850. }};
  5851. Exhibit.Lens.doesSelectContain=function(select,text){for(var i in select.options){var opt=select.options[i];
  5852. if(opt.text==text||opt.value==text){return true;
  5853. }}return false;
  5854. };
  5855. Exhibit.Lens._constructEditableSelect=function(templateNode,elmt,itemID,uiContext,itemValue){if(templateNode.options){var expr=Exhibit.ExpressionParser.parse(templateNode.options);
  5856. var allItems=uiContext.getDatabase().getAllItems();
  5857. var results=expr.evaluate({"value":allItems},{value:"item"},"value",uiContext.getDatabase());
  5858. var sortedResults=results.values.toArray().sort();
  5859. for(var i in sortedResults){var optText=sortedResults[i];
  5860. if(!Exhibit.Lens.doesSelectContain(elmt,optText)){var newOption=new Option(sortedResults[i],sortedResults[i]);
  5861. elmt.add(newOption,null);
  5862. }}}if(!itemValue){if(!Exhibit.Lens.doesSelectContain(elmt,"")){var newOption=new Option("","",true);
  5863. elmt.add(newOption,elmt.options[0]);
  5864. }}else{for(var i in elmt.options){if(elmt.options.hasOwnProperty(i)&&elmt.options[i].value==itemValue){elmt.selectedIndex=i;
  5865. }}}};
  5866. Exhibit.Lens._constructDefaultValueList=function(values,valueType,parentElmt,uiContext){uiContext.formatList(values,values.size(),valueType,function(elmt){parentElmt.appendChild(elmt);
  5867. });
  5868. };
  5869. Exhibit.Lens._attributeValueIsSafe=function(name,value){if(Exhibit.params.safe){if((name=="href"&&value.startsWith("javascript:"))||(name.startsWith("on"))){return false;
  5870. }}return true;
  5871. };
  5872. /* ui-context.js */
  5873. Exhibit.UIContext=function(){this._parent=null;
  5874. this._exhibit=null;
  5875. this._collection=null;
  5876. this._lensRegistry=new Exhibit.LensRegistry();
  5877. this._settings={};
  5878. this._formatters={};
  5879. this._listFormatter=null;
  5880. this._editModeRegistry={};
  5881. this._popupFunc=null;
  5882. };
  5883. Exhibit.UIContext.createRootContext=function(configuration,exhibit){var context=new Exhibit.UIContext();
  5884. context._exhibit=exhibit;
  5885. var settings=Exhibit.UIContext.l10n.initialSettings;
  5886. for(var n in settings){context._settings[n]=settings[n];
  5887. }var formats=Exhibit.getAttribute(document.body,"formats");
  5888. if(formats!=null&&formats.length>0){Exhibit.FormatParser.parseSeveral(context,formats,0,{});
  5889. }Exhibit.SettingsUtilities.collectSettingsFromDOM(document.body,Exhibit.UIContext._settingSpecs,context._settings);
  5890. Exhibit.UIContext._configure(context,configuration);
  5891. return context;
  5892. };
  5893. Exhibit.UIContext.create=function(configuration,parentUIContext,ignoreLenses){var context=Exhibit.UIContext._createWithParent(parentUIContext);
  5894. Exhibit.UIContext._configure(context,configuration,ignoreLenses);
  5895. return context;
  5896. };
  5897. Exhibit.UIContext.createFromDOM=function(configElmt,parentUIContext,ignoreLenses){var context=Exhibit.UIContext._createWithParent(parentUIContext);
  5898. if(!(ignoreLenses)){Exhibit.UIContext.registerLensesFromDOM(configElmt,context.getLensRegistry());
  5899. }var id=Exhibit.getAttribute(configElmt,"collectionID");
  5900. if(id!=null&&id.length>0){context._collection=context._exhibit.getCollection(id);
  5901. }var formats=Exhibit.getAttribute(configElmt,"formats");
  5902. if(formats!=null&&formats.length>0){Exhibit.FormatParser.parseSeveral(context,formats,0,{});
  5903. }Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.UIContext._settingSpecs,context._settings);
  5904. Exhibit.UIContext._configure(context,Exhibit.getConfigurationFromDOM(configElmt),ignoreLenses);
  5905. return context;
  5906. };
  5907. Exhibit.UIContext.prototype.dispose=function(){};
  5908. Exhibit.UIContext.prototype.getParentUIContext=function(){return this._parent;
  5909. };
  5910. Exhibit.UIContext.prototype.getExhibit=function(){return this._exhibit;
  5911. };
  5912. Exhibit.UIContext.prototype.getDatabase=function(){return this.getExhibit().getDatabase();
  5913. };
  5914. Exhibit.UIContext.prototype.getCollection=function(){if(this._collection==null){if(this._parent!=null){this._collection=this._parent.getCollection();
  5915. }else{this._collection=this._exhibit.getDefaultCollection();
  5916. }}return this._collection;
  5917. };
  5918. Exhibit.UIContext.prototype.getLensRegistry=function(){return this._lensRegistry;
  5919. };
  5920. Exhibit.UIContext.prototype.getSetting=function(name){return name in this._settings?this._settings[name]:(this._parent!=null?this._parent.getSetting(name):undefined);
  5921. };
  5922. Exhibit.UIContext.prototype.getBooleanSetting=function(name,defaultValue){var v=this.getSetting(name);
  5923. return v==undefined||v==null?defaultValue:v;
  5924. };
  5925. Exhibit.UIContext.prototype.putSetting=function(name,value){this._settings[name]=value;
  5926. };
  5927. Exhibit.UIContext.prototype.format=function(value,valueType,appender){var f;
  5928. if(valueType in this._formatters){f=this._formatters[valueType];
  5929. }else{f=this._formatters[valueType]=new Exhibit.Formatter._constructors[valueType](this);
  5930. }f.format(value,appender);
  5931. };
  5932. Exhibit.UIContext.prototype.formatList=function(iterator,count,valueType,appender){if(this._listFormatter==null){this._listFormatter=new Exhibit.Formatter._ListFormatter(this);
  5933. }this._listFormatter.formatList(iterator,count,valueType,appender);
  5934. };
  5935. Exhibit.UIContext.prototype.setEditMode=function(itemID,val){if(val){this._editModeRegistry[itemID]=true;
  5936. }else{this._editModeRegistry[itemID]=false;
  5937. }};
  5938. Exhibit.UIContext.prototype.isBeingEdited=function(itemID){return !!this._editModeRegistry[itemID];
  5939. };
  5940. Exhibit.UIContext._createWithParent=function(parent){var context=new Exhibit.UIContext();
  5941. context._parent=parent;
  5942. context._exhibit=parent._exhibit;
  5943. context._lensRegistry=new Exhibit.LensRegistry(parent.getLensRegistry());
  5944. context._editModeRegistry=parent._editModeRegistry;
  5945. return context;
  5946. };
  5947. Exhibit.UIContext._settingSpecs={"bubbleWidth":{type:"int"},"bubbleHeight":{type:"int"}};
  5948. Exhibit.UIContext._configure=function(context,configuration,ignoreLenses){Exhibit.UIContext.registerLenses(configuration,context.getLensRegistry());
  5949. if("collectionID" in configuration){context._collection=context._exhibit.getCollection(configuration["collectionID"]);
  5950. }if("formats" in configuration){Exhibit.FormatParser.parseSeveral(context,configuration.formats,0,{});
  5951. }if(!(ignoreLenses)){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.UIContext._settingSpecs,context._settings);
  5952. }};
  5953. Exhibit.UIContext.registerLens=function(configuration,lensRegistry){var template=configuration.templateFile;
  5954. if(template!=null){if("itemTypes" in configuration){for(var i=0;
  5955. i<configuration.itemTypes.length;
  5956. i++){lensRegistry.registerLensForType(template,configuration.itemTypes[i]);
  5957. }}else{lensRegistry.registerDefaultLens(template);
  5958. }}};
  5959. Exhibit.UIContext.registerLensFromDOM=function(elmt,lensRegistry){elmt.style.display="none";
  5960. var itemTypes=Exhibit.getAttribute(elmt,"itemTypes",",");
  5961. var template=null;
  5962. var url=Exhibit.getAttribute(elmt,"templateFile");
  5963. if(url!=null&&url.length>0){template=url;
  5964. }else{var id=Exhibit.getAttribute(elmt,"template");
  5965. var elmt2=id&&document.getElementById(id);
  5966. if(elmt2!=null){template=elmt2;
  5967. }else{template=elmt;
  5968. }}if(template!=null){if(itemTypes==null||itemTypes.length==0||(itemTypes.length==1&&itemTypes[0]=="")){lensRegistry.registerDefaultLens(template);
  5969. }else{for(var i=0;
  5970. i<itemTypes.length;
  5971. i++){lensRegistry.registerLensForType(template,itemTypes[i]);
  5972. }}}};
  5973. Exhibit.UIContext.registerLenses=function(configuration,lensRegistry){if("lenses" in configuration){for(var i=0;
  5974. i<configuration.lenses.length;
  5975. i++){Exhibit.UIContext.registerLens(configuration.lenses[i],lensRegistry);
  5976. }}if("lensSelector" in configuration){var lensSelector=configuration.lensSelector;
  5977. if(typeof lensSelector=="function"){lensRegistry.addLensSelector(lensSelector);
  5978. }else{SimileAjax.Debug.log("lensSelector is not a function");
  5979. }}};
  5980. Exhibit.UIContext.registerLensesFromDOM=function(parentNode,lensRegistry){var node=parentNode.firstChild;
  5981. while(node!=null){if(node.nodeType==1){var role=Exhibit.getRoleAttribute(node);
  5982. if(role=="lens"||role=="edit-lens"){Exhibit.UIContext.registerLensFromDOM(node,lensRegistry);
  5983. }}node=node.nextSibling;
  5984. }var lensSelectorString=Exhibit.getAttribute(parentNode,"lensSelector");
  5985. if(lensSelectorString!=null&&lensSelectorString.length>0){try{var lensSelector=eval(lensSelectorString);
  5986. if(typeof lensSelector=="function"){lensRegistry.addLensSelector(lensSelector);
  5987. }else{SimileAjax.Debug.log("lensSelector expression "+lensSelectorString+" is not a function");
  5988. }}catch(e){SimileAjax.Debug.exception(e,"Bad lensSelector expression: "+lensSelectorString);
  5989. }}};
  5990. Exhibit.UIContext.createLensRegistry=function(configuration,parentLensRegistry){var lensRegistry=new Exhibit.LensRegistry(parentLensRegistry);
  5991. Exhibit.UIContext.registerLenses(configuration,lensRegistry);
  5992. return lensRegistry;
  5993. };
  5994. Exhibit.UIContext.createLensRegistryFromDOM=function(parentNode,configuration,parentLensRegistry){var lensRegistry=new Exhibit.LensRegistry(parentLensRegistry);
  5995. Exhibit.UIContext.registerLensesFromDOM(parentNode,lensRegistry);
  5996. Exhibit.UIContext.registerLenses(configuration,lensRegistry);
  5997. return lensRegistry;
  5998. };
  5999. /* ui.js */
  6000. Exhibit.UI=new Object();
  6001. Exhibit.UI.componentMap={};
  6002. Exhibit.UI.registerComponent=function(name,comp){var msg="Cannot register component "+name+" -- ";
  6003. if(name in Exhibit.UI.componentMap){SimileAjax.Debug.warn(msg+"another component has taken that name");
  6004. }else{if(!comp){SimileAjax.Debug.warn(msg+"no component object provided");
  6005. }else{if(!comp.create){SimileAjax.Debug.warn(msg+"component has no create function");
  6006. }else{if(!comp.createFromDOM){SimileAjax.Debug.warn(msg+"component has no createFromDOM function");
  6007. }else{Exhibit.UI.componentMap[name]=comp;
  6008. }}}}};
  6009. Exhibit.UI.create=function(configuration,elmt,uiContext){if("role" in configuration){var role=configuration.role;
  6010. if(role!=null&&role.startsWith("exhibit-")){role=role.substr("exhibit-".length);
  6011. }if(role in Exhibit.UI.componentMap){var createFunc=Exhibit.UI.componentMap[role].create;
  6012. return createFunc(configuration,elmt,uiContext);
  6013. }switch(role){case"lens":case"edit-lens":Exhibit.UIContext.registerLens(configuration,uiContext.getLensRegistry());
  6014. return null;
  6015. case"view":return Exhibit.UI.createView(configuration,elmt,uiContext);
  6016. case"facet":return Exhibit.UI.createFacet(configuration,elmt,uiContext);
  6017. case"coordinator":return Exhibit.UI.createCoordinator(configuration,uiContext);
  6018. case"coder":return Exhibit.UI.createCoder(configuration,uiContext);
  6019. case"viewPanel":return Exhibit.ViewPanel.create(configuration,elmt,uiContext);
  6020. case"logo":return Exhibit.Logo.create(configuration,elmt,uiContext);
  6021. case"hiddenContent":elmt.style.display="none";
  6022. return null;
  6023. }}return null;
  6024. };
  6025. Exhibit.UI.createFromDOM=function(elmt,uiContext){var role=Exhibit.getRoleAttribute(elmt);
  6026. if(role in Exhibit.UI.componentMap){var createFromDOMFunc=Exhibit.UI.componentMap[role].createFromDOM;
  6027. return createFromDOMFunc(elmt,uiContext);
  6028. }switch(role){case"lens":case"edit-lens":Exhibit.UIContext.registerLensFromDOM(elmt,uiContext.getLensRegistry());
  6029. return null;
  6030. case"view":return Exhibit.UI.createViewFromDOM(elmt,null,uiContext);
  6031. case"facet":return Exhibit.UI.createFacetFromDOM(elmt,null,uiContext);
  6032. case"coordinator":return Exhibit.UI.createCoordinatorFromDOM(elmt,uiContext);
  6033. case"coder":return Exhibit.UI.createCoderFromDOM(elmt,uiContext);
  6034. case"viewPanel":return Exhibit.ViewPanel.createFromDOM(elmt,uiContext);
  6035. case"logo":return Exhibit.Logo.createFromDOM(elmt,uiContext);
  6036. case"hiddenContent":elmt.style.display="none";
  6037. return null;
  6038. }return null;
  6039. };
  6040. Exhibit.UI.generateCreationMethods=function(constructor){constructor.create=function(configuration,elmt,uiContext){var newContext=Exhibit.UIContext.create(configuration,uiContext);
  6041. var settings={};
  6042. Exhibit.SettingsUtilities.collectSettings(configuration,constructor._settingSpecs||{},settings);
  6043. return new constructor(elmt,newContext,settings);
  6044. };
  6045. constructor.createFromDOM=function(elmt,uiContext){var newContext=Exhibit.UIContext.createFromDOM(elmt,uiContext);
  6046. var settings={};
  6047. Exhibit.SettingsUtilities.collectSettingsFromDOM(elmt,constructor._settingSpecs||{},settings);
  6048. return new constructor(elmt,newContext,settings);
  6049. };
  6050. };
  6051. Exhibit.UI.createView=function(configuration,elmt,uiContext){var viewClass="viewClass" in configuration?configuration.viewClass:Exhibit.TileView;
  6052. if(typeof viewClass=="string"){viewClass=Exhibit.UI.viewClassNameToViewClass(viewClass);
  6053. }return viewClass.create(configuration,elmt,uiContext);
  6054. };
  6055. Exhibit.UI.createViewFromDOM=function(elmt,container,uiContext){var viewClass=Exhibit.UI.viewClassNameToViewClass(Exhibit.getAttribute(elmt,"viewClass"));
  6056. return viewClass.createFromDOM(elmt,container,uiContext);
  6057. };
  6058. Exhibit.UI.viewClassNameToViewClass=function(name){if(name!=null&&name.length>0){try{return Exhibit.UI._stringToObject(name,"View");
  6059. }catch(e){SimileAjax.Debug.warn("Unknown viewClass "+name);
  6060. }}return Exhibit.TileView;
  6061. };
  6062. Exhibit.UI.createFacet=function(configuration,elmt,uiContext){var facetClass="facetClass" in configuration?configuration.facetClass:Exhibit.ListFacet;
  6063. if(typeof facetClass=="string"){facetClass=Exhibit.UI.facetClassNameToFacetClass(facetClass);
  6064. }return facetClass.create(configuration,elmt,uiContext);
  6065. };
  6066. Exhibit.UI.createFacetFromDOM=function(elmt,container,uiContext){var facetClass=Exhibit.UI.facetClassNameToFacetClass(Exhibit.getAttribute(elmt,"facetClass"));
  6067. return facetClass.createFromDOM(elmt,container,uiContext);
  6068. };
  6069. Exhibit.UI.facetClassNameToFacetClass=function(name){if(name!=null&&name.length>0){try{return Exhibit.UI._stringToObject(name,"Facet");
  6070. }catch(e){SimileAjax.Debug.warn("Unknown facetClass "+name);
  6071. }}return Exhibit.ListFacet;
  6072. };
  6073. Exhibit.UI.createCoder=function(configuration,uiContext){var coderClass="coderClass" in configuration?configuration.coderClass:Exhibit.ColorCoder;
  6074. if(typeof coderClass=="string"){coderClass=Exhibit.UI.coderClassNameToCoderClass(coderClass);
  6075. }return coderClass.create(configuration,uiContext);
  6076. };
  6077. Exhibit.UI.createCoderFromDOM=function(elmt,uiContext){var coderClass=Exhibit.UI.coderClassNameToCoderClass(Exhibit.getAttribute(elmt,"coderClass"));
  6078. return coderClass.createFromDOM(elmt,uiContext);
  6079. };
  6080. Exhibit.UI.coderClassNameToCoderClass=function(name){if(name!=null&&name.length>0){try{return Exhibit.UI._stringToObject(name,"Coder");
  6081. }catch(e){SimileAjax.Debug.warn("Unknown coderClass "+name);
  6082. }}return Exhibit.ColorCoder;
  6083. };
  6084. Exhibit.UI.createCoordinator=function(configuration,uiContext){return Exhibit.Coordinator.create(configuration,uiContext);
  6085. };
  6086. Exhibit.UI.createCoordinatorFromDOM=function(elmt,uiContext){return Exhibit.Coordinator.createFromDOM(elmt,uiContext);
  6087. };
  6088. Exhibit.UI._stringToObject=function(name,suffix){if(!name.startsWith("Exhibit.")){if(!name.endsWith(suffix)){try{return eval("Exhibit."+name+suffix);
  6089. }catch(e){}}try{return eval("Exhibit."+name);
  6090. }catch(e){}}if(!name.endsWith(suffix)){try{return eval(name+suffix);
  6091. }catch(e){}}try{return eval(name);
  6092. }catch(e){}throw new Error("Unknown class "+name);
  6093. };
  6094. Exhibit.UI.docRoot="http://service.simile-widgets.org/wiki/";
  6095. Exhibit.UI.validator="http://service.simile-widgets.org/babel/validator";
  6096. Exhibit.UI.showHelp=function(message,url,target){target=(target)?target:"_blank";
  6097. if(url!=null){if(window.confirm(message+"\n\n"+Exhibit.l10n.showDocumentationMessage)){window.open(url,target);
  6098. }}else{window.alert(message);
  6099. }};
  6100. Exhibit.UI.showJavascriptExpressionValidation=function(message,expression){var target="_blank";
  6101. if(window.confirm(message+"\n\n"+Exhibit.l10n.showJavascriptValidationMessage)){window.open(Exhibit.UI.validator+"?expresson="+encodeURIComponent(expression),target);
  6102. }};
  6103. Exhibit.UI.showJsonFileValidation=function(message,url){var target="_blank";
  6104. if(url.indexOf("file:")==0){if(window.confirm(message+"\n\n"+Exhibit.l10n.showJsonValidationFormMessage)){window.open(Exhibit.UI.validator,target);
  6105. }}else{if(window.confirm(message+"\n\n"+Exhibit.l10n.showJsonValidationMessage)){window.open(Exhibit.UI.validator+"?url="+url,target);
  6106. }}};
  6107. Exhibit.UI._busyIndicator=null;
  6108. Exhibit.UI._busyIndicatorCount=0;
  6109. Exhibit.UI.showBusyIndicator=function(){Exhibit.UI._busyIndicatorCount++;
  6110. if(Exhibit.UI._busyIndicatorCount>1){return ;
  6111. }if(Exhibit.UI._busyIndicator==null){Exhibit.UI._busyIndicator=Exhibit.UI.createBusyIndicator();
  6112. }var scrollTop=("scrollTop" in document.body)?document.body.scrollTop:document.body.parentNode.scrollTop;
  6113. var height=("innerHeight" in window)?window.innerHeight:("clientHeight" in document.body?document.body.clientHeight:document.body.parentNode.clientHeight);
  6114. var top=Math.floor(scrollTop+height/3);
  6115. Exhibit.UI._busyIndicator.style.top=top+"px";
  6116. document.body.appendChild(Exhibit.UI._busyIndicator);
  6117. };
  6118. Exhibit.UI.hideBusyIndicator=function(){Exhibit.UI._busyIndicatorCount--;
  6119. if(Exhibit.UI._busyIndicatorCount>0){return ;
  6120. }try{document.body.removeChild(Exhibit.UI._busyIndicator);
  6121. }catch(e){}};
  6122. Exhibit.UI.protectUI=function(elmt){SimileAjax.DOM.appendClassName(elmt,"exhibit-ui-protection");
  6123. };
  6124. Exhibit.UI.makeActionLink=function(text,handler,layer){var a=document.createElement("a");
  6125. a.href="javascript:";
  6126. a.className="exhibit-action";
  6127. a.innerHTML=text;
  6128. var handler2=function(elmt,evt,target){if("true"!=elmt.getAttribute("disabled")){handler(elmt,evt,target);
  6129. }};
  6130. SimileAjax.WindowManager.registerEvent(a,"click",handler2,layer);
  6131. return a;
  6132. };
  6133. Exhibit.UI.enableActionLink=function(a,enabled){a.setAttribute("disabled",enabled?"false":"true");
  6134. a.className=enabled?"exhibit-action":"exhibit-action-disabled";
  6135. };
  6136. Exhibit.UI.makeItemSpan=function(itemID,label,uiContext,layer){if(label==null){label=database.getObject(itemID,"label");
  6137. if(label==null){label=itemID;
  6138. }}var a=SimileAjax.DOM.createElementFromString('<a href="'+Exhibit.Persistence.getItemLink(itemID)+"\" class='exhibit-item'>"+label+"</a>");
  6139. var handler=function(elmt,evt,target){Exhibit.UI.showItemInPopup(itemID,elmt,uiContext);
  6140. };
  6141. SimileAjax.WindowManager.registerEvent(a,"click",handler,layer);
  6142. return a;
  6143. };
  6144. Exhibit.UI.makeValueSpan=function(label,valueType,layer){var span=document.createElement("span");
  6145. span.className="exhibit-value";
  6146. if(valueType=="url"){var url=label;
  6147. if(Exhibit.params.safe&&url.trim().startsWith("javascript:")){span.appendChild(document.createTextNode(url));
  6148. }else{span.innerHTML='<a href="'+url+"\" target='_blank'>"+(label.length>50?label.substr(0,20)+" ... "+label.substr(label.length-20):label)+"</a>";
  6149. }}else{if(Exhibit.params.safe){label=Exhibit.Formatter.encodeAngleBrackets(label);
  6150. }span.innerHTML=label;
  6151. }return span;
  6152. };
  6153. Exhibit.UI.calculatePopupPosition=function(elmt){var coords=SimileAjax.DOM.getPageCoordinates(elmt);
  6154. return{x:coords.left+Math.round(elmt.offsetWidth/2),y:coords.top+Math.round(elmt.offsetHeight/2)};
  6155. };
  6156. Exhibit.UI.showItemInPopup=function(itemID,elmt,uiContext,opts){SimileAjax.WindowManager.popAllLayers();
  6157. opts=opts||{};
  6158. opts.coords=opts.coords||Exhibit.UI.calculatePopupPosition(elmt);
  6159. var itemLensDiv=document.createElement("div");
  6160. var lensOpts={inPopup:true,coords:opts.coords};
  6161. if(opts.lensType=="normal"){lensOpts.lensTemplate=uiContext.getLensRegistry().getNormalLens(itemID,uiContext);
  6162. }else{if(opts.lensType=="edit"){lensOpts.lensTemplate=uiContext.getLensRegistry().getEditLens(itemID,uiContext);
  6163. }else{if(opts.lensType){SimileAjax.Debug.warn("Unknown Exhibit.UI.showItemInPopup opts.lensType: "+opts.lensType);
  6164. }}}uiContext.getLensRegistry().createLens(itemID,itemLensDiv,uiContext,lensOpts);
  6165. SimileAjax.Graphics.createBubbleForContentAndPoint(itemLensDiv,opts.coords.x,opts.coords.y,uiContext.getSetting("bubbleWidth"));
  6166. };
  6167. Exhibit.UI.createButton=function(name,handler,className){var button=document.createElement("button");
  6168. button.className=(className||"exhibit-button")+" screen";
  6169. button.innerHTML=name;
  6170. if(handler){SimileAjax.WindowManager.registerEvent(button,"click",handler);
  6171. }return button;
  6172. };
  6173. Exhibit.UI.createPopupMenuDom=function(element){var div=document.createElement("div");
  6174. div.className="exhibit-menu-popup exhibit-ui-protection";
  6175. var dom={elmt:div,close:function(){document.body.removeChild(this.elmt);
  6176. },open:function(){var self=this;
  6177. this.layer=SimileAjax.WindowManager.pushLayer(function(){self.close();
  6178. },true,div);
  6179. var docWidth=document.body.offsetWidth;
  6180. var docHeight=document.body.offsetHeight;
  6181. var coords=SimileAjax.DOM.getPageCoordinates(element);
  6182. div.style.top=(coords.top+element.scrollHeight)+"px";
  6183. div.style.right=(docWidth-(coords.left+element.scrollWidth))+"px";
  6184. document.body.appendChild(this.elmt);
  6185. },appendMenuItem:function(label,icon,onClick){var self=this;
  6186. var a=document.createElement("a");
  6187. a.className="exhibit-menu-item";
  6188. a.href="javascript:";
  6189. SimileAjax.WindowManager.registerEvent(a,"click",function(elmt,evt,target){onClick(elmt,evt,target);
  6190. SimileAjax.WindowManager.popLayer(self.layer);
  6191. SimileAjax.DOM.cancelEvent(evt);
  6192. return false;
  6193. });
  6194. var div=document.createElement("div");
  6195. a.appendChild(div);
  6196. div.appendChild(SimileAjax.Graphics.createTranslucentImage(icon!=null?icon:(Exhibit.urlPrefix+"images/blank-16x16.png")));
  6197. div.appendChild(document.createTextNode(label));
  6198. this.elmt.appendChild(a);
  6199. },appendSeparator:function(){var hr=document.createElement("hr");
  6200. this.elmt.appendChild(hr);
  6201. }};
  6202. return dom;
  6203. };
  6204. Exhibit.UI.createBusyIndicator=function(){var existing=SimileAjax.jQuery(".exhibit-busyIndicator");
  6205. if(existing.length>0){var node=existing.eq(0);
  6206. node.detach();
  6207. node.show();
  6208. return node.get(0);
  6209. }var urlPrefix=Exhibit.urlPrefix+"images/";
  6210. var containerDiv=document.createElement("div");
  6211. if(SimileAjax.Graphics.pngIsTranslucent){var topDiv=document.createElement("div");
  6212. topDiv.style.height="33px";
  6213. topDiv.style.background="url("+urlPrefix+"message-bubble/message-top-left.png) top left no-repeat";
  6214. topDiv.style.paddingLeft="44px";
  6215. containerDiv.appendChild(topDiv);
  6216. var topRightDiv=document.createElement("div");
  6217. topRightDiv.style.height="33px";
  6218. topRightDiv.style.background="url("+urlPrefix+"message-bubble/message-top-right.png) top right no-repeat";
  6219. topDiv.appendChild(topRightDiv);
  6220. var middleDiv=document.createElement("div");
  6221. middleDiv.style.background="url("+urlPrefix+"message-bubble/message-left.png) top left repeat-y";
  6222. middleDiv.style.paddingLeft="44px";
  6223. containerDiv.appendChild(middleDiv);
  6224. var middleRightDiv=document.createElement("div");
  6225. middleRightDiv.style.background="url("+urlPrefix+"message-bubble/message-right.png) top right repeat-y";
  6226. middleRightDiv.style.paddingRight="44px";
  6227. middleDiv.appendChild(middleRightDiv);
  6228. var contentDiv=document.createElement("div");
  6229. middleRightDiv.appendChild(contentDiv);
  6230. var bottomDiv=document.createElement("div");
  6231. bottomDiv.style.height="55px";
  6232. bottomDiv.style.background="url("+urlPrefix+"message-bubble/message-bottom-left.png) bottom left no-repeat";
  6233. bottomDiv.style.paddingLeft="44px";
  6234. containerDiv.appendChild(bottomDiv);
  6235. var bottomRightDiv=document.createElement("div");
  6236. bottomRightDiv.style.height="55px";
  6237. bottomRightDiv.style.background="url("+urlPrefix+"message-bubble/message-bottom-right.png) bottom right no-repeat";
  6238. bottomDiv.appendChild(bottomRightDiv);
  6239. }else{containerDiv.style.border="2px solid #7777AA";
  6240. containerDiv.style.padding="20px";
  6241. containerDiv.style.background="white";
  6242. SimileAjax.Graphics.setOpacity(containerDiv,90);
  6243. var contentDiv=document.createElement("div");
  6244. containerDiv.appendChild(contentDiv);
  6245. }containerDiv.className="exhibit-busyIndicator";
  6246. contentDiv.className="exhibit-busyIndicator-content";
  6247. var img=document.createElement("img");
  6248. img.src=urlPrefix+"progress-running.gif";
  6249. contentDiv.appendChild(img);
  6250. contentDiv.appendChild(document.createTextNode(" "+Exhibit.l10n.busyIndicatorMessage));
  6251. return containerDiv;
  6252. };
  6253. Exhibit.UI.createFocusDialogBox=function(itemID,exhibit,configuration){var template={tag:"div",className:"exhibit-focusDialog exhibit-ui-protection",children:[{tag:"div",className:"exhibit-focusDialog-viewContainer",field:"viewContainer"},{tag:"div",className:"exhibit-focusDialog-controls",children:[{tag:"button",field:"closeButton",children:[Exhibit.l10n.focusDialogBoxCloseButtonLabel]}]}]};
  6254. var dom=SimileAjax.DOM.createDOMFromTemplate(template);
  6255. dom.close=function(){document.body.removeChild(dom.elmt);
  6256. };
  6257. dom.open=function(){dom.layer=SimileAjax.WindowManager.pushLayer(function(){dom.close();
  6258. },false);
  6259. var lens=new Exhibit.Lens(itemID,dom.viewContainer,exhibit,configuration);
  6260. dom.elmt.style.top=(document.body.scrollTop+100)+"px";
  6261. document.body.appendChild(dom.elmt);
  6262. SimileAjax.WindowManager.registerEvent(dom.closeButton,"click",function(elmt,evt,target){SimileAjax.WindowManager.popLayer(dom.layer);
  6263. SimileAjax.DOM.cancelEvent(evt);
  6264. return false;
  6265. },dom.layer);
  6266. };
  6267. return dom;
  6268. };
  6269. Exhibit.UI.createTranslucentImage=function(relativeUrl,verticalAlign){return SimileAjax.Graphics.createTranslucentImage(Exhibit.urlPrefix+relativeUrl,verticalAlign);
  6270. };
  6271. Exhibit.UI.createTranslucentImageHTML=function(relativeUrl,verticalAlign){return SimileAjax.Graphics.createTranslucentImageHTML(Exhibit.urlPrefix+relativeUrl,verticalAlign);
  6272. };
  6273. Exhibit.UI.findAttribute=function(attr,value,parent){var parent=SimileAjax.jQuery(parent||document.body);
  6274. var f=function(){var v=this.getAttribute(attr);
  6275. if(value===undefined){return !!v;
  6276. }else{if(value instanceof Array){return value.indexOf(v)!=-1;
  6277. }else{return value.toString()==v;
  6278. }}};
  6279. return parent.find("*").add(parent).filter(f);
  6280. };
  6281. /* html-view.js */
  6282. Exhibit.HTMLView=function(containerElmt,uiContext,html){this.html=html;
  6283. this.view=this.moveChildNodes(html,containerElmt);
  6284. };
  6285. Exhibit.HTMLView.create=Exhibit.HTMLView.createFromDOM=function(configElmt,containerElmt,uiContext){return new Exhibit.HTMLView(containerElmt!=null?containerElmt:configElmt,null,configElmt);
  6286. };
  6287. Exhibit.HTMLView.prototype.dispose=function(){this.html=this.moveChildNodes(this.view,this.html);
  6288. this.view=this.html=null;
  6289. };
  6290. Exhibit.HTMLView.prototype.moveChildNodes=function(src,dst){if(src===dst){return dst;
  6291. }var tmp=document.createDocumentFragment();
  6292. while(src.firstChild){tmp.appendChild(src.firstChild);
  6293. }dst.appendChild(tmp);
  6294. return dst;
  6295. };
  6296. /* ordered-view-frame.js */
  6297. Exhibit.OrderedViewFrame=function(uiContext){this._uiContext=uiContext;
  6298. this._orders=null;
  6299. this._possibleOrders=null;
  6300. this._settings={};
  6301. };
  6302. Exhibit.OrderedViewFrame._settingSpecs={"showAll":{type:"boolean",defaultValue:false},"grouped":{type:"boolean",defaultValue:true},"showDuplicates":{type:"boolean",defaultValue:false},"abbreviatedCount":{type:"int",defaultValue:10},"showHeader":{type:"boolean",defaultValue:true},"showSummary":{type:"boolean",defaultValue:true},"showControls":{type:"boolean",defaultValue:true},"showFooter":{type:"boolean",defaultValue:true},"paginate":{type:"boolean",defaultValue:false},"pageSize":{type:"int",defaultValue:20},"pageWindow":{type:"int",defaultValue:2},"page":{type:"int",defaultValue:0},"alwaysShowPagingControls":{type:"boolean",defaultValue:false},"pagingControlLocations":{type:"enum",defaultValue:"topbottom",choices:["top","bottom","topbottom"]}};
  6303. Exhibit.OrderedViewFrame.prototype.configure=function(configuration){if("orders" in configuration){this._orders=[];
  6304. this._configureOrders(configuration.orders);
  6305. }if("possibleOrders" in configuration){this._possibleOrders=[];
  6306. this._configurePossibleOrders(configuration.possibleOrders);
  6307. }Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.OrderedViewFrame._settingSpecs,this._settings);
  6308. this._internalValidate();
  6309. };
  6310. Exhibit.OrderedViewFrame.prototype.configureFromDOM=function(domConfiguration){var orders=Exhibit.getAttribute(domConfiguration,"orders",",");
  6311. if(orders!=null&&orders.length>0){this._orders=[];
  6312. this._configureOrders(orders);
  6313. }var directions=Exhibit.getAttribute(domConfiguration,"directions",",");
  6314. if(directions!=null&&directions.length>0&&this._orders!=null){for(var i=0;
  6315. i<directions.length&&i<this._orders.length;
  6316. i++){this._orders[i].ascending=(directions[i].toLowerCase()!="descending");
  6317. }}var possibleOrders=Exhibit.getAttribute(domConfiguration,"possibleOrders",",");
  6318. if(possibleOrders!=null&&possibleOrders.length>0){this._possibleOrders=[];
  6319. this._configurePossibleOrders(possibleOrders);
  6320. }var possibleDirections=Exhibit.getAttribute(domConfiguration,"possibleDirections",",");
  6321. if(possibleDirections!=null&&possibleDirections.length>0&&this._possibleOrders!=null){for(var i=0;
  6322. i<possibleDirections.length&&i<this._possibleOrders.length;
  6323. i++){this._possibleOrders[i].ascending=(possibleDirections[i].toLowerCase()!="descending");
  6324. }}Exhibit.SettingsUtilities.collectSettingsFromDOM(domConfiguration,Exhibit.OrderedViewFrame._settingSpecs,this._settings);
  6325. this._internalValidate();
  6326. };
  6327. Exhibit.OrderedViewFrame.prototype.dispose=function(){if(this._headerDom){this._headerDom.dispose();
  6328. this._headerDom=null;
  6329. }if(this._footerDom){this._footerDom.dispose();
  6330. this._footerDom=null;
  6331. }this._divHeader=null;
  6332. this._divFooter=null;
  6333. this._uiContext=null;
  6334. };
  6335. Exhibit.OrderedViewFrame.prototype._internalValidate=function(){if(this._orders!=null&&this._orders.length==0){this._orders=null;
  6336. }if(this._possibleOrders!=null&&this._possibleOrders.length==0){this._possibleOrders=null;
  6337. }if(this._settings.paginate){this._settings.grouped=false;
  6338. }};
  6339. Exhibit.OrderedViewFrame.prototype._configureOrders=function(orders){for(var i=0;
  6340. i<orders.length;
  6341. i++){var order=orders[i];
  6342. var expr;
  6343. var ascending=true;
  6344. if(typeof order=="string"){expr=order;
  6345. }else{if(typeof order=="object"){expr=order.expression,ascending=("ascending" in order)?(order.ascending):true;
  6346. }else{SimileAjax.Debug.warn("Bad order object "+order);
  6347. continue;
  6348. }}try{var expression=Exhibit.ExpressionParser.parse(expr);
  6349. if(expression.isPath()){var path=expression.getPath();
  6350. if(path.getSegmentCount()==1){var segment=path.getSegment(0);
  6351. this._orders.push({property:segment.property,forward:segment.forward,ascending:ascending});
  6352. }}}catch(e){SimileAjax.Debug.warn("Bad order expression "+expr);
  6353. }}};
  6354. Exhibit.OrderedViewFrame.prototype._configurePossibleOrders=function(possibleOrders){for(var i=0;
  6355. i<possibleOrders.length;
  6356. i++){var order=possibleOrders[i];
  6357. var expr;
  6358. var ascending=true;
  6359. if(typeof order=="string"){expr=order;
  6360. }else{if(typeof order=="object"){expr=order.expression,ascending=("ascending" in order)?(order.ascending):true;
  6361. }else{SimileAjax.Debug.warn("Bad possible order object "+order);
  6362. continue;
  6363. }}try{var expression=Exhibit.ExpressionParser.parse(expr);
  6364. if(expression.isPath()){var path=expression.getPath();
  6365. if(path.getSegmentCount()==1){var segment=path.getSegment(0);
  6366. this._possibleOrders.push({property:segment.property,forward:segment.forward,ascending:ascending});
  6367. }}}catch(e){SimileAjax.Debug.warn("Bad possible order expression "+expr);
  6368. }}};
  6369. Exhibit.OrderedViewFrame.prototype.initializeUI=function(){var self=this;
  6370. if(this._settings.showHeader){this._headerDom=Exhibit.OrderedViewFrame.createHeaderDom(this._uiContext,this._divHeader,this._settings.showSummary,this._settings.showControls,function(elmt,evt,target){self._openSortPopup(elmt,-1);
  6371. },function(elmt,evt,target){self._toggleGroup();
  6372. },function(pageIndex){self._gotoPage(pageIndex);
  6373. });
  6374. }if(this._settings.showFooter){this._footerDom=Exhibit.OrderedViewFrame.createFooterDom(this._uiContext,this._divFooter,function(elmt,evt,target){self._setShowAll(true);
  6375. },function(elmt,evt,target){self._setShowAll(false);
  6376. },function(pageIndex){self._gotoPage(pageIndex);
  6377. });
  6378. }};
  6379. Exhibit.OrderedViewFrame.prototype.reconstruct=function(){var self=this;
  6380. var collection=this._uiContext.getCollection();
  6381. var database=this._uiContext.getDatabase();
  6382. var originalSize=collection.countAllItems();
  6383. var currentSize=collection.countRestrictedItems();
  6384. var hasSomeGrouping=false;
  6385. if(currentSize>0){var currentSet=collection.getRestrictedItems();
  6386. hasSomeGrouping=this._internalReconstruct(currentSet);
  6387. var orderElmts=[];
  6388. var buildOrderElmt=function(order,index){var property=database.getProperty(order.property);
  6389. var label=property!=null?(order.forward?property.getPluralLabel():property.getReversePluralLabel()):(order.forward?order.property:"reverse of "+order.property);
  6390. orderElmts.push(Exhibit.UI.makeActionLink(label,function(elmt,evt,target){self._openSortPopup(elmt,index);
  6391. }));
  6392. };
  6393. var orders=this._getOrders();
  6394. for(var i=0;
  6395. i<orders.length;
  6396. i++){buildOrderElmt(orders[i],i);
  6397. }if(this._settings.showHeader&&this._settings.showControls){this._headerDom.setOrders(orderElmts);
  6398. this._headerDom.enableThenByAction(orderElmts.length<this._getPossibleOrders().length);
  6399. }}if(this._settings.showHeader&&this._settings.showControls){this._headerDom.groupOptionWidget.setChecked(this._settings.grouped);
  6400. }if(this._settings.showFooter){this._footerDom.setCounts(currentSize,this._settings.abbreviatedCount,this._settings.showAll,!(hasSomeGrouping&&this._grouped)&&!this._settings.paginate);
  6401. }};
  6402. Exhibit.OrderedViewFrame.prototype._internalReconstruct=function(allItems){var self=this;
  6403. var settings=this._settings;
  6404. var database=this._uiContext.getDatabase();
  6405. var orders=this._getOrders();
  6406. var itemIndex=0;
  6407. var hasSomeGrouping=false;
  6408. var createItem=function(itemID){if((itemIndex>=fromIndex&&itemIndex<toIndex)||(hasSomeGrouping&&settings.grouped)){self.onNewItem(itemID,itemIndex);
  6409. }itemIndex++;
  6410. };
  6411. var createGroup=function(label,valueType,index){if((itemIndex>=fromIndex&&itemIndex<toIndex)||(hasSomeGrouping&&settings.grouped)){self.onNewGroup(label,valueType,index);
  6412. }};
  6413. var processLevel=function(items,index){var order=orders[index];
  6414. var values=order.forward?database.getObjectsUnion(items,order.property):database.getSubjectsUnion(items,order.property);
  6415. var valueType="text";
  6416. if(order.forward){var property=database.getProperty(order.property);
  6417. valueType=property!=null?property.getValueType():"text";
  6418. }else{valueType="item";
  6419. }var keys=(valueType=="item"||valueType=="text")?processNonNumericLevel(items,index,values,valueType):processNumericLevel(items,index,values,valueType);
  6420. var grouped=false;
  6421. for(var k=0;
  6422. k<keys.length;
  6423. k++){if(keys[k].items.size()>1){grouped=true;
  6424. }}if(grouped){hasSomeGrouping=true;
  6425. }for(var k=0;
  6426. k<keys.length;
  6427. k++){var key=keys[k];
  6428. if(key.items.size()>0){if(grouped&&settings.grouped){createGroup(key.display,valueType,index);
  6429. }items.removeSet(key.items);
  6430. if(key.items.size()>1&&index<orders.length-1){processLevel(key.items,index+1);
  6431. }else{key.items.visit(createItem);
  6432. }}}if(items.size()>0){if(grouped&&settings.grouped){createGroup(Exhibit.l10n.missingSortKey,valueType,index);
  6433. }if(items.size()>1&&index<orders.length-1){processLevel(items,index+1);
  6434. }else{items.visit(createItem);
  6435. }}};
  6436. var processNonNumericLevel=function(items,index,values,valueType){var keys=[];
  6437. var compareKeys;
  6438. var retrieveItems;
  6439. var order=orders[index];
  6440. if(valueType=="item"){values.visit(function(itemID){var label=database.getObject(itemID,"label");
  6441. label=label!=null?label:itemID;
  6442. keys.push({itemID:itemID,display:label});
  6443. });
  6444. compareKeys=function(key1,key2){var c=key1.display.localeCompare(key2.display);
  6445. return c!=0?c:key1.itemID.localeCompare(key2.itemID);
  6446. };
  6447. retrieveItems=order.forward?function(key){return database.getSubjects(key.itemID,order.property,null,items);
  6448. }:function(key){return database.getObjects(key.itemID,order.property,null,items);
  6449. };
  6450. }else{values.visit(function(value){keys.push({display:value});
  6451. });
  6452. compareKeys=function(key1,key2){return key1.display.localeCompare(key2.display);
  6453. };
  6454. retrieveItems=order.forward?function(key){return database.getSubjects(key.display,order.property,null,items);
  6455. }:function(key){return database.getObjects(key.display,order.property,null,items);
  6456. };
  6457. }keys.sort(function(key1,key2){return(order.ascending?1:-1)*compareKeys(key1,key2);
  6458. });
  6459. for(var k=0;
  6460. k<keys.length;
  6461. k++){var key=keys[k];
  6462. key.items=retrieveItems(key);
  6463. if(!settings.showDuplicates){items.removeSet(key.items);
  6464. }}return keys;
  6465. };
  6466. var processNumericLevel=function(items,index,values,valueType){var keys=[];
  6467. var keyMap={};
  6468. var order=orders[index];
  6469. var valueParser;
  6470. if(valueType=="number"){valueParser=function(value){if(typeof value=="number"){return value;
  6471. }else{try{return parseFloat(value);
  6472. }catch(e){return null;
  6473. }}};
  6474. }else{valueParser=function(value){if(value instanceof Date){return value.getTime();
  6475. }else{try{return SimileAjax.DateTime.parseIso8601DateTime(value.toString()).getTime();
  6476. }catch(e){return null;
  6477. }}};
  6478. }values.visit(function(value){var sortkey=valueParser(value);
  6479. if(sortkey!=null){var key=keyMap[sortkey];
  6480. if(!key){key={sortkey:sortkey,display:value,values:[],items:new Exhibit.Set()};
  6481. keyMap[sortkey]=key;
  6482. keys.push(key);
  6483. }key.values.push(value);
  6484. }});
  6485. keys.sort(function(key1,key2){return(order.ascending?1:-1)*(key1.sortkey-key2.sortkey);
  6486. });
  6487. for(var k=0;
  6488. k<keys.length;
  6489. k++){var key=keys[k];
  6490. var values=key.values;
  6491. for(var v=0;
  6492. v<values.length;
  6493. v++){if(order.forward){database.getSubjects(values[v],order.property,key.items,items);
  6494. }else{database.getObjects(values[v],order.property,key.items,items);
  6495. }}if(!settings.showDuplicates){items.removeSet(key.items);
  6496. }}return keys;
  6497. };
  6498. var totalCount=allItems.size();
  6499. var pageCount=Math.ceil(totalCount/settings.pageSize);
  6500. var fromIndex=0;
  6501. var toIndex=settings.showAll?totalCount:Math.min(totalCount,settings.abbreviatedCount);
  6502. if(!settings.grouped&&settings.paginate&&(pageCount>1||(pageCount>0&&settings.alwaysShowPagingControls))){fromIndex=settings.page*settings.pageSize;
  6503. toIndex=Math.min(fromIndex+settings.pageSize,totalCount);
  6504. if(settings.showHeader&&(settings.pagingControlLocations=="top"||settings.pagingControlLocations=="topbottom")){this._headerDom.renderPageLinks(settings.page,pageCount,settings.pageWindow);
  6505. }if(settings.showFooter&&(settings.pagingControlLocations=="bottom"||settings.pagingControlLocations=="topbottom")){this._footerDom.renderPageLinks(settings.page,pageCount,settings.pageWindow);
  6506. }}else{if(settings.showHeader){this._headerDom.hidePageLinks();
  6507. }if(settings.showFooter){this._footerDom.hidePageLinks();
  6508. }}processLevel(allItems,0);
  6509. return hasSomeGrouping;
  6510. };
  6511. Exhibit.OrderedViewFrame.prototype._getOrders=function(){return this._orders||[this._getPossibleOrders()[0]];
  6512. };
  6513. Exhibit.OrderedViewFrame.prototype._getPossibleOrders=function(){var possibleOrders=null;
  6514. if(this._possibleOrders==null){possibleOrders=this._uiContext.getDatabase().getAllProperties();
  6515. for(var i=0,p;
  6516. p=possibleOrders[i];
  6517. i++){possibleOrders[i]={ascending:true,forward:true,property:p};
  6518. }}else{possibleOrders=[].concat(this._possibleOrders);
  6519. }if(possibleOrders.length==0){possibleOrders.push({property:"label",forward:true,ascending:true});
  6520. }return possibleOrders;
  6521. };
  6522. Exhibit.OrderedViewFrame.prototype._openSortPopup=function(elmt,index){var self=this;
  6523. var database=this._uiContext.getDatabase();
  6524. var popupDom=Exhibit.UI.createPopupMenuDom(elmt);
  6525. var configuredOrders=this._getOrders();
  6526. if(index>=0){var order=configuredOrders[index];
  6527. var property=database.getProperty(order.property);
  6528. var propertyLabel=order.forward?property.getPluralLabel():property.getReversePluralLabel();
  6529. var valueType=order.forward?property.getValueType():"item";
  6530. var sortLabels=Exhibit.Database.l10n.sortLabels[valueType];
  6531. sortLabels=(sortLabels!=null)?sortLabels:Exhibit.Database.l10n.sortLabels["text"];
  6532. popupDom.appendMenuItem(sortLabels.ascending,Exhibit.urlPrefix+(order.ascending?"images/option-check.png":"images/option.png"),order.ascending?function(){}:function(){self._reSort(index,order.property,order.forward,true,false);
  6533. });
  6534. popupDom.appendMenuItem(sortLabels.descending,Exhibit.urlPrefix+(order.ascending?"images/option.png":"images/option-check.png"),order.ascending?function(){self._reSort(index,order.property,order.forward,false,false);
  6535. }:function(){});
  6536. if(configuredOrders.length>1){popupDom.appendSeparator();
  6537. popupDom.appendMenuItem(Exhibit.OrderedViewFrame.l10n.removeOrderLabel,null,function(){self._removeOrder(index);
  6538. });
  6539. }}var orders=[];
  6540. var possibleOrders=this._getPossibleOrders();
  6541. for(i=0;
  6542. i<possibleOrders.length;
  6543. i++){var possibleOrder=possibleOrders[i];
  6544. var skip=false;
  6545. for(var j=(index<0)?configuredOrders.length-1:index;
  6546. j>=0;
  6547. j--){var existingOrder=configuredOrders[j];
  6548. if(existingOrder.property==possibleOrder.property&&existingOrder.forward==possibleOrder.forward){skip=true;
  6549. break;
  6550. }}if(!skip){var property=database.getProperty(possibleOrder.property);
  6551. orders.push({property:possibleOrder.property,forward:possibleOrder.forward,ascending:possibleOrder.ascending,label:possibleOrder.forward?property.getPluralLabel():property.getReversePluralLabel()});
  6552. }}if(orders.length>0){if(index>=0){popupDom.appendSeparator();
  6553. }orders.sort(function(order1,order2){return order1.label.localeCompare(order2.label);
  6554. });
  6555. var appendOrder=function(order){popupDom.appendMenuItem(order.label,null,function(){self._reSort(index,order.property,order.forward,order.ascending,true);
  6556. });
  6557. };
  6558. for(var i=0;
  6559. i<orders.length;
  6560. i++){appendOrder(orders[i]);
  6561. }}popupDom.open();
  6562. };
  6563. Exhibit.OrderedViewFrame.prototype._reSort=function(index,propertyID,forward,ascending,slice){var oldOrders=this._getOrders();
  6564. index=(index<0)?oldOrders.length:index;
  6565. var newOrders=oldOrders.slice(0,index);
  6566. newOrders.push({property:propertyID,forward:forward,ascending:ascending});
  6567. if(!slice){newOrders=newOrders.concat(oldOrders.slice(index+1));
  6568. }var property=this._uiContext.getDatabase().getProperty(propertyID);
  6569. var propertyLabel=forward?property.getPluralLabel():property.getReversePluralLabel();
  6570. var valueType=forward?property.getValueType():"item";
  6571. var sortLabels=Exhibit.Database.l10n.sortLabels[valueType];
  6572. sortLabels=(sortLabels!=null)?sortLabels:Exhibit.Database.l10n.sortLabels["text"];
  6573. var self=this;
  6574. SimileAjax.History.addLengthyAction(function(){self._orders=newOrders;
  6575. self.parentReconstruct();
  6576. },function(){self._orders=oldOrders;
  6577. self.parentReconstruct();
  6578. },Exhibit.OrderedViewFrame.l10n.formatSortActionTitle(propertyLabel,ascending?sortLabels.ascending:sortLabels.descending));
  6579. };
  6580. Exhibit.OrderedViewFrame.prototype._removeOrder=function(index){var oldOrders=this._getOrders();
  6581. var newOrders=oldOrders.slice(0,index).concat(oldOrders.slice(index+1));
  6582. var order=oldOrders[index];
  6583. var property=this._uiContext.getDatabase().getProperty(order.property);
  6584. var propertyLabel=order.forward?property.getPluralLabel():property.getReversePluralLabel();
  6585. var valueType=order.forward?property.getValueType():"item";
  6586. var sortLabels=Exhibit.Database.l10n.sortLabels[valueType];
  6587. sortLabels=(sortLabels!=null)?sortLabels:Exhibit.Database.l10n.sortLabels["text"];
  6588. var self=this;
  6589. SimileAjax.History.addLengthyAction(function(){self._orders=newOrders;
  6590. self.parentReconstruct();
  6591. },function(){self._orders=oldOrders;
  6592. self.parentReconstruct();
  6593. },Exhibit.OrderedViewFrame.l10n.formatRemoveOrderActionTitle(propertyLabel,order.ascending?sortLabels.ascending:sortLabels.descending));
  6594. };
  6595. Exhibit.OrderedViewFrame.prototype._setShowAll=function(showAll){var self=this;
  6596. var settings=this._settings;
  6597. SimileAjax.History.addLengthyAction(function(){settings.showAll=showAll;
  6598. self.parentReconstruct();
  6599. },function(){settings.showAll=!showAll;
  6600. self.parentReconstruct();
  6601. },Exhibit.OrderedViewFrame.l10n[showAll?"showAllActionTitle":"dontShowAllActionTitle"]);
  6602. };
  6603. Exhibit.OrderedViewFrame.prototype._toggleGroup=function(){var settings=this._settings;
  6604. var oldGrouped=settings.grouped;
  6605. var self=this;
  6606. SimileAjax.History.addLengthyAction(function(){settings.grouped=!oldGrouped;
  6607. self.parentReconstruct();
  6608. },function(){settings.grouped=oldGrouped;
  6609. self.parentReconstruct();
  6610. },Exhibit.OrderedViewFrame.l10n[oldGrouped?"ungroupAsSortedActionTitle":"groupAsSortedActionTitle"]);
  6611. };
  6612. Exhibit.OrderedViewFrame.prototype._toggleShowDuplicates=function(){var settings=this._settings;
  6613. var oldShowDuplicates=settings.showDuplicates;
  6614. var self=this;
  6615. SimileAjax.History.addLengthyAction(function(){settings.showDuplicates=!oldShowDuplicates;
  6616. self.parentReconstruct();
  6617. },function(){settings.showDuplicates=oldShowDuplicates;
  6618. self.parentReconstruct();
  6619. },Exhibit.OrderedViewFrame.l10n[oldShowDuplicates?"hideDuplicatesActionTitle":"showDuplicatesActionTitle"]);
  6620. };
  6621. Exhibit.OrderedViewFrame.prototype._gotoPage=function(pageIndex){var settings=this._settings;
  6622. var oldPageIndex=settings.page;
  6623. var self=this;
  6624. SimileAjax.History.addLengthyAction(function(){settings.page=pageIndex;
  6625. self.parentReconstruct();
  6626. },function(){settings.page=oldPageIndex;
  6627. self.parentReconstruct();
  6628. },Exhibit.OrderedViewFrame.l10n.makePagingActionTitle(pageIndex));
  6629. };
  6630. Exhibit.OrderedViewFrame.headerTemplate="<div id='collectionSummaryDiv' style='display: none;'></div><div class='exhibit-collectionView-header-sortControls' style='display: none;' id='controlsDiv'>%0<span class='exhibit-collectionView-header-groupControl'> \u2022 <a id='groupOption' class='exhibit-action'></a></span></div>";
  6631. Exhibit.OrderedViewFrame.createHeaderDom=function(uiContext,headerDiv,showSummary,showControls,onThenSortBy,onGroupToggle,gotoPage){var l10n=Exhibit.OrderedViewFrame.l10n;
  6632. var template=String.substitute(Exhibit.OrderedViewFrame.headerTemplate+"<"+l10n.pagingControlContainerElement+" class='exhibit-collectionView-pagingControls' style='display: none;' id='topPagingDiv'></"+l10n.pagingControlContainerElement+">",[l10n.sortingControlsTemplate]);
  6633. var dom=SimileAjax.DOM.createDOMFromString(headerDiv,template,{});
  6634. headerDiv.className="exhibit-collectionView-header";
  6635. if(showSummary){dom.collectionSummaryDiv.style.display="block";
  6636. dom.collectionSummaryWidget=Exhibit.CollectionSummaryWidget.create({},dom.collectionSummaryDiv,uiContext);
  6637. }if(showControls){dom.controlsDiv.style.display="block";
  6638. dom.groupOptionWidget=Exhibit.OptionWidget.create({label:l10n.groupedAsSortedOptionLabel,onToggle:onGroupToggle},dom.groupOption,uiContext);
  6639. SimileAjax.WindowManager.registerEvent(dom.thenSortByAction,"click",onThenSortBy);
  6640. dom.enableThenByAction=function(enabled){Exhibit.UI.enableActionLink(dom.thenSortByAction,enabled);
  6641. };
  6642. dom.setOrders=function(orderElmts){dom.ordersSpan.innerHTML="";
  6643. var addDelimiter=Exhibit.Formatter.createListDelimiter(dom.ordersSpan,orderElmts.length,uiContext);
  6644. for(var i=0;
  6645. i<orderElmts.length;
  6646. i++){addDelimiter();
  6647. dom.ordersSpan.appendChild(orderElmts[i]);
  6648. }addDelimiter();
  6649. };
  6650. }dom.renderPageLinks=function(page,totalPage,pageWindow){Exhibit.OrderedViewFrame.renderPageLinks(dom.topPagingDiv,page,totalPage,pageWindow,gotoPage);
  6651. dom.topPagingDiv.style.display="block";
  6652. };
  6653. dom.hidePageLinks=function(){dom.topPagingDiv.style.display="none";
  6654. };
  6655. dom.dispose=function(){if("collectionSummaryWidget" in dom){dom.collectionSummaryWidget.dispose();
  6656. dom.collectionSummaryWidget=null;
  6657. }dom.groupOptionWidget.dispose();
  6658. dom.groupOptionWidget=null;
  6659. };
  6660. return dom;
  6661. };
  6662. Exhibit.OrderedViewFrame.footerTemplate="<div id='showAllSpan'></div>";
  6663. Exhibit.OrderedViewFrame.createFooterDom=function(uiContext,footerDiv,onShowAll,onDontShowAll,gotoPage){var l10n=Exhibit.OrderedViewFrame.l10n;
  6664. var dom=SimileAjax.DOM.createDOMFromString(footerDiv,Exhibit.OrderedViewFrame.footerTemplate+"<"+l10n.pagingControlContainerElement+" class='exhibit-collectionView-pagingControls' style='display: none;' id='bottomPagingDiv'></"+l10n.pagingControlContainerElement+">",{});
  6665. footerDiv.className="exhibit-collectionView-footer";
  6666. dom.setCounts=function(count,limitCount,showAll,canToggle){dom.showAllSpan.innerHTML="";
  6667. if(canToggle&&count>limitCount){dom.showAllSpan.style.display="block";
  6668. if(showAll){dom.showAllSpan.appendChild(Exhibit.UI.makeActionLink(l10n.formatDontShowAll(limitCount),onDontShowAll));
  6669. }else{dom.showAllSpan.appendChild(Exhibit.UI.makeActionLink(l10n.formatShowAll(count),onShowAll));
  6670. }}};
  6671. dom.renderPageLinks=function(page,totalPage,pageWindow){Exhibit.OrderedViewFrame.renderPageLinks(dom.bottomPagingDiv,page,totalPage,pageWindow,gotoPage);
  6672. dom.bottomPagingDiv.style.display="block";
  6673. dom.showAllSpan.style.display="none";
  6674. };
  6675. dom.hidePageLinks=function(){dom.bottomPagingDiv.style.display="none";
  6676. };
  6677. dom.dispose=function(){};
  6678. return dom;
  6679. };
  6680. Exhibit.OrderedViewFrame.renderPageLinks=function(parentElmt,page,pageCount,pageWindow,gotoPage){var l10n=Exhibit.OrderedViewFrame.l10n;
  6681. parentElmt.className="exhibit-collectionView-pagingControls";
  6682. parentElmt.innerHTML="";
  6683. var self=this;
  6684. var renderPageLink=function(label,index){var elmt=document.createElement(l10n.pagingControlElement);
  6685. elmt.className="exhibit-collectionView-pagingControls-page";
  6686. parentElmt.appendChild(elmt);
  6687. var a=document.createElement("a");
  6688. a.innerHTML=label;
  6689. a.href="javascript:{}";
  6690. a.title=l10n.makePagingLinkTooltip(index);
  6691. elmt.appendChild(a);
  6692. var handler=function(elmt,evt,target){gotoPage(index);
  6693. SimileAjax.DOM.cancelEvent(evt);
  6694. return false;
  6695. };
  6696. SimileAjax.WindowManager.registerEvent(a,"click",handler);
  6697. };
  6698. var renderPageNumber=function(index){if(index==page){var elmt=document.createElement(l10n.pagingControlElement);
  6699. elmt.className="exhibit-collectionView-pagingControls-currentPage";
  6700. elmt.innerHTML=(index+1);
  6701. parentElmt.appendChild(elmt);
  6702. }else{renderPageLink(index+1,index);
  6703. }};
  6704. var renderHTML=function(html){var elmt=document.createElement(l10n.pagingControlElement);
  6705. elmt.innerHTML=html;
  6706. parentElmt.appendChild(elmt);
  6707. };
  6708. if(page>0){renderPageLink(l10n.previousPage,page-1);
  6709. if(l10n.pageSeparator.length>0){renderHTML(" ");
  6710. }}var pageWindowStart=0;
  6711. var pageWindowEnd=pageCount-1;
  6712. if(page-pageWindow>1){renderPageNumber(0);
  6713. renderHTML(l10n.pageWindowEllipses);
  6714. pageWindowStart=page-pageWindow;
  6715. }if(page+pageWindow<pageCount-2){pageWindowEnd=page+pageWindow;
  6716. }for(var i=pageWindowStart;
  6717. i<=pageWindowEnd;
  6718. i++){if(i>pageWindowStart&&l10n.pageSeparator.length>0){renderHTML(l10n.pageSeparator);
  6719. }renderPageNumber(i);
  6720. }if(pageWindowEnd<pageCount-1){renderHTML(l10n.pageWindowEllipses);
  6721. renderPageNumber(pageCount-1);
  6722. }if(page<pageCount-1){if(l10n.pageSeparator.length>0){renderHTML(" ");
  6723. }renderPageLink(l10n.nextPage,page+1);
  6724. }};
  6725. /* tabular-view.js */
  6726. Exhibit.TabularView=function(containerElmt,uiContext){this._div=containerElmt;
  6727. this._uiContext=uiContext;
  6728. this._settings={rowStyler:null,tableStyler:null,indexMap:{}};
  6729. this._columns=[];
  6730. this._rowTemplate=null;
  6731. var view=this;
  6732. this._listener={onItemsChanged:function(){view._settings.page=0;
  6733. view._reconstruct();
  6734. }};
  6735. uiContext.getCollection().addListener(this._listener);
  6736. };
  6737. Exhibit.TabularView._settingSpecs={"sortAscending":{type:"boolean",defaultValue:true},"sortColumn":{type:"int",defaultValue:0},"showSummary":{type:"boolean",defaultValue:true},"showToolbox":{type:"boolean",defaultValue:true},"border":{type:"int",defaultValue:1},"cellPadding":{type:"int",defaultValue:5},"cellSpacing":{type:"int",defaultValue:3},"paginate":{type:"boolean",defaultValue:false},"pageSize":{type:"int",defaultValue:20},"pageWindow":{type:"int",defaultValue:2},"page":{type:"int",defaultValue:0},"alwaysShowPagingControls":{type:"boolean",defaultValue:false},"pagingControlLocations":{type:"enum",defaultValue:"topbottom",choices:["top","bottom","topbottom"]}};
  6738. Exhibit.TabularView.create=function(configuration,containerElmt,uiContext){var view=new Exhibit.TabularView(containerElmt,Exhibit.UIContext.create(configuration,uiContext));
  6739. Exhibit.TabularView._configure(view,configuration);
  6740. view._internalValidate();
  6741. view._initializeUI();
  6742. return view;
  6743. };
  6744. Exhibit.TabularView.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  6745. uiContext=Exhibit.UIContext.createFromDOM(configElmt,uiContext);
  6746. var view=new Exhibit.TabularView(containerElmt!=null?containerElmt:configElmt,uiContext);
  6747. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.TabularView._settingSpecs,view._settings);
  6748. try{var expressions=[];
  6749. var labels=Exhibit.getAttribute(configElmt,"columnLabels",",")||[];
  6750. var s=Exhibit.getAttribute(configElmt,"columns");
  6751. if(s!=null&&s.length>0){expressions=Exhibit.ExpressionParser.parseSeveral(s);
  6752. }for(var i=0;
  6753. i<expressions.length;
  6754. i++){var expression=expressions[i];
  6755. view._columns.push({expression:expression,uiContext:Exhibit.UIContext.create({},view._uiContext,true),styler:null,label:i<labels.length?labels[i]:null,format:"list"});
  6756. }var formats=Exhibit.getAttribute(configElmt,"columnFormats");
  6757. if(formats!=null&&formats.length>0){var index=0;
  6758. var startPosition=0;
  6759. while(index<view._columns.length&&startPosition<formats.length){var column=view._columns[index];
  6760. var o={};
  6761. column.format=Exhibit.FormatParser.parseSeveral(column.uiContext,formats,startPosition,o);
  6762. startPosition=o.index;
  6763. while(startPosition<formats.length&&" \t\r\n".indexOf(formats.charAt(startPosition))>=0){startPosition++;
  6764. }if(startPosition<formats.length&&formats.charAt(startPosition)==","){startPosition++;
  6765. }index++;
  6766. }}var tables=configElmt.getElementsByTagName("table");
  6767. if(tables.length>0&&tables[0].rows.length>0){view._rowTemplate=Exhibit.Lens.compileTemplate(tables[0].rows[0],false,uiContext);
  6768. }}catch(e){SimileAjax.Debug.exception(e,"TabularView: Error processing configuration of tabular view");
  6769. }var s=Exhibit.getAttribute(configElmt,"rowStyler");
  6770. if(s!=null&&s.length>0){var f=eval(s);
  6771. if(typeof f=="function"){view._settings.rowStyler=f;
  6772. }}s=Exhibit.getAttribute(configElmt,"tableStyler");
  6773. if(s!=null&&s.length>0){f=eval(s);
  6774. if(typeof f=="function"){view._settings.tableStyler=f;
  6775. }}Exhibit.TabularView._configure(view,configuration);
  6776. view._internalValidate();
  6777. view._initializeUI();
  6778. return view;
  6779. };
  6780. Exhibit.TabularView._configure=function(view,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.TabularView._settingSpecs,view._settings);
  6781. if("columns" in configuration){var columns=configuration.columns;
  6782. for(var i=0;
  6783. i<columns.length;
  6784. i++){var column=columns[i];
  6785. var expr;
  6786. var styler=null;
  6787. var label=null;
  6788. var format=null;
  6789. if(typeof column=="string"){expr=column;
  6790. }else{expr=column.expression;
  6791. styler=column.styler;
  6792. label=column.label;
  6793. format=column.format;
  6794. }var expression=Exhibit.ExpressionParser.parse(expr);
  6795. if(expression.isPath()){var path=expression.getPath();
  6796. if(format!=null&&format.length>0){format=Exhibit.FormatParser.parse(view._uiContext,format,0);
  6797. }else{format="list";
  6798. }view._columns.push({expression:expression,styler:styler,label:label,format:format,uiContext:view._uiContext});
  6799. }}}if("rowStyler" in configuration){view._settings.rowStyler=configuration.rowStyler;
  6800. }if("tableStyler" in configuration){view._settings.tableStyler=configuration.tableStyler;
  6801. }};
  6802. Exhibit.TabularView.prototype._internalValidate=function(){if(this._columns.length==0){var database=this._uiContext.getDatabase();
  6803. var propertyIDs=database.getAllProperties();
  6804. for(var i=0;
  6805. i<propertyIDs.length;
  6806. i++){var propertyID=propertyIDs[i];
  6807. if(propertyID!="uri"){this._columns.push({expression:Exhibit.ExpressionParser.parse("."+propertyID),styler:null,label:database.getProperty(propertyID).getLabel(),format:"list"});
  6808. }}}this._settings.sortColumn=Math.max(0,Math.min(this._settings.sortColumn,this._columns.length-1));
  6809. };
  6810. Exhibit.TabularView.prototype.dispose=function(){this._uiContext.getCollection().removeListener(this._listener);
  6811. if(this._toolboxWidget){this._toolboxWidget.dispose();
  6812. this._toolboxWidget=null;
  6813. }this._collectionSummaryWidget.dispose();
  6814. this._collectionSummaryWidget=null;
  6815. this._uiContext.dispose();
  6816. this._uiContext=null;
  6817. this._div.innerHTML="";
  6818. this._dom=null;
  6819. this._div=null;
  6820. };
  6821. Exhibit.TabularView.prototype._initializeUI=function(){var self=this;
  6822. this._div.innerHTML="";
  6823. this._dom=Exhibit.TabularView.createDom(this._div);
  6824. this._collectionSummaryWidget=Exhibit.CollectionSummaryWidget.create({},this._dom.collectionSummaryDiv,this._uiContext);
  6825. if(this._settings.showToolbox){this._toolboxWidget=Exhibit.ToolboxWidget.createFromDOM(this._div,this._div,this._uiContext);
  6826. this._toolboxWidget.getGeneratedHTML=function(){return self._dom.bodyDiv.innerHTML;
  6827. };
  6828. }if(!this._settings.showSummary){this._dom.collectionSummaryDiv.style.display="none";
  6829. }this._reconstruct();
  6830. };
  6831. Exhibit.TabularView.prototype._reconstruct=function(){var self=this;
  6832. var collection=this._uiContext.getCollection();
  6833. var database=this._uiContext.getDatabase();
  6834. var bodyDiv=this._dom.bodyDiv;
  6835. bodyDiv.innerHTML="";
  6836. var items=[];
  6837. var originalSize=collection.countAllItems();
  6838. if(originalSize>0){var currentSet=collection.getRestrictedItems();
  6839. currentSet.visit(function(itemID){items.push({id:itemID,sortKey:""});
  6840. });
  6841. }if(items.length>0){var sortColumn=this._columns[this._settings.sortColumn];
  6842. var sorter=this._createSortFunction(items,sortColumn.expression,this._settings.sortAscending);
  6843. items.sort(this._stabilize(sorter,this._settings.indexMap,originalSize+1));
  6844. for(i=0;
  6845. i<items.length;
  6846. i++){this._settings.indexMap[items[i].id]=i;
  6847. }var table=document.createElement("table");
  6848. table.className="exhibit-tabularView-body";
  6849. if(this._settings.tableStyler!=null){this._settings.tableStyler(table,database);
  6850. }else{table.cellSpacing=this._settings.cellSpacing;
  6851. table.cellPadding=this._settings.cellPadding;
  6852. table.border=this._settings.border;
  6853. }var tr=table.insertRow(0);
  6854. var createColumnHeader=function(i){var column=self._columns[i];
  6855. if(column.label==null){column.label=self._getColumnLabel(column.expression);
  6856. }var td=document.createElement("th");
  6857. Exhibit.TabularView.createColumnHeader(exhibit,td,column.label,i==self._settings.sortColumn,self._settings.sortAscending,function(elmt,evt,target){self._doSort(i);
  6858. SimileAjax.DOM.cancelEvent(evt);
  6859. return false;
  6860. });
  6861. tr.appendChild(td);
  6862. };
  6863. for(var i=0;
  6864. i<this._columns.length;
  6865. i++){createColumnHeader(i);
  6866. }var renderItem;
  6867. if(this._rowTemplate!=null){renderItem=function(i){var item=items[i];
  6868. var tr=Exhibit.Lens.constructFromLensTemplate(item.id,self._rowTemplate,table,self._uiContext);
  6869. if(self._settings.rowStyler!=null){self._settings.rowStyler(item.id,database,tr,i);
  6870. }};
  6871. }else{renderItem=function(i){var item=items[i];
  6872. var tr=table.insertRow(table.rows.length);
  6873. for(var c=0;
  6874. c<self._columns.length;
  6875. c++){var column=self._columns[c];
  6876. var td=tr.insertCell(c);
  6877. var results=column.expression.evaluate({"value":item.id},{"value":"item"},"value",database);
  6878. var valueType=column.format=="list"?results.valueType:column.format;
  6879. column.uiContext.formatList(results.values,results.size,valueType,function(elmt){td.appendChild(elmt);
  6880. });
  6881. if(column.styler!=null){column.styler(item.id,database,td);
  6882. }}if(self._settings.rowStyler!=null){self._settings.rowStyler(item.id,database,tr,i);
  6883. }};
  6884. }var start,end;
  6885. var generatePagingControls=false;
  6886. if(this._settings.paginate){start=this._settings.page*this._settings.pageSize;
  6887. end=Math.min(start+this._settings.pageSize,items.length);
  6888. generatePagingControls=(items.length>this._settings.pageSize)||(items.length>0&&this._settings.alwaysShowPagingControls);
  6889. }else{start=0;
  6890. end=items.length;
  6891. }for(var i=start;
  6892. i<end;
  6893. i++){renderItem(i);
  6894. }bodyDiv.appendChild(table);
  6895. if(generatePagingControls){if(this._settings.pagingControlLocations=="top"||this._settings.pagingControlLocations=="topbottom"){this._renderPagingDiv(this._dom.topPagingDiv,items.length,this._settings.page);
  6896. this._dom.topPagingDiv.style.display="block";
  6897. }if(this._settings.pagingControlLocations=="bottom"||this._settings.pagingControlLocations=="topbottom"){this._renderPagingDiv(this._dom.bottomPagingDiv,items.length,this._settings.page);
  6898. this._dom.bottomPagingDiv.style.display="block";
  6899. }}else{this._dom.topPagingDiv.style.display="none";
  6900. this._dom.bottomPagingDiv.style.display="none";
  6901. }}};
  6902. Exhibit.TabularView.prototype._renderPagingDiv=function(parentElmt,itemCount,page){var pageCount=Math.ceil(itemCount/this._settings.pageSize);
  6903. var self=this;
  6904. Exhibit.OrderedViewFrame.renderPageLinks(parentElmt,page,pageCount,this._settings.pageWindow,function(p){self._gotoPage(p);
  6905. });
  6906. };
  6907. Exhibit.TabularView.prototype._getColumnLabel=function(expression){var database=this._uiContext.getDatabase();
  6908. var path=expression.getPath();
  6909. var segment=path.getSegment(path.getSegmentCount()-1);
  6910. var propertyID=segment.property;
  6911. var property=database.getProperty(propertyID);
  6912. if(property!=null){return segment.forward?property.getLabel():property.getReverseLabel();
  6913. }else{return propertyID;
  6914. }};
  6915. Exhibit.TabularView.prototype._stabilize=function(f,indexMap){var stable=function(item1,item2){var cmp=f(item1,item2);
  6916. if(cmp){return cmp;
  6917. }else{i1=item1.id in indexMap?indexMap[item1.id]:-1;
  6918. i2=item2.id in indexMap?indexMap[item2.id]:-1;
  6919. return i1-i2;
  6920. }};
  6921. return stable;
  6922. };
  6923. Exhibit.TabularView.prototype._createSortFunction=function(items,expression,ascending){var database=this._uiContext.getDatabase();
  6924. var multiply=ascending?1:-1;
  6925. var numericFunction=function(item1,item2){var val=multiply*(item1.sortKey-item2.sortKey);
  6926. return isNaN(val)?0:val;
  6927. };
  6928. var textFunction=function(item1,item2){return multiply*item1.sortKey.localeCompare(item2.sortKey);
  6929. };
  6930. var valueTypes=[];
  6931. var valueTypeMap={};
  6932. for(var i=0;
  6933. i<items.length;
  6934. i++){var item=items[i];
  6935. var r=expression.evaluate({"value":item.id},{"value":"item"},"value",database);
  6936. r.values.visit(function(value){item.sortKey=value;
  6937. });
  6938. if(!(r.valueType in valueTypeMap)){valueTypeMap[r.valueType]=true;
  6939. valueTypes.push(r.valueType);
  6940. }}var coercedValueType="text";
  6941. if(valueTypes.length==1){coercedValueType=valueTypes[0];
  6942. }else{coercedValueType="text";
  6943. }var coersion;
  6944. var sortingFunction;
  6945. if(coercedValueType=="number"){sortingFunction=numericFunction;
  6946. coersion=function(v){if(v==null){return Number.NEGATIVE_INFINITY;
  6947. }else{if(typeof v=="number"){return v;
  6948. }else{var n=parseFloat(v);
  6949. if(isNaN(n)){return Number.MAX_VALUE;
  6950. }else{return n;
  6951. }}}};
  6952. }else{if(coercedValueType=="date"){sortingFunction=numericFunction;
  6953. coersion=function(v){if(v==null){return Number.NEGATIVE_INFINITY;
  6954. }else{if(v instanceof Date){return v.getTime();
  6955. }else{try{return SimileAjax.DateTime.parseIso8601DateTime(v).getTime();
  6956. }catch(e){return Number.MAX_VALUE;
  6957. }}}};
  6958. }else{if(coercedValueType=="boolean"){sortingFunction=numericFunction;
  6959. coersion=function(v){if(v==null){return Number.MAX_VALUE;
  6960. }else{if(typeof v=="boolean"){return v?1:0;
  6961. }else{return v.toString().toLowerCase()=="true";
  6962. }}};
  6963. }else{if(coercedValueType=="item"){sortingFunction=textFunction;
  6964. coersion=function(v){if(v==null){return Exhibit.l10n.missingSortKey;
  6965. }else{var label=database.getObject(v,"label");
  6966. return(label==null)?v:label;
  6967. }};
  6968. }else{sortingFunction=textFunction;
  6969. coersion=function(v){if(v==null){return Exhibit.l10n.missingSortKey;
  6970. }else{return v.toString();
  6971. }};
  6972. }}}}for(var i=0;
  6973. i<items.length;
  6974. i++){var item=items[i];
  6975. item.sortKey=coersion(item.sortKey);
  6976. }return sortingFunction;
  6977. };
  6978. Exhibit.TabularView.prototype._doSort=function(columnIndex){var oldSortColumn=this._settings.sortColumn;
  6979. var oldSortAscending=this._settings.sortAscending;
  6980. var newSortColumn=columnIndex;
  6981. var newSortAscending=oldSortColumn==newSortColumn?!oldSortAscending:true;
  6982. var oldPage=this._settings.page;
  6983. var newPage=0;
  6984. var settings=this._settings;
  6985. var self=this;
  6986. SimileAjax.History.addLengthyAction(function(){settings.sortColumn=newSortColumn;
  6987. settings.sortAscending=newSortAscending;
  6988. settings.page=newPage;
  6989. self._reconstruct();
  6990. },function(){settings.sortColumn=oldSortColumn;
  6991. settings.sortAscending=oldSortAscending;
  6992. settings.page=oldPage;
  6993. self._reconstruct();
  6994. },Exhibit.TabularView.l10n.makeSortActionTitle(this._columns[columnIndex].label,newSortAscending));
  6995. };
  6996. Exhibit.TabularView.prototype._gotoPage=function(page){var oldPage=this._settings.page;
  6997. var newPage=page;
  6998. var settings=this._settings;
  6999. var self=this;
  7000. SimileAjax.History.addLengthyAction(function(){settings.page=newPage;
  7001. self._reconstruct();
  7002. },function(){settings.page=oldPage;
  7003. self._reconstruct();
  7004. },Exhibit.OrderedViewFrame.l10n.makePagingActionTitle(page));
  7005. };
  7006. Exhibit.TabularView._constructDefaultValueList=function(values,valueType,parentElmt,uiContext){uiContext.formatList(values,values.size(),valueType,function(elmt){parentElmt.appendChild(elmt);
  7007. });
  7008. };
  7009. Exhibit.TabularView.createDom=function(div){var l10n=Exhibit.TabularView.l10n;
  7010. var l10n2=Exhibit.OrderedViewFrame.l10n;
  7011. var headerTemplate={elmt:div,className:"exhibit-collectionView-header",children:[{tag:"div",field:"collectionSummaryDiv"},{tag:l10n2.pagingControlContainerElement,className:"exhibit-tabularView-pagingControls",field:"topPagingDiv"},{tag:"div",field:"bodyDiv"},{tag:l10n2.pagingControlContainerElement,className:"exhibit-tabularView-pagingControls",field:"bottomPagingDiv"}]};
  7012. return SimileAjax.DOM.createDOMFromTemplate(headerTemplate);
  7013. };
  7014. Exhibit.TabularView.createColumnHeader=function(exhibit,th,label,sort,sortAscending,sortFunction){var l10n=Exhibit.TabularView.l10n;
  7015. var template={elmt:th,className:sort?"exhibit-tabularView-columnHeader-sorted":"exhibit-tabularView-columnHeader",title:sort?l10n.columnHeaderReSortTooltip:l10n.columnHeaderSortTooltip,children:[label]};
  7016. if(sort){template.children.push({elmt:Exhibit.UI.createTranslucentImage(sortAscending?"images/up-arrow.png":"images/down-arrow.png")});
  7017. }SimileAjax.WindowManager.registerEvent(th,"click",sortFunction,null);
  7018. var dom=SimileAjax.DOM.createDOMFromTemplate(template);
  7019. return dom;
  7020. };
  7021. /* thumbnail-view.js */
  7022. Exhibit.ThumbnailView=function(containerElmt,uiContext){this._div=containerElmt;
  7023. this._uiContext=uiContext;
  7024. this._settings={};
  7025. var view=this;
  7026. this._listener={onItemsChanged:function(){view._orderedViewFrame._settings.page=0;
  7027. view._reconstruct();
  7028. }};
  7029. uiContext.getCollection().addListener(this._listener);
  7030. this._orderedViewFrame=new Exhibit.OrderedViewFrame(uiContext);
  7031. this._orderedViewFrame.parentReconstruct=function(){view._reconstruct();
  7032. };
  7033. };
  7034. Exhibit.ThumbnailView._settingSpecs={"showToolbox":{type:"boolean",defaultValue:true},"columnCount":{type:"int",defaultValue:-1}};
  7035. Exhibit.ThumbnailView._itemContainerClass=SimileAjax.Platform.browser.isIE?"exhibit-thumbnailView-itemContainer-IE":"exhibit-thumbnailView-itemContainer";
  7036. Exhibit.ThumbnailView.create=function(configuration,containerElmt,uiContext){var view=new Exhibit.ThumbnailView(containerElmt,Exhibit.UIContext.create(configuration,uiContext,true));
  7037. view._lensRegistry=Exhibit.UIContext.createLensRegistry(configuration,uiContext.getLensRegistry());
  7038. Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.ThumbnailView._settingSpecs,view._settings);
  7039. view._orderedViewFrame.configure(configuration);
  7040. view._initializeUI();
  7041. return view;
  7042. };
  7043. Exhibit.ThumbnailView.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  7044. var view=new Exhibit.ThumbnailView(containerElmt!=null?containerElmt:configElmt,Exhibit.UIContext.createFromDOM(configElmt,uiContext,true));
  7045. view._lensRegistry=Exhibit.UIContext.createLensRegistryFromDOM(configElmt,configuration,uiContext.getLensRegistry());
  7046. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.ThumbnailView._settingSpecs,view._settings);
  7047. Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.ThumbnailView._settingSpecs,view._settings);
  7048. view._orderedViewFrame.configureFromDOM(configElmt);
  7049. view._orderedViewFrame.configure(configuration);
  7050. view._initializeUI();
  7051. return view;
  7052. };
  7053. Exhibit.ThumbnailView.prototype.dispose=function(){this._uiContext.getCollection().removeListener(this._listener);
  7054. if(this._toolboxWidget){this._toolboxWidget.dispose();
  7055. this._toolboxWidget=null;
  7056. }this._orderedViewFrame.dispose();
  7057. this._orderedViewFrame=null;
  7058. this._lensRegistry=null;
  7059. this._dom=null;
  7060. this._div.innerHTML="";
  7061. this._div=null;
  7062. this._uiContext=null;
  7063. };
  7064. Exhibit.ThumbnailView.prototype._initializeUI=function(){var self=this;
  7065. this._div.innerHTML="";
  7066. var template={elmt:this._div,children:[{tag:"div",field:"headerDiv"},{tag:"div",className:"exhibit-collectionView-body",field:"bodyDiv"},{tag:"div",field:"footerDiv"}]};
  7067. this._dom=SimileAjax.DOM.createDOMFromTemplate(template);
  7068. if(this._settings.showToolbox){this._toolboxWidget=Exhibit.ToolboxWidget.createFromDOM(this._div,this._div,this._uiContext);
  7069. this._toolboxWidget.getGeneratedHTML=function(){return self._dom.bodyDiv.innerHTML;
  7070. };
  7071. }this._orderedViewFrame._divHeader=this._dom.headerDiv;
  7072. this._orderedViewFrame._divFooter=this._dom.footerDiv;
  7073. this._orderedViewFrame._generatedContentElmtRetriever=function(){return self._dom.bodyDiv;
  7074. };
  7075. this._orderedViewFrame.initializeUI();
  7076. this._reconstruct();
  7077. };
  7078. Exhibit.ThumbnailView.prototype._reconstruct=function(){if(this._settings.columnCount<2){this._reconstructWithFloats();
  7079. }else{this._reconstructWithTable();
  7080. }};
  7081. Exhibit.ThumbnailView.prototype._reconstructWithFloats=function(){var view=this;
  7082. var state={div:this._dom.bodyDiv,itemContainer:null,groupDoms:[],groupCounts:[]};
  7083. var closeGroups=function(groupLevel){for(var i=groupLevel;
  7084. i<state.groupDoms.length;
  7085. i++){state.groupDoms[i].countSpan.innerHTML=state.groupCounts[i];
  7086. }state.groupDoms=state.groupDoms.slice(0,groupLevel);
  7087. state.groupCounts=state.groupCounts.slice(0,groupLevel);
  7088. if(groupLevel>0){state.div=state.groupDoms[groupLevel-1].contentDiv;
  7089. }else{state.div=view._dom.bodyDiv;
  7090. }state.itemContainer=null;
  7091. };
  7092. this._orderedViewFrame.onNewGroup=function(groupSortKey,keyType,groupLevel){closeGroups(groupLevel);
  7093. var groupDom=Exhibit.ThumbnailView.constructGroup(groupLevel,groupSortKey);
  7094. state.div.appendChild(groupDom.elmt);
  7095. state.div=groupDom.contentDiv;
  7096. state.groupDoms.push(groupDom);
  7097. state.groupCounts.push(0);
  7098. };
  7099. this._orderedViewFrame.onNewItem=function(itemID,index){if(state.itemContainer==null){state.itemContainer=Exhibit.ThumbnailView.constructItemContainer();
  7100. state.div.appendChild(state.itemContainer);
  7101. }for(var i=0;
  7102. i<state.groupCounts.length;
  7103. i++){state.groupCounts[i]++;
  7104. }var itemLensDiv=document.createElement("div");
  7105. itemLensDiv.className=Exhibit.ThumbnailView._itemContainerClass;
  7106. var itemLens=view._lensRegistry.createLens(itemID,itemLensDiv,view._uiContext);
  7107. state.itemContainer.appendChild(itemLensDiv);
  7108. };
  7109. this._div.style.display="none";
  7110. this._dom.bodyDiv.innerHTML="";
  7111. this._orderedViewFrame.reconstruct();
  7112. closeGroups(0);
  7113. this._div.style.display="block";
  7114. };
  7115. Exhibit.ThumbnailView.prototype._reconstructWithTable=function(){var view=this;
  7116. var state={div:this._dom.bodyDiv,groupDoms:[],groupCounts:[],table:null,columnIndex:0};
  7117. var closeGroups=function(groupLevel){for(var i=groupLevel;
  7118. i<state.groupDoms.length;
  7119. i++){state.groupDoms[i].countSpan.innerHTML=state.groupCounts[i];
  7120. }state.groupDoms=state.groupDoms.slice(0,groupLevel);
  7121. state.groupCounts=state.groupCounts.slice(0,groupLevel);
  7122. if(groupLevel>0){state.div=state.groupDoms[groupLevel-1].contentDiv;
  7123. }else{state.div=view._dom.bodyDiv;
  7124. }state.itemContainer=null;
  7125. state.table=null;
  7126. state.columnIndex=0;
  7127. };
  7128. this._orderedViewFrame.onNewGroup=function(groupSortKey,keyType,groupLevel){closeGroups(groupLevel);
  7129. var groupDom=Exhibit.ThumbnailView.constructGroup(groupLevel,groupSortKey);
  7130. state.div.appendChild(groupDom.elmt);
  7131. state.div=groupDom.contentDiv;
  7132. state.groupDoms.push(groupDom);
  7133. state.groupCounts.push(0);
  7134. };
  7135. this._orderedViewFrame.onNewItem=function(itemID,index){if(state.columnIndex>=view._settings.columnCount){state.columnIndex=0;
  7136. }if(state.table==null){state.table=Exhibit.ThumbnailView.constructTableItemContainer();
  7137. state.div.appendChild(state.table);
  7138. }if(state.columnIndex==0){state.table.insertRow(state.table.rows.length);
  7139. }var td=state.table.rows[state.table.rows.length-1].insertCell(state.columnIndex++);
  7140. for(var i=0;
  7141. i<state.groupCounts.length;
  7142. i++){state.groupCounts[i]++;
  7143. }var itemLensDiv=document.createElement("div");
  7144. itemLensDiv.className=Exhibit.ThumbnailView._itemContainerClass;
  7145. var itemLens=view._lensRegistry.createLens(itemID,itemLensDiv,view._uiContext);
  7146. td.appendChild(itemLensDiv);
  7147. };
  7148. this._div.style.display="none";
  7149. this._dom.bodyDiv.innerHTML="";
  7150. this._orderedViewFrame.reconstruct();
  7151. closeGroups(0);
  7152. this._div.style.display="block";
  7153. };
  7154. Exhibit.ThumbnailView.constructGroup=function(groupLevel,label){var l10n=Exhibit.ThumbnailView.l10n;
  7155. var template={tag:"div",className:"exhibit-thumbnailView-group",children:[{tag:"h"+(groupLevel+1),children:[label,{tag:"span",className:"exhibit-collectionView-group-count",children:[" (",{tag:"span",field:"countSpan"},")"]}],field:"header"},{tag:"div",className:"exhibit-collectionView-group-content",field:"contentDiv"}]};
  7156. return SimileAjax.DOM.createDOMFromTemplate(template);
  7157. };
  7158. Exhibit.ThumbnailView.constructItemContainer=function(){var div=document.createElement("div");
  7159. div.className="exhibit-thumbnailView-body";
  7160. return div;
  7161. };
  7162. Exhibit.ThumbnailView.constructTableItemContainer=function(){var table=document.createElement("table");
  7163. table.className="exhibit-thumbnailView-body";
  7164. return table;
  7165. };
  7166. /* tile-view.js */
  7167. Exhibit.TileView=function(containerElmt,uiContext){this._div=containerElmt;
  7168. this._uiContext=uiContext;
  7169. this._settings={};
  7170. var view=this;
  7171. this._listener={onItemsChanged:function(){view._orderedViewFrame._settings.page=0;
  7172. view._reconstruct();
  7173. }};
  7174. uiContext.getCollection().addListener(this._listener);
  7175. this._orderedViewFrame=new Exhibit.OrderedViewFrame(uiContext);
  7176. this._orderedViewFrame.parentReconstruct=function(){view._reconstruct();
  7177. };
  7178. };
  7179. Exhibit.TileView._settingSpecs={"showToolbox":{type:"boolean",defaultValue:true}};
  7180. Exhibit.TileView.create=function(configuration,containerElmt,uiContext){var view=new Exhibit.TileView(containerElmt,Exhibit.UIContext.create(configuration,uiContext));
  7181. Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.TileView._settingSpecs,view._settings);
  7182. view._orderedViewFrame.configure(configuration);
  7183. view._initializeUI();
  7184. return view;
  7185. };
  7186. Exhibit.TileView.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  7187. var view=new Exhibit.TileView(containerElmt!=null?containerElmt:configElmt,Exhibit.UIContext.createFromDOM(configElmt,uiContext));
  7188. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.TileView._settingSpecs,view._settings);
  7189. Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.TileView._settingSpecs,view._settings);
  7190. view._orderedViewFrame.configureFromDOM(configElmt);
  7191. view._orderedViewFrame.configure(configuration);
  7192. view._initializeUI();
  7193. return view;
  7194. };
  7195. Exhibit.TileView.prototype.dispose=function(){this._uiContext.getCollection().removeListener(this._listener);
  7196. this._div.innerHTML="";
  7197. if(this._toolboxWidget){this._toolboxWidget.dispose();
  7198. this._toolboxWidget=null;
  7199. }this._orderedViewFrame.dispose();
  7200. this._orderedViewFrame=null;
  7201. this._dom=null;
  7202. this._div=null;
  7203. this._uiContext=null;
  7204. };
  7205. Exhibit.TileView.prototype._initializeUI=function(){var self=this;
  7206. this._div.innerHTML="";
  7207. var template={elmt:this._div,children:[{tag:"div",field:"headerDiv"},{tag:"div",className:"exhibit-collectionView-body",field:"bodyDiv"},{tag:"div",field:"footerDiv"}]};
  7208. this._dom=SimileAjax.DOM.createDOMFromTemplate(template);
  7209. if(this._settings.showToolbox){this._toolboxWidget=Exhibit.ToolboxWidget.createFromDOM(this._div,this._div,this._uiContext);
  7210. this._toolboxWidget.getGeneratedHTML=function(){return self._dom.bodyDiv.innerHTML;
  7211. };
  7212. }this._orderedViewFrame._divHeader=this._dom.headerDiv;
  7213. this._orderedViewFrame._divFooter=this._dom.footerDiv;
  7214. this._orderedViewFrame._generatedContentElmtRetriever=function(){return self._dom.bodyDiv;
  7215. };
  7216. this._orderedViewFrame.initializeUI();
  7217. this._reconstruct();
  7218. };
  7219. Exhibit.TileView.prototype._reconstruct=function(){var view=this;
  7220. var state={div:this._dom.bodyDiv,contents:null,groupDoms:[],groupCounts:[]};
  7221. var closeGroups=function(groupLevel){for(var i=groupLevel;
  7222. i<state.groupDoms.length;
  7223. i++){state.groupDoms[i].countSpan.innerHTML=state.groupCounts[i];
  7224. }state.groupDoms=state.groupDoms.slice(0,groupLevel);
  7225. state.groupCounts=state.groupCounts.slice(0,groupLevel);
  7226. if(groupLevel>0){state.div=state.groupDoms[groupLevel-1].contentDiv;
  7227. }else{state.div=view._dom.bodyDiv;
  7228. }state.contents=null;
  7229. };
  7230. this._orderedViewFrame.onNewGroup=function(groupSortKey,keyType,groupLevel){closeGroups(groupLevel);
  7231. var groupDom=Exhibit.TileView.constructGroup(groupLevel,groupSortKey);
  7232. state.div.appendChild(groupDom.elmt);
  7233. state.div=groupDom.contentDiv;
  7234. state.groupDoms.push(groupDom);
  7235. state.groupCounts.push(0);
  7236. };
  7237. this._orderedViewFrame.onNewItem=function(itemID,index){if(state.contents==null){state.contents=Exhibit.TileView.constructList();
  7238. state.div.appendChild(state.contents);
  7239. }for(var i=0;
  7240. i<state.groupCounts.length;
  7241. i++){state.groupCounts[i]++;
  7242. }var itemLensItem=document.createElement("li");
  7243. var itemLens=view._uiContext.getLensRegistry().createLens(itemID,itemLensItem,view._uiContext);
  7244. state.contents.appendChild(itemLensItem);
  7245. };
  7246. this._div.style.display="none";
  7247. this._dom.bodyDiv.innerHTML="";
  7248. this._orderedViewFrame.reconstruct();
  7249. closeGroups(0);
  7250. this._div.style.display="block";
  7251. };
  7252. Exhibit.TileView.constructGroup=function(groupLevel,label){var template={tag:"div",className:"exhibit-collectionView-group",children:[{tag:"h"+(groupLevel+1),children:[label,{tag:"span",className:"exhibit-collectionView-group-count",children:[" (",{tag:"span",field:"countSpan"},")"]}],field:"header"},{tag:"div",className:"exhibit-collectionView-group-content",field:"contentDiv"}]};
  7253. return SimileAjax.DOM.createDOMFromTemplate(template);
  7254. };
  7255. Exhibit.TileView.constructList=function(){var div=document.createElement("ol");
  7256. div.className="exhibit-tileView-body";
  7257. return div;
  7258. };
  7259. /* view-panel.js */
  7260. Exhibit.ViewPanel=function(div,uiContext){this._uiContext=uiContext;
  7261. this._div=div;
  7262. this._uiContextCache={};
  7263. this._viewConstructors=[];
  7264. this._viewConfigs=[];
  7265. this._viewLabels=[];
  7266. this._viewTooltips=[];
  7267. this._viewDomConfigs=[];
  7268. this._viewIDs=[];
  7269. this._viewClassStrings=[];
  7270. this._viewIndex=0;
  7271. this._view=null;
  7272. };
  7273. Exhibit.ViewPanel.create=function(configuration,div,uiContext){var viewPanel=new Exhibit.ViewPanel(div,uiContext);
  7274. if("views" in configuration){for(var i=0;
  7275. i<configuration.views.length;
  7276. i++){var viewConfig=configuration.views[i];
  7277. var viewClass=("viewClass" in view)?view.viewClass:Exhibit.TileView;
  7278. if(typeof viewClass=="string"){viewClass=Exhibit.UI.viewClassNameToViewClass(viewClass);
  7279. }var label=null;
  7280. if("viewLabel" in viewConfig){label=viewConfig.viewLabel;
  7281. }else{if("label" in viewConfig){label=viewConfig.label;
  7282. }else{if("l10n" in viewClass&&"viewLabel" in viewClass.l10n){label=viewClass.l10n.viewLabel;
  7283. }else{label=""+viewClass;
  7284. }}}var tooltip=null;
  7285. if("tooltip" in viewConfig){tooltip=viewConfig.tooltip;
  7286. }else{if("l10n" in viewClass&&"viewTooltip" in viewClass.l10n){tooltip=viewClass.l10n.viewTooltip;
  7287. }else{tooltip=label;
  7288. }}var id=viewPanel._generateViewID();
  7289. if("id" in viewConfig){id=viewConfig.id;
  7290. }viewPanel._viewConstructors.push(viewClass);
  7291. viewPanel._viewConfigs.push(viewConfig);
  7292. viewPanel._viewLabels.push(label);
  7293. viewPanel._viewTooltips.push(tooltip);
  7294. viewPanel._viewDomConfigs.push(null);
  7295. viewPanel._viewIDs.push(id);
  7296. }}if("initialView" in configuration){viewPanel._viewIndex=configuration.initialView;
  7297. }viewPanel._internalValidate();
  7298. viewPanel._initializeUI();
  7299. return viewPanel;
  7300. };
  7301. Exhibit.ViewPanel.createFromDOM=function(div,uiContext){var viewPanel=new Exhibit.ViewPanel(div,Exhibit.UIContext.createFromDOM(div,uiContext,false));
  7302. var node=div.firstChild;
  7303. while(node!=null){if(node.nodeType==1){node.style.display="none";
  7304. var role=Exhibit.getRoleAttribute(node);
  7305. if(role=="view"){var viewClass=Exhibit.TileView;
  7306. var viewClassString=Exhibit.getAttribute(node,"viewClass");
  7307. if(viewClassString!=null&&viewClassString.length>0){viewClass=Exhibit.UI.viewClassNameToViewClass(viewClassString);
  7308. if(viewClass==null){SimileAjax.Debug.warn("Unknown viewClass "+viewClassString);
  7309. }}var viewLabel=Exhibit.getAttribute(node,"viewLabel");
  7310. var label=(viewLabel!=null&&viewLabel.length>0)?viewLabel:Exhibit.getAttribute(node,"label");
  7311. var tooltip=Exhibit.getAttribute(node,"title");
  7312. var id=node.id;
  7313. if(label==null){if("viewLabel" in viewClass.l10n){label=viewClass.l10n.viewLabel;
  7314. }else{label=""+viewClass;
  7315. }}if(tooltip==null){if("l10n" in viewClass&&"viewTooltip" in viewClass.l10n){tooltip=viewClass.l10n.viewTooltip;
  7316. }else{tooltip=label;
  7317. }}if(id==null||id.length==0){id=viewPanel._generateViewID();
  7318. }viewPanel._viewConstructors.push(viewClass);
  7319. viewPanel._viewConfigs.push(null);
  7320. viewPanel._viewLabels.push(label);
  7321. viewPanel._viewTooltips.push(tooltip);
  7322. viewPanel._viewDomConfigs.push(node);
  7323. viewPanel._viewIDs.push(id);
  7324. viewPanel._viewClassStrings.push(viewClassString);
  7325. }}node=node.nextSibling;
  7326. }var initialView=Exhibit.getAttribute(div,"initialView");
  7327. if(initialView!=null&&initialView.length>0){try{var n=parseInt(initialView);
  7328. if(!isNaN(n)){viewPanel._viewIndex=n;
  7329. }}catch(e){}}viewPanel._internalValidate();
  7330. viewPanel._initializeUI();
  7331. return viewPanel;
  7332. };
  7333. Exhibit.ViewPanel.prototype.dispose=function(){this._uiContext.getCollection().removeListener(this._listener);
  7334. if(this._view!=null){this._view.dispose();
  7335. this._view=null;
  7336. }this._div.innerHTML="";
  7337. this._uiContext.dispose();
  7338. this._uiContext=null;
  7339. this._div=null;
  7340. };
  7341. Exhibit.ViewPanel.prototype._generateViewID=function(){return"view"+Math.floor(Math.random()*1000000).toString();
  7342. };
  7343. Exhibit.ViewPanel.prototype._internalValidate=function(){if(this._viewConstructors.length==0){this._viewConstructors.push(Exhibit.TileView);
  7344. this._viewConfigs.push({});
  7345. this._viewLabels.push(Exhibit.TileView.l10n.viewLabel);
  7346. this._viewTooltips.push(Exhibit.TileView.l10n.viewTooltip);
  7347. this._viewDomConfigs.push(null);
  7348. this._viewIDs.push(this._generateViewID());
  7349. }this._viewIndex=Math.max(0,Math.min(this._viewIndex,this._viewConstructors.length-1));
  7350. };
  7351. Exhibit.ViewPanel.prototype._initializeUI=function(){var div=document.createElement("div");
  7352. if(this._div.firstChild!=null){this._div.insertBefore(div,this._div.firstChild);
  7353. }else{this._div.appendChild(div);
  7354. }var self=this;
  7355. this._dom=Exhibit.ViewPanel.constructDom(this._div.firstChild,this._viewLabels,this._viewTooltips,function(index){self._selectView(index);
  7356. });
  7357. this._createView();
  7358. };
  7359. Exhibit.ViewPanel.prototype._createView=function(){var viewContainer=this._dom.getViewContainer();
  7360. viewContainer.innerHTML="";
  7361. var viewDiv=document.createElement("div");
  7362. viewContainer.appendChild(viewDiv);
  7363. var index=this._viewIndex;
  7364. var context=this._uiContextCache[index]||this._uiContext;
  7365. try{if(this._viewDomConfigs[index]!=null){this._view=this._viewConstructors[index].createFromDOM(this._viewDomConfigs[index],viewContainer,context);
  7366. }else{this._view=this._viewConstructors[index].create(this._viewConfigs[index],viewContainer,context);
  7367. }}catch(e){SimileAjax.Debug.log("Failed to create view "+this._viewLabels[index]);
  7368. SimileAjax.Debug.exception(e);
  7369. }this._uiContextCache[index]=this._view._uiContext;
  7370. this._uiContext.getExhibit().setComponent(this._viewIDs[index],this._view);
  7371. this._dom.setViewIndex(index);
  7372. };
  7373. Exhibit.ViewPanel.prototype._switchView=function(newIndex){if(this._view){this._uiContext.getExhibit().disposeComponent(this._viewIDs[this._viewIndex]);
  7374. this._view=null;
  7375. }this._viewIndex=newIndex;
  7376. this._createView();
  7377. };
  7378. Exhibit.ViewPanel.prototype._selectView=function(newIndex){var oldIndex=this._viewIndex;
  7379. var self=this;
  7380. SimileAjax.History.addLengthyAction(function(){self._switchView(newIndex);
  7381. },function(){self._switchView(oldIndex);
  7382. },Exhibit.ViewPanel.l10n.createSelectViewActionTitle(self._viewLabels[newIndex]));
  7383. if(SimileAjax.RemoteLog.logActive){var dat={"action":"switchView","oldIndex":oldIndex,"newIndex":newIndex,"oldLabel":this._viewLabels[oldIndex],"newLabel":this._viewLabels[newIndex],"oldID":this._viewIDs[oldIndex],"newID":this._viewIDs[newIndex]};
  7384. if(newIndex<this._viewClassStrings.length){dat["newClass"]=this._viewClassStrings[newIndex];
  7385. }if(oldIndex<this._viewClassStrings.length){dat["oldClass"]=this._viewClassStrings[oldIndex];
  7386. }SimileAjax.RemoteLog.possiblyLog(dat);
  7387. }};
  7388. Exhibit.ViewPanel.getPropertyValuesPairs=function(itemID,propertyEntries,database){var pairs=[];
  7389. var enterPair=function(propertyID,forward){var property=database.getProperty(propertyID);
  7390. var values=forward?database.getObjects(itemID,propertyID):database.getSubjects(itemID,propertyID);
  7391. var count=values.size();
  7392. if(count>0){var itemValues=property.getValueType()=="item";
  7393. var pair={propertyLabel:forward?(count>1?property.getPluralLabel():property.getLabel()):(count>1?property.getReversePluralLabel():property.getReverseLabel()),valueType:property.getValueType(),values:[]};
  7394. if(itemValues){values.visit(function(value){var label=database.getObject(value,"label");
  7395. pair.values.push(label!=null?label:value);
  7396. });
  7397. }else{values.visit(function(value){pair.values.push(value);
  7398. });
  7399. }pairs.push(pair);
  7400. }};
  7401. for(var i=0;
  7402. i<propertyEntries.length;
  7403. i++){var entry=propertyEntries[i];
  7404. if(typeof entry=="string"){enterPair(entry,true);
  7405. }else{enterPair(entry.property,entry.forward);
  7406. }}return pairs;
  7407. };
  7408. Exhibit.ViewPanel.constructDom=function(div,viewLabels,viewTooltips,onSelectView){var l10n=Exhibit.ViewPanel.l10n;
  7409. var template={elmt:div,className:"exhibit-viewPanel exhibit-ui-protection",children:[{tag:"div",className:"exhibit-viewPanel-viewSelection",field:"viewSelectionDiv"},{tag:"div",className:"exhibit-viewPanel-viewContainer",field:"viewContainerDiv"}]};
  7410. var dom=SimileAjax.DOM.createDOMFromTemplate(template);
  7411. dom.getViewContainer=function(){return dom.viewContainerDiv;
  7412. };
  7413. dom.setViewIndex=function(index){if(viewLabels.length>1){dom.viewSelectionDiv.innerHTML="";
  7414. var appendView=function(i){var selected=(i==index);
  7415. if(i>0){dom.viewSelectionDiv.appendChild(document.createTextNode(" \u2022 "));
  7416. }var span=document.createElement("span");
  7417. span.className=selected?"exhibit-viewPanel-viewSelection-selectedView":"exhibit-viewPanel-viewSelection-view";
  7418. span.title=viewTooltips[i];
  7419. span.innerHTML=viewLabels[i];
  7420. if(!selected){var handler=function(elmt,evt,target){onSelectView(i);
  7421. SimileAjax.DOM.cancelEvent(evt);
  7422. return false;
  7423. };
  7424. SimileAjax.WindowManager.registerEvent(span,"click",handler);
  7425. }dom.viewSelectionDiv.appendChild(span);
  7426. };
  7427. for(var i=0;
  7428. i<viewLabels.length;
  7429. i++){appendView(i);
  7430. }}};
  7431. return dom;
  7432. };
  7433. /* collection-summary-widget.js */
  7434. Exhibit.CollectionSummaryWidget=function(containerElmt,uiContext){this._exhibit=uiContext.getExhibit();
  7435. this._collection=uiContext.getCollection();
  7436. this._uiContext=uiContext;
  7437. this._div=containerElmt;
  7438. var widget=this;
  7439. this._listener={onItemsChanged:function(){widget._reconstruct();
  7440. }};
  7441. this._collection.addListener(this._listener);
  7442. };
  7443. Exhibit.CollectionSummaryWidget.create=function(configuration,containerElmt,uiContext){var widget=new Exhibit.CollectionSummaryWidget(containerElmt,Exhibit.UIContext.create(configuration,uiContext));
  7444. widget._initializeUI();
  7445. return widget;
  7446. };
  7447. Exhibit.CollectionSummaryWidget.createFromDOM=function(configElmt,containerElmt,uiContext){var widget=new Exhibit.CollectionSummaryWidget(containerElmt!=null?containerElmt:configElmt,Exhibit.UIContext.createFromDOM(configElmt,uiContext));
  7448. widget._initializeUI();
  7449. return widget;
  7450. };
  7451. Exhibit.CollectionSummaryWidget.prototype.dispose=function(){this._collection.removeListener(this._listener);
  7452. this._div.innerHTML="";
  7453. this._noResultsDom=null;
  7454. this._allResultsDom=null;
  7455. this._filteredResultsDom=null;
  7456. this._div=null;
  7457. this._collection=null;
  7458. this._exhibit=null;
  7459. };
  7460. Exhibit.CollectionSummaryWidget.prototype._initializeUI=function(){var self=this;
  7461. var l10n=Exhibit.CollectionSummaryWidget.l10n;
  7462. var onClearFilters=function(elmt,evt,target){self._resetCollection();
  7463. SimileAjax.DOM.cancelEvent(evt);
  7464. return false;
  7465. };
  7466. this._allResultsDom=SimileAjax.DOM.createDOMFromString("span",String.substitute(l10n.allResultsTemplate,["exhibit-collectionSummaryWidget-results"]));
  7467. this._filteredResultsDom=SimileAjax.DOM.createDOMFromString("span",String.substitute(l10n.filteredResultsTemplate,["exhibit-collectionSummaryWidget-results"]),{resetActionLink:Exhibit.UI.makeActionLink(l10n.resetFiltersLabel,onClearFilters)});
  7468. this._noResultsDom=SimileAjax.DOM.createDOMFromString("span",String.substitute(l10n.noResultsTemplate,["exhibit-collectionSummaryWidget-results","exhibit-collectionSummaryWidget-count"]),{resetActionLink:Exhibit.UI.makeActionLink(l10n.resetFiltersLabel,onClearFilters)});
  7469. this._div.innerHTML="";
  7470. this._reconstruct();
  7471. };
  7472. Exhibit.CollectionSummaryWidget.prototype._reconstruct=function(){var originalSize=this._collection.countAllItems();
  7473. var currentSize=this._collection.countRestrictedItems();
  7474. var database=this._uiContext.getDatabase();
  7475. var dom=this._dom;
  7476. while(this._div.childNodes.length>0){this._div.removeChild(this._div.firstChild);
  7477. }if(originalSize>0){if(currentSize==0){this._div.appendChild(this._noResultsDom.elmt);
  7478. }else{var typeIDs=database.getTypeIDs(this._collection.getRestrictedItems()).toArray();
  7479. var typeID=typeIDs.length==1?typeIDs[0]:"Item";
  7480. var description=Exhibit.Database.l10n.labelItemsOfType(currentSize,typeID,database,"exhibit-collectionSummaryWidget-count");
  7481. if(currentSize==originalSize){this._div.appendChild(this._allResultsDom.elmt);
  7482. this._allResultsDom.resultDescription.innerHTML="";
  7483. this._allResultsDom.resultDescription.appendChild(description);
  7484. }else{this._div.appendChild(this._filteredResultsDom.elmt);
  7485. this._filteredResultsDom.resultDescription.innerHTML="";
  7486. this._filteredResultsDom.resultDescription.appendChild(description);
  7487. this._filteredResultsDom.originalCountSpan.innerHTML=originalSize;
  7488. }}}};
  7489. Exhibit.CollectionSummaryWidget.prototype._resetCollection=function(){var state={};
  7490. var collection=this._collection;
  7491. SimileAjax.History.addLengthyAction(function(){state.restrictions=collection.clearAllRestrictions();
  7492. },function(){collection.applyRestrictions(state.restrictions);
  7493. },Exhibit.CollectionSummaryWidget.l10n.resetActionTitle);
  7494. };
  7495. /* legend-gradient-widget.js */
  7496. Exhibit.LegendGradientWidget=function(containerElmt,uiContext){this._div=containerElmt;
  7497. this._uiContext=uiContext;
  7498. this._initializeUI();
  7499. };
  7500. Exhibit.LegendGradientWidget.create=function(containerElmt,uiContext){return new Exhibit.LegendGradientWidget(containerElmt,uiContext);
  7501. };
  7502. Exhibit.LegendGradientWidget.prototype.addGradient=function(configuration){var gradientPoints=[];
  7503. var gradientPoints=configuration;
  7504. var sortObj=function(a,b){return a.value-b.value;
  7505. };
  7506. gradientPoints.sort(sortObj);
  7507. var theTable=document.createElement("table");
  7508. var tableBody=document.createElement("tbody");
  7509. var theRow1=document.createElement("tr");
  7510. var theRow2=document.createElement("tr");
  7511. var theRow3=document.createElement("tr");
  7512. theRow1.style.height="2em";
  7513. theRow2.style.height="2em";
  7514. theRow3.style.height="2em";
  7515. theTable.style.width="80%";
  7516. theTable.cellSpacing="0";
  7517. theTable.style.emptyCells="show";
  7518. theTable.style.marginLeft="auto";
  7519. theTable.style.marginRight="auto";
  7520. tableBody.appendChild(theRow1);
  7521. tableBody.appendChild(theRow2);
  7522. tableBody.appendChild(theRow3);
  7523. theTable.appendChild(tableBody);
  7524. this._theRow1=theRow1;
  7525. this._theRow2=theRow2;
  7526. this._theRow3=theRow3;
  7527. var globLowPoint=gradientPoints[0].value;
  7528. var globHighPoint=gradientPoints[gradientPoints.length-1].value;
  7529. var stepSize=(globHighPoint-globLowPoint)/50;
  7530. var counter=0;
  7531. for(var i=0;
  7532. i<gradientPoints.length-1;
  7533. i++){var lowPoint=gradientPoints[i].value;
  7534. var highPoint=gradientPoints[i+1].value;
  7535. var colorRect=document.createElement("td");
  7536. colorRect.style.backgroundColor="rgb("+gradientPoints[i].red+","+gradientPoints[i].green+","+gradientPoints[i].blue+")";
  7537. var numberRect=document.createElement("td");
  7538. var textDiv=document.createElement("div");
  7539. var theText=document.createTextNode(gradientPoints[i].value);
  7540. textDiv.appendChild(theText);
  7541. numberRect.appendChild(textDiv);
  7542. theRow1.appendChild(document.createElement("td"));
  7543. theRow2.appendChild(colorRect);
  7544. theRow3.appendChild(numberRect);
  7545. colorRect.onmouseover=function(){this.style.border="solid 1.2px";
  7546. };
  7547. colorRect.onmouseout=function(){this.style.border="none";
  7548. };
  7549. counter++;
  7550. for(var j=lowPoint+stepSize;
  7551. j<highPoint;
  7552. j+=stepSize){var fraction=(j-lowPoint)/(highPoint-lowPoint);
  7553. var newRed=Math.floor(gradientPoints[i].red+fraction*(gradientPoints[i+1].red-gradientPoints[i].red));
  7554. var newGreen=Math.floor(gradientPoints[i].green+fraction*(gradientPoints[i+1].green-gradientPoints[i].green));
  7555. var newBlue=Math.floor(gradientPoints[i].blue+fraction*(gradientPoints[i+1].blue-gradientPoints[i].blue));
  7556. var colorRect=document.createElement("td");
  7557. colorRect.count=counter;
  7558. colorRect.style.backgroundColor="rgb("+newRed+","+newGreen+","+newBlue+")";
  7559. var numberRect=document.createElement("td");
  7560. var textDiv=document.createElement("div");
  7561. var theText=document.createTextNode((Math.floor(j*100))/100);
  7562. textDiv.appendChild(theText);
  7563. numberRect.appendChild(textDiv);
  7564. textDiv.style.width="2px";
  7565. textDiv.style.overflow="hidden";
  7566. textDiv.style.visibility="hidden";
  7567. theRow1.appendChild(numberRect);
  7568. theRow2.appendChild(colorRect);
  7569. theRow3.appendChild(document.createElement("td"));
  7570. counter++;
  7571. colorRect.onmouseover=function(){this.parentNode.parentNode.childNodes[0].childNodes[this.count].childNodes[0].style.visibility="visible";
  7572. this.parentNode.parentNode.childNodes[0].childNodes[this.count].childNodes[0].style.overflow="visible";
  7573. this.style.border="solid 1.2px";
  7574. };
  7575. colorRect.onmouseout=function(){this.parentNode.parentNode.childNodes[0].childNodes[this.count].childNodes[0].style.visibility="hidden";
  7576. this.parentNode.parentNode.childNodes[0].childNodes[this.count].childNodes[0].style.overflow="hidden";
  7577. this.style.border="none";
  7578. };
  7579. }}var high=gradientPoints.length-1;
  7580. var colorRect=document.createElement("td");
  7581. colorRect.style.backgroundColor="rgb("+gradientPoints[high].red+","+gradientPoints[high].green+","+gradientPoints[high].blue+")";
  7582. var numberRect=document.createElement("td");
  7583. var textDiv=document.createElement("div");
  7584. var theText=document.createTextNode(globHighPoint);
  7585. textDiv.appendChild(theText);
  7586. numberRect.appendChild(textDiv);
  7587. theRow1.appendChild(document.createElement("td"));
  7588. theRow2.appendChild(colorRect);
  7589. theRow3.appendChild(numberRect);
  7590. counter++;
  7591. colorRect.onmouseover=function(){this.style.border="solid 1.2px";
  7592. };
  7593. colorRect.onmouseout=function(){this.style.border="none";
  7594. };
  7595. this._div.appendChild(theTable);
  7596. };
  7597. Exhibit.LegendGradientWidget.prototype.addEntry=function(color,label){var cell=document.createElement("td");
  7598. cell.style.width="1.5em";
  7599. cell.style.height="2em";
  7600. this._theRow1.appendChild(cell);
  7601. this._theRow1.appendChild(document.createElement("td"));
  7602. this._theRow2.appendChild(document.createElement("td"));
  7603. this._theRow3.appendChild(document.createElement("td"));
  7604. var colorCell=document.createElement("td");
  7605. colorCell.style.backgroundColor=color;
  7606. this._theRow2.appendChild(colorCell);
  7607. var labelCell=document.createElement("td");
  7608. var labelDiv=document.createElement("div");
  7609. labelDiv.appendChild(document.createTextNode(label));
  7610. labelCell.appendChild(labelDiv);
  7611. this._theRow3.appendChild(labelCell);
  7612. };
  7613. Exhibit.LegendGradientWidget.prototype.dispose=function(){this._div.innerHTML="";
  7614. this._div=null;
  7615. this._uiContext=null;
  7616. };
  7617. Exhibit.LegendGradientWidget.prototype._initializeUI=function(){this._div.className="exhibit-legendGradientWidget";
  7618. this._div.innerHTML="";
  7619. };
  7620. Exhibit.LegendGradientWidget.prototype.clear=function(){this._div.innerHTML="";
  7621. };
  7622. /* legend-widget.js */
  7623. Exhibit.LegendWidget=function(configuration,containerElmt,uiContext){this._configuration=configuration;
  7624. this._div=containerElmt;
  7625. this._jq=SimileAjax.jQuery(this._div);
  7626. this._uiContext=uiContext;
  7627. this._colorMarkerGenerator="colorMarkerGenerator" in configuration?configuration.colorMarkerGenerator:Exhibit.LegendWidget._defaultColorMarkerGenerator;
  7628. this._sizeMarkerGenerator="sizeMarkerGenerator" in configuration?configuration.sizeMarkerGenerator:Exhibit.LegendWidget._defaultSizeMarkerGenerator;
  7629. this._iconMarkerGenerator="iconMarkerGenerator" in configuration?configuration.iconMarkerGenerator:Exhibit.LegendWidget._defaultIconMarkerGenerator;
  7630. this._labelStyler="labelStyler" in configuration?configuration.labelStyler:Exhibit.LegendWidget._defaultColorLabelStyler;
  7631. this._initializeUI();
  7632. };
  7633. Exhibit.LegendWidget.create=function(configuration,containerElmt,uiContext){return new Exhibit.LegendWidget(configuration,containerElmt,uiContext);
  7634. };
  7635. Exhibit.LegendWidget.prototype.dispose=function(){this._div.innerHTML="";
  7636. this._div=null;
  7637. this._jq=null;
  7638. this._uiContext=null;
  7639. };
  7640. Exhibit.LegendWidget.prototype._initializeUI=function(){this._div.className="exhibit-legendWidget";
  7641. this._div.innerHTML="<div class='exhibit-color-legend'></div><div class='exhibit-size-legend'></div><div class='exhibit-icon-legend'></div>";
  7642. };
  7643. Exhibit.LegendWidget.prototype.clear=function(){this._div.innerHTML="<div class='exhibit-color-legend'></div><div class='exhibit-size-legend'></div><div class='exhibit-icon-legend'></div>";
  7644. };
  7645. Exhibit.LegendWidget.prototype.addLegendLabel=function(label,type){var dom=SimileAjax.DOM.createDOMFromString("div","<div class='legend-label'><span class='label' class='exhibit-legendWidget-entry-title'>"+label.replace(/\s+/g,"\u00a0")+"</span>\u00a0\u00a0 </div>",{});
  7646. dom.elmt.className="exhibit-legendWidget-label";
  7647. this._jq.find(".exhibit-"+type+"-legend").append(dom.elmt);
  7648. };
  7649. Exhibit.LegendWidget.prototype.addEntry=function(value,label,type){type=type||"color";
  7650. label=(label!=null)?label.toString():"";
  7651. var legendDiv=this._jq.find(".exhibit-"+type+"-legend");
  7652. var marker;
  7653. if(type=="color"){var dom=SimileAjax.DOM.createDOMFromString("span","<span id='marker'></span>\u00a0<span id='label' class='exhibit-legendWidget-entry-title'>"+label.replace(/\s+/g,"\u00a0")+"</span>\u00a0\u00a0 ",{marker:this._colorMarkerGenerator(value)});
  7654. }if(type=="size"){var dom=SimileAjax.DOM.createDOMFromString("span","<span id='marker'></span>\u00a0<span id='label' class='exhibit-legendWidget-entry-title'>"+label.replace(/\s+/g,"\u00a0")+"</span>\u00a0\u00a0 ",{marker:this._sizeMarkerGenerator(value)});
  7655. }if(type=="icon"){var dom=SimileAjax.DOM.createDOMFromString("span","<span id='marker'></span>\u00a0<span id='label' class='exhibit-legendWidget-entry-title'>"+label.replace(/\s+/g,"\u00a0")+"</span>\u00a0\u00a0 ",{marker:this._iconMarkerGenerator(value)});
  7656. }dom.elmt.className="exhibit-legendWidget-entry";
  7657. this._labelStyler(dom.label,value);
  7658. legendDiv.append(dom.elmt);
  7659. };
  7660. Exhibit.LegendWidget._localeSort=function(a,b){return a.localeCompare(b);
  7661. };
  7662. Exhibit.LegendWidget._defaultColorMarkerGenerator=function(value){var span=document.createElement("span");
  7663. span.className="exhibit-legendWidget-entry-swatch";
  7664. span.style.background=value;
  7665. span.innerHTML="\u00a0\u00a0";
  7666. return span;
  7667. };
  7668. Exhibit.LegendWidget._defaultSizeMarkerGenerator=function(value){var span=document.createElement("span");
  7669. span.className="exhibit-legendWidget-entry-swatch";
  7670. span.style.height=value;
  7671. span.style.width=value;
  7672. span.style.background="#C0C0C0";
  7673. span.innerHTML="\u00a0\u00a0";
  7674. return span;
  7675. };
  7676. Exhibit.LegendWidget._defaultIconMarkerGenerator=function(value){var span=document.createElement("span");
  7677. span.className="<img src="+value+"/>";
  7678. return span;
  7679. };
  7680. Exhibit.LegendWidget._defaultColorLabelStyler=function(elmt,value){};
  7681. /* logo.js */
  7682. Exhibit.Logo=function(elmt,exhibit){this._exhibit=exhibit;
  7683. this._elmt=elmt;
  7684. this._color="Silver";
  7685. };
  7686. Exhibit.Logo.create=function(configuration,elmt,exhibit){var logo=new Exhibit.Logo(elmt,exhibit);
  7687. if("color" in configuration){logo._color=configuration.color;
  7688. }logo._initializeUI();
  7689. return logo;
  7690. };
  7691. Exhibit.Logo.createFromDOM=function(elmt,exhibit){var logo=new Exhibit.Logo(elmt,exhibit);
  7692. var color=Exhibit.getAttribute(elmt,"color");
  7693. if(color!=null&&color.length>0){logo._color=color;
  7694. }logo._initializeUI();
  7695. return logo;
  7696. };
  7697. Exhibit.Logo.prototype.dispose=function(){this._elmt=null;
  7698. this._exhibit=null;
  7699. };
  7700. Exhibit.Logo.prototype._initializeUI=function(){var logoURL="http://static.simile-widgets.org/graphics/logos/exhibit/exhibit-small-"+this._color+".png";
  7701. var img=SimileAjax.Graphics.createTranslucentImage(logoURL);
  7702. var id="exhibit-logo-image";
  7703. if(!document.getElementById(id)){img.id=id;
  7704. }var a=document.createElement("a");
  7705. a.href="http://simile-widgets.org/exhibit/";
  7706. a.title="http://simile-widgets.org/exhibit/";
  7707. a.target="_blank";
  7708. a.appendChild(img);
  7709. this._elmt.appendChild(a);
  7710. };
  7711. /* option-widget.js */
  7712. Exhibit.OptionWidget=function(configuration,containerElmt,uiContext){this._label=configuration.label;
  7713. this._checked="checked" in configuration?configuration.checked:false;
  7714. this._onToggle=configuration.onToggle;
  7715. this._containerElmt=containerElmt;
  7716. this._uiContext=uiContext;
  7717. this._initializeUI();
  7718. };
  7719. Exhibit.OptionWidget.create=function(configuration,containerElmt,uiContext){return new Exhibit.OptionWidget(configuration,containerElmt,uiContext);
  7720. };
  7721. Exhibit.OptionWidget.prototype.dispose=function(){this._containerElmt.innerHTML="";
  7722. this._dom=null;
  7723. this._containerElmt=null;
  7724. this._uiContext=null;
  7725. };
  7726. Exhibit.OptionWidget.uncheckedImageURL=Exhibit.urlPrefix+"images/option.png";
  7727. Exhibit.OptionWidget.checkedImageURL=Exhibit.urlPrefix+"images/option-check.png";
  7728. Exhibit.OptionWidget.uncheckedTemplate="<span id='uncheckedSpan' style='display: none;'><img id='uncheckedImage' /> %0</span>";
  7729. Exhibit.OptionWidget.checkedTemplate="<span id='checkedSpan' style='display: none;'><img id='checkedImage' /> %0</span>";
  7730. Exhibit.OptionWidget.prototype._initializeUI=function(){this._containerElmt.className="exhibit-optionWidget";
  7731. this._dom=SimileAjax.DOM.createDOMFromString(this._containerElmt,String.substitute(Exhibit.OptionWidget.uncheckedTemplate+Exhibit.OptionWidget.checkedTemplate,[this._label]),{uncheckedImage:SimileAjax.Graphics.createTranslucentImage(Exhibit.OptionWidget.uncheckedImageURL),checkedImage:SimileAjax.Graphics.createTranslucentImage(Exhibit.OptionWidget.checkedImageURL)});
  7732. if(this._checked){this._dom.checkedSpan.style.display="inline";
  7733. }else{this._dom.uncheckedSpan.style.display="inline";
  7734. }SimileAjax.WindowManager.registerEvent(this._containerElmt,"click",this._onToggle);
  7735. };
  7736. Exhibit.OptionWidget.prototype.getChecked=function(){return this._checked;
  7737. };
  7738. Exhibit.OptionWidget.prototype.setChecked=function(checked){if(checked!=this._checked){this._checked=checked;
  7739. if(checked){this._dom.checkedSpan.style.display="inline";
  7740. this._dom.uncheckedSpan.style.display="none";
  7741. }else{this._dom.checkedSpan.style.display="none";
  7742. this._dom.uncheckedSpan.style.display="inline";
  7743. }}};
  7744. Exhibit.OptionWidget.prototype.toggle=function(){this.setChecked(!this._checked);
  7745. };
  7746. /* resizable-div-widget.js */
  7747. Exhibit.ResizableDivWidget=function(configuration,elmt,uiContext){this._div=elmt;
  7748. this._configuration=configuration;
  7749. if(!("minHeight" in configuration)){configuration["minHeight"]=10;
  7750. }this._initializeUI();
  7751. };
  7752. Exhibit.ResizableDivWidget.create=function(configuration,elmt,uiContext){return new Exhibit.ResizableDivWidget(configuration,elmt,uiContext);
  7753. };
  7754. Exhibit.ResizableDivWidget.prototype.dispose=function(){this._div.innerHTML="";
  7755. this._contentDiv=null;
  7756. this._resizerDiv=null;
  7757. this._div=null;
  7758. };
  7759. Exhibit.ResizableDivWidget.prototype.getContentDiv=function(){return this._contentDiv;
  7760. };
  7761. Exhibit.ResizableDivWidget.prototype._initializeUI=function(){var self=this;
  7762. this._div.innerHTML="<div></div><div class='exhibit-resizableDivWidget-resizer'>"+SimileAjax.Graphics.createTranslucentImageHTML(Exhibit.urlPrefix+"images/down-arrow.png")+"</div>";
  7763. this._contentDiv=this._div.childNodes[0];
  7764. this._resizerDiv=this._div.childNodes[1];
  7765. SimileAjax.WindowManager.registerForDragging(this._resizerDiv,{onDragStart:function(){this._height=self._contentDiv.offsetHeight;
  7766. },onDragBy:function(diffX,diffY){this._height+=diffY;
  7767. self._contentDiv.style.height=Math.max(self._configuration.minHeight,this._height)+"px";
  7768. },onDragEnd:function(){if("onResize" in self._configuration){self._configuration["onResize"]();
  7769. }}});
  7770. };
  7771. /* toolbox-widget.js */
  7772. Exhibit.ToolboxWidget=function(containerElmt,uiContext){this._containerElmt=containerElmt;
  7773. this._uiContext=uiContext;
  7774. this._settings={};
  7775. this._customExporters=[];
  7776. this._hovering=false;
  7777. this._initializeUI();
  7778. };
  7779. Exhibit.ToolboxWidget._settingSpecs={"itemID":{type:"text"}};
  7780. Exhibit.ToolboxWidget.create=function(configuration,containerElmt,uiContext){var widget=new Exhibit.ToolboxWidget(containerElmt,Exhibit.UIContext.create(configuration,uiContext));
  7781. Exhibit.ToolboxWidget._configure(widget,configuration);
  7782. widget._initializeUI();
  7783. return widget;
  7784. };
  7785. Exhibit.ToolboxWidget.createFromDOM=function(configElmt,containerElmt,uiContext){var configuration=Exhibit.getConfigurationFromDOM(configElmt);
  7786. var widget=new Exhibit.ToolboxWidget(containerElmt!=null?containerElmt:configElmt,Exhibit.UIContext.createFromDOM(configElmt,uiContext));
  7787. Exhibit.SettingsUtilities.collectSettingsFromDOM(configElmt,Exhibit.ToolboxWidget._settingSpecs,widget._settings);
  7788. Exhibit.ToolboxWidget._configure(widget,configuration);
  7789. widget._initializeUI();
  7790. return widget;
  7791. };
  7792. Exhibit.ToolboxWidget._configure=function(widget,configuration){Exhibit.SettingsUtilities.collectSettings(configuration,Exhibit.ToolboxWidget._settingSpecs,widget._settings);
  7793. };
  7794. Exhibit.ToolboxWidget.prototype.dispose=function(){this._containerElmt.onmouseover=null;
  7795. this._containerElmt.onmouseout=null;
  7796. this._dismiss();
  7797. this._settings=null;
  7798. this._containerElmt=null;
  7799. this._uiContext=null;
  7800. };
  7801. Exhibit.ToolboxWidget.prototype.addExporter=function(exporter){this._customExporters.push(exporter);
  7802. };
  7803. Exhibit.ToolboxWidget.prototype._initializeUI=function(){var self=this;
  7804. this._containerElmt.onmouseover=function(evt){self._onContainerMouseOver(evt);
  7805. };
  7806. this._containerElmt.onmouseout=function(evt){self._onContainerMouseOut(evt);
  7807. };
  7808. };
  7809. Exhibit.ToolboxWidget.prototype._onContainerMouseOver=function(evt){if(!this._hovering){var self=this;
  7810. var coords=SimileAjax.DOM.getPageCoordinates(this._containerElmt);
  7811. var docWidth=document.body.offsetWidth;
  7812. var docHeight=document.body.offsetHeight;
  7813. var popup=document.createElement("div");
  7814. popup.className="exhibit-toolboxWidget-popup screen";
  7815. popup.style.top=coords.top+"px";
  7816. popup.style.right=(docWidth-coords.left-this._containerElmt.offsetWidth)+"px";
  7817. this._fillPopup(popup);
  7818. document.body.appendChild(popup);
  7819. popup.onmouseover=function(evt){self._onPopupMouseOver(evt);
  7820. };
  7821. popup.onmouseout=function(evt){self._onPopupMouseOut(evt);
  7822. };
  7823. this._popup=popup;
  7824. this._hovering=true;
  7825. }else{this._clearTimeout();
  7826. }};
  7827. Exhibit.ToolboxWidget.prototype._onContainerMouseOut=function(evt){if(Exhibit.ToolboxWidget._mouseOutsideElmt(Exhibit.ToolboxWidget._getEvent(evt),this._containerElmt)){this._setTimeout();
  7828. }};
  7829. Exhibit.ToolboxWidget.prototype._onPopupMouseOver=function(evt){this._clearTimeout();
  7830. };
  7831. Exhibit.ToolboxWidget.prototype._onPopupMouseOut=function(evt){if(Exhibit.ToolboxWidget._mouseOutsideElmt(Exhibit.ToolboxWidget._getEvent(evt),this._containerElmt)){this._setTimeout();
  7832. }};
  7833. Exhibit.ToolboxWidget.prototype._setTimeout=function(){var self=this;
  7834. this._timer=window.setTimeout(function(){self._onTimeout();
  7835. },200);
  7836. };
  7837. Exhibit.ToolboxWidget.prototype._clearTimeout=function(){if(this._timer){window.clearTimeout(this._timer);
  7838. this._timer=null;
  7839. }};
  7840. Exhibit.ToolboxWidget.prototype._onTimeout=function(){this._dismiss();
  7841. this._hovering=false;
  7842. this._timer=null;
  7843. };
  7844. Exhibit.ToolboxWidget.prototype._fillPopup=function(elmt){var self=this;
  7845. var exportImg=Exhibit.UI.createTranslucentImage("images/liveclipboard-icon.png");
  7846. exportImg.className="exhibit-toolboxWidget-button";
  7847. SimileAjax.WindowManager.registerEvent(exportImg,"click",function(elmt,evt,target){self._showExportMenu(exportImg);
  7848. });
  7849. elmt.appendChild(exportImg);
  7850. };
  7851. Exhibit.ToolboxWidget.prototype._dismiss=function(){if(this._popup){document.body.removeChild(this._popup);
  7852. this._popup=null;
  7853. }};
  7854. Exhibit.ToolboxWidget._mouseOutsideElmt=function(evt,elmt){var eventCoords=SimileAjax.DOM.getEventPageCoordinates(evt);
  7855. var coords=SimileAjax.DOM.getPageCoordinates(elmt);
  7856. return((eventCoords.x<coords.left||eventCoords.x>coords.left+elmt.offsetWidth)||(eventCoords.y<coords.top||eventCoords.y>coords.top+elmt.offsetHeight));
  7857. };
  7858. Exhibit.ToolboxWidget._getEvent=function(evt){return(evt)?evt:((event)?event:null);
  7859. };
  7860. Exhibit.ToolboxWidget.prototype._showExportMenu=function(elmt){var self=this;
  7861. var popupDom=Exhibit.UI.createPopupMenuDom(elmt);
  7862. var makeMenuItem=function(exporter){popupDom.appendMenuItem(exporter.getLabel(),null,function(){var database=self._uiContext.getDatabase();
  7863. var text=("itemID" in self._settings)?exporter.exportOne(self._settings.itemID,database):exporter.exportMany(self._uiContext.getCollection().getRestrictedItems(),database);
  7864. Exhibit.ToolboxWidget.createExportDialogBox(text).open();
  7865. });
  7866. };
  7867. var exporters=Exhibit.getExporters();
  7868. for(var i=0;
  7869. i<exporters.length;
  7870. i++){makeMenuItem(exporters[i]);
  7871. }for(var i=0;
  7872. i<this._customExporters.length;
  7873. i++){makeMenuItem(this._customExporters[i]);
  7874. }if("getGeneratedHTML" in this){makeMenuItem({getLabel:function(){return Exhibit.l10n.htmlExporterLabel;
  7875. },exportOne:this.getGeneratedHTML,exportMany:this.getGeneratedHTML});
  7876. }popupDom.open();
  7877. };
  7878. Exhibit.ToolboxWidget.createExportDialogBox=function(string){var template={tag:"div",className:"exhibit-copyDialog exhibit-ui-protection",children:[{tag:"button",field:"closeButton",children:[Exhibit.l10n.exportDialogBoxCloseButtonLabel]},{tag:"p",children:[Exhibit.l10n.exportDialogBoxPrompt]},{tag:"div",field:"textAreaContainer"}]};
  7879. var dom=SimileAjax.DOM.createDOMFromTemplate(template);
  7880. dom.textAreaContainer.innerHTML="<textarea wrap='off' rows='15'>"+string+"</textarea>";
  7881. dom.close=function(){document.body.removeChild(dom.elmt);
  7882. };
  7883. dom.open=function(){dom.elmt.style.top=(document.body.scrollTop+100)+"px";
  7884. document.body.appendChild(dom.elmt);
  7885. dom.layer=SimileAjax.WindowManager.pushLayer(function(){dom.close();
  7886. },false);
  7887. var textarea=dom.textAreaContainer.firstChild;
  7888. textarea.select();
  7889. SimileAjax.WindowManager.registerEvent(dom.closeButton,"click",function(elmt,evt,target){SimileAjax.WindowManager.popLayer(dom.layer);
  7890. },dom.layer);
  7891. SimileAjax.WindowManager.registerEvent(textarea,"keyup",function(elmt,evt,target){if(evt.keyCode==27){SimileAjax.WindowManager.popLayer(dom.layer);
  7892. }},dom.layer);
  7893. };
  7894. return dom;
  7895. };
  7896. /* coders.js */
  7897. Exhibit.Coders=new Object();
  7898. Exhibit.Coders.mixedCaseColor="#fff";
  7899. Exhibit.Coders.othersCaseColor="#aaa";
  7900. Exhibit.Coders.missingCaseColor="#888";
  7901. /* facets.js */
  7902. Exhibit.FacetUtilities=new Object();
  7903. Exhibit.FacetUtilities.constructFacetFrame=function(forFacet,div,facetLabel,onClearAllSelections,uiContext,collapsible,collapsed){div.className="exhibit-facet";
  7904. var dom=SimileAjax.DOM.createDOMFromString(div,"<div class='exhibit-facet-header'><div class='exhibit-facet-header-filterControl' id='clearSelectionsDiv' title='"+Exhibit.FacetUtilities.l10n.clearSelectionsTooltip+"'><span id='filterCountSpan'></span><img id='checkImage' /></div>"+((collapsible)?"<img src='"+Exhibit.urlPrefix+"images/collapse.png' class='exhibit-facet-header-collapse' id='collapseImg' />":"")+"<span class='exhibit-facet-header-title'>"+facetLabel+"</span></div><div class='exhibit-facet-body-frame' id='frameDiv'></div>",{checkImage:Exhibit.UI.createTranslucentImage("images/black-check.png")});
  7905. var resizableDivWidget=Exhibit.ResizableDivWidget.create({},dom.frameDiv,uiContext);
  7906. dom.valuesContainer=resizableDivWidget.getContentDiv();
  7907. dom.valuesContainer.className="exhibit-facet-body";
  7908. dom.setSelectionCount=function(count){this.filterCountSpan.innerHTML=count;
  7909. this.clearSelectionsDiv.style.display=count>0?"block":"none";
  7910. };
  7911. SimileAjax.WindowManager.registerEvent(dom.clearSelectionsDiv,"click",onClearAllSelections);
  7912. if(collapsible){SimileAjax.WindowManager.registerEvent(dom.collapseImg,"click",function(){Exhibit.FacetUtilities.toggleCollapse(dom,forFacet);
  7913. });
  7914. if(collapsed){Exhibit.FacetUtilities.toggleCollapse(dom,forFacet);
  7915. }}return dom;
  7916. };
  7917. Exhibit.FacetUtilities.toggleCollapse=function(dom,facet){var el=dom.frameDiv;
  7918. if(el.style.display!="none"){el.style.display="none";
  7919. dom.collapseImg.src=Exhibit.urlPrefix+"images/expand.png";
  7920. }else{el.style.display="block";
  7921. dom.collapseImg.src=Exhibit.urlPrefix+"images/collapse.png";
  7922. if(typeof facet.onUncollapse=="function"){facet.onUncollapse();
  7923. }}};
  7924. Exhibit.FacetUtilities.isCollapsed=function(facet){var el=facet._dom.frameDiv;
  7925. return el.style.display=="none";
  7926. };
  7927. Exhibit.FacetUtilities.constructFacetItem=function(label,count,color,selected,facetHasSelection,onSelect,onSelectOnly,uiContext){if(Exhibit.params.safe){label=Exhibit.Formatter.encodeAngleBrackets(label);
  7928. }var dom=SimileAjax.DOM.createDOMFromString("div","<div class='exhibit-facet-value-count'>"+count+"</div><div class='exhibit-facet-value-inner' id='inner'>"+("<div class='exhibit-facet-value-checkbox'>&#160;"+SimileAjax.Graphics.createTranslucentImageHTML(Exhibit.urlPrefix+(facetHasSelection?(selected?"images/black-check.png":"images/no-check.png"):"images/no-check-no-border.png"))+"</div>")+"<a class='exhibit-facet-value-link' href='javascript:{}' id='link'></a></div>");
  7929. dom.elmt.className=selected?"exhibit-facet-value exhibit-facet-value-selected":"exhibit-facet-value";
  7930. if(typeof label=="string"){dom.elmt.title=label;
  7931. dom.link.innerHTML=label;
  7932. if(color!=null){dom.link.style.color=color;
  7933. }}else{dom.link.appendChild(label);
  7934. if(color!=null){label.style.color=color;
  7935. }}SimileAjax.WindowManager.registerEvent(dom.elmt,"click",onSelectOnly,SimileAjax.WindowManager.getBaseLayer());
  7936. if(facetHasSelection){SimileAjax.WindowManager.registerEvent(dom.inner.firstChild,"click",onSelect,SimileAjax.WindowManager.getBaseLayer());
  7937. }return dom.elmt;
  7938. };
  7939. Exhibit.FacetUtilities.constructFlowingFacetFrame=function(forFacet,div,facetLabel,onClearAllSelections,uiContext,collapsible,collapsed){div.className="exhibit-flowingFacet";
  7940. var dom=SimileAjax.DOM.createDOMFromString(div,"<div class='exhibit-flowingFacet-header'>"+((collapsible)?"<img src='"+Exhibit.urlPrefix+"images/collapse.png' class='exhibit-facet-header-collapse' id='collapseImg' />":"")+"<span class='exhibit-flowingFacet-header-title'>"+facetLabel+"</span></div><div id='frameDiv'><div class='exhibit-flowingFacet-body' id='valuesContainer'></div></div>");
  7941. dom.setSelectionCount=function(count){};
  7942. if(collapsible){SimileAjax.WindowManager.registerEvent(dom.collapseImg,"click",function(){Exhibit.FacetUtilities.toggleCollapse(dom,forFacet);
  7943. });
  7944. if(collapsed){Exhibit.FacetUtilities.toggleCollapse(dom,forFacet);
  7945. }}return dom;
  7946. };
  7947. Exhibit.FacetUtilities.constructFlowingFacetItem=function(label,count,color,selected,facetHasSelection,onSelect,onSelectOnly,uiContext){if(Exhibit.params.safe){label=Exhibit.Formatter.encodeAngleBrackets(label);
  7948. }var dom=SimileAjax.DOM.createDOMFromString("div",("<div class='exhibit-flowingFacet-value-checkbox'>"+SimileAjax.Graphics.createTranslucentImageHTML(Exhibit.urlPrefix+(facetHasSelection?(selected?"images/black-check.png":"images/no-check.png"):"images/no-check-no-border.png"))+"</div>")+"<a class='exhibit-flowingFacet-value-link' href='javascript:{}' id='inner'></a> <span class='exhibit-flowingFacet-value-count'>("+count+")</span>");
  7949. dom.elmt.className=selected?"exhibit-flowingFacet-value exhibit-flowingFacet-value-selected":"exhibit-flowingFacet-value";
  7950. if(typeof label=="string"){dom.elmt.title=label;
  7951. dom.inner.innerHTML=label;
  7952. if(color!=null){dom.inner.style.color=color;
  7953. }}else{dom.inner.appendChild(label);
  7954. if(color!=null){label.style.color=color;
  7955. }}SimileAjax.WindowManager.registerEvent(dom.elmt,"click",onSelectOnly,SimileAjax.WindowManager.getBaseLayer());
  7956. if(facetHasSelection){SimileAjax.WindowManager.registerEvent(dom.elmt.firstChild,"click",onSelect,SimileAjax.WindowManager.getBaseLayer());
  7957. }return dom.elmt;
  7958. };
  7959. Exhibit.FacetUtilities.constructHierarchicalFacetItem=function(label,count,color,selected,hasChildren,expanded,facetHasSelection,onSelect,onSelectOnly,onToggleChildren,uiContext){if(Exhibit.params.safe){label=Exhibit.Formatter.encodeAngleBrackets(label);
  7960. }var dom=SimileAjax.DOM.createDOMFromString("div","<div class='exhibit-facet-value-count'>"+count+"</div><div class='exhibit-facet-value-inner' id='inner'>"+("<div class='exhibit-facet-value-checkbox'>&#160;"+SimileAjax.Graphics.createTranslucentImageHTML(Exhibit.urlPrefix+(facetHasSelection?(selected?"images/black-check.png":"images/no-check.png"):"images/no-check-no-border.png"))+"</div>")+"<a class='exhibit-facet-value-link' href='javascript:{}' id='link'></a>"+(hasChildren?("<a class='exhibit-facet-value-children-toggle' href='javascript:{}' id='toggle'>"+SimileAjax.Graphics.createTranslucentImageHTML(Exhibit.urlPrefix+"images/down-arrow.png")+SimileAjax.Graphics.createTranslucentImageHTML(Exhibit.urlPrefix+"images/right-arrow.png")+"</a>"):"")+"</div>"+(hasChildren?"<div class='exhibit-facet-childrenContainer' id='childrenContainer'></div>":""));
  7961. dom.elmt.className=selected?"exhibit-facet-value exhibit-facet-value-selected":"exhibit-facet-value";
  7962. if(typeof label=="string"){dom.elmt.title=label;
  7963. dom.link.appendChild(document.createTextNode(label));
  7964. if(color!=null){dom.link.style.color=color;
  7965. }}else{dom.link.appendChild(label);
  7966. if(color!=null){label.style.color=color;
  7967. }}SimileAjax.WindowManager.registerEvent(dom.elmt,"click",onSelectOnly,SimileAjax.WindowManager.getBaseLayer());
  7968. if(facetHasSelection){SimileAjax.WindowManager.registerEvent(dom.inner.firstChild,"click",onSelect,SimileAjax.WindowManager.getBaseLayer());
  7969. }if(hasChildren){dom.showChildren=function(show){dom.childrenContainer.style.display=show?"block":"none";
  7970. dom.toggle.childNodes[0].style.display=show?"inline":"none";
  7971. dom.toggle.childNodes[1].style.display=show?"none":"inline";
  7972. };
  7973. SimileAjax.WindowManager.registerEvent(dom.toggle,"click",onToggleChildren,SimileAjax.WindowManager.getBaseLayer());
  7974. dom.showChildren(expanded);
  7975. }return dom;
  7976. };
  7977. Exhibit.FacetUtilities.constructFlowingHierarchicalFacetItem=function(label,count,color,selected,hasChildren,expanded,facetHasSelection,onSelect,onSelectOnly,onToggleChildren,uiContext){if(Exhibit.params.safe){label=Exhibit.Formatter.encodeAngleBrackets(label);
  7978. }var dom=SimileAjax.DOM.createDOMFromString("div",("<div class='exhibit-flowingFacet-value-checkbox'>"+SimileAjax.Graphics.createTranslucentImageHTML(Exhibit.urlPrefix+(facetHasSelection?(selected?"images/black-check.png":"images/no-check.png"):"images/no-check-no-border.png"))+"</div>")+"<a class='exhibit-flowingFacet-value-link' href='javascript:{}' id='inner'></a> <span class='exhibit-flowingFacet-value-count'>("+count+")</span>"+(hasChildren?("<a class='exhibit-flowingFacet-value-children-toggle' href='javascript:{}' id='toggle'>"+SimileAjax.Graphics.createTranslucentImageHTML(Exhibit.urlPrefix+"images/down-arrow.png")+SimileAjax.Graphics.createTranslucentImageHTML(Exhibit.urlPrefix+"images/right-arrow.png")+"</a>"):"")+(hasChildren?"<div class='exhibit-flowingFacet-childrenContainer' id='childrenContainer'></div>":""));
  7979. dom.elmt.className=selected?"exhibit-flowingFacet-value exhibit-flowingFacet-value-selected":"exhibit-flowingFacet-value";
  7980. if(typeof label=="string"){dom.elmt.title=label;
  7981. dom.inner.appendChild(document.createTextNode(label));
  7982. if(color!=null){dom.inner.style.color=color;
  7983. }}else{dom.inner.appendChild(label);
  7984. if(color!=null){label.style.color=color;
  7985. }}SimileAjax.WindowManager.registerEvent(dom.elmt,"click",onSelectOnly,SimileAjax.WindowManager.getBaseLayer());
  7986. if(facetHasSelection){SimileAjax.WindowManager.registerEvent(dom.elmt.firstChild,"click",onSelect,SimileAjax.WindowManager.getBaseLayer());
  7987. }if(hasChildren){dom.showChildren=function(show){dom.childrenContainer.style.display=show?"block":"none";
  7988. dom.toggle.childNodes[0].style.display=show?"inline":"none";
  7989. dom.toggle.childNodes[1].style.display=show?"none":"inline";
  7990. };
  7991. SimileAjax.WindowManager.registerEvent(dom.toggle,"click",onToggleChildren,SimileAjax.WindowManager.getBaseLayer());
  7992. dom.showChildren(expanded);
  7993. }return dom;
  7994. };
  7995. Exhibit.FacetUtilities.Cache=function(database,collection,expression){var self=this;
  7996. this._database=database;
  7997. this._collection=collection;
  7998. this._expression=expression;
  7999. this._listener={onRootItemsChanged:function(){if("_itemToValue" in self){delete self._itemToValue;
  8000. }if("_valueToItem" in self){delete self._valueToItem;
  8001. }if("_missingItems" in self){delete self._missingItems;
  8002. }}};
  8003. collection.addListener(this._listener);
  8004. };
  8005. Exhibit.FacetUtilities.Cache.prototype.dispose=function(){this._collection.removeListener(this._listener);
  8006. this._collection=null;
  8007. this._listener=null;
  8008. this._itemToValue=null;
  8009. this._valueToItem=null;
  8010. this._missingItems=null;
  8011. };
  8012. Exhibit.FacetUtilities.Cache.prototype.getItemsFromValues=function(values,filter){var set;
  8013. if(this._expression.isPath()){set=this._expression.getPath().walkBackward(values,"item",filter,this._database).getSet();
  8014. }else{this._buildMaps();
  8015. set=new Exhibit.Set();
  8016. var valueToItem=this._valueToItem;
  8017. values.visit(function(value){if(value in valueToItem){var itemA=valueToItem[value];
  8018. for(var i=0;
  8019. i<itemA.length;
  8020. i++){var item=itemA[i];
  8021. if(filter.contains(item)){set.add(item);
  8022. }}}});
  8023. }return set;
  8024. };
  8025. Exhibit.FacetUtilities.Cache.prototype.getItemsMissingValue=function(filter,results){this._buildMaps();
  8026. results=results||new Exhibit.Set();
  8027. var missingItems=this._missingItems;
  8028. filter.visit(function(item){if(item in missingItems){results.add(item);
  8029. }});
  8030. return results;
  8031. };
  8032. Exhibit.FacetUtilities.Cache.prototype.getValueCountsFromItems=function(items){var entries=[];
  8033. var database=this._database;
  8034. var valueType="text";
  8035. if(this._expression.isPath()){var path=this._expression.getPath();
  8036. var facetValueResult=path.walkForward(items,"item",database);
  8037. valueType=facetValueResult.valueType;
  8038. if(facetValueResult.size>0){facetValueResult.forEachValue(function(facetValue){var itemSubcollection=path.evaluateBackward(facetValue,valueType,items,database);
  8039. entries.push({value:facetValue,count:itemSubcollection.size});
  8040. });
  8041. }}else{this._buildMaps();
  8042. valueType=this._valueType;
  8043. for(var value in this._valueToItem){var itemA=this._valueToItem[value];
  8044. var count=0;
  8045. for(var i=0;
  8046. i<itemA.length;
  8047. i++){if(items.contains(itemA[i])){count++;
  8048. }}if(count>0){entries.push({value:value,count:count});
  8049. }}}return{entries:entries,valueType:valueType};
  8050. };
  8051. Exhibit.FacetUtilities.Cache.prototype.getValuesFromItems=function(items){if(this._expression.isPath()){return this._expression.getPath().walkForward(items,"item",database).getSet();
  8052. }else{this._buildMaps();
  8053. var set=new Exhibit.Set();
  8054. var itemToValue=this._itemToValue;
  8055. items.visit(function(item){if(item in itemToValue){var a=itemToValue[item];
  8056. for(var i=0;
  8057. i<a.length;
  8058. i++){set.add(a[i]);
  8059. }}});
  8060. return set;
  8061. }};
  8062. Exhibit.FacetUtilities.Cache.prototype.countItemsMissingValue=function(items){this._buildMaps();
  8063. var count=0;
  8064. for(var item in this._missingItems){if(items.contains(item)){count++;
  8065. }}return count;
  8066. };
  8067. Exhibit.FacetUtilities.Cache.prototype._buildMaps=function(){if(!("_itemToValue" in this)){var itemToValue={};
  8068. var valueToItem={};
  8069. var missingItems={};
  8070. var valueType="text";
  8071. var insert=function(x,y,map){if(x in map){map[x].push(y);
  8072. }else{map[x]=[y];
  8073. }};
  8074. var expression=this._expression;
  8075. var database=this._database;
  8076. this._collection.getAllItems().visit(function(item){var results=expression.evaluateOnItem(item,database);
  8077. if(results.values.size()>0){valueType=results.valueType;
  8078. results.values.visit(function(value){insert(item,value,itemToValue);
  8079. insert(value,item,valueToItem);
  8080. });
  8081. }else{missingItems[item]=true;
  8082. }});
  8083. this._itemToValue=itemToValue;
  8084. this._valueToItem=valueToItem;
  8085. this._missingItems=missingItems;
  8086. this._valueType=valueType;
  8087. }};
  8088. /* set.js */
  8089. Exhibit.Set=function(a){this._hash={};
  8090. this._count=0;
  8091. if(a instanceof Array){for(var i=0;
  8092. i<a.length;
  8093. i++){this.add(a[i]);
  8094. }}else{if(a instanceof Exhibit.Set){this.addSet(a);
  8095. }}};
  8096. Exhibit.Set.prototype.add=function(o){if(!(o in this._hash)){this._hash[o]=true;
  8097. this._count++;
  8098. return true;
  8099. }return false;
  8100. };
  8101. Exhibit.Set.prototype.addSet=function(set){for(var o in set._hash){this.add(o);
  8102. }};
  8103. Exhibit.Set.prototype.remove=function(o){if(o in this._hash){delete this._hash[o];
  8104. this._count--;
  8105. return true;
  8106. }return false;
  8107. };
  8108. Exhibit.Set.prototype.removeSet=function(set){for(var o in set._hash){this.remove(o);
  8109. }};
  8110. Exhibit.Set.prototype.retainSet=function(set){for(var o in this._hash){if(!set.contains(o)){delete this._hash[o];
  8111. this._count--;
  8112. }}};
  8113. Exhibit.Set.prototype.contains=function(o){return(o in this._hash);
  8114. };
  8115. Exhibit.Set.prototype.size=function(){return this._count;
  8116. };
  8117. Exhibit.Set.prototype.toArray=function(){var a=[];
  8118. for(var o in this._hash){a.push(o);
  8119. }return a;
  8120. };
  8121. Exhibit.Set.prototype.visit=function(f){for(var o in this._hash){if(f(o)==true){break;
  8122. }}};
  8123. Exhibit.Set.createIntersection=function(set1,set2,result){var set=(result)?result:new Exhibit.Set();
  8124. var setA,setB;
  8125. if(set1.size()<set2.size()){setA=set1;
  8126. setB=set2;
  8127. }else{setA=set2;
  8128. setB=set1;
  8129. }setA.visit(function(v){if(setB.contains(v)){set.add(v);
  8130. }});
  8131. return set;
  8132. };
  8133. /* settings.js */
  8134. Exhibit.SettingsUtilities=new Object();
  8135. Exhibit.SettingsUtilities.collectSettings=function(config,specs,settings){Exhibit.SettingsUtilities._internalCollectSettings(function(field){return config[field];
  8136. },specs,settings);
  8137. };
  8138. Exhibit.SettingsUtilities.collectSettingsFromDOM=function(configElmt,specs,settings){Exhibit.SettingsUtilities._internalCollectSettings(function(field){return Exhibit.getAttribute(configElmt,field);
  8139. },specs,settings);
  8140. };
  8141. Exhibit.SettingsUtilities._internalCollectSettings=function(f,specs,settings){for(var field in specs){var spec=specs[field];
  8142. var name=field;
  8143. if("name" in spec){name=spec.name;
  8144. }if(!(name in settings)&&"defaultValue" in spec){settings[name]=spec.defaultValue;
  8145. }var value=f(field);
  8146. if(value==null){continue;
  8147. }if(typeof value=="string"){value=value.trim();
  8148. if(value.length==0){continue;
  8149. }}var type="text";
  8150. if("type" in spec){type=spec.type;
  8151. }var dimensions=1;
  8152. if("dimensions" in spec){dimensions=spec.dimensions;
  8153. }try{if(dimensions>1){var separator=",";
  8154. if("separator" in spec){separator=spec.separator;
  8155. }var a=value.split(separator);
  8156. if(a.length!=dimensions){throw new Error("Expected a tuple of "+dimensions+" dimensions separated with "+separator+" but got "+value);
  8157. }else{for(var i=0;
  8158. i<a.length;
  8159. i++){a[i]=Exhibit.SettingsUtilities._parseSetting(a[i].trim(),type,spec);
  8160. }settings[name]=a;
  8161. }}else{settings[name]=Exhibit.SettingsUtilities._parseSetting(value,type,spec);
  8162. }}catch(e){SimileAjax.Debug.exception(e);
  8163. }}};
  8164. Exhibit.SettingsUtilities._parseSetting=function(s,type,spec){var sType=typeof s;
  8165. if(type=="text"){return s;
  8166. }else{if(type=="float"){if(sType=="number"){return s;
  8167. }else{if(sType=="string"){var f=parseFloat(s);
  8168. if(!isNaN(f)){return f;
  8169. }}}throw new Error("Expected a floating point number but got "+s);
  8170. }else{if(type=="int"){if(sType=="number"){return Math.round(s);
  8171. }else{if(sType=="string"){var n=parseInt(s);
  8172. if(!isNaN(n)){return n;
  8173. }}}throw new Error("Expected an integer but got "+s);
  8174. }else{if(type=="boolean"){if(sType=="boolean"){return s;
  8175. }else{if(sType=="string"){s=s.toLowerCase();
  8176. if(s=="true"){return true;
  8177. }else{if(s=="false"){return false;
  8178. }}}}throw new Error("Expected either 'true' or 'false' but got "+s);
  8179. }else{if(type=="function"){if(sType=="function"){return s;
  8180. }else{if(sType=="string"){try{var f=eval(s);
  8181. if(typeof f=="function"){return f;
  8182. }}catch(e){}}}throw new Error("Expected a function or the name of a function but got "+s);
  8183. }else{if(type=="enum"){var choices=spec.choices;
  8184. for(var i=0;
  8185. i<choices.length;
  8186. i++){if(choices[i]==s){return s;
  8187. }}throw new Error("Expected one of "+choices.join(", ")+" but got "+s);
  8188. }else{throw new Error("Unknown setting type "+type);
  8189. }}}}}}};
  8190. Exhibit.SettingsUtilities.createAccessors=function(config,specs,accessors){Exhibit.SettingsUtilities._internalCreateAccessors(function(field){return config[field];
  8191. },specs,accessors);
  8192. };
  8193. Exhibit.SettingsUtilities.createAccessorsFromDOM=function(configElmt,specs,accessors){Exhibit.SettingsUtilities._internalCreateAccessors(function(field){return Exhibit.getAttribute(configElmt,field);
  8194. },specs,accessors);
  8195. };
  8196. Exhibit.SettingsUtilities._internalCreateAccessors=function(f,specs,accessors){for(var field in specs){var spec=specs[field];
  8197. var accessorName=spec.accessorName;
  8198. var accessor=null;
  8199. var isTuple=false;
  8200. var createOneAccessor=function(spec2){isTuple=false;
  8201. if("bindings" in spec2){return Exhibit.SettingsUtilities._createBindingsAccessor(f,spec2.bindings);
  8202. }else{if("bindingNames" in spec2){isTuple=true;
  8203. return Exhibit.SettingsUtilities._createTupleAccessor(f,spec2);
  8204. }else{return Exhibit.SettingsUtilities._createElementalAccessor(f,spec2);
  8205. }}};
  8206. if("alternatives" in spec){var alternatives=spec.alternatives;
  8207. for(var i=0;
  8208. i<alternatives.length;
  8209. i++){accessor=createOneAccessor(alternatives[i]);
  8210. if(accessor!=null){break;
  8211. }}}else{accessor=createOneAccessor(spec);
  8212. }if(accessor!=null){accessors[accessorName]=accessor;
  8213. }else{if(!(accessorName in accessors)){accessors[accessorName]=function(value,database,visitor){};
  8214. }}}};
  8215. Exhibit.SettingsUtilities._createBindingsAccessor=function(f,bindingSpecs){var bindings=[];
  8216. for(var i=0;
  8217. i<bindingSpecs.length;
  8218. i++){var bindingSpec=bindingSpecs[i];
  8219. var accessor=null;
  8220. var isTuple=false;
  8221. if("bindingNames" in bindingSpec){isTuple=true;
  8222. accessor=Exhibit.SettingsUtilities._createTupleAccessor(f,bindingSpec);
  8223. }else{accessor=Exhibit.SettingsUtilities._createElementalAccessor(f,bindingSpec);
  8224. }if(accessor==null){if(!("optional" in bindingSpec)||!bindingSpec.optional){return null;
  8225. }}else{bindings.push({bindingName:bindingSpec.bindingName,accessor:accessor,isTuple:isTuple});
  8226. }}return function(value,database,visitor){Exhibit.SettingsUtilities._evaluateBindings(value,database,visitor,bindings);
  8227. };
  8228. };
  8229. Exhibit.SettingsUtilities._createTupleAccessor=function(f,spec){var value=f(spec.attributeName);
  8230. if(value==null){return null;
  8231. }if(typeof value=="string"){value=value.trim();
  8232. if(value.length==0){return null;
  8233. }}try{var expression=Exhibit.ExpressionParser.parse(value);
  8234. var parsers=[];
  8235. var bindingTypes=spec.types;
  8236. for(var i=0;
  8237. i<bindingTypes.length;
  8238. i++){parsers.push(Exhibit.SettingsUtilities._typeToParser(bindingTypes[i]));
  8239. }var bindingNames=spec.bindingNames;
  8240. var separator=",";
  8241. if("separator" in spec){separator=spec.separator;
  8242. }return function(itemID,database,visitor,tuple){expression.evaluateOnItem(itemID,database).values.visit(function(v){var a=v.split(separator);
  8243. if(a.length==parsers.length){var tuple2={};
  8244. if(tuple){for(var n in tuple){tuple2[n]=tuple[n];
  8245. }}for(var i=0;
  8246. i<bindingNames.length;
  8247. i++){tuple2[bindingNames[i]]=null;
  8248. parsers[i](a[i],function(v){tuple2[bindingNames[i]]=v;
  8249. });
  8250. }visitor(tuple2);
  8251. }});
  8252. };
  8253. }catch(e){SimileAjax.Debug.exception(e);
  8254. return null;
  8255. }};
  8256. Exhibit.SettingsUtilities._createElementalAccessor=function(f,spec){var value=f(spec.attributeName);
  8257. if(value==null){return null;
  8258. }if(typeof value=="string"){value=value.trim();
  8259. if(value.length==0){return null;
  8260. }}var bindingType="text";
  8261. if("type" in spec){bindingType=spec.type;
  8262. }try{var expression=Exhibit.ExpressionParser.parse(value);
  8263. var parser=Exhibit.SettingsUtilities._typeToParser(bindingType);
  8264. return function(itemID,database,visitor){expression.evaluateOnItem(itemID,database).values.visit(function(v){return parser(v,visitor);
  8265. });
  8266. };
  8267. }catch(e){SimileAjax.Debug.exception(e);
  8268. return null;
  8269. }};
  8270. Exhibit.SettingsUtilities._typeToParser=function(type){switch(type){case"text":return Exhibit.SettingsUtilities._textParser;
  8271. case"url":return Exhibit.SettingsUtilities._urlParser;
  8272. case"float":return Exhibit.SettingsUtilities._floatParser;
  8273. case"int":return Exhibit.SettingsUtilities._intParser;
  8274. case"date":return Exhibit.SettingsUtilities._dateParser;
  8275. case"boolean":return Exhibit.SettingsUtilities._booleanParser;
  8276. default:throw new Error("Unknown setting type "+type);
  8277. }};
  8278. Exhibit.SettingsUtilities._textParser=function(v,f){return f(v);
  8279. };
  8280. Exhibit.SettingsUtilities._floatParser=function(v,f){var n=parseFloat(v);
  8281. if(!isNaN(n)){return f(n);
  8282. }return false;
  8283. };
  8284. Exhibit.SettingsUtilities._intParser=function(v,f){var n=parseInt(v);
  8285. if(!isNaN(n)){return f(n);
  8286. }return false;
  8287. };
  8288. Exhibit.SettingsUtilities._dateParser=function(v,f){if(v instanceof Date){return f(v);
  8289. }else{if(typeof v=="number"){var d=new Date(0);
  8290. d.setUTCFullYear(v);
  8291. return f(d);
  8292. }else{var d=SimileAjax.DateTime.parseIso8601DateTime(v.toString());
  8293. if(d!=null){return f(d);
  8294. }}}return false;
  8295. };
  8296. Exhibit.SettingsUtilities._booleanParser=function(v,f){v=v.toString().toLowerCase();
  8297. if(v=="true"){return f(true);
  8298. }else{if(v=="false"){return f(false);
  8299. }}return false;
  8300. };
  8301. Exhibit.SettingsUtilities._urlParser=function(v,f){return f(Exhibit.Persistence.resolveURL(v.toString()));
  8302. };
  8303. Exhibit.SettingsUtilities._evaluateBindings=function(value,database,visitor,bindings){var maxIndex=bindings.length-1;
  8304. var f=function(tuple,index){var binding=bindings[index];
  8305. var visited=false;
  8306. var recurse=index==maxIndex?function(){visitor(tuple);
  8307. }:function(){f(tuple,index+1);
  8308. };
  8309. if(binding.isTuple){binding.accessor(value,database,function(tuple2){visited=true;
  8310. tuple=tuple2;
  8311. recurse();
  8312. },tuple);
  8313. }else{var bindingName=binding.bindingName;
  8314. binding.accessor(value,database,function(v){visited=true;
  8315. tuple[bindingName]=v;
  8316. recurse();
  8317. });
  8318. }if(!visited){recurse();
  8319. }};
  8320. f({},0);
  8321. };
  8322. /* util.js */
  8323. Exhibit.Util={};
  8324. Exhibit.Util.round=function(n,precision){precision=precision||1;
  8325. var lg=Math.floor(Math.log(precision)/Math.log(10));
  8326. n=(Math.round(n/precision)*precision).toString();
  8327. var d=n.split(".");
  8328. if(lg>=0){return d[0];
  8329. }lg=-lg;
  8330. d[1]=(d[1]||"").substring(0,lg);
  8331. while(d[1].length<lg){d[1]+="0";
  8332. }return d.join(".");
  8333. };
  8334. if(!Array.prototype.indexOf){Array.prototype.indexOf=function(elt){var len=this.length;
  8335. var from=Number(arguments[1])||0;
  8336. from=(from<0)?Math.ceil(from):Math.floor(from);
  8337. if(from<0){from+=len;
  8338. }for(;
  8339. from<len;
  8340. from++){if(from in this&&this[from]===elt){return from;
  8341. }}return -1;
  8342. };
  8343. }if(!Array.prototype.filter){Array.prototype.filter=function(fun){var len=this.length;
  8344. if(typeof fun!="function"){throw new TypeError();
  8345. }var res=new Array();
  8346. var thisp=arguments[1];
  8347. for(var i=0;
  8348. i<len;
  8349. i++){if(i in this){var val=this[i];
  8350. if(fun.call(thisp,val,i,this)){res.push(val);
  8351. }}}return res;
  8352. };
  8353. }if(!Array.prototype.map){Array.prototype.map=function(f,thisp){if(typeof f!="function"){throw new TypeError();
  8354. }if(typeof thisp=="undefined"){thisp=this;
  8355. }var res=[],length=this.length;
  8356. for(var i=0;
  8357. i<length;
  8358. i++){if(this.hasOwnProperty(i)){res[i]=f.call(thisp,this[i],i,this);
  8359. }}return res;
  8360. };
  8361. }if(!Array.prototype.forEach){Array.prototype.forEach=function(fun){var len=this.length;
  8362. if(typeof fun!="function"){throw new TypeError();
  8363. }var thisp=arguments[1];
  8364. for(var i=0;
  8365. i<len;
  8366. i++){if(i in this){fun.call(thisp,this[i],i,this);
  8367. }}};
  8368. }
  8369. /* views.js */
  8370. Exhibit.ViewUtilities=new Object();
  8371. Exhibit.ViewUtilities.openBubbleForItems=function(anchorElmt,arrayOfItemIDs,uiContext){var coords=SimileAjax.DOM.getPageCoordinates(anchorElmt);
  8372. var bubble=SimileAjax.Graphics.createBubbleForPoint(coords.left+Math.round(anchorElmt.offsetWidth/2),coords.top+Math.round(anchorElmt.offsetHeight/2),uiContext.getSetting("bubbleWidth"),uiContext.getSetting("bubbleHeight"));
  8373. Exhibit.ViewUtilities.fillBubbleWithItems(bubble.content,arrayOfItemIDs,uiContext);
  8374. };
  8375. Exhibit.ViewUtilities.fillBubbleWithItems=function(bubbleElmt,arrayOfItemIDs,uiContext){if(bubbleElmt==null){bubbleElmt=document.createElement("div");
  8376. }if(arrayOfItemIDs.length>1){bubbleElmt.className=[bubbleElmt.className,"exhibit-views-bubbleWithItems"].join(" ");
  8377. var ul=document.createElement("ul");
  8378. for(var i=0;
  8379. i<arrayOfItemIDs.length;
  8380. i++){uiContext.format(arrayOfItemIDs[i],"item",function(elmt){var li=document.createElement("li");
  8381. li.appendChild(elmt);
  8382. ul.appendChild(li);
  8383. });
  8384. }bubbleElmt.appendChild(ul);
  8385. }else{var itemLensDiv=document.createElement("div");
  8386. var itemLens=uiContext.getLensRegistry().createLens(arrayOfItemIDs[0],itemLensDiv,uiContext);
  8387. bubbleElmt.appendChild(itemLensDiv);
  8388. }return bubbleElmt;
  8389. };
  8390. Exhibit.ViewUtilities.constructPlottingViewDom=function(div,uiContext,showSummary,resizableDivWidgetSettings,legendWidgetSettings){var dom=SimileAjax.DOM.createDOMFromString(div,"<div class='exhibit-views-header'>"+(showSummary?"<div id='collectionSummaryDiv'></div>":"")+"<div id='unplottableMessageDiv' class='exhibit-views-unplottableMessage'></div></div><div id='resizableDiv'></div><div id='legendDiv'></div>",{});
  8391. if(showSummary){dom.collectionSummaryWidget=Exhibit.CollectionSummaryWidget.create({},dom.collectionSummaryDiv,uiContext);
  8392. }dom.resizableDivWidget=Exhibit.ResizableDivWidget.create(resizableDivWidgetSettings,dom.resizableDiv,uiContext);
  8393. dom.plotContainer=dom.resizableDivWidget.getContentDiv();
  8394. dom.legendWidget=Exhibit.LegendWidget.create(legendWidgetSettings,dom.legendDiv,uiContext);
  8395. if(legendWidgetSettings.colorGradient==true){dom.legendGradientWidget=Exhibit.LegendGradientWidget.create(dom.legendDiv,uiContext);
  8396. }dom.setUnplottableMessage=function(totalCount,unplottableItems){Exhibit.ViewUtilities._setUnplottableMessage(dom,totalCount,unplottableItems,uiContext);
  8397. };
  8398. dom.dispose=function(){if(showSummary){dom.collectionSummaryWidget.dispose();
  8399. }if(dom.resizableDivWidget){dom.resizableDivWidget.dispose();
  8400. }if(dom.legendWidget){dom.legendWidget.dispose();
  8401. }};
  8402. return dom;
  8403. };
  8404. Exhibit.ViewUtilities._setUnplottableMessage=function(dom,totalCount,unplottableItems,uiContext){var div=dom.unplottableMessageDiv;
  8405. if(unplottableItems.length==0){div.style.display="none";
  8406. }else{div.innerHTML="";
  8407. var dom=SimileAjax.DOM.createDOMFromString(div,Exhibit.ViewUtilities.l10n.unplottableMessageFormatter(totalCount,unplottableItems,uiContext),{});
  8408. SimileAjax.WindowManager.registerEvent(dom.unplottableCountLink,"click",function(elmt,evt,target){Exhibit.ViewUtilities.openBubbleForItems(elmt,unplottableItems,uiContext);
  8409. });
  8410. div.style.display="block";
  8411. }};