JimMorrison723

Untitled

Sep 3rd, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.91 KB | None | 0 0
  1. function SmileyButtons() {
  2.         var arr = [ "heart", "minishock", "biggrin", "blushing", "bored", "mellow", "tongue", "ohmy", "blink", "smile", "sad", "crying", "wink", "xd" ];
  3.         for (var i = 0; i < arr.length-1; i++) {
  4.                 $('#hozzaszolas').before('<button id="smiley" value="'+arr[i]+'"><img src="'+chrome.extension.getURL('/img/smiley/'+arr[i]+'.png')+'" /></button>'); //value=":'+arr[i]+':" width=16 height=16
  5.         }
  6.         $(":button[id=|smiley]").click(function () {
  7.                 wherever_cursor_is = $('#message').val($('#message').val()+":"+$(this).val()+":");
  8.         });    
  9.  }
  10.  
  11. function FormattingButtons() {
  12.     $('#hozzaszolas').before('<button id="bold">[B]</button>');
  13.    
  14.     $('#bold').click(function () {
  15.         var textarea = jQuery('textarea#someTextArea');
  16.         textarea.val(textarea.val() + '<b>' + getSelectedText()'</b>');
  17.         evt.preventDefault();
  18.     });  
  19.    
  20.     function getSelectedText() {
  21.         if (window.getSelection) {
  22.             return window.getSelection();
  23.         }
  24.         else if (document.selection) {
  25.             return document.selection.createRange().text;
  26.         }
  27.         return '';
  28.     }
  29. }
  30.  
  31.  
  32. function extInit() {
  33.         if(dataStore['smiley_bar'] == 'checked') {
  34.                 SmileyButtons();
  35.         }
  36.         if(dataStore['formatting_toolbar'] == 'checked') {
  37.                 FormattingButtons();
  38.         }
  39. }
  40.  
  41. var dataStore;
  42. // Create a port to BG process
  43. var port = chrome.extension.connect();
  44. // Filter out iframes
  45. // Send "getSettings" request
  46. if (window.top === window) {
  47.     port.postMessage({ name : "getSettings" });
  48. }
  49.  
  50. // Catch incoming messages
  51. port.onMessage.addListener(function(event) {
  52.         // Here comes the settings, save a copy to dataStore var
  53.         if(event.name == 'setSettings') {
  54.                 dataStore = event.message;
  55.                 $(document).ready(function() {
  56.                         extInit();
  57.                 });
  58.         }
  59. });
Advertisement
Add Comment
Please, Sign In to add comment