PageSourceSearch

https://daewoo.com.pk/refunds/assets/js/ace/ace.ajax-content.js

js daewoo.com.pk collected 2026-09-24 22:28:34 UTC 11,785 bytes, 381 lines download raw bytes

1/**
2 <b>Load content via Ajax </b>. For more information please refer to documentation #basics/ajax
3*/
4
5(function($ , undefined) {
6	var ajax_loaded_scripts = {}
7
8	function AceAjax(contentArea, settings) {
9		var $contentArea = $(contentArea);
10		var self = this;
11		$contentArea.attr('data-ajax-content', 'true');
12
13		//get a list of 'data-*' attributes that override 'defaults' and 'settings'
14		var attrib_values = ace.helper.getAttrSettings(contentArea, $.fn.ace_ajax.defaults);
15		this.settings = $.extend({}, $.fn.ace_ajax.defaults, settings, attrib_values);
16
17		var working = false;
18		var $overlay = $();//empty set
19
20		this.force_reload = false;//set jQuery ajax's cache option to 'false' to reload content
21		this.loadUrl = function(hash, cache) {
22			var url = false;
23			hash = hash.replace(/^(\#\!)?\#/, '');
24
25			this.force_reload = (cache === false)
26
27			if(typeof this.settings.content_url === 'function') url = this.settings.content_url(hash);
28			if(typeof url === 'string') this.getUrl(url, hash, false);
29		}
30
31		this.loadAddr = function(url, hash, cache) {
32			this.force_reload = (cache === false);
33			this.getUrl(url, hash, false);
34		}
35
36		this.getUrl = function(url, hash, manual_trigger) {
37			if(working) {
38				return;
39			}
40
41			var event
42			$contentArea.trigger(event = $.Event('ajaxloadstart'), {url: url, hash: hash})
43			if (event.isDefaultPrevented()) return;
44
45			self.startLoading();
46
47			$.ajax({
48				'url': url,
49				'cache': !this.force_reload
50			})
51			.error(function() {
52				$contentArea.trigger('ajaxloaderror', {url: url, hash: hash});
53
54				self.stopLoading(true);
55			})
56			.done(function(result) {
57				$contentArea.trigger('ajaxloaddone', {url: url, hash: hash});
58
59				var link_element = null, link_text = '';;
60				if(typeof self.settings.update_active === 'function') {
61					link_element = self.settings.update_active.call(null, hash, url);
62				}
63				else if(self.settings.update_active === true && hash) {
64					link_element = $('a[data-url="'+hash+'"]');
65					if(link_element.length > 0) {
66						var nav = link_element.closest('.nav');
67						if(nav.length > 0) {
68							nav.find('.active').each(function(){
69								var $class = 'active';
70								if( $(this).hasClass('hover') || self.settings.close_active ) $class += ' open';
71
72								$(this).removeClass($class);
73								if(self.settings.close_active) {
74									$(this).find(' > .submenu').css('display', '');
75								}
76							})
77
78							var active_li = link_element.closest('li').addClass('active').parents('.nav li').addClass('active open');
79							nav.closest('.sidebar[data-sidebar-scroll=true]').each(function() {
80								var $this = $(this);
81								$this.ace_sidebar_scroll('reset');
82								if(manual_trigger) $this.ace_sidebar_scroll('scroll_to_active');//first time only
83							})
84						}
85					}
86				}
87
88				/////////
89				if(typeof self.settings.update_breadcrumbs === 'function') {
90					link_text = self.settings.update_breadcrumbs.call(null, hash, url, link_element);
91				}
92				else if(self.settings.update_breadcrumbs === true && link_element != null && link_element.length > 0) {
93					link_text = updateBreadcrumbs(link_element);
94				}
95				/////////
96
97				//convert "title" and "link" tags to "div" tags for later processing
98				result = String(result)
99					.replace(/<(title|link)([\s\>])/gi,'<div class="hidden ajax-append-$1"$2')
100					.replace(/<\/(title|link)\>/gi,'</div>')
101
102				$overlay.addClass('content-loaded').detach();
103				$contentArea.empty().html(result);
104
105				$(self.settings.loading_overlay || $contentArea).append($overlay);
106
107				//remove previous stylesheets inserted via ajax
108				setTimeout(function() {
109					$('head').find('link.ace-ajax-stylesheet').remove();
110
111					var main_selectors = ['link.ace-main-stylesheet', 'link#main-ace-style', 'link[href*="/ace.min.css"]', 'link[href*="/ace.css"]']
112					var ace_style = [];
113					for(var m = 0; m < main_selectors.length; m++) {
114						ace_style = $('head').find(main_selectors[m]).first();
115						if(ace_style.length > 0) break;
116					}
117
118					$contentArea.find('.ajax-append-link').each(function(e) {
119						var $link = $(this);
120						if ( $link.attr('href') ) {
121							var new_link = jQuery('<link />', {type : 'text/css', rel: 'stylesheet', 'class': 'ace-ajax-stylesheet'})
122							if( ace_style.length > 0 ) new_link.insertBefore(ace_style);
123							else new_link.appendTo('head');
124							new_link.attr('href', $link.attr('href'));//we set "href" after insertion, for IE to work
125						}
126						$link.remove();
127					})
128				}, 10);
129
130				//////////////////////
131
132				if(typeof self.settings.update_title === 'function') {
133					self.settings.update_title.call(null, hash, url, link_text);
134				}
135				else if(self.settings.update_title === true) {
136					updateTitle(link_text);
137				}
138
139				if( !manual_trigger ) {
140					$('html,body').animate({scrollTop: 0}, 250);
141				}
142
143				//////////////////////
144				$contentArea.trigger('ajaxloadcomplete', {url: url, hash: hash});
145				//////////////////////
146
147				self.stopLoading();
148			})
149		}
150
151		///////////////////////
152		var fixPos = false;
153		var loadTimer = null;
154		this.startLoading = function() {
155			if(working) return;
156			working = true;
157
158			if(!this.settings.loading_overlay && $contentArea.css('position') == 'static') {
159				$contentArea.css('position', 'relative');//for correct icon positioning
160				fixPos = true;
161			}
162
163			$overlay.remove();
164			$overlay = $('<div class="ajax-loading-overlay"><i class="ajax-loading-icon '+(this.settings.loading_icon || '')+'"></i> '+this.settings.loading_text+'</div>')
165
166			if(this.settings.loading_overlay == 'body') $('body').append($overlay.addClass('ajax-overlay-body'));
167			else if(this.settings.loading_overlay) $(this.settings.loading_overlay).append($overlay);
168			else $contentArea.append($overlay);
169
170			if(this.settings.max_load_wait !== false)
171			 loadTimer = setTimeout(function() {
172				loadTimer = null;
173				if(!working) return;
174
175				var event
176				$contentArea.trigger(event = $.Event('ajaxloadlong'))
177				if (event.isDefaultPrevented()) return;
178
179				self.stopLoading(true);
180			 }, this.settings.max_load_wait * 1000);
181		}
182
183		this.stopLoading = function(stopNow) {
184			if(stopNow === true) {
185				working = false;
186
187				$overlay.remove();
188				if(fixPos) {
189					$contentArea.css('position', '');//restore previous 'position' value
190					fixPos = false;
191				}
192
193				if(loadTimer != null) {
194					clearTimeout(loadTimer);
195					loadTimer = null;
196				}
197			}
198			else {
199				$overlay.addClass('almost-loaded');
200
201				$contentArea.one('ajaxscriptsloaded.inner_call', function() {
202					self.stopLoading(true);
203					/**
204					if(window.Pace && Pace.running == true) {
205						Pace.off('done');
206						Pace.once('done', function() { self.stopLoading(true) })
207					}
208					else self.stopLoading(true);
209					*/
210				})
211			}
212		}
213
214		this.working = function() {
215			return working;
216		}
217		///////////////////////
218
219		function updateBreadcrumbs(link_element) {
220			var link_text = '';
221
222			//update breadcrumbs
223			var breadcrumbs = $('.breadcrumb');
224			if(breadcrumbs.length > 0 && breadcrumbs.is(':visible')) {
225				breadcrumbs.find('> li:not(:first-child)').remove();
226
227				var i = 0;
228				link_element.parents('.nav li').each(function() {
229					var link = $(this).find('> a');
230
231					var link_clone = link.clone();
232					link_clone.find('i,.fa,.glyphicon,.ace-icon,.menu-icon,.badge,.label').remove();
233					var text = link_clone.text();
234					link_clone.remove();
235
236					var href = link.attr('href');
237
238					if(i == 0) {
239						var li = $('<li class="active"></li>').appendTo(breadcrumbs);
240						li.text(text);
241						link_text = text;
242					}
243					else {
244						var li = $('<li><a /></li>').insertAfter(breadcrumbs.find('> li:first-child'));
245						li.find('a').attr('href', href).text(text);
246					}
247					i++;
248				})
249			}
250
251			return link_text;
252		 }
253
254		 function updateTitle(link_text) {
255			var $title = $contentArea.find('.ajax-append-title');
256			if($title.length > 0) {
257				document.title = $title.text();
258				$title.remove();
259			}
260			else if(link_text.length > 0) {
261				var extra = $.trim(String(document.title).replace(/^(.*)[\-]/, ''));//for example like " - Ace Admin"
262				if(extra) extra = ' - ' + extra;
263				link_text = $.trim(link_text) + extra;
264			}
265		 }
266
267		 this.loadScripts = function(scripts, callback) {
268			$.ajaxPrefilter('script', function(opts) {opts.cache = true});
269			setTimeout(function() {
270				//let's keep a list of loaded scripts so that we don't load them more than once!
271
272				function finishLoading() {
273					if(typeof callback === 'function') callback();
274					$('.btn-group[data-toggle="buttons"] > .btn').button();
275
276					$contentArea.trigger('ajaxscriptsloaded');
277				}
278
279				//var deferreds = [];
280				var deferred_count = 0;//deferreds count
281				var resolved = 0;
282				for(var i = 0; i < scripts.length; i++) if(scripts[i]) {
283					(function() {
284						var script_name = "js-"+scripts[i].replace(/[^\w\d\-]/g, '-').replace(/\-\-/g, '-');
285						if( ajax_loaded_scripts[script_name] !== true )	deferred_count++;
286					})()
287				}
288
289				function nextScript(index) {
290					index += 1;
291					if(index < scripts.length) loadScript(index);
292					else {
293						finishLoading();
294					}
295				}
296
297				function loadScript(index) {
298					index = index || 0;
299					if(!scripts[index]) {//could be null sometimes
300						return nextScript(index);
301					}
302
303					var script_name = "js-"+scripts[index].replace(/[^\w\d\-]/g, '-').replace(/\-\-/g, '-');
304					//only load scripts that are not loaded yet!
305					if( ajax_loaded_scripts[script_name] !== true ) {
306						$.getScript(scripts[index])
307						.done(function() {
308							ajax_loaded_scripts[script_name] = true;
309						})
310						//.fail(function() {
311						//})
312						.complete(function() {
313							resolved++;
314							if(resolved >= deferred_count && working) {
315								finishLoading();
316							}
317							else {
318								nextScript(index);
319							}
320						})
321					}
322					else {//script previoisly loaded
323						nextScript(index);
324					}
325				}
326
327				if (deferred_count > 0) {
328					loadScript();
329				}
330				else {
331					finishLoading();
332				}
333			}, 10)
334		}
335
336		/////////////////
337		$(window)
338		.off('hashchange.ace_ajax')
339		.on('hashchange.ace_ajax', function(e, manual_trigger) {
340			var hash = $.trim(window.location.hash);
341			if(!hash || hash.length == 0) return;
342
343			self.loadUrl(hash);
344		}).trigger('hashchange.ace_ajax', [true]);
345
346		var hash = $.trim(window.location.hash);
347		if(!hash && this.settings.default_url) window.location.hash = this.settings.default_url;
348	}//AceAjax
349
350	$.fn.aceAjax = $.fn.ace_ajax = function (option, value, value2, value3) {
351		var method_call;
352
353		var $set = this.each(function () {
354			var $this = $(this);
355			var data = $this.data('ace_ajax');
356			var options = typeof option === 'object' && option;
357
358			if (!data) $this.data('ace_ajax', (data = new AceAjax(this, options)));
359			if (typeof option === 'string' && typeof data[option] === 'function') {
360				if(value3 != undefined) method_call = data[option](value, value2, value3);
361				else if(value2 != undefined) method_call = data[option](value, value2);
362				else method_call = data[option](value);
363			}
364		});
365
366		return (method_call === undefined) ? $set : method_call;
367	}
368
369	$.fn.aceAjax.defaults = $.fn.ace_ajax.defaults = {
370		content_url: false,
371		default_url: false,
372		loading_icon: 'fa fa-spin fa-spinner fa-2x orange',
373		loading_text: '',
374		loading_overlay: null,
375		update_breadcrumbs: true,
376		update_title: true,
377		update_active: true,
378		close_active: false,
379		max_load_wait: false
380     }
381})(window.jQuery);

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.