Explorar o código

forceClassName

Adam Shaw %!s(int64=7) %!d(string=hai) anos
pai
achega
f414227efe
Modificáronse 3 ficheiros con 17 adicións e 4 borrados
  1. 3 3
      src/Calendar.ts
  2. 2 1
      src/exports.ts
  3. 12 0
      src/util/dom-manip.ts

+ 3 - 3
src/Calendar.ts

@@ -1,5 +1,5 @@
 import * as moment from 'moment'
-import { createElement, removeElement, applyStyle, prependToElement } from './util/dom-manip'
+import { createElement, removeElement, applyStyle, prependToElement, forceClassName } from './util/dom-manip'
 import { computeHeightAndMargins } from './util/dom-geom'
 import { listenBySelector } from './util/dom-event'
 import { capitaliseFirstLetter, debounce } from './util/misc'
@@ -386,8 +386,8 @@ export default class Calendar {
     // called immediately, and upon option change.
     // HACK: locale often affects isRTL, so we explicitly listen to that too.
     this.optionsManager.watch('applyingDirClasses', [ '?isRTL', '?locale' ], (opts) => {
-      el.classList.toggle('fc-ltr', !opts.isRTL)
-      el.classList.toggle('fc-rtl', opts.isRTL)
+      forceClassName(el, 'fc-ltr', !opts.isRTL)
+      forceClassName(el, 'fc-rtl', opts.isRTL)
     })
 
     prependToElement(el, this.contentEl = createElement('div', { className: 'fc-view-container' }))

+ 2 - 1
src/exports.ts

@@ -62,7 +62,8 @@ export {
   appendToElement,
   applyStyle,
   applyStyleProp,
-  elementMatches
+  elementMatches,
+  forceClassName
 } from './util/dom-manip'
 
 export {

+ 12 - 0
src/util/dom-manip.ts

@@ -187,6 +187,18 @@ export function findChildren(parent: HTMLElement[] | HTMLElement, selector?: str
 }
 
 
+// Attributes
+// ----------------------------------------------------------------------------------------------------------------
+
+export function forceClassName(el: HTMLElement, className: string, bool) {
+  if (bool) {
+    el.classList.add(className)
+  } else {
+    el.classList.remove(className)
+  }
+}
+
+
 // Style
 // ----------------------------------------------------------------------------------------------------------------