diff --git a/assets/javascripts/plantuml.js b/assets/javascripts/plantuml.js index 2320121..c3d5f8d 100644 --- a/assets/javascripts/plantuml.js +++ b/assets/javascripts/plantuml.js @@ -1,14 +1,20 @@ -if(typeof(jsToolBar) != 'undefined') { - - jsToolBar.prototype.elements.plantuml = { - type: 'button', - after: 'h3', - title: 'Add PlantUML diagramm', - fn: { - wiki: function() { - this.encloseLineSelection('{{plantuml(png)\n', '\n}}') - } +/** + * Extend the jsToolBar function to add the plantUML buttons to editor toolbar. + * Needs to run after the jsToolbar function is defined and before toolbars are drawn + * + * The position cannot be set (see http://www.redmine.org/issues/14936 ) + */ +if (typeof(jsToolBar) != 'undefined') { + jsToolBar.prototype.elements.plantuml = { + type: 'button', + title: 'Add PlantUML diagramm', + fn: { + wiki: function () { + // this.singleTag('{{plantuml(png)\n', '\n}}'); + this.encloseLineSelection('{{plantuml(png)\n', '\n}}') + } + } } - } - +} else { + throw 'could not add plantUML button to Toolbar. jsToolbar is undefined'; } diff --git a/init.rb b/init.rb index da3589a..5297b97 100644 --- a/init.rb +++ b/init.rb @@ -5,7 +5,7 @@ version '0.3.0' url 'https://github.com/dkd/plantuml' - requires_redmine version: '2.6'..'3.3' + requires_redmine version: '2.6'..'3.4' settings(partial: 'settings/plantuml', default: { 'plantuml_binary' => {}, 'cache_seconds' => '0' }) @@ -38,6 +38,5 @@ unless Redmine::WikiFormatting::Textile::Helper.included_modules.include? PlantumlHelperPatch Redmine::WikiFormatting::Textile::Helper.send(:include, PlantumlHelperPatch) - require_dependency 'plantuml/hooks/views_layouts_hook' end end diff --git a/lib/plantuml_helper_patch.rb b/lib/plantuml_helper_patch.rb index f51e3ea..f96b149 100644 --- a/lib/plantuml_helper_patch.rb +++ b/lib/plantuml_helper_patch.rb @@ -12,24 +12,17 @@ def self.included(base) # :nodoc: end module HelperMethodsWikiExtensions + # extend the editor Toolbar for adding a plantuml button + # overwrite this helper method to have full control about the load order def heads_for_wiki_formatter_with_plantuml - heads_for_wiki_formatter_without_plantuml - return if ie6_or_ie7? - - unless @heads_for_wiki_plantuml_included - content_for :header_tags do - o = javascript_include_tag('plantuml.js', plugin: 'plantuml') - o << stylesheet_link_tag('plantuml.css', plugin: 'plantuml') - o.html_safe - end - @heads_for_wiki_plantuml_included = true + return if @heads_for_wiki_plantuml_included + content_for :header_tags do + javascript_include_tag('jstoolbar/jstoolbar-textile.min') + + javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") + + stylesheet_link_tag('jstoolbar') + + javascript_include_tag('plantuml.js', plugin: 'plantuml') + + stylesheet_link_tag('plantuml.css', plugin: 'plantuml') end - end - - private - - def ie6_or_ie7? - useragent = request.env['HTTP_USER_AGENT'].to_s - useragent.match(/IE[ ]+[67]./).nil? + @heads_for_wiki_plantuml_included = true end end