Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,8 @@
"*.config.js",
"spec/javascripts/setupTests.ts",
"spec/javascripts/__mocks__/"
]
],
"globals": {
"$": "readonly"
}
}
10 changes: 5 additions & 5 deletions app/assets/javascripts/provider/admin/cms/sidebar.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Sidebar

constructor: (@selector) ->

@fire_ajax()
@fetch_sidebar()

@filter = new SidebarFilter(this)

Expand Down Expand Up @@ -61,11 +61,11 @@ class Sidebar
@expand_collapse_all_button().
html(Sidebar.icon(if all_packed then 'plus-square' else 'minus-square'))

fire_ajax: ->
fetch_sidebar: ->
@ajax.abort() if @ajax
@ajax = $.ajax('/p/admin/cms/templates/sidebar.json')
.success (json) => @update(json)
.error (xhr, status, error) ->
.done (json) => @update(json)
.fail (xhr, status, error) ->
console.error("#{xhr.status} #{error}")
console.error(xhr.responseText)

Expand Down Expand Up @@ -480,7 +480,7 @@ class SidebarToggle
ids.splice(i, 1) if i >= 0
@el.trigger('toggle:unpack')

sets_are_equal = new Set(SidebarToggle.load()).difference(new Set(ids)).size == 0
sets_are_equal = new Set(SidebarToggle.load()).symmetricDifference(new Set(ids)).size == 0
unless sets_are_equal
SidebarToggle.save(ids)

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/provider/layout/iframe.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//= require jquery
//= require jquery3
//= require rails-ujs
4 changes: 2 additions & 2 deletions app/assets/javascripts/provider/layout/provider.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//= require jquery
//= require vendor/colorbox
//= require jquery3
//= require rails-ujs
//= require vendor/jquery.colorbox-min.js
2 changes: 1 addition & 1 deletion app/assets/javascripts/swagger-ui/extensions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ThreeScaleAutoComplete
$(document).on "focus","input[data-threescale-name]", (event)=>
@currentField = $(event.currentTarget)
type = @currentField.attr("data-threescale-name")
return false if $.trim(type) is ""
return false if type.trim() is ""
@currentTip = if +ThreeScaleAutoComplete.DataStatus is 401 then $(".apidocs-param-tips.apidocs-signin-message") else $(".apidocs-param-tips."+type)
pos = @getPosition()
@currentTip.css({top:pos[0], left:pos[1]}).fadeIn("fast")
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/swagger-ui2/autocomplete.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ThreeScaleAutoComplete
$(document).on "focus","input[data-threescale-name]", (event)=>
@currentField = $(event.currentTarget)
type = @currentField.attr("data-threescale-name")
return false if $.trim(type) is ""
return false if type.trim() is ""
@currentTip = if +ThreeScaleAutoComplete.DataStatus is 401 then $(".apidocs-param-tips.apidocs-signin-message") else $(".apidocs-param-tips."+type)
pos = @getPosition()
@currentTip.css({top:pos[0], left:pos[1]}).fadeIn("fast")
Expand Down
27 changes: 27 additions & 0 deletions app/assets/javascripts/vendor/colorbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Spoiler alert: if you're reading this, it's already too late. jQuery 1 is loaded.
*
* Colorbox 1.6.4 is incompatible with jQuery 3 (uses .live, .bind, $.isFunction, $.support). It
* must run on jQuery 1.12.4.
*
* This file loads jQuery 1.12.4 first, then colorbox (which attaches to it), then exports colorbox
* to the global scope as window.colorbox. After this file, provider.js loads jquery3 which
* overwrites the global $ and jQuery with jQuery 3.7.0.
*
* The loading order in provider.js is critical:
* 1. vendor/colorbox
* 2. jquery3
* 3. rails-ujs
*
* All colorbox calls must use window.colorbox, not $.colorbox.
*
* jQuery.colorbox is both a callable function and an object with methods (.close, .resize).
* .bind(jQuery) fixes the "this" context so colorbox works when called as window.colorbox().
* Object.assign copies .close, .resize, etc. onto the bound function because .bind() creates
* a bare function without the original's custom properties.
*/

//= require jquery
//= require vendor/jquery.colorbox-min.js

window.colorbox = Object.assign(jQuery.colorbox.bind(jQuery), jQuery.colorbox);
7 changes: 3 additions & 4 deletions app/javascript/packs/bulk_operations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const jquery1 = window.$

document.addEventListener('DOMContentLoaded', () => {
const dataSelectedTotal = 'data-selected-total-entries'
Expand All @@ -13,7 +12,7 @@ document.addEventListener('DOMContentLoaded', () => {
function hrefFor (url: string) {
// url address might already include some parameters
const connector = url.includes('?') ? '&' : '?'
let href = url.concat(connector, jquery1('table tbody .select :checked').serialize())
let href = url.concat(connector, $('table tbody .select :checked').serialize())
Comment thread
qltysh[bot] marked this conversation as resolved.

const selectTotalEntries = findSelectTotalEntries()
if (selectTotalEntries?.hasAttribute(dataSelectedTotal)) {
Expand Down Expand Up @@ -69,7 +68,7 @@ document.addEventListener('DOMContentLoaded', () => {
}

function updateBulkOperationsCard () {
const bulk = jquery1('#bulk-operations')
const bulk = $('#bulk-operations')
Comment thread
qltysh[bot] marked this conversation as resolved.
const selected = selectedRows()

if (selected > 0) {
Expand Down Expand Up @@ -97,7 +96,7 @@ document.addEventListener('DOMContentLoaded', () => {
.forEach(dt => {
dt.querySelector('button')!
.addEventListener('click', () => {
jquery1.colorbox({
window.colorbox({
title: dt.nextElementSibling!.textContent,
href: hrefFor(dt.dataset.url!)
})
Expand Down
36 changes: 17 additions & 19 deletions app/javascript/packs/cms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import $ from 'jquery'
import 'jquery-ui/ui/widgets/droppable'
import 'jquery-ui/ui/widgets/draggable'
import 'jquery-ui/ui/widgets/tabs'
Expand All @@ -8,21 +7,19 @@ import { toast } from 'utilities/toast'

import type { EditorFromTextArea } from 'codemirror'

const jQuery1 = window.$

/**
* Called every time a CMS section is selected in the sidebar, including first render.
*/
jQuery1(document).on('cms-template:init', () => {
$(document).on('cms-template:init', () => {
Comment thread
qltysh[bot] marked this conversation as resolved.
advanceOptionsToggle()
setUpSectionDrop()
setUpEditorTabs()
setUpPjax()

jQuery1('#cms_template_content_type, #cms_template_liquid_enabled').trigger('change')
$('#cms_template_content_type, #cms_template_liquid_enabled').trigger('change')
Comment thread
qltysh[bot] marked this conversation as resolved.
})

jQuery1(document).on('cms-sidebar:update', () => {
$(document).on('cms-sidebar:update', () => {
Comment thread
qltysh[bot] marked this conversation as resolved.
setUpSidebarDrag()
setUpDropdownButtonOpen()
})
Expand All @@ -34,7 +31,7 @@ document.addEventListener('DOMContentLoaded', () => {
setUpDropdownButtonClose()
setUpPreviewButton()

jQuery1('#tab-content').trigger('cms-template:init')
$('#tab-content').trigger('cms-template:init')
Comment thread
qltysh[bot] marked this conversation as resolved.
})

/**
Expand All @@ -58,7 +55,7 @@ function advanceOptionsToggle () {
/* eslint-disable @typescript-eslint/no-non-null-assertion -- It's all there */
const icon = fieldset.querySelector('legend i')!
const list = fieldset.querySelector('ol')!
const cookie = jQuery1.cookie(cookieName)!
const cookie = $.cookie(cookieName)!
Comment thread
qltysh[bot] marked this conversation as resolved.
const legend = fieldset.querySelector('legend')!
/* eslint-enable @typescript-eslint/no-non-null-assertion */

Expand All @@ -80,7 +77,7 @@ function advanceOptionsToggle () {
icon.classList.toggle('fa-caret-down')

const isNowExpanded = icon.classList.contains('fa-caret-down')
jQuery1.cookie(cookieName, String(isNowExpanded), { expires: 30, path: cookiePath })
$.cookie(cookieName, String(isNowExpanded), { expires: 30, path: cookiePath })
Comment thread
qltysh[bot] marked this conversation as resolved.
})
}

Expand Down Expand Up @@ -182,7 +179,7 @@ function setUpEditorTabs () {
* accordingly. Codemirror's own listener here: app/views/provider/admin/cms/_codemirror.html.erb
*/
function setUpContentTypeLiquidEnabledListener () {
jQuery1(document).on('change', '#cms_template_content_type, #cms_template_liquid_enabled', () => {
$(document).on('change', '#cms_template_content_type, #cms_template_liquid_enabled', () => {
Comment thread
qltysh[bot] marked this conversation as resolved.
const contentTypeInput = document.querySelector<HTMLInputElement>('#cms_template_content_type')
const liquidEnabledInput = document.querySelector<HTMLInputElement>('#cms_template_liquid_enabled')

Expand All @@ -193,17 +190,17 @@ function setUpContentTypeLiquidEnabledListener () {
const contentType = contentTypeInput.value
const liquidEnabled = liquidEnabledInput.checked

const codemirror = jQuery1('#cms_template_draft').data('codemirror') as EditorFromTextArea
const codemirror = $('#cms_template_draft').data('codemirror') as EditorFromTextArea
Comment thread
qltysh[bot] marked this conversation as resolved.

jQuery1(codemirror).trigger('change', [contentType, liquidEnabled])
$(codemirror).trigger('change', [contentType, liquidEnabled])
Comment thread
qltysh[bot] marked this conversation as resolved.
})

jQuery1(document).on('click', 'a[href^="#cms-set-content-type-"]', (event) => {
$(document).on('click', 'a[href^="#cms-set-content-type-"]', (event) => {
Comment thread
qltysh[bot] marked this conversation as resolved.
event.stopImmediatePropagation()
event.preventDefault()

const { mimeType } = (event.target as HTMLAnchorElement).dataset as { mimeType: string }
const input = jQuery1('#cms_template_content_type')
const input = $('#cms_template_content_type')
Comment thread
qltysh[bot] marked this conversation as resolved.

if (input.val() !== mimeType) {
input.val(mimeType).trigger('change')
Expand All @@ -218,8 +215,8 @@ function setUpRevertButton () {
event.stopImmediatePropagation()
event.preventDefault()

const draft = jQuery1('#cms_template_draft').data('codemirror') as EditorFromTextArea
const published = jQuery1('#cms_template_published').data('codemirror') as EditorFromTextArea
const draft = $('#cms_template_draft').data('codemirror') as EditorFromTextArea
Comment thread
qltysh[bot] marked this conversation as resolved.
const published = $('#cms_template_published').data('codemirror') as EditorFromTextArea
Comment thread
qltysh[bot] marked this conversation as resolved.

draft.setValue(published.getValue())
toast('Reverted draft to a currently published version', 'success')
Expand Down Expand Up @@ -255,9 +252,10 @@ function setUpRemoveFromSectionAction () {
* PJAX automatically extends window.$, that is 1.12.4 (JQueryStaticV1Plugins)
*/
function setUpPjax () {
jQuery1(document).pjax('#cms-sidebar .cms-sidebar-listing a', '#tab-content', { timeout: 3000 })
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Imported on top
$(document).pjax!('#cms-sidebar .cms-sidebar-listing a', '#tab-content', { timeout: 3000 })
Comment thread
qltysh[bot] marked this conversation as resolved.

jQuery1(document)
$(document)
Comment thread
qltysh[bot] marked this conversation as resolved.
.on('pjax:send', () => {
const spinner = document.createElement('img')
spinner.src = '/assets/ajax-loader.gif'
Expand All @@ -268,7 +266,7 @@ function setUpPjax () {
window.ThreeScale.hideSpinner()
})
Comment thread
qltysh[bot] marked this conversation as resolved.
.on('pjax:end', (event) => {
jQuery1(event.target).trigger('cms-template:init')
$(event.target).trigger('cms-template:init')
Comment thread
qltysh[bot] marked this conversation as resolved.
})
}

Expand Down
1 change: 0 additions & 1 deletion app/javascript/packs/cms_intro_tabs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import $ from 'jquery'
import 'jquery-ui/ui/widgets/tabs'

document.addEventListener('DOMContentLoaded', () => {
Expand Down
1 change: 0 additions & 1 deletion app/javascript/packs/fields_definitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import $ from 'jquery'
import 'jquery-ui/themes/base/core.css'
import 'jquery-ui/themes/base/sortable.css'
import 'jquery-ui/themes/base/theme.css'
Expand Down
3 changes: 1 addition & 2 deletions app/javascript/packs/master_providers_plans_widget.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import $ from 'jquery'

import type { AJAXCompleteEvent } from 'Types/rails-ujs'

Expand All @@ -9,7 +8,7 @@ import type { AJAXCompleteEvent } from 'Types/rails-ujs'
$(document).on('ajax:complete', 'form.colorbox[data-remote]', (event) => {
const [xhr] = (event.originalEvent as AJAXCompleteEvent).detail

window.$.colorbox({
window.colorbox({
open: true,
html: xhr.responseText,
maxWidth: '85%',
Expand Down
6 changes: 2 additions & 4 deletions app/javascript/packs/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import application from 'Common/application'
import 'Common/ajaxEvents'
import { setUpToasts } from 'utilities/toast'

const jQuery1 = window.$

document.addEventListener('DOMContentLoaded', () => {
renderVerticalNav()
renderQuickStarts()
Expand All @@ -19,9 +17,9 @@ document.addEventListener('DOMContentLoaded', () => {
*/
document.querySelectorAll<HTMLFormElement>('form.autosubmit')
.forEach(form => {
form.addEventListener('change', () => {
form.addEventListener('change', e => {
if (form.dataset.remote) {
void window.Rails.handleRemote.call(form, jQuery1(form))
void window.Rails.handleRemote.call(form, e)
} else {
form.submit()
}
Expand Down
2 changes: 0 additions & 2 deletions app/javascript/packs/provider_stats.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import $ from 'jquery'

import { statsUsage } from 'Stats/provider/stats_usage'
import { statsDaysOfWeek } from 'Stats/provider/stats_days_of_week'
Expand All @@ -8,7 +7,6 @@ import { statsApplication } from 'Stats/provider/stats_application'
import { statsResponseCodes } from 'Stats/provider/stats_response_codes'

document.addEventListener('DOMContentLoaded', () => {
window.$ = $
window.statsUsage = statsUsage
window.statsDaysOfWeek = statsDaysOfWeek
window.statsHoursOfDay = statsHoursOfDay
Expand Down
7 changes: 3 additions & 4 deletions app/javascript/packs/stats.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// This is Developer Portal stats

import $ from 'jquery'
// Developer Portal stats. Loaded by lib/developer_portal/app/views/developer_portal/stats/_chart.html.liquid.
// jQuery comes from the tenant's template (e.g. cdn_asset or essential_assets).
// jQuery UI datepicker is bundled by webpack via Stats/lib/menu.js and attaches to the tenant's jQuery.
Comment on lines +1 to +3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this part. Before, it always took jequey1, right? and now it will take whatever the admin added to the template. So we moved from a fixed value to a dynamic value in the hands of the admin. IS this not a breaking change? Don't you think we have templates in SaaS which doesn't load Jquery or load a different version?


import { statsApplication } from 'Stats/buyer/stats_application'

window.$ = $
window.Stats = { statsApplication }
4 changes: 1 addition & 3 deletions app/javascript/src/Common/ajaxEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* Origin: app/assets/javascripts/ajax_events.js
*/

import $ from 'jquery'

import type { AJAXErrorEvent } from 'Types/rails-ujs'

/**
Expand Down Expand Up @@ -44,7 +42,7 @@ $(document).on('ajax:error', 'form[data-remote]:not(.pf-c-form)', (event) => {

// If EventTarget (modal's content) is replaced immediately, ajax:success and ajax:complete are not called and the spinner will stay
setTimeout(() => {
window.$.colorbox({ html: xhr.responseText })
window.colorbox({ html: xhr.responseText })
})
event.stopPropagation()
})
9 changes: 3 additions & 6 deletions app/javascript/src/Common/application.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import $ from 'jquery'

const jQuery1 = window.$

export default function (): void {
// disable links with 'data-disabled' attribute and display alert instead
// delegation on body fires before rails.js. FIXME: this is not a valid guard. If "data-disabled"
Expand All @@ -16,14 +12,15 @@ export default function (): void {
// TODO: replace .fancybox with .colorbox
// This link will load its content into a colorbox modal
$(document).on('click', 'a.fancybox, a.colorbox', (e) => {
jQuery1(e.currentTarget as HTMLAnchorElement).colorbox({ open: true })
const { title, href } = e.currentTarget as HTMLAnchorElement
Comment thread
qltysh[bot] marked this conversation as resolved.
window.colorbox({ title, href })
e.preventDefault()
})

// TODO: replace .fancybox with .colorbox
// This is used in some modals with a "Cancel" button.
$(document).on('click', '.fancybox-close', (e) => {
jQuery1.colorbox.close()
window.colorbox.close()
e.preventDefault()
e.stopPropagation()
})
Expand Down
6 changes: 2 additions & 4 deletions app/javascript/src/Common/components/BulkActionsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ interface Props {
isDisabled: boolean;
}

const jquery1 = window.$

const BulkActionsDropdown: FunctionComponent<Props> = ({ actions, allSelected, isDisabled }) => {
const [actionsDropdownOpen, setActionsDropdownOpen] = useState(false)

Expand All @@ -34,15 +32,15 @@ const BulkActionsDropdown: FunctionComponent<Props> = ({ actions, allSelected, i
return url.concat(connector, 'selected_total_entries=true')
} else {
// TODO: can we generate this data without reading the DOM? Using selectedItems as a prop
return url.concat(connector, jquery1('table tbody .pf-c-table__check input:checked').serialize())
return url.concat(connector, $('table tbody .pf-c-table__check input:checked').serialize())
Comment thread
qltysh[bot] marked this conversation as resolved.
}
}

const dropdownItems = actions.map(({ name, title, url }) => (
<DropdownItem
key={name}
onClick={() => {
jquery1.colorbox({
window.colorbox({
title,
href: generateHrefForColorbox(url)
})
Expand Down
1 change: 0 additions & 1 deletion app/javascript/src/Common/threescale.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import $ from 'jquery'

import { render } from 'Dashboard/chart'
import { toast, hideToast } from 'utilities/toast'
Expand Down
Loading