jquery.hipchat.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. (function ($) {
  2. // Creates an iframe with an embedded HipChat conversation window.
  3. //
  4. // Options:
  5. // url - The url to the room to embed; required
  6. // container - The container in which to insert the HipChat panel; required
  7. // timezone - The timezone to use in the embedded room; required
  8. // welcome - A welcome message to display when the room is joined; optional
  9. // noframes - Content to include when iframes are disabled in the browser; optional
  10. // width - The width of the iframe; defaults to 100%
  11. // height - The height of the iframe; defaults to 400px
  12. $.createHipChat = function (options) {
  13. if (options && options.url && options.container && options.timezone) {
  14. var $container = $(options.container);
  15. if ($container.length === 0) return;
  16. var params = {
  17. anonymous: 0,
  18. timezone: options.timezone,
  19. minimal: 0
  20. };
  21. if (options.welcome) {
  22. params.welcome_msg = options.welcome;
  23. }
  24. var url = options.url + (options.url.indexOf('?') > 0 ? '&' : '?') + $.param(params);
  25. if (url.indexOf('https://') !== 0) {
  26. url = 'https://' + url;
  27. }
  28. var w = options.width || '100%';
  29. var h = options.height || 400;
  30. var nf = (options.noframes || '');
  31. return {
  32. show: function () {
  33. $container.html('<iframe src="' + url + '" frameborder="' + 0 + '" width="' + w + '" height="' + h + '">' + nf + '</iframe>');
  34. }
  35. };
  36. }
  37. };
  38. $.fn.hipChatPanel = function (options) {
  39. options.container = this[0];
  40. var panel = $.createHipChat(options);
  41. this.html('<button class="show-hipchat ' + options.buttonClasses + '">' + (options.buttonTitle || 'Chat') + '</button>')
  42. .find('.show-hipchat').click(function (e) { panel.show(); });
  43. };
  44. }(jQuery));