Changes ExhibitInterceptorsJS in space Macros
From Version 1.2
edited by NielsMayer.com Administrator
on Jun 03, 2009 17:13:08 GMT-08:00
on Jun 03, 2009 17:13:08 GMT-08:00
To Version 9.1
edited by NielsMayer.com Administrator
on Jun 03, 2009 21:41:55 GMT-08:00
on Jun 03, 2009 21:41:55 GMT-08:00
Change comment: There is no comment for this version
| Metadata changes | ||
|---|---|---|
| Property | Version 1.2 | Version 9.1 |
| There are no metadata changes | ||
| Content changes |
|---|
|
##XWiki.JavaScriptExtension[0]## XWiki.JavaScriptExtension[0] contains previous addExhibitInterceptorsAndOverides() ##which## which sets globals to access various Exhibit facets and views, as well as the ##Timeline## Timeline widget. Turns out the same thing can be achieved much better by ##naming## naming (id="the-search-facet") the exhibit HTML element and then calling ##exhibit.getComponent("the-search-facet")## exhibit.getComponent("episodes-timeline-view") to get back the exhibit UI object. ## the_tl_obj = exhibit.getComponent("episodes-timeline-view")._timeline ## the_tl_event_src = exhibit.getComponent("episodes-timeline-view")._eventSource ## Called out of XWiki.JavaScriptExtension[2]:onLoadExhibit() via macro ## #exhibit_create(). This allows overriding existing Exhibit code by ## importing another Macro/Document after Macros.Exhibit to redefine ## addExhibitInterceptorsAndOverides(), e.g.: ## #includeMacros("Macros.Exhibit")## ## #exhibit_xwiki_init()## ## #includeMacros("Macros.ExhibitInterceptorsJS")## ## #exhibitinterceptors_xwiki_init()## |
| Attachment changes | ||
|---|---|---|
| Filename | Action | |
| There are no attachment changes | ||
| Comment changes | ||
|---|---|---|
| There are no comment changes |
| Object Changes | ||
|---|---|---|
| Property | Version 1.2 | Version 9.1 |
| cache of class XWiki.JavaScriptExtension | default | |
| name of class XWiki.JavaScriptExtension | addExhibitInterceptorsAndOverides(). etc. | |
| use of class XWiki.JavaScriptExtension | onDemand | |
| code of class XWiki.JavaScriptExtension | /****************************************************************************** * XWiki.JavaScriptExtension[0]: JavaScript Utilities for Exhibit * Copyright (C) 2009, Niels Mayer. All Rights Reserved. http://nielsmayer.com ******************************************************************************/ /* * TODO: replace get*Facet() functions with exhibit.getComponent("the-search-facet") * remove interceptors. Not sure if can replace exhibit_SwitchView() although it should * work if those are named as well */ var the_tl_obj = null; var the_tl_event_src = null; { // BEGIN: Closure for accessors and addExhibitInterceptorsAndOverides() var ex_viewpanels = []; /**************************************************************************** * exhibit_switchView(viewPanelIdx, viewIdx) * viewPanelIdx=0 --> top view panel * viewPanelIdx=1 --> second view panel, etc * viewIdx --> 0 means the first view in the given viewpanel ****************************************************************************/ function exhibit_switchView(viewPanelIdx, viewIdx) { if (ex_viewpanels.length > viewPanelIdx) { ex_viewpanels[viewPanelIdx]._switchView(viewIdx); } } /**************************************************************************** * exhibit_getView(viewPanelIdx) --> returns the index of selected view. * viewPanelIdx=0 --> top view panel * viewPanelIdx=1 --> second view panel, etc * Returns: index --> 0 means the first view in the given viewpanel ****************************************************************************/ function exhibit_getView(viewPanelIdx) { if (ex_viewpanels.length > viewPanelIdx) { return(0); //TODO } } var ex_cloud_facets = []; /**************************************************************************** * exhibit_getCloudFacet(facetIdx) --> returns instance of Exhibit.CloudFacet.prototype * facetIdx=0 --> first created facet * facetIdx=1 --> second created facet... ****************************************************************************/ function exhibit_getCloudFacet(facetIdx) { if (ex_cloud_facets.length > facetIdx) { return (ex_cloud_facets[facetIdx]); } return (null); } var ex_hierarchical_facets = []; /**************************************************************************** * exhibit_getHierarchicalFacet(facetIdx) --> returns instance of Exhibit.HierarchicalFacet.prototype * facetIdx=0 --> first created facet * facetIdx=1 --> second created facet... ****************************************************************************/ function exhibit_getHierarchicalFacet(facetIdx) { if (ex_hierarchical_facets.length > facetIdx) { return (ex_hierarchical_facets[facetIdx]); } return (null); } var ex_image_facets = []; /**************************************************************************** * exhibit_getImageFacets(facetIdx) --> returns instance of Exhibit..prototype * facetIdx=0 --> first created facet * facetIdx=1 --> second created facet... ****************************************************************************/ function exhibit_getImageFacets(facetIdx) { if (ex_image_facets.length > facetIdx) { return (ex_image_facets[facetIdx]); } return (null); } var ex_list_facets = []; /**************************************************************************** * exhibit_getListFacets(facetIdx) --> returns instance of Exhibit..prototype * facetIdx=0 --> first created facet * facetIdx=1 --> second created facet... ****************************************************************************/ function exhibit_getListFacets(facetIdx) { if (ex_list_facets.length > facetIdx) { return (ex_list_facets[facetIdx]); } return (null); } var ex_numeric_range_facets = []; /**************************************************************************** * exhibit_getNumericRangeFacets(facetIdx) --> returns instance of Exhibit..prototype * facetIdx=0 --> first created facet * facetIdx=1 --> second created facet... ****************************************************************************/ function exhibit_getNumericRangeFacets(facetIdx) { if (ex_numeric_range_facets.length > facetIdx) { return (ex_numeric_range_facets[facetIdx]); } return (null); } var ex_slider_facets = []; /**************************************************************************** * exhibit_getSliderFacets(facetIdx) --> returns instance of Exhibit..prototype * facetIdx=0 --> first created facet * facetIdx=1 --> second created facet... ****************************************************************************/ function exhibit_getSliderFacets(facetIdx) { if (ex_slider_facets.length > facetIdx) { return (ex_slider_facets[facetIdx]); } return (null); } var ex_text_search_facets = []; /**************************************************************************** * exhibit_getTextSearchFacets(facetIdx) --> returns instance of Exhibit..prototype * facetIdx=0 --> first created facet * facetIdx=1 --> second created facet... ****************************************************************************/ function exhibit_getTextSearchFacets(facetIdx) { if (ex_text_search_facets.length > facetIdx) { return (ex_text_search_facets[facetIdx]); } return (null); } /**************************************************************************** * Called out of XWiki.JavaScriptExtension[2]:onLoadExhibit() via macro * #exhibit_create(). This allows overriding existing Exhibit code. ****************************************************************************/ function addExhibitInterceptorsAndOverides() { /* * Intercept Viewpanel creation, and store the objects in * viewpanels array. viewpanels[0] represents the topmost or first-created * view-panel and if there are more than one, the second will be viewpanels[1] etc. */ var old_ViewPanelcreateView = Exhibit.ViewPanel.prototype._createView; Exhibit.ViewPanel.prototype._createView = function() { old_ViewPanelcreateView.call(this); ex_viewpanels.push(this); }; /* * Intercept cloud-facet creation, and store the objects in * ex_cloud_facets array. ex_cloud_facets[0] represents the topmost or first-created * facet and if there are more than one, the second will be ex_cloud_facets[1] etc. * http://code.google.com/p/simile-widgets/source/browse/exhibit/trunk/src/webapp/api/scripts/ui/facets/cloud-facet.js?r=1697 */ var old_CloudFacetinitializeUI = Exhibit.CloudFacet.prototype._initializeUI; Exhibit.CloudFacet.prototype._initializeUI = function() { old_CloudFacetinitializeUI.call(this); ex_cloud_facets.push(this); }; /* * Intercept hierarchical-facet creation, and store the objects in * ex_hierarchical_facets array. ex_hierarchical_facets[0] represents the topmost or first-created * facet and if there are more than one, the second will be ex_hierarchical_facets[1] etc. * http://code.google.com/p/simile-widgets/source/browse/exhibit/trunk/src/webapp/api/scripts/ui/facets/hierarchical-facet.js?r=1697 */ var oldHierarchicalFacetinitializeUI = Exhibit.HierarchicalFacet.prototype._initializeUI; Exhibit.HierarchicalFacet.prototype._initializeUI = function() { oldHierarchicalFacetinitializeUI.call(this); ex_hierarchical_facets.push(this); //alert('length of ex_hierarchical_facets = ' + ex_hierarchical_facets.length); }; /* * Intercept image-facet creation, and store the objects in * ex_image_facets array. ex_image_facets[0] represents the topmost or first-created * facet and if there are more than one, the second will be ex_image_facets[1] etc. * http://code.google.com/p/simile-widgets/source/browse/exhibit/trunk/src/webapp/api/scripts/ui/facets/image-facet.js?r=1697 */ var oldImageFacetinitializeUI = Exhibit.ImageFacet.prototype._initializeUI; Exhibit.ImageFacet.prototype._initializeUI = function() { oldImageFacetinitializeUI.call(this); ex_image_facets.push(this); }; /* * Intercept list-facet creation, and store the objects in * ex_list_facets array. ex_list_facets[0] represents the topmost or first-created * facet and if there are more than one, the second will be ex_list_facets[1] etc. * http://code.google.com/p/simile-widgets/source/browse/exhibit/trunk/src/webapp/api/scripts/ui/facets/list-facet.js?r=1697 */ var oldListFacetinitializeUI = Exhibit.ListFacet.prototype._initializeUI; Exhibit.ListFacet.prototype._initializeUI = function() { oldListFacetinitializeUI.call(this); ex_list_facets.push(this); //alert('length of ex_list_facets = ' + ex_list_facets.length); }; /* * Intercept numeric-range-facet creation, and store the objects in * ex_numeric_range_facets array. ex_numeric_range_facets[0] represents the topmost or first-created * facet and if there are more than one, the second will be ex_numeric_range_facets[1] etc. * http://code.google.com/p/simile-widgets/source/browse/exhibit/trunk/src/webapp/api/scripts/ui/facets/numeric-range-facet.js?r=1697 */ var oldNumericRangeFacetinitializeUI = Exhibit.NumericRangeFacet.prototype._initializeUI; Exhibit.NumericRangeFacet.prototype._initializeUI = function() { oldNumericRangeFacetinitializeUI.call(this); ex_numeric_range_facets.push(this); }; /* * Intercept slider-facet creation, and store the objects in * ex_slider_facets array. ex_slider_facets[0] represents the topmost or first-created * facet and if there are more than one, the second will be ex_slider_facets[1] etc. * http://code.google.com/p/simile-widgets/source/browse/exhibit/trunk/src/webapp/api/scripts/ui/facets/slider-facet.js?r=1697 */ var oldSliderFacetinitializeUI = Exhibit.SliderFacet.prototype._initializeUI; Exhibit.SliderFacet.prototype._initializeUI = function() { oldSliderFacetinitializeUI.call(this); ex_slider_facets.push(this); }; /* * Intercept text-search-facet creation, and store the objects in * ex_text_search_facets array. ex_text_search_facets[0] represents the topmost or first-created * facet and if there are more than one, the second will be ex_text_search_facets[1] etc. * http://code.google.com/p/simile-widgets/source/browse/exhibit/trunk/src/webapp/api/scripts/ui/facets/text-search-facet.js?r=1697 */ var oldTextSearchFacetinitializeUI = Exhibit.TextSearchFacet.prototype._initializeUI; Exhibit.TextSearchFacet.prototype._initializeUI = function() { oldTextSearchFacetinitializeUI.call(this); ex_text_search_facets.push(this); //alert('length of ex_text_search_facets = ' + ex_text_search_facets.length); }; /* * apply overrides/intercepts for Timeline iff it was specified as a view. * See Exhibit.Presidents4, Exhibit.NPRPods2, Exhibit.NPRPods3 which set this * global in XWiki.JavaScriptExtension[0]. Note that Macros.Exhibit requires * 'exhibit_views' to be set before calling #includeMacros(). */ if (exhibit_views.indexOf("timeline") != -1) { // if "timeline" in exhibit_views... // As suggested by David Huynh 04 Jan 2009 http://groups.google.com/group/simile-widgets/msg/aadec56fd8c3b575 var oldTimelineViewreconstructTimeline = Exhibit.TimelineView.prototype._reconstructTimeline; Exhibit.TimelineView.prototype._reconstructTimeline = function(newEvents) { oldTimelineViewreconstructTimeline.call(this, newEvents); the_tl_obj = this._timeline; the_tl_event_src = this._eventSource; //alert('intercepted _reconstructTimeline newevents: "' + newEvents + '" the_tl_obj: "' + the_tl_obj + '" the_tl_event_src: "' + the_tl_event_src + '"'); }; // As suggested by David Huynh 13 May 2009 http://groups.google.com/group/simile-widgets/msg/945e19dbd15079d7 // http://trunk.simile-widgets.org/exhibit/api/extensions/time/scripts/timeline-view.js // Look for // Exhibit.TimelineView.prototype._reconstruct // // This function is called whenever the timeline needs to be updated. You // could make a copy of it after including all exhibit's code (so that your // copy overrides the default implementation) and modify the copy to do // what you want. More specifically, after this chunk of code // // if (plottableSize > this._largestSize) { // this._largestSize = plottableSize; // this._reconstructTimeline(events); // } else { // this._eventSource.addMany(events); // } // // the timeline should have laid out itself. Then you can get the number of // track and resize the timeline: // // var trackCount = this._timeline.getBand(0)._tracks.length; // this._dom.plotContainer.style.height = ... some expression here, ending with px ... // this._timeline.layout(); var oldTimelineViewreconstruct = Exhibit.TimelineView.prototype._reconstruct; Exhibit.TimelineView.prototype._reconstruct = function() { oldTimelineViewreconstruct.call(this); the_tl_obj = this._timeline; the_tl_event_src = this._eventSource; //alert('intercepted _reconstruct the_tl_obj: "' + the_tl_obj + '" the_tl_event_src: "' + the_tl_event_src + '"'); }; } //END: if "timeline" in exhibit_views } //END: addExhibitInterceptorsAndOverides() } //END: Closure for accessors and addExhibitInterceptorsAndOverides() | |
| parse of class XWiki.JavaScriptExtension | No | |