-
Notifications
You must be signed in to change notification settings - Fork 73
Upgrade Developer portal's default template to jQuery 3.7.1 #4348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
60ae2b5
bd1e639
6c23dec
b96b669
7dd9215
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| //= require jquery | ||
| //= require jquery3 | ||
| //= require rails-ujs |
| 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 |
| 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); |
| 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' | ||
|
|
@@ -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()) | ||
|
|
||
| const selectTotalEntries = findSelectTotalEntries() | ||
| if (selectTotalEntries?.hasAttribute(dataSelectedTotal)) { | ||
|
|
@@ -69,7 +68,7 @@ document.addEventListener('DOMContentLoaded', () => { | |
| } | ||
|
|
||
| function updateBulkOperationsCard () { | ||
| const bulk = jquery1('#bulk-operations') | ||
| const bulk = $('#bulk-operations') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const selected = selectedRows() | ||
|
|
||
| if (selected > 0) { | ||
|
|
@@ -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!) | ||
| }) | ||
|
|
||
| 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' | ||
|
|
@@ -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', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 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') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }) | ||
|
|
||
| jQuery1(document).on('cms-sidebar:update', () => { | ||
| $(document).on('cms-sidebar:update', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| setUpSidebarDrag() | ||
| setUpDropdownButtonOpen() | ||
| }) | ||
|
|
@@ -34,7 +31,7 @@ document.addEventListener('DOMContentLoaded', () => { | |
| setUpDropdownButtonClose() | ||
| setUpPreviewButton() | ||
|
|
||
| jQuery1('#tab-content').trigger('cms-template:init') | ||
| $('#tab-content').trigger('cms-template:init') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }) | ||
|
|
||
| /** | ||
|
|
@@ -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)! | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const legend = fieldset.querySelector('legend')! | ||
| /* eslint-enable @typescript-eslint/no-non-null-assertion */ | ||
|
|
||
|
|
@@ -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 }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }) | ||
| } | ||
|
|
||
|
|
@@ -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', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const contentTypeInput = document.querySelector<HTMLInputElement>('#cms_template_content_type') | ||
| const liquidEnabledInput = document.querySelector<HTMLInputElement>('#cms_template_liquid_enabled') | ||
|
|
||
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found 4 issues: |
||
|
|
||
| jQuery1(codemirror).trigger('change', [contentType, liquidEnabled]) | ||
| $(codemirror).trigger('change', [contentType, liquidEnabled]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }) | ||
|
|
||
| jQuery1(document).on('click', 'a[href^="#cms-set-content-type-"]', (event) => { | ||
| $(document).on('click', 'a[href^="#cms-set-content-type-"]', (event) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 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') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| if (input.val() !== mimeType) { | ||
| input.val(mimeType).trigger('change') | ||
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found 4 issues: |
||
| const published = $('#cms_template_published').data('codemirror') as EditorFromTextArea | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found 4 issues: |
||
|
|
||
| draft.setValue(published.getValue()) | ||
| toast('Reverted draft to a currently published version', 'success') | ||
|
|
@@ -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 }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| jQuery1(document) | ||
| $(document) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| .on('pjax:send', () => { | ||
| const spinner = document.createElement('img') | ||
| spinner.src = '/assets/ajax-loader.gif' | ||
|
|
@@ -268,7 +266,7 @@ function setUpPjax () { | |
| window.ThreeScale.hideSpinner() | ||
| }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| .on('pjax:end', (event) => { | ||
| jQuery1(event.target).trigger('cms-template:init') | ||
| $(event.target).trigger('cms-template:init') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found 4 issues: |
||
| }) | ||
| } | ||
|
|
||
|
|
||
| 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', () => { | ||
|
|
||
| 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. | ||
|
|
||
| import { statsApplication } from 'Stats/buyer/stats_application' | ||
|
|
||
| window.$ = $ | ||
| window.Stats = { statsApplication } |
| 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" | ||
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 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() | ||
| }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,6 @@ interface Props { | |
| isDisabled: boolean; | ||
| } | ||
|
|
||
| const jquery1 = window.$ | ||
|
|
||
| const BulkActionsDropdown: FunctionComponent<Props> = ({ actions, allSelected, isDisabled }) => { | ||
| const [actionsDropdownOpen, setActionsDropdownOpen] = useState(false) | ||
|
|
||
|
|
@@ -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()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found 4 issues: |
||
| } | ||
| } | ||
|
|
||
| const dropdownItems = actions.map(({ name, title, url }) => ( | ||
| <DropdownItem | ||
| key={name} | ||
| onClick={() => { | ||
| jquery1.colorbox({ | ||
| window.colorbox({ | ||
| title, | ||
| href: generateHrefForColorbox(url) | ||
| }) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found 4 issues:
1. Unsafe argument of type
anyassigned to a parameter of typestring. [eslint:@typescript-eslint/no-unsafe-argument]2. Unsafe call of an
anytyped value. [eslint:@typescript-eslint/no-unsafe-call]3. Unsafe call of an
anytyped value. [eslint:@typescript-eslint/no-unsafe-call]4. Unsafe member access .serialize on an
anyvalue. [eslint:@typescript-eslint/no-unsafe-member-access]