context_ui_dialog.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. (function ($) {
  2. Drupal.behaviors.context_ui_dialog = {
  3. attach: function(context) {
  4. var selector = $('#context_ui_dialog-context-ui', context).not('context_ui_dialog-processed');
  5. if(selector) {
  6. selector.addClass('context_ui_dialog-processed');
  7. selector.detach();
  8. $('#page').prepend(selector);
  9. var labelOpen = Drupal.t('Select context');
  10. var labelClose = Drupal.t('Hide');
  11. // Create a tab to show/hide our edit area
  12. var tab = $('<a href="javascript:" class="context-ui-dialog-open" title="' + Drupal.t('Show context selector') + '">'+labelClose+'</a>');
  13. selector.append(tab);
  14. selector.toggled = false;
  15. var width = $(selector).outerWidth();
  16. tab.click(function(e){
  17. if(selector.toggled) {
  18. selector.stop(true, false).animate({'left':0}, 400);
  19. selector.toggled = false;
  20. $(this).text(labelClose);
  21. } else {
  22. selector.stop(true, false).animate({'left':-width-4}, 400);
  23. selector.toggled = true;
  24. $(this).text(labelOpen);
  25. }
  26. });
  27. $('#context_ui_dialog-context-ui').show();
  28. // Make sure the UI is 60% of the size of the window
  29. var context_ui_height = Math.round(6 * $(window).height() / 10);
  30. var item_list_height = context_ui_height - 200;
  31. item_list_height = (item_list_height < 50) ? 50 : item_list_height;
  32. $('#context_ui_dialog-context-ui').height(context_ui_height);
  33. $('#context_ui_dialog-context-ui .item-list').height(item_list_height);
  34. // Add a class to body
  35. $('body').once().addClass('context-field-editor');
  36. }
  37. }
  38. };
  39. })(jQuery);