Vlad Kurkin (b_vladi) wrote in changelog,
Vlad Kurkin
b_vladi
changelog

[livejournal] r21571: LJSUP-11658: Add HTTP header for CDN

Committer: vkurkin
LJSUP-11658: Add HTTP header for CDN
U   trunk/cgi-bin/LJ/Widget/EntryForm.pm
A   trunk/htdocs/js/jquery/jquery.xdomainrequest.js
U   trunk/htdocs/js/rte.js
Modified: trunk/cgi-bin/LJ/Widget/EntryForm.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/EntryForm.pm	2012-03-28 09:28:36 UTC (rev 21570)
+++ trunk/cgi-bin/LJ/Widget/EntryForm.pm	2012-03-28 11:27:08 UTC (rev 21571)
@@ -175,6 +175,7 @@
         js/ck/ckeditor.js
         js/rte.js
         js/jquery/jquery.lj.basicWidget.js
+        js/jquery/jquery.xdomainrequest.js
         js/jquery/jquery.lj.trava.js
         js/jquery/jquery.lj.modalWindow.js
         js/jquery/jquery.lj.entryDatePicker.js

Added: trunk/htdocs/js/jquery/jquery.xdomainrequest.js
===================================================================
--- trunk/htdocs/js/jquery/jquery.xdomainrequest.js	                        (rev 0)
+++ trunk/htdocs/js/jquery/jquery.xdomainrequest.js	2012-03-28 11:27:08 UTC (rev 21571)
@@ -0,0 +1,80 @@
+// jQuery.XDomainRequest.js
+// IE8+
+if (!jQuery.support.cors && window.XDomainRequest) {
+	var httpRegEx = /^https?:\/\//i;
+	var getOrPostRegEx = /^GET|POST$/i;
+	var sameSchemeRegEx = new RegExp('^' + location.protocol, 'i');
+	var xmlRegEx = /\/xml/i;
+
+	// ajaxTransport exists in jQuery 1.5+
+	jQuery.ajaxTransport('text html xml json', function(options, userOptions, jqXHR) {
+		// XDomainRequests must be: asynchronous, GET or POST methods, HTTP or HTTPS protocol, and same scheme as calling page
+		if (options.crossDomain && options.async && getOrPostRegEx.test(options.type) && httpRegEx.test(userOptions.url) && sameSchemeRegEx.test(userOptions.url)) {
+			var xdr = null;
+			var userType = (userOptions.dataType || '').toLowerCase();
+
+			return {
+				send: function(headers, complete) {
+					xdr = new XDomainRequest();
+					if (/^\d+$/.test(userOptions.timeout)) {
+						xdr.timeout = userOptions.timeout;
+					}
+					xdr.ontimeout = function() {
+						complete(500, 'timeout');
+					};
+					xdr.onload = function() {
+						var allResponseHeaders = 'Content-Length: ' + xdr.responseText.length + '\r\nContent-Type: ' + xdr.contentType;
+						var status = {
+							code: 200,
+							message: 'success'
+						};
+						var responses = {
+							text: xdr.responseText
+						};
+						try {
+							if (userType === 'json') {
+								try {
+									responses.json = JSON.parse(xdr.responseText);
+								} catch(e) {
+									status.code = 500;
+									status.message = 'parseerror';
+									throw 'Invalid JSON: ' + xdr.responseText;
+								}
+							} else if ((userType === 'xml') || ((userType !== 'text') && xmlRegEx.test(xdr.contentType))) {
+								var doc = new ActiveXObject('Microsoft.XMLDOM');
+								doc.async = false;
+								try {
+									doc.loadXML(xdr.responseText);
+								} catch(e) {
+									doc = undefined;
+								}
+								if (!doc || !doc.documentElement || doc.getElementsByTagName('parsererror').length) {
+									status.code = 500;
+									status.message = 'parseerror';
+									throw 'Invalid XML: ' + xdr.responseText;
+								}
+								responses.xml = doc;
+							}
+						} catch(parseMessage) {
+							throw parseMessage;
+						} finally {
+							complete(status.code, status.message, responses, allResponseHeaders);
+						}
+					};
+					xdr.onerror = function() {
+						complete(500, 'error', {
+							text: xdr.responseText
+						});
+					};
+					xdr.open(options.type, options.url);
+					xdr.send();
+				},
+				abort: function() {
+					if (xdr) {
+						xdr.abort();
+					}
+				}
+			};
+		}
+	});
+}
\ No newline at end of file

Modified: trunk/htdocs/js/rte.js
===================================================================
--- trunk/htdocs/js/rte.js	2012-03-28 09:28:36 UTC (rev 21570)
+++ trunk/htdocs/js/rte.js	2012-03-28 11:27:08 UTC (rev 21571)
@@ -113,6 +113,7 @@
 				$.ajax({
 					url: statPrefix + '/ck/contents.css?t=' + Site.version,
 					cache: true,
+					dataType: 'text',
 					success: function (data) {
 						CKEDITOR.styleText = data;
 					}

Tags: b_vladi, js, livejournal, pm, vkurkin
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments