All Downloads are FREE. Search and download functionalities are using the official Maven repository.

public.component.assets.js.ace.elements.onpage-help.js Maven / Gradle / Ivy

There is a newer version: 3.0.1.11
Show newest version
window.Onpage_Help = function(options) {
	var $ = window.jQuery || null;
	if($ == null) return;

	options = options || {}
	var defaults = {
		include_all: true,
		icon_1: 'fa fa-question',
		icon_2: 'fa fa-lightbulb-o',
		base: '',
		code_highlight: (!!window.Rainbow ? 'rainbow' : (!!window.Prism ? 'prism' : null)),

		add_panels: true,
		panel_content_selector: '.info-section',
		panel_content_title: '.info-title'
	}
	this.settings = $.extend({}, defaults, options);
	

	var $base = this.settings['base'];
	var ie_fix = document.all && !window.atob;//ie9 and below need a little fix

	var section_start = {};
	var section_end = {};
	var section_rect = {};
	var section_count = 0;
	
	var created = false;
	var active = false;
	
	var self = this, _ = this;
	var ovfx = '';
	var help_container = null;
	
	var body_h, body_w;
	
	var captureFocus = function() {
		if(!help_container) return;
		var scroll = -1;
		//like bootstrap modal
		$(document)
		.off('focusin.ace.help') //remove any previously attached handler
		.on('focusin.ace.help', function (e) {
			if (!( help_container[0] == e.target || $.contains(help_container[0], e.target) )) {
			  help_container.focus();
			}

			if(e.target == document && scroll > -1) {
				//when window regains focus and container is focused, it scrolls to bottom
				//so we put it back to its place
				$('body,html').scrollTop(scroll);
				scroll = -1;
			}
		})

		$(window).on('blur.ace.help', function(){
			scroll = $(window).scrollTop();
		});
	}
	var releaseFocus = function() {
		$(document).off('focusin.ace.help');
		$(window).off('blur.ace.help');
	}


	this.toggle = function() {
		if(active) {
			self.disable();
		}
		else {
			self.enable();
		}
	}

	this.enable = function() {
		if(active) return;
		if(typeof _.settings.before_enable === 'function' && _.settings.before_enable.call(self) === false) return;
		////

		//if( !created ) this.init();
		active = true;
		
		$('.onpage-help-backdrop, .onpage-help-section').removeClass('hidden');
		
		ovfx = document.body.style.overflowX;
		document.body.style.overflowX = 'hidden';//hide body:overflow-x
		
		display_help_sections();
		captureFocus();

		////
		if(typeof _.settings.after_enable === 'function') _.settings.after_enable.call(self);
	}
	
	this.disable = function() {
		if(!active) return;
		if(typeof _.settings.before_disable === 'function' && _.settings.before_disable.call(self)) return;
		////
				
		active = false;
		$('.onpage-help-backdrop, .onpage-help-section').addClass('hidden');

		document.body.style.overflowX = ovfx;//restore body:overflow-x
		releaseFocus();
		
		////
		if(typeof _.settings.after_disable === 'function') _.settings.after_disable.call(self);
	}
	
	this.is_active = function() {
		return active;
	}
	this.show_section_help = function(section) {
		launch_help_modal(section, true);
	}
	
	
	this.init = function() {
		if( created ) return;
	
		help_container = 
		$('
') .appendTo('body'); help_container.append('
'; }); } //modify image paths if needed! if(typeof _.settings.img_url === 'function') { excerpt = excerpt.replace(/\') .wrap('
') .closest('.panel-heading'); $(this).wrap('
'); $(this).closest('.panel').prepend(header); }) var group_count = $('.panel-group').length; content.find('.panel').each(function() { if( $(this).parent().hasClass('panel-group') ) return; var group_id = 'panel-group-help-'+ (++group_count); var group = $('
').insertBefore(this); group.attr('id', group_id); var panel_id = 0; group.siblings('.panel').appendTo(group); group.find('.help-panel-toggle') .append('') .attr('data-parent', '#'+group_id) .each(function() { panel_id++; $(this).attr('data-target', '#'+group_id+'-'+panel_id); $(this).closest('.panel-heading').siblings('.panel-collapse').attr('id', group_id+'-'+panel_id); }); }); $(document).off('click.help-panel-toggle', '.help-panel-toggle').on('click.help-panel-toggle', '.help-panel-toggle', function(e) { e.preventDefault(); }); } /////////////////////////////////////////// content.removeClass('hidden') var images = content.find('img:visible'); if(images.length > 0) { //handle scrollbars when all images are loaded var ev_count = 0; images.off('.help_body_scroll').on('load.help_body_scroll error.help_body_scroll', function() { $(this).off('.help_body_scroll'); ev_count++; if(ev_count >= images.length) disableBodyScroll(); }); } disableBodyScroll(); content.find('.panel > .panel-collapse').on('shown.bs.collapse hidden.bs.collapse', function() { disableBodyScroll(); }); //save history list add_to_nav_list(section_name, save_to_list); var pos = -1; if((pos = section_name.lastIndexOf('.')) > -1) { section_name = section_name.substr(0, pos); help_modal.find('button[data-navdir=up]').removeClass('disabled').attr('data-url', section_name); } else { help_modal.find('button[data-navdir=up]').addClass('disabled').removeAttr('data-url').blur(); } }) .fail(function() { help_modal.find('.modal-title').find('.fa-spin').remove().end().find('.hidden').children().unwrap(); }); }//launch_help_modal $(document).on('click', '.onpage-help-modal a[href^="http"]', function() { $(this).attr('target', '_blank'); }); $(document).on('click', '.help-more', function(e) { e.preventDefault(); var href = $(this).attr('href'); launch_help_modal(href); }); function add_to_nav_list(section_name, save_to_list) { if(save_to_list !== false) { if(nav_list.length > 0) { nav_list = nav_list.slice(0, nav_pos + 1); } if(nav_list[nav_list.length - 1] != section_name) { nav_list.push(section_name); nav_pos = nav_list.length - 1; } } if(nav_pos == 0){ help_modal.find('button[data-navdir=back]').addClass('disabled').blur(); } else { help_modal.find('button[data-navdir=back]').removeClass('disabled'); } if(nav_pos == nav_list.length - 1){ help_modal.find('button[data-navdir=forward]').addClass('disabled').blur(); } else { help_modal.find('button[data-navdir=forward]').removeClass('disabled'); } } $(document).on('click', '.open-file[data-open-file]', function() { help_modal.find('.modal-title').wrapInner("


© 2015 - 2025 Weber Informatics LLC | Privacy Policy