lib/dynamic_menu.rb in dynamic_menu-0.2.3 vs lib/dynamic_menu.rb in dynamic_menu-1.0.0
- old
+ new
@@ -1,49 +1,43 @@
module DynamicMenu
-
- class ActionMenuItem
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::JavaScriptHelper
-
- attr_accessor :name, :link, :method, :link_tag
-
- def initialize(name, link , method = :get, confirm="Are You Sure?")
- @name = name
- @link = link
- @method = method
- @link_tag = ""
+ require 'engine' if defined?(Rails)
+
+ module MenuItems
+ def newmenuitem(name,link,method=:get,confirm="Are you sure?")
+ genlink = ""
-
- if method == :delete
- @link_tag = link_to name, link, :method=>method, :confirm=>confirm
- else
- if link == :submit
- #make it easy to include a submit button via link...for enter support...requires
- #JQUERY!!!
- @link_tag = link_to_function name, "$('form').submit()"
+ if method==:delete
+ genlink += "<a href=\"#{link}\" data-confirm=\"#{confirm}\" data-method=\"delete\" rel=\"nofollow\">
+ #{name}</a>".html_safe
+ elsif link==:submit
+ genlink += "<a href=\"#\" onclick=\"$('form').submit(); return false;\">#{name}</a>".html_safe
@link_tag += "<script type=\"text/javascript\">
$(document).ready(function(){
$('html').keypress(function(e){
- if(e.which == 13){
+ if(e.which == 13){
$('form').submit();
- return false;
- }
+ return false;
+ }
});
});</script>".html_safe
- elsif link == :back
- @link_tag = "<a href=\"#\" id=\"jcheats-back\">#{name}</a>".html_safe
- @link_tag += "<script type=\"text/javascript\">
- $(\"#jcheats-back\").live(\"click\",
+ elsif link == :back
+ genlink = "<a href=\"#\" id=\"jcheats-back\">#{name}</a>".html_safe
+ genlink += "<script type=\"text/javascript\">
+ $(\"#jcheats-back\").live(\"click\",
function(){
- var ref = document.referrer;
- document.location=ref;
+ var ref = document.referrer;
+ document.location=ref;
});
- </script>".html_safe
- else
- @link_tag = link_to name, link
- end #end if submit
- end #end if delete
- end #end initalize
+ </script>".html_safe
+ else
+ genlink = "<a href=\"#{link}\">#{name}<a>".html_safe
+ end
+ return genlink
+ end
- end #end actionmenu Item
- end #end Modlue
\ No newline at end of file
+ def foo
+ "bar"
+ end
+
+ end
+end