materio_search_api_ajax.min.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. // * date 2011/10/19 *
  2. /**
  3. * misc
  4. */
  5. // ------ TRACE ------
  6. function trace(s,o){
  7. if(window.console && window.console.debug){
  8. arguments.length === 2 ? window.console.debug(s,o) : window.console.debug(s);
  9. }else if(console && console.log){
  10. arguments.length === 2 ? console.log(s,o) : console.log(s);
  11. }
  12. };
  13. // ------ LOADJSCSSFILE ------
  14. function loadjscssfile(filename, filetype){
  15. if (filetype=="js"){ //if filename is a external JavaScript file
  16. var fileref=document.createElement('script')
  17. fileref.setAttribute("type","text/javascript")
  18. fileref.setAttribute("src", filename)
  19. }
  20. else if (filetype=="css"){ //if filename is an external CSS file
  21. var fileref=document.createElement("link")
  22. fileref.setAttribute("rel", "stylesheet")
  23. fileref.setAttribute("type", "text/css")
  24. fileref.setAttribute("href", filename)
  25. }
  26. if (typeof fileref!="undefined")
  27. document.getElementsByTagName("head")[0].appendChild(fileref)
  28. };
  29. // ------ TIMEOUT
  30. function Timeout(fn, interval) {
  31. var id = setTimeout(fn, interval);
  32. this.cleared = false;
  33. this.clear = function () {
  34. this.cleared = true;
  35. clearTimeout(id);
  36. };
  37. }
  38. // ------ HEXTORGB convert hex to rgb color ------
  39. function HexToRGB(h){
  40. if(h.charAt(0)=="#"){
  41. var coul = h.substring(1,7);
  42. var r = parseInt(coul.substring(0,2),16);
  43. var g = parseInt(coul.substring(2,4),16);
  44. var b = parseInt(coul.substring(4,6),16);
  45. return 'rgb('+r+', '+g+', '+b+')';
  46. }else{
  47. return null;
  48. }
  49. }
  50. // ------ PAIR check if number is pair of impair ------
  51. function pair(n){return typeof n=='number'?(n%2==0?true:false):null;}
  52. // ------ RANDOM ------
  53. function random(n1,n2){
  54. return arguments.length === 1 && typeof n1 === 'number'? Math.random()*n1 : ( arguments.length === 2 && typeof n1 === typeof n2 && typeof n1 === 'number' ? n1 + Math.random()*(n2-n1) : NaN );
  55. }
  56. function randomInt(n1,n2){
  57. var rand = arguments.length === 1 && typeof n1 === 'number'? Math.random()*n1 : ( arguments.length === 2 && typeof n1 === typeof n2 && typeof n1 === 'number' ? n1 + Math.random()*(n2-n1) : NaN );
  58. return parseInt(rand);
  59. }
  60. // ------ ROUNDED ------
  61. function round(n,granularity){
  62. if(arguments.length == 1){
  63. n = Math.round(n);
  64. }else{
  65. granularity = granularity.toString();
  66. granularity = granularity.replace(/./gi, 0);
  67. granularity = granularity.replace(/^./gi, 1);
  68. granularity = parseInt(granularity);
  69. n = Math.round(n*granularity)/granularity;
  70. }
  71. return n;
  72. }
  73. // ------ FLOOR ------
  74. function floor(n,granularity){
  75. if(arguments.length == 1){
  76. n = Math.floor(n);
  77. }else{
  78. granularity = granularity.toString();
  79. granularity = granularity.replace(/./gi, 0);
  80. granularity = granularity.replace(/^./gi, 1);
  81. granularity = parseInt(granularity);
  82. n = Math.floor(n*granularity)/granularity;
  83. }
  84. return n;
  85. }
  86. // ------ CEIL ------
  87. function ceil(n,granularity){
  88. if(arguments.length == 1){
  89. n = Math.ceil(n);
  90. }else{
  91. granularity = granularity.toString();
  92. granularity = granularity.replace(/./gi, 0);
  93. granularity = granularity.replace(/^./gi, 1);
  94. granularity = parseInt(granularity);
  95. n = Math.ceil(n*granularity)/granularity;
  96. }
  97. return n;
  98. }
  99. /**
  100. * String
  101. */
  102. // ------ TRIM remove multiple, leading or trailing spaces ------
  103. String.prototype.trim = function() {
  104. return this.replace(/(^\s*)|(\s*$)/gi,"").replace(/[ ]{2,}/gi," ").replace(/\n /,"\n");
  105. }
  106. // ------ remove all accents, for sort() by example ------
  107. var Latinise={};Latinise.latin_map={"Á":"A","Ă":"A","Ắ":"A","Ặ":"A","Ằ":"A","Ẳ":"A","Ẵ":"A","Ǎ":"A","Â":"A","Ấ":"A","Ậ":"A","Ầ":"A","Ẩ":"A","Ẫ":"A","Ä":"A","Ǟ":"A","Ȧ":"A","Ǡ":"A","Ạ":"A","Ȁ":"A","À":"A","Ả":"A","Ȃ":"A","Ā":"A","Ą":"A","Å":"A","Ǻ":"A","Ḁ":"A","Ⱥ":"A","Ã":"A","Ꜳ":"AA","Æ":"AE","Ǽ":"AE","Ǣ":"AE","Ꜵ":"AO","Ꜷ":"AU","Ꜹ":"AV","Ꜻ":"AV","Ꜽ":"AY","Ḃ":"B","Ḅ":"B","Ɓ":"B","Ḇ":"B","Ƀ":"B","Ƃ":"B","Ć":"C","Č":"C","Ç":"C","Ḉ":"C","Ĉ":"C","Ċ":"C","Ƈ":"C","Ȼ":"C","Ď":"D","Ḑ":"D","Ḓ":"D","Ḋ":"D","Ḍ":"D","Ɗ":"D","Ḏ":"D","Dz":"D","Dž":"D","Đ":"D","Ƌ":"D","DZ":"DZ","DŽ":"DZ","É":"E","Ĕ":"E","Ě":"E","Ȩ":"E","Ḝ":"E","Ê":"E","Ế":"E","Ệ":"E","Ề":"E","Ể":"E","Ễ":"E","Ḙ":"E","Ë":"E","Ė":"E","Ẹ":"E","Ȅ":"E","È":"E","Ẻ":"E","Ȇ":"E","Ē":"E","Ḗ":"E","Ḕ":"E","Ę":"E","Ɇ":"E","Ẽ":"E","Ḛ":"E","Ꝫ":"ET","Ḟ":"F","Ƒ":"F","Ǵ":"G","Ğ":"G","Ǧ":"G","Ģ":"G","Ĝ":"G","Ġ":"G","Ɠ":"G","Ḡ":"G","Ǥ":"G","Ḫ":"H","Ȟ":"H","Ḩ":"H","Ĥ":"H","Ⱨ":"H","Ḧ":"H","Ḣ":"H","Ḥ":"H","Ħ":"H","Í":"I","Ĭ":"I","Ǐ":"I","Î":"I","Ï":"I","Ḯ":"I","İ":"I","Ị":"I","Ȉ":"I","Ì":"I","Ỉ":"I","Ȋ":"I","Ī":"I","Į":"I","Ɨ":"I","Ĩ":"I","Ḭ":"I","Ꝺ":"D","Ꝼ":"F","Ᵹ":"G","Ꞃ":"R","Ꞅ":"S","Ꞇ":"T","Ꝭ":"IS","Ĵ":"J","Ɉ":"J","Ḱ":"K","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":"W","ʏ":"Y","ᴢ":"Z","á":"a","ă":"a","ắ":"a","ặ":"a","ằ":"a","ẳ":"a","ẵ":"a","ǎ":"a","â":"a","ấ":"a","ậ":"a","ầ":"a","ẩ":"a","ẫ":"a","ä":"a","ǟ":"a","ȧ":"a","ǡ":"a","ạ":"a","ȁ":"a","à":"a","ả":"a","ȃ":"a","ā":"a","ą":"a","ᶏ":"a","ẚ":"a","å":"a","ǻ":"a","ḁ":"a","ⱥ":"a","ã":"a","ꜳ":"aa","æ":"ae","ǽ":"ae","ǣ":"ae","ꜵ":"ao","ꜷ":"au","ꜹ":"av","ꜻ":"av","ꜽ":"ay","ḃ":"b","ḅ":"b","ɓ":"b","ḇ":"b","ᵬ":"b","ᶀ":"b","ƀ":"b","ƃ":"b","ɵ":"o","ć":"c","č":"c","ç":"c","ḉ":"c","ĉ":"c","ɕ":"c","ċ":"c","ƈ":"c","ȼ":"c","ď":"d","ḑ":"d","ḓ":"d","ȡ":"d","ḋ":"d","ḍ":"d","ɗ":"d","ᶑ":"d","ḏ":"d","ᵭ":"d","ᶁ":"d","đ":"d","ɖ":"d","ƌ":"d","ı":"i","ȷ":"j","ɟ":"j","ʄ":"j","dz":"dz","dž":"dz","é":"e","ĕ":"e","ě":"e","ȩ":"e","ḝ":"e","ê":"e","ế":"e","ệ":"e","ề":"e","ể":"e","ễ":"e","ḙ":"e","ë":"e","ė":"e","ẹ":"e","ȅ":"e","è":"e","ẻ":"e","ȇ":"e","ē":"e","ḗ":"e","ḕ":"e","ⱸ":"e","ę":"e","ᶒ":"e","ɇ":"e","ẽ":"e","ḛ":"e","ꝫ":"et","ḟ":"f","ƒ":"f","ᵮ":"f","ᶂ":"f","ǵ":"g","ğ":"g","ǧ":"g","ģ":"g","ĝ":"g","ġ":"g","ɠ":"g","ḡ":"g","ᶃ":"g","ǥ":"g","ḫ":"h","ȟ":"h","ḩ":"h","ĥ":"h","ⱨ":"h","ḧ":"h","ḣ":"h","ḥ":"h","ɦ":"h","ẖ":"h","ħ":"h","ƕ":"hv","í":"i","ĭ":"i","ǐ":"i","î":"i","ï":"i","ḯ":"i","ị":"i","ȉ":"i","ì":"i","ỉ":"i","ȋ":"i","ī":"i","į":"i","ᶖ":"i","ɨ":"i","ĩ":"i","ḭ":"i","ꝺ":"d","ꝼ":"f","ᵹ":"g","ꞃ":"r","ꞅ":"s","ꞇ":"t","ꝭ":"is","ǰ":"j","ĵ":"j","ʝ":"j","ɉ":"j","ḱ":"k","ǩ":"k","ķ":"k","ⱪ":"k","ꝃ":"k","ḳ":"k","ƙ":"k","ḵ":"k","ᶄ":"k","ꝁ":"k","ꝅ":"k","ĺ":"l","ƚ":"l","ɬ":"l","ľ":"l","ļ":"l","ḽ":"l","ȴ":"l","ḷ":"l","ḹ":"l","ⱡ":"l","ꝉ":"l","ḻ":"l","ŀ":"l","ɫ":"l","ᶅ":"l","ɭ":"l","ł":"l","lj":"lj","ſ":"s","ẜ":"s","ẛ":"s","ẝ":"s","ḿ":"m","ṁ":"m","ṃ":"m","ɱ":"m","ᵯ":"m","ᶆ":"m","ń":"n","ň":"n","ņ":"n","ṋ":"n","ȵ":"n","ṅ":"n","ṇ":"n","ǹ":"n","ɲ":"n","ṉ":"n","ƞ":"n","ᵰ":"n","ᶇ":"n","ɳ":"n","ñ":"n","nj":"nj","ó":"o","ŏ":"o","ǒ":"o","ô":"o","ố":"o","ộ":"o","ồ":"o","ổ":"o","ỗ":"o","ö":"o","ȫ":"o","ȯ":"o","ȱ":"o","ọ":"o","ő":"o","ȍ":"o","ò":"o","ỏ":"o","ơ":"o","ớ":"o","ợ":"o","ờ":"o","ở":"o","ỡ":"o","ȏ":"o","ꝋ":"o","ꝍ":"o","ⱺ":"o","ō":"o","ṓ":"o","ṑ":"o","ǫ":"o","ǭ":"o","ø":"o","ǿ":"o","õ":"o","ṍ":"o","ṏ":"o","ȭ":"o","ƣ":"oi","ꝏ":"oo","ɛ":"e","ᶓ":"e","ɔ":"o","ᶗ":"o","ȣ":"ou","ṕ":"p","ṗ":"p","ꝓ":"p","ƥ":"p","ᵱ":"p","ᶈ":"p","ꝕ":"p","ᵽ":"p","ꝑ":"p","ꝙ":"q","ʠ":"q","ɋ":"q","ꝗ":"q","ŕ":"r","ř":"r","ŗ":"r","ṙ":"r","ṛ":"r","ṝ":"r","ȑ":"r","ɾ":"r","ᵳ":"r","ȓ":"r","ṟ":"r","ɼ":"r","ᵲ":"r","ᶉ":"r","ɍ":"r","ɽ":"r","ↄ":"c","ꜿ":"c","ɘ":"e","ɿ":"r","ś":"s","ṥ":"s","š":"s","ṧ":"s","ş":"s","ŝ":"s","ș":"s","ṡ":"s","ṣ":"s","ṩ":"s","ʂ":"s","ᵴ":"s","ᶊ":"s","ȿ":"s","ɡ":"g","ᴑ":"o","ᴓ":"o","ᴝ":"u","ť":"t","ţ":"t","ṱ":"t","ț":"t","ȶ":"t","ẗ":"t","ⱦ":"t","ṫ":"t","ṭ":"t","ƭ":"t","ṯ":"t","ᵵ":"t","ƫ":"t","ʈ":"t","ŧ":"t","ᵺ":"th","ɐ":"a","ᴂ":"ae","ǝ":"e","ᵷ":"g","ɥ":"h","ʮ":"h","ʯ":"h","ᴉ":"i","ʞ":"k","ꞁ":"l","ɯ":"m","ɰ":"m","ᴔ":"oe","ɹ":"r","ɻ":"r","ɺ":"r","ⱹ":"r","ʇ":"t","ʌ":"v","ʍ":"w","ʎ":"y","ꜩ":"tz","ú":"u","ŭ":"u","ǔ":"u","û":"u","ṷ":"u","ü":"u","ǘ":"u","ǚ":"u","ǜ":"u","ǖ":"u","ṳ":"u","ụ":"u","ű":"u","ȕ":"u","ù":"u","ủ":"u","ư":"u","ứ":"u","ự":"u","ừ":"u","ử":"u","ữ":"u","ȗ":"u","ū":"u","ṻ":"u","ų":"u","ᶙ":"u","ů":"u","ũ":"u","ṹ":"u","ṵ":"u","ᵫ":"ue","ꝸ":"um","ⱴ":"v","ꝟ":"v","ṿ":"v","ʋ":"v","ᶌ":"v","ⱱ":"v","ṽ":"v","ꝡ":"vy","ẃ":"w","ŵ":"w","ẅ":"w","ẇ":"w","ẉ":"w","ẁ":"w","ⱳ":"w","ẘ":"w","ẍ":"x","ẋ":"x","ᶍ":"x","ý":"y","ŷ":"y","ÿ":"y","ẏ":"y","ỵ":"y","ỳ":"y","ƴ":"y","ỷ":"y","ỿ":"y","ȳ":"y","ẙ":"y","ɏ":"y","ỹ":"y","ź":"z","ž":"z","ẑ":"z","ʑ":"z","ⱬ":"z","ż":"z","ẓ":"z","ȥ":"z","ẕ":"z","ᵶ":"z","ᶎ":"z","ʐ":"z","ƶ":"z","ɀ":"z","ff":"ff","ffi":"ffi","ffl":"ffl","fi":"fi","fl":"fl","ij":"ij","œ":"oe","st":"st","ₐ":"a","ₑ":"e","ᵢ":"i","ⱼ":"j","ₒ":"o","ᵣ":"r","ᵤ":"u","ᵥ":"v","ₓ":"x"};
  108. String.prototype.latinise=function(){return this.replace(/[^A-Za-z0-9\[\] ]/g,function(a){return Latinise.latin_map[a]||a})};
  109. String.prototype.latinize=String.prototype.latinise;
  110. String.prototype.isLatin=function(){return this==this.latinise()}
  111. /**
  112. * Array
  113. */
  114. // ------ UNIQUE reduces duplicates ------
  115. array_unique = function(ar){
  116. var r = new Array();
  117. o:for(var i = 0, n = ar.length; i < n; i++)
  118. {
  119. for(var x = 0, y = r.length; x < y; x++)
  120. {
  121. if(r[x]==ar[i])
  122. {
  123. continue o;
  124. }
  125. }
  126. r[r.length] = ar[i];
  127. }
  128. return r;
  129. };
  130. // ------ SUBSTRACT substract two array ------
  131. array_subtract = function(ara1,ara2) {
  132. var aRes = new Array() ;
  133. for (var i = ara1.length-1; i >= 0; i--)
  134. if(array_contains(ara2,ara1[i]))
  135. aRes.push(ara1[i]);
  136. return aRes ;
  137. }
  138. /*
  139. SHUFFLE Add a shuffle function to Array object prototype
  140. author: Stephane Roucheray
  141. src: http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/
  142. found 2011/09/08.
  143. */
  144. array_shuffle = function(ar){
  145. var i = ar.length, j, temp;
  146. if ( i == 0 ) return;
  147. while ( --i ) {
  148. j = Math.floor( Math.random() * ( i + 1 ) );
  149. temp = ar[i];
  150. ar[i] = ar[j];
  151. ar[j] = temp;
  152. }
  153. return ar;
  154. };
  155. // ------ CONTAINS ------
  156. array_contains = function(ar, obj) {
  157. var i = ar.length;
  158. while (i--)
  159. if (ar[i] === obj)
  160. return true;
  161. return false;
  162. };
  163. // ------ REMOVE ------
  164. // /!\ Found on the Internet, not sure of efficiency.
  165. // Array.prototype.remove = function(v) {
  166. // var x, _i, _len, _results;
  167. // _results = [];
  168. // for (_i = 0, _len = this.length; _i < _len; _i++) {
  169. // x = this[_i];
  170. // if (x !== v) {
  171. // _results.push(x);
  172. // }
  173. // }
  174. // return _results;
  175. // };
  176. array_remove = function(ar){
  177. var what, a= arguments, L= a.length, ax;
  178. while(L && ar.length){
  179. what= a[--L];
  180. while((ax= ar.indexOf(what))!= -1){
  181. ar.splice(ax, 1);
  182. }
  183. }
  184. return ar;
  185. };
  186. // for IE
  187. // if(!Array.prototype.indexOf){
  188. // Array.prototype.indexOf= function(what, i){
  189. // i= i || 0;
  190. // var L= this.length;
  191. // while(i< L){
  192. // if(this[i]=== what) return i;
  193. // ++i;
  194. // }
  195. // return -1;
  196. // };
  197. // }
  198. array_indexOf = function(ar, what, i){
  199. i= i || 0;
  200. var L= ar.length;
  201. while(i< L){
  202. if(ar[i]=== what) return i;
  203. ++i;
  204. }
  205. return -1;
  206. };
  207. // ------ SUBSTRACT substract two array ------
  208. function array_subtract(ara1,ara2) {
  209. var aRes = new Array() ;
  210. for (var i = ara1.length-1; i >= 0; i--)
  211. if( !array_contains(ara1[i],ara2) )
  212. aRes.push(ara1[i]);
  213. return aRes ;
  214. };
  215. /**
  216. * Objects
  217. *
  218. */
  219. // ------ OBJECTSIZE get the length of objects ------
  220. function objectSize(o) {
  221. var len = o.length ? --o.length : 0;
  222. for (var k in o)
  223. len++;
  224. return len;
  225. }
  226. // Object.prototype.size = function () {
  227. // // var len = this.length ? --this.length : -1; // POURQUOI NE FONCTIONNE PAS?
  228. // var len = this.length ? --this.length : -2;
  229. // for (var k in this)
  230. // len++;
  231. // return len;
  232. // }
  233. function objectIsEmpty(obj){
  234. for (var prop in obj) {
  235. if (obj.hasOwnProperty(prop))
  236. return false;
  237. }
  238. return true;
  239. };
  240. // ------ OBJECTGETKEY get key of index ------
  241. function objectGetKey(o,index){
  242. var i = 0;
  243. for (var k in o){
  244. if (k === 'length' || !o.hasOwnProperty(k))
  245. continue;
  246. if(i == index)
  247. return k;
  248. i ++;
  249. }
  250. }
  251. // Object.prototype.getKey = function(index){
  252. // var i = 0;
  253. // for (var key in this){
  254. // if (key === 'length' || !this.hasOwnProperty(key))
  255. // continue;
  256. // if(i == index)
  257. // return key;
  258. // i ++;
  259. // }
  260. // }
  261. // ------ OBJECTSORT sort object ------
  262. function objectSort(o,value) {
  263. var connection = new Array();
  264. for (var i = objectSize(o) - 1; i >= 0; i--){
  265. var k = objectGetKey(o,i);
  266. for (var j = objectSize(o[k].wit) - 1; j >= 0; j--){
  267. var k2 = objectGetKey(o[k].wit,j);
  268. if (k2==value) {
  269. var the_wit = parseFloat(o[k].wit[k2]);
  270. connection.push( {wit:the_wit,nid:k} );
  271. };
  272. };
  273. };
  274. connection.sort(function(a,b){
  275. // return (a.wit - b.wit);//ascending
  276. return (b.wit - a.wit);//descending
  277. });
  278. var o_sort = {};
  279. for (var i = connection.length - 1; i >= 0; i--){
  280. // o_sort[connection[i].wit+'-'+connection[i].nid] = o[connection[i].nid];
  281. o_sort[connection[i].nid] = o[connection[i].nid];
  282. };
  283. return o_sort;
  284. }
  285. /**
  286. * trigo
  287. */
  288. // -------- getElementAngle ----------
  289. // L'angle 0 correspond au nord (vers le haut)
  290. // Exemple : getElementAngle(posElementX, posElementY, posSourisX, posSourisY)
  291. // Ceci retournera l'angle de l'élément par rapport à la position de la souris
  292. function getElementAngle(x1, y1, x2, y2) {
  293. var adj = x2 - x1;
  294. var opp = y2 - y1;
  295. var angle = Math.abs(Math.atan(opp/adj) * 180/Math.PI);
  296. if (adj > 0 && opp < 0 ) {
  297. angle = 90 - angle;
  298. }
  299. else if (adj >= 0 && opp >= 0) {
  300. angle += 90;
  301. }
  302. else if (adj < 0 && opp >= 0) {
  303. angle = 180 + (90 - angle);
  304. }
  305. else {
  306. angle += 270;
  307. }
  308. return angle;
  309. }
  310. // * date 2011/10/19 *
  311. /**
  312. * misc
  313. */
  314. // ------ TRACE ------
  315. function trace(s,o){
  316. if(window.console && window.console.debug){
  317. arguments.length === 2 ? window.console.debug(s,o) : window.console.debug(s);
  318. }else if(window.console && window.console.log){
  319. arguments.length === 2 ? window.console.log(s,o) : window.console.log(s);
  320. }
  321. };
  322. // ------ LOADJSCSSFILE ------
  323. function loadjscssfile(filename, filetype){
  324. if (filetype=="js"){ //if filename is a external JavaScript file
  325. var fileref=document.createElement('script')
  326. fileref.setAttribute("type","text/javascript")
  327. fileref.setAttribute("src", filename)
  328. }
  329. else if (filetype=="css"){ //if filename is an external CSS file
  330. var fileref=document.createElement("link")
  331. fileref.setAttribute("rel", "stylesheet")
  332. fileref.setAttribute("type", "text/css")
  333. fileref.setAttribute("href", filename)
  334. }
  335. if (typeof fileref!="undefined")
  336. document.getElementsByTagName("head")[0].appendChild(fileref)
  337. }
  338. // ------ TIMEOUT
  339. function Timeout(fn, interval) {
  340. var id = setTimeout(fn, interval);
  341. this.cleared = false;
  342. this.clear = function () {
  343. this.cleared = true;
  344. clearTimeout(id);
  345. };
  346. }
  347. // ------ HEXTORGB convert hex to rgb color ------
  348. function HexToRGB(h){
  349. if(h.charAt(0)=="#"){
  350. var coul = h.substring(1,7);
  351. var r = parseInt(coul.substring(0,2),16);
  352. var g = parseInt(coul.substring(2,4),16);
  353. var b = parseInt(coul.substring(4,6),16);
  354. return 'rgb('+r+', '+g+', '+b+')';
  355. }else{
  356. return null;
  357. }
  358. }
  359. // ------ PAIR check if number is pair of impair ------
  360. function pair(n){return typeof n=='number'?(n%2==0?true:false):null;}
  361. // ------ RANDOM ------
  362. function random(n1,n2){
  363. return arguments.length === 1 && typeof n1 === 'number'? Math.random()*n1 : ( arguments.length === 2 && typeof n1 === typeof n2 && typeof n1 === 'number' ? n1 + Math.random()*(n2-n1) : NaN );
  364. }
  365. function randomInt(n1,n2){
  366. var rand = arguments.length === 1 && typeof n1 === 'number'? Math.random()*n1 : ( arguments.length === 2 && typeof n1 === typeof n2 && typeof n1 === 'number' ? n1 + Math.random()*(n2-n1) : NaN );
  367. return parseInt(rand);
  368. }
  369. // ------ ROUNDED ------
  370. function round(n,granularity){
  371. if(arguments.length == 1){
  372. n = Math.round(n);
  373. }else{
  374. granularity = granularity.toString();
  375. granularity = granularity.replace(/./gi, 0);
  376. granularity = granularity.replace(/^./gi, 1);
  377. granularity = parseInt(granularity);
  378. n = Math.round(n*granularity)/granularity;
  379. }
  380. return n;
  381. }
  382. // ------ FLOOR ------
  383. function floor(n,granularity){
  384. if(arguments.length == 1){
  385. n = Math.floor(n);
  386. }else{
  387. granularity = granularity.toString();
  388. granularity = granularity.replace(/./gi, 0);
  389. granularity = granularity.replace(/^./gi, 1);
  390. granularity = parseInt(granularity);
  391. n = Math.floor(n*granularity)/granularity;
  392. }
  393. return n;
  394. }
  395. // ------ CEIL ------
  396. function ceil(n,granularity){
  397. if(arguments.length == 1){
  398. n = Math.ceil(n);
  399. }else{
  400. granularity = granularity.toString();
  401. granularity = granularity.replace(/./gi, 0);
  402. granularity = granularity.replace(/^./gi, 1);
  403. granularity = parseInt(granularity);
  404. n = Math.ceil(n*granularity)/granularity;
  405. }
  406. return n;
  407. }
  408. /**
  409. * String
  410. */
  411. // ------ TRIM remove multiple, leading or trailing spaces ------
  412. String.prototype.trim = function() {
  413. return this.replace(/(^\s*)|(\s*$)/gi,"").replace(/[ ]{2,}/gi," ").replace(/\n /,"\n");
  414. }
  415. // ------ remove all accents, for sort() by example ------
  416. var Latinise={};Latinise.latin_map={"Á":"A","Ă":"A","Ắ":"A","Ặ":"A","Ằ":"A","Ẳ":"A","Ẵ":"A","Ǎ":"A","Â":"A","Ấ":"A","Ậ":"A","Ầ":"A","Ẩ":"A","Ẫ":"A","Ä":"A","Ǟ":"A","Ȧ":"A","Ǡ":"A","Ạ":"A","Ȁ":"A","À":"A","Ả":"A","Ȃ":"A","Ā":"A","Ą":"A","Å":"A","Ǻ":"A","Ḁ":"A","Ⱥ":"A","Ã":"A","Ꜳ":"AA","Æ":"AE","Ǽ":"AE","Ǣ":"AE","Ꜵ":"AO","Ꜷ":"AU","Ꜹ":"AV","Ꜻ":"AV","Ꜽ":"AY","Ḃ":"B","Ḅ":"B","Ɓ":"B","Ḇ":"B","Ƀ":"B","Ƃ":"B","Ć":"C","Č":"C","Ç":"C","Ḉ":"C","Ĉ":"C","Ċ":"C","Ƈ":"C","Ȼ":"C","Ď":"D","Ḑ":"D","Ḓ":"D","Ḋ":"D","Ḍ":"D","Ɗ":"D","Ḏ":"D","Dz":"D","Dž":"D","Đ":"D","Ƌ":"D","DZ":"DZ","DŽ":"DZ","É":"E","Ĕ":"E","Ě":"E","Ȩ":"E","Ḝ":"E","Ê":"E","Ế":"E","Ệ":"E","Ề":"E","Ể":"E","Ễ":"E","Ḙ":"E","Ë":"E","Ė":"E","Ẹ":"E","Ȅ":"E","È":"E","Ẻ":"E","Ȇ":"E","Ē":"E","Ḗ":"E","Ḕ":"E","Ę":"E","Ɇ":"E","Ẽ":"E","Ḛ":"E","Ꝫ":"ET","Ḟ":"F","Ƒ":"F","Ǵ":"G","Ğ":"G","Ǧ":"G","Ģ":"G","Ĝ":"G","Ġ":"G","Ɠ":"G","Ḡ":"G","Ǥ":"G","Ḫ":"H","Ȟ":"H","Ḩ":"H","Ĥ":"H","Ⱨ":"H","Ḧ":"H","Ḣ":"H","Ḥ":"H","Ħ":"H","Í":"I","Ĭ":"I","Ǐ":"I","Î":"I","Ï":"I","Ḯ":"I","İ":"I","Ị":"I","Ȉ":"I","Ì":"I","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":"L","ᴍ":"M","ɴ":"N","ᴏ":"O","ɶ":"OE","ᴐ":"O","ᴕ":"OU","ᴘ":"P","ʀ":"R","ᴎ":"N","ᴙ":"R","ꜱ":"S","ᴛ":"T","ⱻ":"E","ᴚ":"R","ᴜ":"U","ᴠ":"V","ᴡ":"W","ʏ":"Y","ᴢ":"Z","á":"a","ă":"a","ắ":"a","ặ":"a","ằ":"a","ẳ":"a","ẵ":"a","ǎ":"a","â":"a","ấ":"a","ậ":"a","ầ":"a","ẩ":"a","ẫ":"a","ä":"a","ǟ":"a","ȧ":"a","ǡ":"a","ạ":"a","ȁ":"a","à":"a","ả":"a","ȃ":"a","ā":"a","ą":"a","ᶏ":"a","ẚ":"a","å":"a","ǻ":"a","ḁ":"a","ⱥ":"a","ã":"a","ꜳ":"aa","æ":"ae","ǽ":"ae","ǣ":"ae","ꜵ":"ao","ꜷ":"au","ꜹ":"av","ꜻ":"av","ꜽ":"ay","ḃ":"b","ḅ":"b","ɓ":"b","ḇ":"b","ᵬ":"b","ᶀ":"b","ƀ":"b","ƃ":"b","ɵ":"o","ć":"c","č":"c","ç":"c","ḉ":"c","ĉ":"c","ɕ":"c","ċ":"c","ƈ":"c","ȼ":"c","ď":"d","ḑ":"d","ḓ":"d","ȡ":"d","ḋ":"d","ḍ":"d","ɗ":"d","ᶑ":"d","ḏ":"d","ᵭ":"d","ᶁ":"d","đ":"d","ɖ":"d","ƌ":"d","ı":"i","ȷ":"j","ɟ":"j","ʄ":"j","dz":"dz","dž":"dz","é":"e","ĕ":"e","ě":"e","ȩ":"e","ḝ":"e","ê":"e","ế":"e","ệ":"e","ề":"e","ể":"e","ễ":"e","ḙ":"e","ë":"e","ė":"e","ẹ":"e","ȅ":"e","è":"e","ẻ":"e","ȇ":"e","ē":"e","ḗ":"e","ḕ":"e","ⱸ":"e","ę":"e","ᶒ":"e","ɇ":"e","ẽ":"e","ḛ":"e","ꝫ":"et","ḟ":"f","ƒ":"f","ᵮ":"f","ᶂ":"f","ǵ":"g","ğ":"g","ǧ":"g","ģ":"g","ĝ":"g","ġ":"g","ɠ":"g","ḡ":"g","ᶃ":"g","ǥ":"g","ḫ":"h","ȟ":"h","ḩ":"h","ĥ":"h","ⱨ":"h","ḧ":"h","ḣ":"h","ḥ":"h","ɦ":"h","ẖ":"h","ħ":"h","ƕ":"hv","í":"i","ĭ":"i","ǐ":"i","î":"i","ï":"i","ḯ":"i","ị":"i","ȉ":"i","ì":"i","ỉ":"i","ȋ":"i","ī":"i","į":"i","ᶖ":"i","ɨ":"i","ĩ":"i","ḭ":"i","ꝺ":"d","ꝼ":"f","ᵹ":"g","ꞃ":"r","ꞅ":"s","ꞇ":"t","ꝭ":"is","ǰ":"j","ĵ":"j","ʝ":"j","ɉ":"j","ḱ":"k","ǩ":"k","ķ":"k","ⱪ":"k","ꝃ":"k","ḳ":"k","ƙ":"k","ḵ":"k","ᶄ":"k","ꝁ":"k","ꝅ":"k","ĺ":"l","ƚ":"l","ɬ":"l","ľ":"l","ļ":"l","ḽ":"l","ȴ":"l","ḷ":"l","ḹ":"l","ⱡ":"l","ꝉ":"l","ḻ":"l","ŀ":"l","ɫ":"l","ᶅ":"l","ɭ":"l","ł":"l","lj":"lj","ſ":"s","ẜ":"s","ẛ":"s","ẝ":"s","ḿ":"m","ṁ":"m","ṃ":"m","ɱ":"m","ᵯ":"m","ᶆ":"m","ń":"n","ň":"n","ņ":"n","ṋ":"n","ȵ":"n","ṅ":"n","ṇ":"n","ǹ":"n","ɲ":"n","ṉ":"n","ƞ":"n","ᵰ":"n","ᶇ":"n","ɳ":"n","ñ":"n","nj":"nj","ó":"o","ŏ":"o","ǒ":"o","ô":"o","ố":"o","ộ":"o","ồ":"o","ổ":"o","ỗ":"o","ö":"o","ȫ":"o","ȯ":"o","ȱ":"o","ọ":"o","ő":"o","ȍ":"o","ò":"o","ỏ":"o","ơ":"o","ớ":"o","ợ":"o","ờ":"o","ở":"o","ỡ":"o","ȏ":"o","ꝋ":"o","ꝍ":"o","ⱺ":"o","ō":"o","ṓ":"o","ṑ":"o","ǫ":"o","ǭ":"o","ø":"o","ǿ":"o","õ":"o","ṍ":"o","ṏ":"o","ȭ":"o","ƣ":"oi","ꝏ":"oo","ɛ":"e","ᶓ":"e","ɔ":"o","ᶗ":"o","ȣ":"ou","ṕ":"p","ṗ":"p","ꝓ":"p","ƥ":"p","ᵱ":"p","ᶈ":"p","ꝕ":"p","ᵽ":"p","ꝑ":"p","ꝙ":"q","ʠ":"q","ɋ":"q","ꝗ":"q","ŕ":"r","ř":"r","ŗ":"r","ṙ":"r","ṛ":"r","ṝ":"r","ȑ":"r","ɾ":"r","ᵳ":"r","ȓ":"r","ṟ":"r","ɼ":"r","ᵲ":"r","ᶉ":"r","ɍ":"r","ɽ":"r","ↄ":"c","ꜿ":"c","ɘ":"e","ɿ":"r","ś":"s","ṥ":"s","š":"s","ṧ":"s","ş":"s","ŝ":"s","ș":"s","ṡ":"s","ṣ":"s","ṩ":"s","ʂ":"s","ᵴ":"s","ᶊ":"s","ȿ":"s","ɡ":"g","ᴑ":"o","ᴓ":"o","ᴝ":"u","ť":"t","ţ":"t","ṱ":"t","ț":"t","ȶ":"t","ẗ":"t","ⱦ":"t","ṫ":"t","ṭ":"t","ƭ":"t","ṯ":"t","ᵵ":"t","ƫ":"t","ʈ":"t","ŧ":"t","ᵺ":"th","ɐ":"a","ᴂ":"ae","ǝ":"e","ᵷ":"g","ɥ":"h","ʮ":"h","ʯ":"h","ᴉ":"i","ʞ":"k","ꞁ":"l","ɯ":"m","ɰ":"m","ᴔ":"oe","ɹ":"r","ɻ":"r","ɺ":"r","ⱹ":"r","ʇ":"t","ʌ":"v","ʍ":"w","ʎ":"y","ꜩ":"tz","ú":"u","ŭ":"u","ǔ":"u","û":"u","ṷ":"u","ü":"u","ǘ":"u","ǚ":"u","ǜ":"u","ǖ":"u","ṳ":"u","ụ":"u","ű":"u","ȕ":"u","ù":"u","ủ":"u","ư":"u","ứ":"u","ự":"u","ừ":"u","ử":"u","ữ":"u","ȗ":"u","ū":"u","ṻ":"u","ų":"u","ᶙ":"u","ů":"u","ũ":"u","ṹ":"u","ṵ":"u","ᵫ":"ue","ꝸ":"um","ⱴ":"v","ꝟ":"v","ṿ":"v","ʋ":"v","ᶌ":"v","ⱱ":"v","ṽ":"v","ꝡ":"vy","ẃ":"w","ŵ":"w","ẅ":"w","ẇ":"w","ẉ":"w","ẁ":"w","ⱳ":"w","ẘ":"w","ẍ":"x","ẋ":"x","ᶍ":"x","ý":"y","ŷ":"y","ÿ":"y","ẏ":"y","ỵ":"y","ỳ":"y","ƴ":"y","ỷ":"y","ỿ":"y","ȳ":"y","ẙ":"y","ɏ":"y","ỹ":"y","ź":"z","ž":"z","ẑ":"z","ʑ":"z","ⱬ":"z","ż":"z","ẓ":"z","ȥ":"z","ẕ":"z","ᵶ":"z","ᶎ":"z","ʐ":"z","ƶ":"z","ɀ":"z","ff":"ff","ffi":"ffi","ffl":"ffl","fi":"fi","fl":"fl","ij":"ij","œ":"oe","st":"st","ₐ":"a","ₑ":"e","ᵢ":"i","ⱼ":"j","ₒ":"o","ᵣ":"r","ᵤ":"u","ᵥ":"v","ₓ":"x"};
  417. String.prototype.latinise=function(){return this.replace(/[^A-Za-z0-9\[\] ]/g,function(a){return Latinise.latin_map[a]||a})};
  418. String.prototype.latinize=String.prototype.latinise;
  419. String.prototype.isLatin=function(){return this==this.latinise()}
  420. /**
  421. * Array
  422. */
  423. // ------ UNIQUE reduces duplicates ------
  424. array_unique = function(ar){
  425. var r = new Array();
  426. o:for(var i = 0, n = ar.length; i < n; i++)
  427. {
  428. for(var x = 0, y = r.length; x < y; x++)
  429. {
  430. if(r[x]==ar[i])
  431. {
  432. continue o;
  433. }
  434. }
  435. r[r.length] = ar[i];
  436. }
  437. return r;
  438. };
  439. // ------ SUBSTRACT substract two array ------
  440. array_subtract = function(ara1,ara2) {
  441. var aRes = new Array() ;
  442. for (var i = ara1.length-1; i >= 0; i--)
  443. if(array_contains(ara2,ara1[i]))
  444. aRes.push(ara1[i]);
  445. return aRes ;
  446. }
  447. /*
  448. SHUFFLE Add a shuffle function to Array object prototype
  449. author: Stephane Roucheray
  450. src: http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/
  451. found 2011/09/08.
  452. */
  453. array_shuffle = function(ar){
  454. var i = ar.length, j, temp;
  455. if ( i == 0 ) return;
  456. while ( --i ) {
  457. j = Math.floor( Math.random() * ( i + 1 ) );
  458. temp = ar[i];
  459. ar[i] = ar[j];
  460. ar[j] = temp;
  461. }
  462. return ar;
  463. };
  464. // ------ CONTAINS ------
  465. array_contains = function(ar, obj) {
  466. var i = ar.length;
  467. while (i--)
  468. if (ar[i] === obj)
  469. return true;
  470. return false;
  471. };
  472. // ------ REMOVE ------
  473. // /!\ Found on the Internet, not sure of efficiency.
  474. // Array.prototype.remove = function(v) {
  475. // var x, _i, _len, _results;
  476. // _results = [];
  477. // for (_i = 0, _len = this.length; _i < _len; _i++) {
  478. // x = this[_i];
  479. // if (x !== v) {
  480. // _results.push(x);
  481. // }
  482. // }
  483. // return _results;
  484. // };
  485. array_remove = function(ar){
  486. var what, a= arguments, L= a.length, ax;
  487. while(L && ar.length){
  488. what= a[--L];
  489. while((ax= ar.indexOf(what))!= -1){
  490. ar.splice(ax, 1);
  491. }
  492. }
  493. return ar;
  494. };
  495. // for IE
  496. // if(!Array.prototype.indexOf){
  497. // Array.prototype.indexOf= function(what, i){
  498. // i= i || 0;
  499. // var L= this.length;
  500. // while(i< L){
  501. // if(this[i]=== what) return i;
  502. // ++i;
  503. // }
  504. // return -1;
  505. // };
  506. // }
  507. array_indexOf = function(ar, what, i){
  508. i= i || 0;
  509. var L= ar.length;
  510. while(i< L){
  511. if(ar[i]=== what) return i;
  512. ++i;
  513. }
  514. return -1;
  515. };
  516. // ------ SUBSTRACT substract two array ------
  517. function array_subtract(ara1,ara2) {
  518. var aRes = new Array() ;
  519. for (var i = ara1.length-1; i >= 0; i--)
  520. if( !array_contains(ara1[i],ara2) )
  521. aRes.push(ara1[i]);
  522. return aRes ;
  523. };
  524. /**
  525. * Objects
  526. *
  527. */
  528. // ------ OBJECTSIZE get the length of objects ------
  529. function objectSize(o) {
  530. var len = o.length ? --o.length : 0;
  531. for (var k in o)
  532. len++;
  533. return len;
  534. }
  535. // Object.prototype.size = function () {
  536. // // var len = this.length ? --this.length : -1; // POURQUOI NE FONCTIONNE PAS?
  537. // var len = this.length ? --this.length : -2;
  538. // for (var k in this)
  539. // len++;
  540. // return len;
  541. // }
  542. function objectIsEmpty(obj){
  543. for (var prop in obj) {
  544. if (obj.hasOwnProperty(prop))
  545. return false;
  546. }
  547. return true;
  548. };
  549. // ------ OBJECTGETKEY get key of index ------
  550. function objectGetKey(o,index){
  551. var i = 0;
  552. for (var k in o){
  553. if (k === 'length' || !o.hasOwnProperty(k))
  554. continue;
  555. if(i == index)
  556. return k;
  557. i ++;
  558. }
  559. }
  560. // Object.prototype.getKey = function(index){
  561. // var i = 0;
  562. // for (var key in this){
  563. // if (key === 'length' || !this.hasOwnProperty(key))
  564. // continue;
  565. // if(i == index)
  566. // return key;
  567. // i ++;
  568. // }
  569. // }
  570. // ------ OBJECTSORT sort object ------
  571. function objectSort(o,value) {
  572. var connection = new Array();
  573. for (var i = objectSize(o) - 1; i >= 0; i--){
  574. var k = objectGetKey(o,i);
  575. for (var j = objectSize(o[k].wit) - 1; j >= 0; j--){
  576. var k2 = objectGetKey(o[k].wit,j);
  577. if (k2==value) {
  578. var the_wit = parseFloat(o[k].wit[k2]);
  579. connection.push( {wit:the_wit,nid:k} );
  580. };
  581. };
  582. };
  583. connection.sort(function(a,b){
  584. // return (a.wit - b.wit);//ascending
  585. return (b.wit - a.wit);//descending
  586. });
  587. var o_sort = {};
  588. for (var i = connection.length - 1; i >= 0; i--){
  589. // o_sort[connection[i].wit+'-'+connection[i].nid] = o[connection[i].nid];
  590. o_sort[connection[i].nid] = o[connection[i].nid];
  591. };
  592. return o_sort;
  593. }
  594. /**
  595. * trigo
  596. */
  597. // -------- getElementAngle ----------
  598. // L'angle 0 correspond au nord (vers le haut)
  599. // Exemple : getElementAngle(posElementX, posElementY, posSourisX, posSourisY)
  600. // Ceci retournera l'angle de l'élément par rapport à la position de la souris
  601. function getElementAngle(x1, y1, x2, y2) {
  602. var adj = x2 - x1;
  603. var opp = y2 - y1;
  604. var angle = Math.abs(Math.atan(opp/adj) * 180/Math.PI);
  605. if (adj > 0 && opp < 0 ) {
  606. angle = 90 - angle;
  607. }
  608. else if (adj >= 0 && opp >= 0) {
  609. angle += 90;
  610. }
  611. else if (adj < 0 && opp >= 0) {
  612. angle = 180 + (90 - angle);
  613. }
  614. else {
  615. angle += 270;
  616. }
  617. return angle;
  618. }
  619. // @codekit-prepend "gui.js"
  620. // @koala-prepend "gui_ck_fw/gui.js"
  621. (function($) {
  622. MaterioSearchApiAjax = function(){
  623. var _isloadingresults = false;
  624. var _$content = $('#content');
  625. // TODO: define $content by module settings
  626. /**
  627. * init()
  628. */
  629. function init(){
  630. //trace('init MaterioSearchApiAjax');
  631. initSearchAjax();
  632. initViewMode();
  633. };
  634. /**
  635. * searchAjax
  636. */
  637. function initSearchAjax(){
  638. // trace('initSearchAjax');
  639. $('#materio-search-api-search-form').bind('submit', function(event) {
  640. // trace('search submited', event);
  641. // var $this = $(this);
  642. setTimeout(function(){
  643. loadResults(getSearchKeys());
  644. },10);
  645. return false;
  646. });
  647. // /!\ AUTOCOMPLETE SELECT EVENT need a patch http://drupal.org/node/365241#comment-5374686
  648. $("#edit-searchfield")
  649. .bind('autocompleteSelect', function(event) {
  650. // $(this).parents('.form').trigger('submit');
  651. setTimeout(function(){
  652. loadResults(getSearchKeys(), "taxonomy");
  653. },10);
  654. })
  655. .bind('focus', function(event){
  656. $(this).select();
  657. });
  658. $(document)
  659. .bind('theme-ready', onThemeReady)
  660. .bind('init-scroller-pager', onInitScrollerPager)
  661. .bind('load-scroller-pager', onLoadScrollerPager)
  662. .bind('view-mode-changed', onViewModeChanged)
  663. .bind('history-state-change', onHistoryStateChange);
  664. };
  665. function onThemeReady(event){
  666. // trace('MaterioSearchApiAjax :: onThemeReady');
  667. if( isActuality() || isExplore() ){
  668. $.event.trigger({
  669. type : 'resultschanged',
  670. container : isActuality() ? '#content .actuality-items' : '#content .search-results'
  671. });
  672. }
  673. };
  674. function getSearchKeys(){
  675. return $('#materio-search-api-search-form').find('input[name*="searchfield"]').val();
  676. };
  677. function loadResults(keys, searchmode){
  678. //trace('keys', keys);
  679. if(keys !== undefined && keys !== '' && keys.length >= 2){
  680. keys = keys.replace('/', ' ');
  681. // define mode (between full text or only term selected on autocompletion)
  682. searchmode = searchmode || "fulltext";
  683. // record the "node type filter" form item
  684. var types = {}, stringTypes = [];
  685. $('#edit-bundles-filter', '#materio-search-api-search-form').find('input[type*="checkbox"]').each(function(i){
  686. $this = $(this);
  687. if ( $this.attr('checked') )
  688. stringTypes.push($this.val());
  689. types[$this.val()] = $this.attr('checked');
  690. });
  691. //trace('types', types);
  692. if(!_isloadingresults){
  693. $.event.trigger('loading-content');
  694. _isloadingresults = true;
  695. $('#materio-search-api-search-form').addClass('loading');
  696. // trace('window.location.href',window.location.href);
  697. // TODO: record ajax path in a variable from materio_search_api_ajax_init
  698. $.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/search/',
  699. {'types':types,'current_path':document.location.href, 'keys':keys, 'searchmode':searchmode},
  700. function(json){
  701. //trace('json', json);
  702. // google analytics
  703. $.event.trigger({
  704. type : "record-stat",
  705. categorie : 'Search',
  706. action : keys,
  707. label : 'filters : '+ stringTypes.join(' ,'),
  708. value : json.count
  709. });
  710. if(json.redirect){
  711. window.location = json.redirect;
  712. }else{
  713. $.event.trigger('loaded-content');
  714. _isloadingresults = false;
  715. $('#materio-search-api-search-form').removeClass('loading');
  716. changeContent(json);
  717. }
  718. });
  719. }
  720. }
  721. };
  722. function loadActuality(){
  723. if(!_isloadingresults){
  724. $.event.trigger('loading-content');
  725. _isloadingresults = true;
  726. $('#materio-search-api-search-form').addClass('loading');
  727. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/actuality';
  728. $.getJSON(url,
  729. function(json){
  730. //trace('json', json);
  731. $.event.trigger('loaded-content');
  732. _isloadingresults = false;
  733. $('#materio-search-api-search-form').removeClass('loading');
  734. changeContent(json);
  735. });
  736. }
  737. };
  738. function changeContent(json){
  739. //trace('MaterioSearchApiAjax changeContent | json', json);
  740. if(json.returned){
  741. $.event.trigger('loaded-content');
  742. $('.inner-content',_$content).html(json.returned).find('ul.pager').hide();
  743. triggerContentChanged();
  744. }else{
  745. //trace('no results');
  746. }
  747. $.event.trigger({
  748. type : 'new-history-page',
  749. path : Drupal.settings.basePath + Drupal.settings.pathPrefix + json.path,
  750. title : json.title,
  751. content : json.returned
  752. });
  753. for (language in Drupal.settings.materio_search_api_ajax.languages) {
  754. var l = Drupal.settings.materio_search_api_ajax.languages[language];
  755. $('#block-locale-language li.'+language+' a').attr('href', Drupal.settings.basePath + l.prefix+'/' + json.search_path + '/' + json.keys)
  756. };
  757. };
  758. function triggerContentChanged(){
  759. //trace('MaterioSearchApiAjax :: triggerContentChanged');
  760. $.event.trigger({
  761. type : 'resultschanged',
  762. container : '#content .search-results, #content .actuality-items'
  763. });
  764. };
  765. function onInitScrollerPager(event){
  766. // trace("onInitScrollerPager");
  767. if(isActuality() || isExplore())
  768. event.pager.hide();
  769. };
  770. function onLoadScrollerPager(event){
  771. // trace("onLoadScrollerPager");
  772. if(!_isloadingresults){
  773. if (isExplore())
  774. loadNextResultsPage(event.href);
  775. if(isActuality())
  776. loadNextActualityPage(event.href);
  777. }
  778. };
  779. function loadNextResultsPage(href){
  780. // trace('loadNextResultsPage');
  781. var keys = href.match(/explore\/([^\/|\?]+)/);
  782. var page = href.match(/\?page=([0-9]+)/);
  783. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/search/'+page[1];
  784. loadNextPage(url, keys[1], $('.materiobase-results', _$content), '.search-results');
  785. };
  786. function loadNextActualityPage(href){
  787. // trace('loadNextActualityPage');
  788. var page = href.match(/\?page=([0-9]+)/);
  789. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/actuality/'+page[1];
  790. loadNextPage(url, '', $('.materiobase-actuality', _$content), '.actuality-items');
  791. };
  792. function loadNextPage(url, keys, $container, target){
  793. // trace('MaterioSearchApiAjax :: loadNextPage()');
  794. _isloadingresults = true;
  795. $container.addClass('loading');
  796. $.getJSON(url, {'keys':keys}, function(json){
  797. //trace('json', json);
  798. $container.removeClass('loading');
  799. addNextpage(json, target);
  800. // addNextpageItemByItem($(json.return), target);
  801. });
  802. };
  803. function addNextpage(json, container_class){
  804. // trace('json',json);
  805. if(json){
  806. var $newcontent = $(json.returned),
  807. $newitems = $(container_class, $newcontent).children('article'), //.addClass('just-added'),
  808. $newpager = $('ul.pager', $newcontent);
  809. $(container_class, _$content).append($newitems);
  810. $('ul.pager', _$content).replaceWith($newpager.hide());
  811. // TODO: animation, this should be on theme side
  812. $(container_class, _$content).children('.just-added').each(function(i){
  813. var $this = $(this);
  814. setTimeout(function(){
  815. $this.removeClass('just-added');
  816. }, 150*i);
  817. });
  818. $.event.trigger({
  819. type : 'resultscompleted',
  820. container : $(container_class, _$content)
  821. });
  822. }
  823. _isloadingresults = false;
  824. };
  825. // TEST not used
  826. function addNextpageItemByItem($newcontent, container_class){
  827. //trace('MaterioSearchApiAjax :: addNextpageItemByItem()');
  828. $('ul.pager', _$content).remove();
  829. $(container_class, _$content).append($(container_class, $newcontent).children('article').eq(0));
  830. if($(container_class, $newcontent).children('article').length){
  831. setTimeout(function(){
  832. addNextpageItemByItem($newcontent, container_class);
  833. }, 200);
  834. }else{
  835. _isloadingresults = false;
  836. $('ul.pager', _$content).replaceWith($('ul.pager', $newcontent).hide());
  837. $.event.trigger({
  838. type : 'resultscompleted',
  839. container : $(container_class, _$content)
  840. });
  841. }
  842. };
  843. /**
  844. * viewmode
  845. */
  846. function initViewMode(){
  847. $('.viewmode-link').click(function(event){
  848. event.preventDefault();
  849. if(!$(this).is('.active')){
  850. $(this).trigger({type:'vm-clicked'});
  851. changeViewMode($(this).attr('rel'), $(this));
  852. }else{
  853. $(this).trigger({type:'vm-clicked-active'});
  854. }
  855. return false;
  856. });
  857. };
  858. function changeViewMode(vm, $btn){
  859. if(!_isloadingresults){
  860. _isloadingresults = true;
  861. $.getJSON(Drupal.settings.basePath+'materio_search_api_ajax/viewmode/change/'+vm, function(json){
  862. //trace('viewmode json', json);
  863. _isloadingresults = false;
  864. if (json.statut == "saved"){
  865. // google analytics
  866. $.event.trigger({
  867. type : "record-stat",
  868. categorie : 'Viewmode',
  869. action : vm,
  870. label : isActuality() ? 'Actualities' : 'Search results'
  871. });
  872. $.event.trigger('view-mode-changed');
  873. $('.viewmode-link, .viewmode-link i').removeClass('active');
  874. $btn.addClass('active').find('i').addClass('active');
  875. }
  876. });
  877. }
  878. };
  879. function onViewModeChanged(event){
  880. if (isExplore())
  881. loadResults(getSearchKeys());
  882. if(isActuality())
  883. loadActuality();
  884. };
  885. /**
  886. * history
  887. */
  888. function onHistoryStateChange(event){
  889. if(isExplore() || isActuality())
  890. triggerContentChanged();
  891. // TODO: pushstate trogger state change, so we have a retriggerring here on loading new results … how to avoid this
  892. };
  893. /**
  894. * helpers
  895. */
  896. function isExplore(){
  897. return $('.search-results', '#content').length;
  898. };
  899. function isActuality(){
  900. return $('.actuality-items', '#content').length;
  901. };
  902. init();
  903. };
  904. $(document).ready(function() {
  905. var materiosearchapiajax = new MaterioSearchApiAjax();
  906. });
  907. })(jQuery);