muzich.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Scripts de Muzi.ch
  3. * Rédigé et propriété de Sevajol Bastien (http://www.bux.fr)
  4. *
  5. */
  6. // Messages flashs
  7. var myMessages = ['info','warning','error','success']; // define the messages types
  8. function hideAllMessages()
  9. {
  10. var messagesHeights = new Array(); // this array will store height for each
  11. for (i=0; i<myMessages.length; i++)
  12. {
  13. messagesHeights[i] = $('.' + myMessages[i]).outerHeight();
  14. $('.' + myMessages[i]).css('top', -messagesHeights[i]); //move element outside viewport
  15. }
  16. }
  17. $(document).ready(function(){
  18. // Initially, hide them all
  19. hideAllMessages();
  20. $('.message').animate({top:"0"}, 500);
  21. // When message is clicked, hide it
  22. $('.message a.message-close').click(function(){
  23. $(this).parent('.message').animate({top: -$(this).outerHeight()-50}, 700);
  24. return false;
  25. });
  26. });
  27. function findKeyWithValue(arrayt, value)
  28. {
  29. for(i in arrayt)
  30. {
  31. if (arrayt[i] == value)
  32. {
  33. return i;
  34. }
  35. }
  36. return "";
  37. }
  38. function json_to_array(json_string)
  39. {
  40. if (json_string.length)
  41. {
  42. return eval("(" + json_string + ")");
  43. }
  44. return new Array();
  45. }
  46. /**
  47. * Converts the given data structure to a JSON string.
  48. * Argument: arr - The data structure that must be converted to JSON
  49. * Example: var json_string = array2json(['e', {pluribus: 'unum'}]);
  50. * var json = array2json({"success":"Sweet","failure":false,"empty_array":[],"numbers":[1,2,3],"info":{"name":"Binny","site":"http:\/\/www.openjs.com\/"}});
  51. * http://www.openjs.com/scripts/data/json_encode.php
  52. */
  53. function array2json(arr) {
  54. var parts = [];
  55. var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');
  56. for(var key in arr) {
  57. var value = arr[key];
  58. if(typeof value == "object") { //Custom handling for arrays
  59. if(is_list) parts.push(array2json(value)); /* :RECURSION: */
  60. else parts[key] = array2json(value); /* :RECURSION: */
  61. } else {
  62. var str = "";
  63. if(!is_list) str = '"' + key + '":';
  64. //Custom handling for multiple data types
  65. if(typeof value == "number") str += value; //Numbers
  66. else if(value === false) str += 'false'; //The booleans
  67. else if(value === true) str += 'true';
  68. else str += '"' + value + '"'; //All other things
  69. // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)
  70. parts.push(str);
  71. }
  72. }
  73. var json = parts.join(",");
  74. if(is_list) return '[' + json + ']';//Return numerical JSON
  75. return '{' + json + '}';//Return associative JSON
  76. }
  77. function isInteger(s) {
  78. return (s.toString().search(/^-?[0-9]+$/) == 0);
  79. }
  80. function inArray(array, p_val) {
  81. var l = array.length;
  82. for(var i = 0; i < l; i++) {
  83. if(array[i] == p_val) {
  84. return true;
  85. }
  86. }
  87. return false;
  88. }
  89. if(typeof(String.prototype.trim) === "undefined")
  90. {
  91. String.prototype.trim = function()
  92. {
  93. return String(this).replace(/^\s+|\s+$/g, '');
  94. };
  95. }
  96. $(document).ready(function(){
  97. // Affichage un/des embed
  98. $('a.element_embed_open_link').click(function(){
  99. $(this).parent('li.element').find('a.element_embed_open_link').hide();
  100. $(this).parent('li.element').find('a.element_embed_close_link').show();
  101. $(this).parent('li.element').find('div.element_embed').show();
  102. return false;
  103. });
  104. // Fermeture du embed si demandé
  105. $('a.element_embed_close_link').click(function(){
  106. $(this).parent('li.element').find('a.element_embed_open_link').show();
  107. $(this).parent('li.element').find('a.element_embed_close_link').hide();
  108. $(this).parent('li.element').find('div.element_embed').hide();
  109. return false;
  110. });
  111. });