mirror of
https://github.com/discourse/discourse.git
synced 2025-06-11 10:35:00 +08:00
FIX: call method only if it exists
discourse-objects creating empty Discourse object in window. It fails the _registerPluginCode method call since it is not exist.
This commit is contained in:
@ -63,7 +63,7 @@ class ThemeField < ActiveRecord::Base
|
|||||||
def transpile(es6_source, version)
|
def transpile(es6_source, version)
|
||||||
template = Tilt::ES6ModuleTranspilerTemplate.new {}
|
template = Tilt::ES6ModuleTranspilerTemplate.new {}
|
||||||
wrapped = <<PLUGIN_API_JS
|
wrapped = <<PLUGIN_API_JS
|
||||||
if ('Discourse' in window) {
|
if ('Discourse' in window && typeof Discourse._registerPluginCode === 'function') {
|
||||||
Discourse._registerPluginCode('#{version}', api => {
|
Discourse._registerPluginCode('#{version}', api => {
|
||||||
#{settings(es6_source)}
|
#{settings(es6_source)}
|
||||||
#{es6_source}
|
#{es6_source}
|
||||||
|
@ -326,7 +326,7 @@ HTML
|
|||||||
theme.save!
|
theme.save!
|
||||||
|
|
||||||
transpiled = <<~HTML
|
transpiled = <<~HTML
|
||||||
if ('Discourse' in window) {
|
if ('Discourse' in window && typeof Discourse._registerPluginCode === 'function') {
|
||||||
Discourse._registerPluginCode('1.0', function (api) {
|
Discourse._registerPluginCode('1.0', function (api) {
|
||||||
var settings = { "name": "bob" };
|
var settings = { "name": "bob" };
|
||||||
alert(settings.name);var a = function a() {};
|
alert(settings.name);var a = function a() {};
|
||||||
@ -342,7 +342,7 @@ HTML
|
|||||||
setting.value = 'bill'
|
setting.value = 'bill'
|
||||||
|
|
||||||
transpiled = <<~HTML
|
transpiled = <<~HTML
|
||||||
if ('Discourse' in window) {
|
if ('Discourse' in window && typeof Discourse._registerPluginCode === 'function') {
|
||||||
Discourse._registerPluginCode('1.0', function (api) {
|
Discourse._registerPluginCode('1.0', function (api) {
|
||||||
var settings = { "name": "bill" };
|
var settings = { "name": "bill" };
|
||||||
alert(settings.name);var a = function a() {};
|
alert(settings.name);var a = function a() {};
|
||||||
|
Reference in New Issue
Block a user