瀏覽代碼

remove jquery plugin initialization from dist script

Adam Shaw 7 年之前
父節點
當前提交
d7b42455bd
共有 6 個文件被更改,包括 52 次插入63 次删除
  1. 3 0
      karma.config.js
  2. 1 1
      locale/_reset.js
  3. 2 10
      package-lock.json
  4. 1 1
      package.json
  5. 0 51
      src/main.ts
  6. 45 0
      tests/automated/lib/fullcalendar-jquery-plugin.js

+ 3 - 0
karma.config.js

@@ -27,6 +27,9 @@ module.exports = function(config) {
       'dist/gcal.js',
       'dist/locale-all.js',
 
+      // temporary. needs to go first.
+      'tests/automated/lib/fullcalendar-jquery-plugin.js',
+
       // a way to dump variables into the test environment
       'tmp/automated-test-config.js',
 

+ 1 - 1
locale/_reset.js

@@ -4,6 +4,6 @@ import * as FullCalendar from 'fullcalendar';
 moment.locale('en');
 FullCalendar.locale('en');
 
-if (window.jQuery.datepicker) {
+if (window.jQuery && window.jQuery.datepicker) {
   window.jQuery.datepicker.setDefaults(window.jQuery.datepicker.regional['']);
 }

+ 2 - 10
package-lock.json

@@ -5793,16 +5793,8 @@
     "jquery": {
       "version": "3.3.1",
       "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz",
-      "integrity": "sha1-lYzinoHJeQ8xvneS311NlfxX+8o="
-    },
-    "jquery-mockjax": {
-      "version": "2.3.0",
-      "resolved": "https://registry.npmjs.org/jquery-mockjax/-/jquery-mockjax-2.3.0.tgz",
-      "integrity": "sha1-5V62VibUS/NbOZDcVu+UpkxrXB8=",
-      "dev": true,
-      "requires": {
-        "jquery": "3.3.1"
-      }
+      "integrity": "sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg==",
+      "dev": true
     },
     "jquery-simulate": {
       "version": "github:jquery/jquery-simulate#665801cf93f25336efcaa10327a28fb623ca4e86",

+ 1 - 1
package.json

@@ -22,7 +22,6 @@
   },
   "copyright": "2018 Adam Shaw",
   "dependencies": {
-    "jquery": "2 - 3",
     "moment": "^2.20.1",
     "reqwest": "^2.0.5"
   },
@@ -59,6 +58,7 @@
     "jasmine-core": "2.5.2",
     "jasmine-fixture": "^2.0.0",
     "jasmine-jquery": "^2.1.1",
+    "jquery": "^3.3.1",
     "jquery-simulate": "github:jquery/jquery-simulate",
     "karma": "^0.13.22",
     "karma-jasmine": "^1.0.2",

+ 0 - 51
src/main.ts

@@ -1,7 +1,4 @@
-import * as $ from 'jquery'
 import * as exportHooks from './exports'
-import { warn } from './util/misc'
-import Calendar from './Calendar'
 
 // for intentional side-effects
 import './moment-ext'
@@ -13,52 +10,4 @@ import './agenda/config'
 import './list/config'
 import './types/jquery-hooks'
 
-
-($ as any).fullCalendar = exportHooks
 export = exportHooks
-
-
-$.fn.fullCalendar = function(options?): (JQuery | any) {
-  let args = Array.prototype.slice.call(arguments, 1) // for a possible method call
-  let res = this // what this function will return (this jQuery object by default)
-
-  this.each(function(i, el) { // loop each DOM element involved
-    let $el = $(el)
-    let calendar = $el.data('fullCalendar') // get the existing calendar object (if any)
-    let singleRes // the returned value of this single method call
-
-    // a method call
-    if (typeof options === 'string') {
-
-      if (options === 'getCalendar') {
-        if (!i) { // first element only
-          res = calendar
-        }
-      } else if (options === 'destroy') { // don't warn if no calendar object
-        if (calendar) {
-          calendar.destroy()
-          $el.removeData('fullCalendar')
-        }
-      } else if (!calendar) {
-        warn('Attempting to call a FullCalendar method on an element with no calendar.')
-      } else if (typeof calendar[options] === 'function') {
-        singleRes = calendar[options].apply(calendar, args)
-
-        if (!i) {
-          res = singleRes // record the first method call result
-        }
-        if (options === 'destroy') { // for the destroy method, must remove Calendar object data
-          $el.removeData('fullCalendar')
-        }
-      } else {
-        warn("'" + options + "' is an unknown FullCalendar method.")
-      }
-    } else if (!calendar) { // don't initialize twice
-      calendar = new Calendar(el, options)
-      $el.data('fullCalendar', calendar)
-      calendar.render()
-    }
-  })
-
-  return res
-}

+ 45 - 0
tests/automated/lib/fullcalendar-jquery-plugin.js

@@ -0,0 +1,45 @@
+
+$.fn.fullCalendar = function(options) {
+  let args = Array.prototype.slice.call(arguments, 1) // for a possible method call
+  let res = this // what this function will return (this jQuery object by default)
+
+  this.each(function(i, el) { // loop each DOM element involved
+    let $el = $(el)
+    let calendar = $el.data('fullCalendar') // get the existing calendar object (if any)
+    let singleRes // the returned value of this single method call
+
+    // a method call
+    if (typeof options === 'string') {
+
+      if (options === 'getCalendar') {
+        if (!i) { // first element only
+          res = calendar
+        }
+      } else if (options === 'destroy') { // don't warn if no calendar object
+        if (calendar) {
+          calendar.destroy()
+          $el.removeData('fullCalendar')
+        }
+      } else if (!calendar) {
+        FullCalendar.warn('Attempting to call a FullCalendar method on an element with no calendar.')
+      } else if (typeof calendar[options] === 'function') {
+        singleRes = calendar[options].apply(calendar, args)
+
+        if (!i) {
+          res = singleRes // record the first method call result
+        }
+        if (options === 'destroy') { // for the destroy method, must remove Calendar object data
+          $el.removeData('fullCalendar')
+        }
+      } else {
+        FullCalendar.warn("'" + options + "' is an unknown FullCalendar method.")
+      }
+    } else if (!calendar) { // don't initialize twice
+      calendar = new FullCalendar.Calendar(el, options)
+      $el.data('fullCalendar', calendar)
+      calendar.render()
+    }
+  })
+
+  return res
+}