Created
August 1, 2013 18:48
-
-
Save onestepcreative/6134095 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // =================================================================== | |
| // === FUNCTION TO SUPPORT CROSS-DOMAIN AJAX REQUESTS FOR CAT TREE === | |
| // =================================================================== | |
| jQuery.ajax = (function(_ajax){ | |
| var protocol = location.protocol, | |
| hostname = location.hostname, | |
| exRegex = RegExp(protocol + '//' + hostname), | |
| YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?', | |
| query = 'select * from html where url="{URL}" and xpath="*" and compat="html5"'; | |
| function isExternal(url) { | |
| return !exRegex.test(url) && /:\/\//.test(url); | |
| } | |
| return function(o) { | |
| var url = o.url; | |
| if (/get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url)) { | |
| o.url = YQL; | |
| o.dataType = 'json'; | |
| o.data = { q: query.replace('{URL}', url + (o.data ? (/\?/.test(url) ? '&' : '?') + jQuery.param(o.data) : '')), format: 'xml' }; | |
| if (!o.success && o.complete) { | |
| o.success = o.complete; | |
| delete o.complete; | |
| } | |
| o.success = (function(_success) { | |
| return function(data) { | |
| if(_success) { | |
| // FAKE XHR CALLBACK | |
| _success.call(this, { | |
| responseText: (data.results[0] || '').replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '') | |
| }, 'success'); | |
| } | |
| }; | |
| })(o.success); | |
| } | |
| return _ajax.apply(this, arguments); | |
| }; | |
| })(jQuery.ajax); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment