Skip to content

Commit b92063b

Browse files
Atlas UI: Normalize Bootstrap button loading text handling (#501)
1 parent 928a378 commit b92063b

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

dashboardv2/public/js/main.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,34 @@ require(['App',
212212
'select2'
213213
], function(App, Router, Helper, CommonViewFunction, Globals, UrlLinks, VEntityList, VTagList, VRelationshipSearchList, Enums, Utils) {
214214
var that = this;
215+
var sanitizeBootstrapButtonLoadingText = function() {
216+
if (!window.jQuery || !$.fn || !$.fn.button ||
217+
!$.fn.button.Constructor) {
218+
return
219+
}
220+
221+
var Button = $.fn.button.Constructor
222+
if (Button.prototype._safeSetState) {
223+
return
224+
}
225+
226+
var originalSetState = Button.prototype.setState
227+
if (!originalSetState) {
228+
return
229+
}
230+
231+
Button.prototype.setState = function(state) {
232+
var data = this.$element ? this.$element.data() : null
233+
var key = state + 'Text'
234+
if (data && data[key]) {
235+
data[key] = $('<div/>').text(data[key]).text()
236+
}
237+
return originalSetState.call(this, state)
238+
}
239+
Button.prototype._safeSetState = true
240+
}
241+
242+
sanitizeBootstrapButtonLoadingText()
215243
this.asyncFetchCounter = 5 + (Enums.addOnEntities.length + 1);
216244
// entity
217245
this.entityDefCollection = new VEntityList();

dashboardv2/public/js/migration.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,34 @@ require([
200200
'bootstrap'
201201
], function(Marionette, Helper) {
202202
var that = this;
203+
var sanitizeBootstrapButtonLoadingText = function() {
204+
if (!window.jQuery || !$.fn || !$.fn.button ||
205+
!$.fn.button.Constructor) {
206+
return
207+
}
208+
209+
var Button = $.fn.button.Constructor
210+
if (Button.prototype._safeSetState) {
211+
return
212+
}
213+
214+
var originalSetState = Button.prototype.setState
215+
if (!originalSetState) {
216+
return
217+
}
218+
219+
Button.prototype.setState = function(state) {
220+
var data = this.$element ? this.$element.data() : null
221+
var key = state + 'Text'
222+
if (data && data[key]) {
223+
data[key] = $('<div/>').text(data[key]).text()
224+
}
225+
return originalSetState.call(this, state)
226+
}
227+
Button.prototype._safeSetState = true
228+
}
229+
230+
sanitizeBootstrapButtonLoadingText()
203231
var App = new Marionette.Application();
204232

205233
App.addRegions({

dashboardv3/public/js/main.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,34 @@ require(['App',
241241
'select2'
242242
], function(App, Router, Helper, CommonViewFunction, Globals, UrlLinks, VEntityList, VTagList, VRelationshipSearchList, Enums, Utils) {
243243
var that = this;
244+
var sanitizeBootstrapButtonLoadingText = function() {
245+
if (!window.jQuery || !$.fn || !$.fn.button ||
246+
!$.fn.button.Constructor) {
247+
return
248+
}
249+
250+
var Button = $.fn.button.Constructor
251+
if (Button.prototype._safeSetState) {
252+
return
253+
}
254+
255+
var originalSetState = Button.prototype.setState
256+
if (!originalSetState) {
257+
return
258+
}
259+
260+
Button.prototype.setState = function(state) {
261+
var data = this.$element ? this.$element.data() : null
262+
var key = state + 'Text'
263+
if (data && data[key]) {
264+
data[key] = $('<div/>').text(data[key]).text()
265+
}
266+
return originalSetState.call(this, state)
267+
}
268+
Button.prototype._safeSetState = true
269+
}
270+
271+
sanitizeBootstrapButtonLoadingText()
244272
this.asyncFetchCounter = 5 + (Enums.addOnEntities.length + 1);
245273
// entity
246274
this.entityDefCollection = new VEntityList();

dashboardv3/public/js/migration.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,34 @@ require([
201201
'select2'
202202
], function(Marionette, Helper) {
203203
var that = this;
204+
var sanitizeBootstrapButtonLoadingText = function() {
205+
if (!window.jQuery || !$.fn || !$.fn.button ||
206+
!$.fn.button.Constructor) {
207+
return
208+
}
209+
210+
var Button = $.fn.button.Constructor
211+
if (Button.prototype._safeSetState) {
212+
return
213+
}
214+
215+
var originalSetState = Button.prototype.setState
216+
if (!originalSetState) {
217+
return
218+
}
219+
220+
Button.prototype.setState = function(state) {
221+
var data = this.$element ? this.$element.data() : null
222+
var key = state + 'Text'
223+
if (data && data[key]) {
224+
data[key] = $('<div/>').text(data[key]).text()
225+
}
226+
return originalSetState.call(this, state)
227+
}
228+
Button.prototype._safeSetState = true
229+
}
230+
231+
sanitizeBootstrapButtonLoadingText()
204232
var App = new Marionette.Application();
205233

206234
App.addRegions({

0 commit comments

Comments
 (0)