PageSourceSearch

https://www.aerialclick.com/modules/advanceblog/views/js/unitegallery/js/ug-panelsbase.js

js aerialclick.com collected 2026-10-08 23:15:36 UTC 12,329 bytes, 560 lines download raw bytes

1/**
2* The MIT License (MIT)
3*
4* Copyright (c) 2015 Max Valiano | http://unitegallery.net
5*
6* Permission is hereby granted, free of charge, to any person
7* obtaining a copy of this software and associated documentation
8* files (the "Software"), to deal in the Software without
9* restriction, including without limitation the rights to use,
10* copy, modify, merge, publish, distribute, sublicense, and/or sell
11* copies of the Software, and to permit persons to whom the
12* Software is furnished to do so, subject to the following
13* conditions:
14*
15* The above copyright notice and this permission notice shall be
16* included in all copies or substantial portions of the Software.
17*
18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25* OTHER DEALINGS IN THE SOFTWARE.
26*
27* @author    Max Valiano
28* @copyright Copyright (c) 2017 Max Valiano | http://unitegallery.net
29* @license   The MIT License (MIT)
30*/
31
32/** -------------- Panel Base Functions ---------------------*/
33
34function UGPanelsBase(){
35
36	var g_temp, g_panel, g_objPanel, g_options, g_objThis;
37	var g_gallery = new UniteGalleryMain();
38	var t = this, g_objHandle, g_objGallery;
39	var g_functions = new UGFunctions();
40
41
42	/**
43	 * init the base panel
44	 */
45	this.init = function(gallery, g_tempArg, g_panelArg, options, g_objThisArg){
46		g_temp = g_tempArg;
47		g_panel = g_panelArg;
48		g_gallery = gallery;
49		g_options = options;
50		g_objThis = g_objThisArg;
51
52		g_objGallery = jQuery(g_gallery);
53	}
54
55	/**
56	 * set common panels html
57	 */
58	this.setHtml = function(g_objPanelArg){
59
60		g_objPanel = g_objPanelArg;
61
62		if(g_temp.panelType == "strip")
63			var enable_handle = g_options.strippanel_enable_handle;
64		else
65			var enable_handle = g_options.gridpanel_enable_handle;
66
67		// add handle
68		if (enable_handle == true) {
69			g_objHandle = new UGPanelHandle();
70			g_objHandle.init(g_panel, g_objPanel, g_options, g_temp.panelType, g_gallery);
71			g_objHandle.setHtml();
72		}
73
74
75		//set disabled at start if exists
76		if(g_temp.isDisabledAtStart === true){
77			var html = "<div class='ug-overlay-disabled'></div>";
78			g_objPanel.append(html);
79
80			setTimeout(function(){
81				g_objPanel.children(".ug-overlay-disabled").hide();
82			}, g_temp.disabledAtStartTimeout);
83
84		}
85
86	}
87
88
89	/**
90	 * place common elements
91	 */
92	this.placeElements = function(){
93
94		// place handle
95		if (g_objHandle)
96			g_objHandle.placeHandle();
97	}
98
99
100	/**
101	 * init common events
102	 */
103	this.initEvents = function(){
104
105		// set handle events
106		if (g_objHandle){
107			g_objHandle.initEvents();
108
109			//set on slider action events
110			g_objGallery.on(g_gallery.events.SLIDER_ACTION_START, function(){
111				g_objHandle.hideHandle();
112			});
113
114			g_objGallery.on(g_gallery.events.SLIDER_ACTION_END, function(){
115				g_objHandle.showHandle();
116			});
117
118		}
119
120	}
121
122	/**
123	 * destroy the panel events
124	 */
125	this.destroy = function(){
126
127		if(g_objHandle){
128			g_objHandle.destroy();
129			g_objGallery.off(g_gallery.events.SLIDER_ACTION_START);
130			g_objGallery.off(g_gallery.events.SLIDER_ACTION_END);
131		}
132
133	}
134
135	/**
136	 * place panel with some animation
137	 */
138	function placePanelAnimation(panelDest, functionOnComplete) {
139
140		switch (g_temp.orientation) {
141		case "right": // vertical
142		case "left":
143			var objCss = {
144				left : panelDest + "px"
145			};
146			break;
147		case "top":
148		case "bottom":
149			var objCss = {
150				top : panelDest + "px"
151			};
152			break;
153		}
154
155		g_objPanel.stop(true).animate(objCss, {
156			duration : 300,
157			easing : "easeInOutQuad",
158			queue : false,
159			complete : function() {
160				if (functionOnComplete)
161					functionOnComplete();
162			}
163		});
164
165	}
166
167
168	/**
169	 * place the panel without animation
170	 *
171	 * @param panelDest
172	 */
173	function placePanelNoAnimation(panelDest) {
174
175		switch (g_temp.orientation) {
176		case "right": // vertical
177		case "left":
178			g_functions.placeElement(g_objPanel, panelDest, null);
179			break;
180		case "top":
181		case "bottom":
182			g_functions.placeElement(g_objPanel, null, panelDest);
183			break;
184		}
185	}
186
187	/**
188	 * event on panel slide finish
189	 */
190	function onPanelSlideFinish() {
191
192		g_objThis.trigger(g_panel.events.FINISH_MOVE);
193
194	}
195
196
197	/**
198	 * open the panel
199	 */
200	this.openPanel = function(noAnimation) {
201
202		if (!noAnimation)
203			var noAnimation = false;
204
205		if (g_objPanel.is(":animated"))
206			return (false);
207
208		if (g_temp.isClosed == false)
209			return (false);
210
211		g_temp.isClosed = false;
212
213		g_objThis.trigger(g_panel.events.OPEN_PANEL);
214
215		if (noAnimation === false)
216			placePanelAnimation(g_temp.originalPos, onPanelSlideFinish);
217		else {
218
219			placePanelNoAnimation(g_temp.originalPos);
220			onPanelSlideFinish();
221		}
222
223	}
224
225
226	/**
227	 * close the panel (slide in)
228	 */
229	this.closePanel = function(noAnimation) {
230
231		if (!noAnimation)
232			var noAnimation = false;
233
234		if (g_objPanel.is(":animated"))
235			return (false);
236
237		if (g_temp.isClosed == true)
238			return (false);
239
240		var panelDest = t.getClosedPanelDest();
241
242		g_temp.isClosed = true;
243
244		g_objThis.trigger(g_panel.events.CLOSE_PANEL);
245
246		if (noAnimation === false)
247			placePanelAnimation(panelDest, onPanelSlideFinish);
248		else {
249			placePanelNoAnimation(panelDest);
250			onPanelSlideFinish();
251		}
252
253	}
254
255	/**
256	 * set the panel that it's in closed state, and set original pos for opening
257	 * later
258	 */
259	this.setClosedState = function(originalPos) {
260
261		g_temp.originalPos = originalPos;
262		g_objThis.trigger(g_panel.events.CLOSE_PANEL);
263
264		g_temp.isClosed = true;
265	}
266
267	/**
268	 * set the panel opened state
269	 */
270	this.setOpenedState = function(originalPos) {
271		g_objThis.trigger(g_panel.events.OPEN_PANEL);
272
273		g_temp.isClosed = false;
274	}
275
276	/**
277	 * get closed panel destanation
278	 */
279	this.getClosedPanelDest = function() {
280
281		var objPanelSize = g_functions.getElementSize(g_objPanel), panelDest;
282
283		switch (g_temp.orientation) {
284		case "left":
285			g_temp.originalPos = objPanelSize.left;
286			panelDest = -g_temp.panelWidth;
287			break;
288		case "right":
289			g_temp.originalPos = objPanelSize.left;
290			var gallerySize = g_gallery.getSize();
291			panelDest = gallerySize.width;
292			break;
293		case "top":
294			g_temp.originalPos = objPanelSize.top;
295			panelDest = -g_temp.panelHeight;
296			break;
297		case "bottom":
298			g_temp.originalPos = objPanelSize.top;
299			var gallerySize = g_gallery.getSize();
300			panelDest = gallerySize.height;
301			break;
302		}
303
304		return (panelDest);
305	}
306
307
308	/**
309	 * tells if the panel is closed
310	 */
311	this.isPanelClosed = function() {
312
313		return (g_temp.isClosed);
314	}
315
316
317	/**
318	 * set the panel disabled at start, called after init before setHtml
319	 * it's enabled again after timeout end
320	 */
321	this.setDisabledAtStart = function(timeout){
322
323		if(timeout <= 0)
324			return(false);
325
326		g_temp.isDisabledAtStart = true;
327		g_temp.disabledAtStartTimeout = timeout;
328
329	}
330
331
332}
333
334
335/** -------------- Panel Handle object ---------------------*/
336
337function UGPanelHandle(){
338
339	var t = this, g_objPanel, g_panel, g_objHandleTip, g_panelOptions = {};
340	var g_functions = new UGFunctions();
341
342	var g_options = {
343			panel_handle_align: "top",		//top, middle, bottom , left, right, center - close handle tip align on the handle bar according panel orientation
344			panel_handle_offset: 0,			//offset of handle bar according the valign
345			panel_handle_skin: 0			//skin of the handle, if empty inherit from gallery skin
346	};
347
348
349	/**
350	 * init the handle
351	 */
352	this.init = function(panel, objPanel, panelOptions, panelType, gallery){
353		g_panel = panel;
354		g_objPanel = objPanel;
355
356		//set needed options
357		switch(panelType){
358			case "grid":
359				g_options.panel_handle_align = panelOptions.gridpanel_handle_align;
360				g_options.panel_handle_offset = panelOptions.gridpanel_handle_offset;
361				g_options.panel_handle_skin = panelOptions.gridpanel_handle_skin;
362			break;
363			case "strip":
364				g_options.panel_handle_align = panelOptions.strippanel_handle_align;
365				g_options.panel_handle_offset = panelOptions.strippanel_handle_offset;
366				g_options.panel_handle_skin = panelOptions.strippanel_handle_skin;
367			break;
368			default:
369				throw new Error("Panel handle error: wrong panel type: " + panelType);
370			break;
371		}
372
373		//set arrows skin:
374		var galleryOptions = gallery.getOptions();
375		var globalSkin = galleryOptions.gallery_skin;
376		if(g_options.panel_handle_skin == "")
377			g_options.panel_handle_skin = globalSkin;
378
379
380	}
381
382
383	/**
384	 * set handle html
385	 */
386	this.setHtml = function(){
387
388		var orientation = g_panel.getOrientation();
389
390		var classTip = "ug-panel-handle-tip";
391
392		switch(orientation){
393			case "right":
394				classTip += " ug-handle-tip-left";
395			break;
396			case "left":
397				classTip += " ug-handle-tip-right";
398			break;
399			case "bottom":
400				classTip += " ug-handle-tip-top";
401			break;
402			case "top":
403				classTip += " ug-handle-tip-bottom";
404			break;
405		}
406
407		g_objPanel.append("<div class='"+classTip+" ug-skin-" + g_options.panel_handle_skin + "'></div>");
408		g_objHandleTip = g_objPanel.children(".ug-panel-handle-tip");
409	}
410
411
412	/**
413	 * remove hover state of the tip
414	 */
415	function removeHoverState(){
416
417		g_objHandleTip.removeClass("ug-button-hover");
418	}
419
420	/**
421	 * add closed state class
422	 */
423	function setClosedState(){
424
425		g_objHandleTip.addClass("ug-button-closed");
426	}
427
428	/**
429	 * add closed state class
430	 */
431	function removeClosedState(){
432		g_objHandleTip.removeClass("ug-button-closed");
433	}
434
435	/**
436	 * on handle click, close or open panel
437	 */
438	function onHandleClick(event){
439
440		event.stopPropagation();
441		event.stopImmediatePropagation();
442
443		if(g_functions.validateClickTouchstartEvent(event.type) == false)
444			return(true);
445
446		if(g_panel.isPanelClosed())
447			g_panel.openPanel();
448		else
449			g_panel.closePanel();
450	}
451
452	/**
453	 * init events
454	 */
455	this.initEvents = function(){
456		g_functions.addClassOnHover(g_objHandleTip);
457		g_objHandleTip.bind("click touchstart", onHandleClick);
458
459		//on panel open
460		jQuery(g_panel).on(g_panel.events.OPEN_PANEL, function(){
461			removeHoverState();
462			removeClosedState();
463		});
464
465		//one panel close
466		jQuery(g_panel).on(g_panel.events.CLOSE_PANEL, function(){
467			removeHoverState();
468			setClosedState();
469		});
470
471	}
472
473	/**
474	 * destroy the handle panel events
475	 */
476	this.destroy = function(){
477		g_functions.destroyButton(g_objHandleTip);
478		jQuery(g_panel).off(g_panel.events.OPEN_PANEL);
479		jQuery(g_panel).off(g_panel.events.CLOSE_PANEL);
480	}
481
482
483
484	/**
485	 * check and fix align option, set write direction
486	 */
487	function checkAndFixAlign(){
488		var orientation = g_panel.getOrientation();
489
490		switch(orientation){
491			case "right":
492			case "left":
493				if(g_options.panel_handle_align != "top" && g_options.panel_handle_align != "bottom")
494					g_options.panel_handle_align = "top";
495			break;
496			case "bottom":
497				if(g_options.panel_handle_align != "left" && g_options.panel_handle_align != "right")
498					g_options.panel_handle_align = "left";
499			break;
500			case "top":
501				if(g_options.panel_handle_align != "left" && g_options.panel_handle_align != "right")
502					g_options.panel_handle_align = "right";
503			break;
504		}
505
506	}
507
508
509	/**
510	 * place the panel
511	 */
512	this.placeHandle = function(){
513		var handleSize = g_functions.getElementSize(g_objHandleTip);
514
515		checkAndFixAlign();
516
517		var orientation = g_panel.getOrientation();
518
519		switch(orientation){
520			case "left":
521				g_functions.placeElement(g_objHandleTip, "right", g_options.panel_handle_align, -handleSize.width);
522			break;
523			case "right":
524				g_functions.placeElement(g_objHandleTip, -handleSize.width, g_options.panel_handle_align, 0 ,g_options.panel_handle_offset);
525			break;
526			case "top":
527				g_functions.placeElement(g_objHandleTip, g_options.panel_handle_align, "bottom", g_options.panel_handle_offset, -handleSize.height);
528			break;
529			case "bottom":
530				g_functions.placeElement(g_objHandleTip, g_options.panel_handle_align, "top", g_options.panel_handle_offset, -handleSize.height);
531			break;
532			default:
533				throw new Error("Wrong panel orientation: " + orientation);
534			break;
535		}
536
537	}
538
539	/**
540	 * hide the handle
541	 */
542	this.hideHandle = function(){
543
544		if(g_objHandleTip.is(":visible") == true)
545			g_objHandleTip.hide();
546
547	}
548
549	/**
550	 * show the handle
551	 */
552	this.showHandle = function(){
553
554		if(g_objHandleTip.is(":visible") == false)
555			g_objHandleTip.show();
556
557	}
558
559
560}

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.