From 0cbee23fa528bbd812640fc94eda7ae87415751d Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 28 Oct 2015 18:57:02 +0800 Subject: [PATCH] now internal links open in same page and also removed dependency of rails --- .../site_menu_widgets_controller.rb | 24 +++++++++++++++++-- site_menu_widget.gemspec | 3 +-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/controllers/site_menu_widgets_controller.rb b/app/controllers/site_menu_widgets_controller.rb index 6fcbe7d..beac8c4 100644 --- a/app/controllers/site_menu_widgets_controller.rb +++ b/app/controllers/site_menu_widgets_controller.rb @@ -40,7 +40,7 @@ class SiteMenuWidgetsController < ApplicationController else item["page_name"] = page.name item["url"] = page.external_url - item["target"] = "_blank" + item["target"] = (is_internal_url?(page.external_url) ? "_self" : "_blank") rescue "_blank" item["children"] = [] end end @@ -57,4 +57,24 @@ class SiteMenuWidgetsController < ApplicationController } end -end \ No newline at end of file + + def is_internal_url?(link) + internal = false + if !link.nil? + link = link.split("?").first + temp_url = URI.parse(link) + if temp_url.host.nil? + internal = true + end + end + return internal + end +end + + + + + + + + diff --git a/site_menu_widget.gemspec b/site_menu_widget.gemspec index 784af69..5c13eee 100644 --- a/site_menu_widget.gemspec +++ b/site_menu_widget.gemspec @@ -15,5 +15,4 @@ Gem::Specification.new do |s| s.license = "MIT" s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] - s.test_files = Dir["test/**/*"] -end + s.test_files = Dir["test/**/*"] \ No newline at end of file