当前位置

网站首页> 程序设计 > 开源项目 > 程序开发 > 浏览文章

check window.jQuery in requirejs

作者:小梦 来源: 网络 时间: 2024-04-05 阅读:

http://pastebin.com/r23ceraC

require.config({  paths: {    // jquery here is needed only if window.jQuery is undefined    'jquery': '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min'  }});       require.config({  paths: {    'jquery': {       uri: '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min',       // if this function returns false or undefined load the script from the url       define: function(){ return window.jQuery; }    }  }});       require.config({  paths: {    // jquery here is needed only if window.jQuery is undefined    'jquery':'//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min',    'lodash':'//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.0.0/lodash.underscore.min',    'backbone':'//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min'  },  shim:{    'jquery':{      // with my fix now I detect whether window.jQuery has been already defined      // in this case I avoid to load the script from the cdn      exports:'jQuery',      // if this feature is missing I need to load the new jQuery from the cdn      validate: function(){        return  window.jQuery.Defferred;      }    },    'lodash':{      // lodash will be loaded only if it does not exist in the DOM      exports:'_',      // if this function returns false or undefined load the script from the cdn      validate: function() {        // is the lodash version already available in the DOM new enough for my application?        return  window.parseInt(window._.VERSION) >= 2;      }    },    'backbone':{      deps:['lodash','jquery'],      // if backbone exists we don't need to load it twice      exports:'Backbone'    }  }});       require.config({  paths: {    jquery: {      toString: function () {        return window.jQuery ?          // fake a require inline          'data:application/javascript,define("jquery",function(){return(window.jQuery)});this' :          // pass through the CDN          '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min'      }    }  }});       require(['jquery'], function($){  alert($);});       define('jquery', [], function() { /* stuff */ });//        ^ Module 'jquery' is defined here. Require.js won't load it twice.

相关阅读

热点阅读

网友最爱