PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/elgg/views/default/js/initialise_elgg.php

https://bitbucket.org/rhizomatik/lorea_production/
PHP | 280 lines | 206 code | 45 blank | 29 comment | 37 complexity | bc5a2a61c6ede4fa494f5ef8192ed9dc MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, BSD-3-Clause, LGPL-2.1
  1. $(document).ready(function ($) {
  2. // COLLAPSABLE WIDGETS (on Dashboard & Profile pages)
  3. // toggle widget box contents
  4. $('a.toggle_box_contents').bind('click', toggleContent);
  5. // toggle widget box edit panel
  6. $('a.toggle_box_edit_panel').click(function () {
  7. $(this.parentNode.parentNode).children(".collapsable_box_editpanel").slideToggle("fast");
  8. return false;
  9. });
  10. // toggle customise edit panel
  11. $('a.toggle_customise_edit_panel').click(function () {
  12. $('div#customise_editpanel').slideToggle("fast");
  13. return false;
  14. });
  15. // toggle plugin's settings nad more info on admin tools admin
  16. $('a.pluginsettings_link').click(function () {
  17. $(this.parentNode.parentNode).children(".pluginsettings").slideToggle("fast");
  18. return false;
  19. });
  20. $('a.manifest_details').click(function () {
  21. $(this.parentNode.parentNode).children(".manifest_file").slideToggle("fast");
  22. return false;
  23. });
  24. // reusable generic hidden panel
  25. $('a.collapsibleboxlink').click(function () {
  26. $(this.parentNode.parentNode).children(".collapsible_box").slideToggle("fast");
  27. return false;
  28. });
  29. // WIDGET GALLERY EDIT PANEL
  30. // Sortable widgets
  31. var els = ['#leftcolumn_widgets', '#middlecolumn_widgets', '#rightcolumn_widgets', '#widget_picker_gallery' ];
  32. var $els = $(els.toString());
  33. $els.sortable({
  34. items: '.draggable_widget',
  35. handle: '.drag_handle',
  36. forcePlaceholderSize: true,
  37. placeholder: 'ui-state-highlight',
  38. cursor: 'move',
  39. opacity: 0.9,
  40. appendTo: 'body',
  41. connectWith: els,
  42. start:function(e,ui) {
  43. },
  44. stop: function(e,ui) {
  45. // refresh list before updating hidden fields with new widget order
  46. $(this).sortable( "refresh" );
  47. var widgetNamesLeft = outputWidgetList('#leftcolumn_widgets');
  48. var widgetNamesMiddle = outputWidgetList('#middlecolumn_widgets');
  49. var widgetNamesRight = outputWidgetList('#rightcolumn_widgets');
  50. document.getElementById('debugField1').value = widgetNamesLeft;
  51. document.getElementById('debugField2').value = widgetNamesMiddle;
  52. document.getElementById('debugField3').value = widgetNamesRight;
  53. }
  54. });
  55. // bind more info buttons - called when new widgets are created
  56. widget_moreinfo();
  57. // set-up hover class for dragged widgets
  58. $("#rightcolumn_widgets").droppable({
  59. accept: ".draggable_widget",
  60. hoverClass: 'droppable-hover'
  61. });
  62. $("#middlecolumn_widgets").droppable({
  63. accept: ".draggable_widget",
  64. hoverClass: 'droppable-hover'
  65. });
  66. $("#leftcolumn_widgets").droppable({
  67. accept: ".draggable_widget",
  68. hoverClass: 'droppable-hover'
  69. });
  70. }); /* end document ready function */
  71. // List active widgets for each page column
  72. function outputWidgetList(forElement) {
  73. return( $("input[name='handler'], input[name='guid']", forElement ).makeDelimitedList("value") );
  74. }
  75. // Make delimited list
  76. jQuery.fn.makeDelimitedList = function(elementAttribute) {
  77. var delimitedListArray = new Array();
  78. var listDelimiter = "::";
  79. // Loop over each element in the stack and add the elementAttribute to the array
  80. this.each(function(e) {
  81. var listElement = $(this);
  82. // Add the attribute value to our values array
  83. delimitedListArray[delimitedListArray.length] = listElement.attr(elementAttribute);
  84. }
  85. );
  86. // Return value list by joining the array
  87. return(delimitedListArray.join(listDelimiter));
  88. }
  89. // Read each widgets collapsed/expanded state from cookie and apply
  90. function widget_state(forWidget) {
  91. var thisWidgetState = $.cookie(forWidget);
  92. if (thisWidgetState == 'collapsed') {
  93. forWidget = "#" + forWidget;
  94. $(forWidget).find("div.collapsable_box_content").hide();
  95. $(forWidget).find("a.toggle_box_contents").html('+');
  96. $(forWidget).find("a.toggle_box_edit_panel").fadeOut('medium');
  97. };
  98. }
  99. // Toggle widgets contents and save to a cookie
  100. var toggleContent = function(e) {
  101. var targetContent = $('div.collapsable_box_content', this.parentNode.parentNode);
  102. if (targetContent.css('display') == 'none') {
  103. targetContent.slideDown(400);
  104. $(this).html('-');
  105. $(this.parentNode).children(".toggle_box_edit_panel").fadeIn('medium');
  106. // set cookie for widget panel open-state
  107. var thisWidgetName = $(this.parentNode.parentNode.parentNode).attr('id');
  108. $.cookie(thisWidgetName, 'expanded', { expires: 365 });
  109. } else {
  110. targetContent.slideUp(400);
  111. $(this).html('+');
  112. $(this.parentNode).children(".toggle_box_edit_panel").fadeOut('medium');
  113. // make sure edit pane is closed
  114. $(this.parentNode.parentNode).children(".collapsable_box_editpanel").hide();
  115. // set cookie for widget panel closed-state
  116. var thisWidgetName = $(this.parentNode.parentNode.parentNode).attr('id');
  117. $.cookie(thisWidgetName, 'collapsed', { expires: 365 });
  118. }
  119. return false;
  120. };
  121. // More info tooltip in widget gallery edit panel
  122. function widget_moreinfo() {
  123. $("img.more_info").hover(function(e) {
  124. var widgetdescription = $("input[name='description']", this.parentNode.parentNode.parentNode ).attr('value');
  125. $("body").append("<p id='widget_moreinfo'><b>"+ widgetdescription +" </b></p>");
  126. if (e.pageX < 900) {
  127. $("#widget_moreinfo")
  128. .css("top",(e.pageY + 10) + "px")
  129. .css("left",(e.pageX + 10) + "px")
  130. .fadeIn("medium");
  131. }
  132. else {
  133. $("#widget_moreinfo")
  134. .css("top",(e.pageY + 10) + "px")
  135. .css("left",(e.pageX - 210) + "px")
  136. .fadeIn("medium");
  137. }
  138. },
  139. function() {
  140. $("#widget_moreinfo").remove();
  141. });
  142. $("img.more_info").mousemove(function(e) {
  143. // action on mousemove
  144. });
  145. };
  146. // COOKIES
  147. jQuery.cookie = function(name, value, options) {
  148. if (typeof value != 'undefined') { // name and value given, set cookie
  149. options = options || {};
  150. if (value === null) {
  151. value = '';
  152. options.expires = -1;
  153. }
  154. var expires = '';
  155. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  156. var date;
  157. if (typeof options.expires == 'number') {
  158. date = new Date();
  159. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  160. } else {
  161. date = options.expires;
  162. }
  163. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  164. }
  165. // CAUTION: Needed to parenthesize options.path and options.domain
  166. // in the following expressions, otherwise they evaluate to undefined
  167. // in the packed version for some reason.
  168. var path = options.path ? '; path=' + (options.path) : '';
  169. var domain = options.domain ? '; domain=' + (options.domain) : '';
  170. var secure = options.secure ? '; secure' : '';
  171. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  172. } else { // only name given, get cookie
  173. var cookieValue = null;
  174. if (document.cookie && document.cookie != '') {
  175. var cookies = document.cookie.split(';');
  176. for (var i = 0; i < cookies.length; i++) {
  177. var cookie = jQuery.trim(cookies[i]);
  178. // Does this cookie string begin with the name we want?
  179. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  180. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  181. break;
  182. }
  183. }
  184. }
  185. return cookieValue;
  186. }
  187. };
  188. // ELGG TOOLBAR MENU
  189. $.fn.elgg_topbardropdownmenu = function(options) {
  190. options = $.extend({speed: 350}, options || {});
  191. this.each(function() {
  192. var root = this, zIndex = 5000;
  193. function getSubnav(ele) {
  194. if (ele.nodeName.toLowerCase() == 'li') {
  195. var subnav = $('> ul', ele);
  196. return subnav.length ? subnav[0] : null;
  197. } else {
  198. return ele;
  199. }
  200. }
  201. function getActuator(ele) {
  202. if (ele.nodeName.toLowerCase() == 'ul') {
  203. return $(ele).parents('li')[0];
  204. } else {
  205. return ele;
  206. }
  207. }
  208. function hide() {
  209. var subnav = getSubnav(this);
  210. if (!subnav) return;
  211. $.data(subnav, 'cancelHide', false);
  212. setTimeout(function() {
  213. if (!$.data(subnav, 'cancelHide')) {
  214. $(subnav).slideUp(100);
  215. }
  216. }, 250);
  217. }
  218. function show() {
  219. var subnav = getSubnav(this);
  220. if (!subnav) return;
  221. $.data(subnav, 'cancelHide', true);
  222. $(subnav).css({zIndex: zIndex++}).slideDown(options.speed);
  223. if (this.nodeName.toLowerCase() == 'ul') {
  224. var li = getActuator(this);
  225. $(li).addClass('hover');
  226. $('> a', li).addClass('hover');
  227. }
  228. }
  229. $('ul, li', this).hover(show, hide);
  230. $('li', this).hover(
  231. function() { $(this).addClass('hover'); $('> a', this).addClass('hover'); },
  232. function() { $(this).removeClass('hover'); $('> a', this).removeClass('hover'); }
  233. );
  234. });
  235. };