From a224aff0634c02201197d483cd7bd746fef81b26 Mon Sep 17 00:00:00 2001 From: Benjamin Athlan Date: Wed, 18 May 2011 18:27:24 +0200 Subject: [PATCH] Fixed open/close folder arrows by plugin --- config/assets.yml | 1 + public/javascripts/admin/pages.js | 19 +-------- .../javascripts/admin/plugins/menu_toggler.js | 41 +++++++++++++++++++ 3 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 public/javascripts/admin/plugins/menu_toggler.js diff --git a/config/assets.yml b/config/assets.yml index c42bd1d3..4deae37b 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -56,6 +56,7 @@ javascripts: - public/javascripts/admin/account.js pages: - public/javascripts/admin/pages.js + - public/javascripts/admin/menu_toggler.js edit_page: - public/javascripts/admin/plugins/tiny_mce/tinymce.js - public/javascripts/admin/editable_elements.js diff --git a/public/javascripts/admin/pages.js b/public/javascripts/admin/pages.js index 29a8b826..12790847 100644 --- a/public/javascripts/admin/pages.js +++ b/public/javascripts/admin/pages.js @@ -1,24 +1,7 @@ $(document).ready(function() { // open / close folder - $('#pages-list ul.folder img.toggler').click(function(e) { - var toggler = $(this); - var children = toggler.parent().find('> ul.folder'); - - children.each(function(){ - if ($(this).is(':visible')) { - $(this).slideUp('fast', function() { - toggler.attr('src', toggler.attr('src').replace('open', 'closed')); - $.cookie($(this).attr('id'), 'none'); - }); - } else { - $(this).slideDown('fast', function() { - toggler.attr('src', toggler.attr('src').replace('closed', 'open')); - $.cookie($(this).attr('id'), 'block'); - }); - } - }); - }); + $('#pages-list ul.folder img.toggler').toggleMe(); // sortable folder items $('#pages-list ul.folder').sortable({ diff --git a/public/javascripts/admin/plugins/menu_toggler.js b/public/javascripts/admin/plugins/menu_toggler.js new file mode 100644 index 00000000..8d09879d --- /dev/null +++ b/public/javascripts/admin/plugins/menu_toggler.js @@ -0,0 +1,41 @@ +/** + * Version 1.0 + * Init and deploy childs on menu (admin) + * Benjamin Athlan - Bewcultures + */ +$.fn.toggleMe = function(settings) { + + settings = $.extend({ + }, settings); + + function toggle(element){ + var children = $(element).parent().find('> ul.folder'); + + children.each(function(){ + if ($(this).is(':visible')) { + $(this).slideUp('fast', function() { + element.attr('src', element.attr('src').replace('open', 'closed')); + $.cookie($(this).attr('id'), 'none'); + }); + } else { + $(this).slideDown('fast', function() { + element.attr('src', element.attr('src').replace('closed', 'open')); + $.cookie($(this).attr('id'), 'block'); + }); + } + }); + }; + + return this.each(function(){ + toggle($(this)); + + $(this).bind("click", function(){ + // console.log(this); + toggle($(this)); + }); + }); + +}; + + +