Created
February 29, 2012 21:12
-
-
Save jasonferrier/1944396 to your computer and use it in GitHub Desktop.
jQuery noConflict in *different namespace* in order to continue using one or more jQuery versions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Jquery for fancy things!--> | |
<script language="JavaScript" src="/js/public/jquery-latest.min.js" type="text/javascript"></script> | |
<script> | |
// to make fancy buttons. Uses noConflict just in case | |
var $jQ = jQuery.noConflict(); | |
// Use jQuery via $j(...) | |
$jQ(document).ready(function(){ | |
$jQ("#mktFrmSubmit").wrap("<div class='buttonSubmit'></div>"); | |
$jQ(".buttonSubmit").prepend("<span></span>"); | |
}); | |
</script> | |
<!-- HERE IS THE JQUERY I WANT TO USE. THE ABOVE IS REQUIRED FOR OTHER STUFF NOT OWNED BY ME --> | |
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> | |
<script type="text/javascript"> | |
//Completely move jQuery to a new namespace in another object. | |
var dom = {}; | |
dom.query = jQuery.noConflict(true); | |
/*! | |
* jQuery Cookie Plugin | |
* https://github.com/carhartl/jquery-cookie | |
* | |
* Copyright 2011, Klaus Hartl | |
* Dual licensed under the MIT or GPL Version 2 licenses. | |
* http://www.opensource.org/licenses/mit-license.php | |
* http://www.opensource.org/licenses/GPL-2.0 | |
*/ | |
(function(a){a.cookie=function(g,f,k){if(arguments.length>1&&(!/Object/.test(Object.prototype.toString.call(f))||f===null||f===undefined)){k=a.extend({},k);if(f===null||f===undefined){k.expires=-1}if(typeof k.expires==="number"){var h=k.expires,j=k.expires=new Date();j.setDate(j.getDate()+h)}f=String(f);return(document.cookie=[encodeURIComponent(g),"=",k.raw?f:encodeURIComponent(f),k.expires?"; expires="+k.expires.toUTCString():"",k.path?"; path="+k.path:"",k.domain?"; domain="+k.domain:"",k.secure?"; secure":""].join(""))}k=f||{};var b=k.raw?function(i){return i}:decodeURIComponent;var c=document.cookie.split("; ");for(var e=0,d;d=c[e]&&c[e].split("=");e++){if(b(d[0])===g){return b(d[1]||"")}}return null}})(dom.query); | |
// Take the assigned value created on the main purestorage.com site for last referrer | |
// and create a hidden field on the form in order to submit the data to Marketo | |
dom.query(document).ready(function() { | |
var referrer = dom.query.cookie('referrer'); | |
if (null == referrer) | |
{ | |
referrer = "None"; | |
} | |
// Add on the hidden form field IF IT DOES NOT EXIST | |
if (null == dom.query('#last_referrer__c').val()) | |
{ | |
dom.query('form').append('<input type="hidden" name="last_referrer__c" id="last_referrer__c" value="' + referrer + '">'); | |
} | |
else | |
{ | |
dom.query('#last_referrer__c').val(referrer); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment