extension as an example:
var LinkrCCB = LinkrTree.getInstance();
The getInstance method takes 4 arguments:
- Object options: same as in LinkrObject
- Initial tree items: the very first tree items
- Search settings: SQL queries
- Template methods: same as in LinkrObject
Object options example:
var LinkrCCB_options = { title : 'ccBoard', objName : 'LinkrCCB' };
Tree items example:
var LinkrCCB_tree = []; // Items have name, description, URL, // expandIcon, and collapseIcon values var LinkrCCB_tree_item = { id : 'first-item', name : 'First Item' }; LinkrCCB_tree.include(LinkrCCB_tree_item);For documentation on using include (on arrays), follow this link
.Search settings example:
var LinkrCCB_search = { sql : { category : '', forum : '' } }; // Category SQL LinkrCCB_search.sql.category = 'SELECT id, forum_name AS name '+ 'FROM #__ccb_forums '+ 'WHERE published = 1 AND cat_id = [query]'; // Forum SQL LinkrCCB_search.sql.forum = 'SELECT id, post_subject AS name, forum_id '+ 'FROM #__ccb_topics '+ 'WHERE forum_id = [query]';Note that there's only one query for every search type, unlike with the LinkrObject class.
Template methods example:
var LinkrCCB_tmpl = { setupTree : function(array, level) { // Tree items var tree = {}; // The current tree level will // determine the search type switch (level) { // For demonstration purposes. // If you go back to the Search // settings example, you'll notice // that there's no "topic" type. // That's because topics won't // have any children items. case 2: var type = 'topic'; break; case 1: var type = 'forum'; break; default: var type = 'category'; } // "array" is a list of database objects // resulting from one of the queries in // LinkrCCB_search.sql (see Search settings example). array.each(function(item) { // Item title var title = item.name; // Item URL. NOTE: In the ccBoard // extension, there is no "category" view. var url = false; if (type != 'category') { // Use the custom "url" helper method url = this.tmpl.url(type, item); } // Children items. NOTE: topics // don't have children items. var children = false; if (type != 'topic') { children = [type, item.id]; } // Add item tree[item.id] = { title : title, url : url, level : level, children : children } }, this); return tree; }, // Helper method to get URL url : function(type, item) { // Base for all URLs var url = 'index.php?option=com_ccboard'; switch (type) { case 'forum': url += '&view=topiclist&forum='+ item.id; break; case 'topic': url += '&view=postlist&forum='+ i.forum_id + '&topic='+ i.id; break; } return url; } };
The final statement to get the object instance will look like:
var LinkrCCB = LinkrTree.getInstance( LinkrCCB_options, LinkrCCB_tree, LinkrCCB_search, LinkrCCB_tmpl );
Get the working plugin from JoomlaCode
.| Next > |
|---|



