1/*! 2 * @version $Id: roksprocket.request.js 10889 2013-05-30 07:48:35Z btowles $ 3 * @author RocketTheme http://www.rockettheme.com 4 * @copyright Copyright (C) 2007 - 2020 RocketTheme, LLC 5 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only 6 */ 7((function(){ 8 9 if (typeof this.RokSprocket == 'undefined') this.RokSprocket = {}; 10 else Object.merge(this.RokSprocket, {Request: null}); 11 12var defined = function(value){ 13 return value != null; 14}; 15 16var hasOwnProperty = Object.prototype.hasOwnProperty; 17 18Object.extend({ 19 20 getFromPath: function(source, parts){ 21 if (typeof parts == 'string') parts = parts.split('.'); 22 for (var i = 0, l = parts.length; i < l; i++){ 23 if (hasOwnProperty.call(source, parts[i])) source = source[parts[i]]; 24 else return null; 25 } 26 return source; 27 }, 28 29 cleanValues: function(object, method){ 30 method = method || defined; 31 for (var key in object) if (!method(object[key])){ 32 delete object[key]; 33 } 34 return object; 35 }, 36 37 erase: function(object, key){ 38 if (hasOwnProperty.call(object, key)) delete object[key]; 39 return object; 40 }, 41 42 run: function(object){ 43 var args = Array.slice(arguments, 1); 44 for (var key in object) if (object[key].apply){ 45 object[key].apply(object, args); 46 } 47 return object; 48 } 49 50}); 51 52var empty = function(){}, 53 progressSupport = ('onprogress' in new Browser.Request()), 54 Request = new Class({ 55 Extends: this.Request, 56 57 options: { 58 method: 'post', 59 model: '', 60 model_action: '', 61 params: {} 62 }, 63 64 initialize: function(options){ 65 this.options.url = RokSprocket.AjaxURL.replace(/&/g, '&'); 66 67 this.parent(options); 68 }, 69 70 processScripts: function(text){ 71 return text; 72 }, 73 74 onStateChange: function(){ 75 var xhr = this.xhr; 76 if (xhr.readyState != 4 || !this.running) return; 77 this.running = false; 78 this.status = 0; 79 Function.attempt(function(){ 80 var status = xhr.status; 81 this.status = (status == 1223) ? 204 : status; 82 }.bind(this)); 83 xhr.onreadystatechange = empty; 84 if (progressSupport) xhr.onprogress = xhr.onloadstart = empty; 85 clearTimeout(this.timer); 86 87 this.response = new Response(this.xhr.responseText || '', {onError: this.onResponseError.bind(this)}); 88 if (this.options.isSuccess.call(this, this.status)){ 89 if (this.response.getPath('status') == 'success') this.success(this.response); 90 else this.onResponseError(this.response); 91 } else { 92 this.failure(); 93 this.onResponseError(this.response); 94 } 95 }, 96 97 onResponseError: function(xhr){ 98 var d = this.options.data, 99 message = 'RokSprocket Error [model: '+d.model+', model_action: '+d.model_action+', params: '+d.params+']: '; 100 message += (xhr.status ? xhr.status + ' - ' + xhr.statusText : xhr); 101 this.fireEvent('onResponseError', xhr, message); 102 throw new Error(message); 103 }, 104 105 setParams: function(params){ 106 var data = Object.merge(this.options.data || {}, {params: params || {}}); 107 108 data.params = JSON.encode(data.params); 109 this.options.data = data; 110 111 ['model', 'model_action'].each(function(type){ 112 this.options.data[type] = this.options[type]; 113 }, this); 114 115 return this; 116 } 117 }); 118 119 120 var Response = new Class({ 121 122 Implements: [Options, Events], 123 124 options:{ 125 /* 126 onParse: function(data){}, 127 onSuccess: function(data){}, 128 onError: function(data){} 129 */ 130 }, 131 132 initialize: function(data, options){ 133 this.setOptions(options); 134 this.setData(data); 135 136 return this; 137 }, 138 139 setData: function(data){ 140 if (typeOf(data) == 'string') data = data.trim(); 141 142 this.data = data; 143 }, 144 145 getData: function(){ 146 return (typeOf(this.data) != 'object') ? this.parseData(this.data) : this.data; 147 }, 148 149 parseData: function(){ 150 if (!JSON.validate(this.data)) return this.error('Invalid JSON data <hr /> ' + this.data); 151 152 this.data = JSON.decode(this.data); 153 154 if (this.data.status != 'success') return this.error(this.data.message); 155 156 this.fireEvent('parse', this.data); 157 158 return this.success(this.data); 159 160 }, 161 162 getPath: function(path){ 163 var data = this.getData(); 164 165 if (typeOf(data) == 'object') return Object.getFromPath(data, path || ''); 166 else return null; 167 }, 168 169 success: function(data){ 170 this.data = data; 171 172 this.fireEvent('success', this.data); 173 return this.data; 174 }, 175 176 error: function(message){ 177 this.data = message; 178 179 this.fireEvent('error', this.data); 180 return this.data; 181 } 182 183 }); 184 185 this.RokSprocket.Request = Request; 186 187})());
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.