/* Jappix - An open social platform These are the tooltip JS scripts for Jappix ------------------------------------------------- License: AGPL Author: Vanaryon Last revision: 27/08/11 */ // Creates a tooltip code function createTooltip(xid, hash, type) { // Path to the element var path = '#' + hash; var path_tooltip = path + ' .chat-tools-' + type; var path_bubble = path_tooltip + ' .bubble-' + type; // Yet exists? if(exists(path_bubble)) return false; // Generates special tooltip HTML code var title = ''; var content = ''; switch(type) { // Smileys case 'smileys': title = _e("Smiley insertion"); content = smileyLinks(hash); break; // Style case 'style': title = _e("Change style"); content = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + ''; break; // File send case 'file': title = _e("Send a file"); content = '

' + _e("Once uploaded, your friend will be prompted to download the file you sent.") + '

'; content += '
' + generateFileShare() + '
'; break; // Chat log case 'save': title = _e("Save chat"); content = '

' + _e("Click on the following link to get the chat log, and wait. Then click again to get the file.") + '

'; // Possible to generate any log? if($(path + ' .one-line').size()) content += '' + _e("Generate file!") + ''; else content += '' + _e("This chat is empty!") + ''; break; } // Generates general tooltip HTML code var html = '
' + '
' + '

' + title + '

' + content + '
' + '
' + '
'; // Append the HTML code $(path_tooltip).append(html); // Special events switch(type) { // Smileys case 'smileys': // Apply click event on smiley links $(path_tooltip + ' a.emoticon').click(function() { return insertSmiley($(this).attr('data-smiley'), hash); }); break; // Style case 'style': // Paths to items var message_area = path + ' .message-area'; var bubble_style = path_tooltip + ' .bubble-style '; var style = bubble_style + 'input:checkbox'; var colors = bubble_style + 'a.color'; // Click event on color picker $(colors).click(function() { // The clicked color is yet selected if($(this).hasClass('selected')) { $(message_area).removeAttr('data-color'); $(this).removeClass('selected'); } else { $(message_area).attr('data-color', $(this).attr('data-color')); $(colors).removeClass('selected'); $(this).addClass('selected'); } return false; }); // Change event on text style checkboxes $(style).change(function() { // Get current type var style_data = 'data-' + $(this).attr('class'); // Checked checkbox? if($(this).filter(':checked').size()) $(message_area).attr(style_data, true); else $(message_area).removeAttr(style_data); }); // Update the textarea style when it is changed $(style + ', ' + colors).click(function() { var style = generateStyle(hash); // Any style to apply? if(style) $(message_area).attr('style', style); else $(message_area).removeAttr('style'); // Focus again on the message textarea $(document).oneTime(10, function() { $(message_area).focus(); }); }); // Load current style loadStyleSelector(hash); break; // File send case 'file': // File upload vars var oob_upload_options = { dataType: 'xml', beforeSubmit: waitUploadOOB, success: handleUploadOOB }; // Upload form submit event $(path_tooltip + ' #oob-upload').submit(function() { if($(path_tooltip + ' #oob-upload input[type=file]').val()) $(this).ajaxSubmit(oob_upload_options); return false; }); // Upload input change event $(path_tooltip + ' #oob-upload input[type=file]').change(function() { if($(this).val()) $(path_tooltip + ' #oob-upload').ajaxSubmit(oob_upload_options); return false; }); // Input click event $(path_tooltip + ' #oob-upload input[type=file], ' + path_tooltip + ' #oob-upload input[type=submit]').click(function() { if(exists(path_tooltip + ' #oob-upload input[type=reset]')) return; // Lock the bubble $(path_bubble).addClass('locked'); // Add a cancel button $(this).after(''); // Cancel button click event $(path_tooltip + ' #oob-upload input[type=reset]').click(function() { // Remove the bubble $(path_bubble).removeClass('locked'); destroyTooltip(hash, 'file'); }); }); break; // Chat log case 'save': // Chat log generation click event $(path_tooltip + ' .tooltip-actionlog').click(function() { // Replace it with a waiting notice $(this).replaceWith('' + _e("Please wait...") + ''); generateChatLog(xid, hash); return false; }); break; } return true; } // Destroys a tooltip code function destroyTooltip(hash, type) { $('#' + hash + ' .chat-tools-content:not(.mini) .bubble-' + type + ':not(.locked)').remove(); } // Applies the page-engine tooltips hover event function hoverTooltip(xid, hash, type) { $('#' + hash + ' .chat-tools-' + type).hover(function() { createTooltip(xid, hash, type); }, function() { destroyTooltip(hash, type) }); } // Applies the hoverTooltip function to the needed things function tooltipIcons(xid, hash) { // Hover events hoverTooltip(xid, hash, 'smileys'); hoverTooltip(xid, hash, 'style'); hoverTooltip(xid, hash, 'file'); hoverTooltip(xid, hash, 'save'); // Click events $('#' + hash + ' a.chat-tools-content, #' + hash + ' .chat-tools-content a').click(function() { return false; }); } // Loads the style selector options function loadStyleSelector(hash) { // Define the vars var path = '#' + hash; var message_area = $(path + ' .message-area'); var bubble_style = path + ' .bubble-style'; // Apply the options to the style selector $(bubble_style + ' input[type=checkbox]').each(function() { // Current input enabled? if(message_area.attr('data-' + $(this).attr('class'))) $(this).attr('checked', true); }); // Apply message color $(bubble_style + ' a.color[data-color=' + message_area.attr('data-color') + ']').addClass('selected'); }