/* * post-menu.js - adds dropdown menu to posts * * Creates a global Menu object with four public methods: * * Menu.onclick(fnc) * registers a function to be executed after button click, before the menu is displayed * Menu.add_item(id, text[, title]) * adds an item to the top level of menu * Menu.add_submenu(id, text) * creates and returns a List object through which to manipulate the content of the submenu * Menu.get_submenu(id) * returns the submenu with the specified id from the top level menu * * The List object contains all the methods from Menu except onclick() * * Example usage: * Menu.add_item('filter-menu-hide', 'Hide post'); * Menu.add_item('filter-menu-unhide', 'Unhide post'); * * submenu = Menu.add_submenu('filter-menu-add', 'Add filter'); * submenu.add_item('filter-add-post-plus', 'Post +', 'Hide post and all replies'); * submenu.add_item('filter-add-id', 'ID'); * * Usage: * $config['additional_javascript'][] = 'js/jquery.min.js'; * $config['additional_javascript'][] = 'js/post-menu.js'; */ $(document).ready(function () { var List = function (menuId, text) { this.id = menuId; this.text = text; this.items = []; this.add_item = function (itemId, text, title) { this.items.push(new Item(itemId, text, title)); }; this.list_items = function () { var array = []; var i, length, obj, $ele; if ($.isEmptyObject(this.items)) return; length = this.items.length; for (i = 0; i < length; i++) { obj = this.items[i]; $ele = $('
  • ', {id: obj.id}).text(obj.text); if ('title' in obj) $ele.attr('title', obj.title); if (obj instanceof Item) { $ele.addClass('post-item'); } else { $ele.addClass('post-submenu'); $ele.prepend(obj.list_items()); $ele.append($('', {class: 'post-menu-arrow'}).text('»')); } array.push($ele); } return $('