2019-12-11 09:07:22 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# name: discourse-internet-explorer
|
|
|
|
# about: Attempts to provide backward support for internt explorer
|
|
|
|
# version: 1.0
|
|
|
|
# authors: Joffrey Jaffeux, David Taylor, Daniel Waterworth, Robin Ward
|
|
|
|
# url: https://github.com/discourse/discourse/tree/master/plugins/discourse-internet-explorer
|
|
|
|
|
|
|
|
enabled_site_setting :discourse_internet_explorer_enabled
|
|
|
|
hide_plugin if self.respond_to?(:hide_plugin)
|
|
|
|
|
|
|
|
register_asset 'stylesheets/ie.scss'
|
|
|
|
|
2020-01-10 15:06:15 -05:00
|
|
|
# We can't use register asset for an optional resource. Instead copy it after plugins have
|
|
|
|
# been activated so it can be uploaded to CDNs.
|
|
|
|
DiscourseEvent.on(:after_plugin_activation) do ||
|
|
|
|
polyfill_path = "#{Plugin::Instance.js_path}/#{self.directory_name}-optional.js"
|
|
|
|
FileUtils.cp("#{Rails.root}/public/plugins/discourse-internet-explorer/js/ie.js", polyfill_path)
|
2020-01-10 15:14:32 -05:00
|
|
|
Rails.configuration.assets.precompile << "plugins/discourse-internet-explorer-optional.js"
|
2020-01-10 15:06:15 -05:00
|
|
|
end
|
|
|
|
|
2019-12-11 09:07:22 -05:00
|
|
|
after_initialize do
|
2020-03-13 11:30:31 -04:00
|
|
|
# Conditionally load the stylesheet
|
|
|
|
register_asset_filter do |type, request|
|
|
|
|
request.nil? || request.env['HTTP_USER_AGENT'] =~ /MSIE|Trident/
|
2019-12-11 09:07:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
register_anonymous_cache_key(:ie) do
|
|
|
|
unless defined?(@is_ie)
|
|
|
|
session = @env[self.class::RACK_SESSION]
|
|
|
|
# don't initialize params until later
|
|
|
|
# otherwise you get a broken params on the request
|
|
|
|
params = {}
|
|
|
|
|
|
|
|
@is_ie = BrowserDetection.browser(@env[self.class::USER_AGENT]) == :ie
|
|
|
|
end
|
|
|
|
|
|
|
|
@is_ie
|
|
|
|
end
|
|
|
|
|
|
|
|
# not using patch on preload_script as js is fine and we need this file
|
|
|
|
# to be loaded before other files
|
|
|
|
register_html_builder('server:before-script-load') do |controller|
|
|
|
|
if BrowserDetection.browser(controller.request.env['HTTP_USER_AGENT']) == :ie
|
2020-01-10 15:06:15 -05:00
|
|
|
path = controller.helpers.script_asset_path('plugins/discourse-internet-explorer-optional')
|
2019-12-11 09:07:22 -05:00
|
|
|
|
|
|
|
<<~JAVASCRIPT
|
|
|
|
<script src="#{path}"></script>
|
|
|
|
JAVASCRIPT
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|