materio_flag.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. // @codekit-prepend "gui.js"
  2. // @koala-prepend "gui.js"
  3. (function($) {
  4. MaterioFlag = function(){
  5. var _isLoadingList = false ;
  6. /**
  7. * init()
  8. */
  9. function init(){
  10. //trace('MaterioFlag :: init MaterioFlag');
  11. buildBlocks();
  12. $(document)
  13. .bind('flagGlobalAfterLinkUpdate', onFlaging)
  14. .bind('resultscompleted resultschanged previewloaded', onResultsUpdated)
  15. .bind('init-scroller-pager', onInitScrollerPager)
  16. .bind('load-scroller-pager', onLoadScrollerPager)
  17. .bind('view-mode-changed', onViewModeChanged)
  18. .bind('history-state-change', onHistoryStateChange);
  19. // ajaxifyLinks();
  20. // trigger updated event for direct html loading
  21. if(isList()){
  22. setTimeout(function(){
  23. triggerContentChanged();
  24. }, 10);
  25. }
  26. };
  27. function onFlaging(event){
  28. //trace('MaterioFlag :: onFlaging', event);
  29. refreshBlocks();
  30. };
  31. function onResultsUpdated(event){
  32. //trace('MaterioFlag :: onResultsUpdated', event);
  33. ajaxifyLinks(event.container);
  34. };
  35. function buildBlocks(activename){
  36. //trace('MaterioFlag :: buildBlocks | activename', activename);
  37. if($('#block-materio-flag-materio-flag-mybookmarks').length){
  38. var type = 'bookmarks';
  39. var block = '#block-materio-flag-materio-flag-mybookmarks';
  40. }else if($('#block-materio-flag-materio-flag-mylists').length){
  41. var type = 'lists';
  42. var block = '#block-materio-flag-materio-flag-mylists';
  43. }
  44. switch(type){
  45. case 'bookmarks':
  46. var name = type;
  47. $('h2 .listname', block).attr('name', name).bind('click', onClickShowPreview);
  48. $('<i class="fi-x"></i>').appendTo($('h2', block)).attr('name', name).bind('click', onClickClosePreview);
  49. // $('<span class="preview"><i class="icon-eye-open"></i></span>').appendTo($('h2', block)).bind('click', onClickShowPreview);
  50. // if(!readCookie('materiobookmarkspreviewopened')){
  51. // showPreview('bookmarks', block);
  52. // }else{
  53. // }
  54. break;
  55. case 'lists':
  56. // nav block
  57. $('a.open-list:not(.ajax-processed)', '#block-materio-flag-materio-flag-mylists-nav').each(function(index){
  58. //trace('nav block a.open-list this', this);
  59. $this = $(this)
  60. .bind('click', onClickOpenLink)
  61. .addClass('ajax-processed');
  62. var name = $this.attr('class').match(/flag_lists_[^_]+_[0-9]+/);
  63. // trace('MaterioFlag :: name', name);
  64. $('<span class="preview"><i class="fi-eye"></i></span>').attr('name', name).insertAfter($this).bind('click', onClickShowPreview);
  65. });
  66. $('a.edit-list:not(.ajax-processed)', '#block-materio-flag-materio-flag-mylists-nav')
  67. .bind('click', onCLickEditList)
  68. .addClass('ajax-processed');
  69. $('a.flag-lists-create:not(.ajax-processed)', '#block-materio-flag-materio-flag-mylists-nav')
  70. .bind('click', onClickCreatLink)
  71. .addClass('ajax-processed');
  72. // preview block
  73. $('section.flag-list:not(.ajax-processed)', '#block-materio-flag-materio-flag-mylists').each(function(index){
  74. var name = $(this).attr('class').match(/flag_lists_[^_]+_[0-9]+/);
  75. $('<i class="fi-x"></i>').appendTo($('h2.listname', this)).attr('name', name).bind('click', onClickClosePreview);
  76. $('a.open-list', this).bind('click', onClickOpenLink);
  77. }).addClass('ajax-processed');
  78. break;
  79. }
  80. // trigger refresh block event for enabling lazyload images
  81. setTimeout(function(){
  82. $.event.trigger({
  83. type : 'my'+type+'-block-builded',
  84. block : block,
  85. name : name
  86. });
  87. },10);
  88. // trace('MaterioFlag :: activename', activename);
  89. if(activename == undefined)
  90. activename = readCookie('materiomyflaglistsopened');
  91. // trace('MaterioFlag :: activename', activename);
  92. if(activename)
  93. showPreview(activename, block);
  94. };
  95. function refreshBlocks(name){
  96. //trace('MaterioFlag :: refreshBlocks | name', name);
  97. if($('#block-materio-flag-materio-flag-mybookmarks').length){
  98. var type = 'bookmarks';
  99. }else if($('#block-materio-flag-materio-flag-mylists').length){
  100. var type = 'lists';
  101. }
  102. if(type != undefined){
  103. var id = '#block-materio-flag-materio-flag-my'+type;
  104. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/refresh/block/'+type;
  105. $.getJSON(url, function(json){
  106. // trace('MaterioFlag :: block refreshed '+type, json);
  107. $(id).replaceWith(json.block);
  108. $('#block-materio-flag-materio-flag-mylists-nav').replaceWith(json.block_nav);
  109. buildBlocks(name);
  110. $.event.trigger({
  111. type : 'my'+type+'-block-updated',
  112. listname : name
  113. });
  114. });
  115. }
  116. };
  117. function ajaxifyLinks(container){
  118. //trace('MaterioFlag :: ajaxifyLinks', container);
  119. container = ((container != null) ? container : 'body');
  120. // trace('MaterioFlag :: typeof Drupal.flagLink', typeof Drupal.flagLink);
  121. if (typeof Drupal.flagLink != 'undefined')
  122. Drupal.flagLink(container);
  123. if(isList()){
  124. var fid = $('.materio-flags-list', '#content').attr('fid');
  125. $('li.unflag-action.fid-'+fid+' a:not(.ajax-processed), li.flag-bookmarks a.unflag-action:not(.ajax-processed)')
  126. .bind('click', onUnflagList)
  127. .addClass('ajax-processed');
  128. }
  129. $('a.flag-lists-create:not(.ajax-processed)', container)
  130. .bind('click', onClickCreatLink)
  131. .addClass('ajax-processed');
  132. };
  133. /**
  134. * show hide preview
  135. */
  136. function onClickShowPreview(event){
  137. //trace('MaterioFlag :: onClickShowPreview', event);
  138. showPreview($(this).attr('name'), $(this).parent('.block').attr('id'));
  139. };
  140. function showPreview(name, block){
  141. //trace('MaterioFlag :: showPreview', name);
  142. $('section.'+name, block).addClass('active')
  143. .siblings('section').removeClass('active');
  144. createCookie('materiomyflaglistsopened', name, 1);
  145. $.event.trigger('init-layout');
  146. };
  147. function onClickClosePreview(event){
  148. //trace('MaterioFlag :: onClickClosePreview', event);
  149. eraseCookie('materiomyflaglistsopened');
  150. if($(this).attr('name') == 'bookmarks'){
  151. $(this).parents('.block').find('section.bookmarks').removeClass('active');
  152. }else{
  153. $(this).parents('section.flag-list').removeClass('active');
  154. }
  155. $.event.trigger('init-layout');
  156. };
  157. /**
  158. * onClickOpenLink
  159. */
  160. function onClickOpenLink(event){
  161. event.preventDefault();
  162. var $link = $(event.currentTarget);
  163. var fid = $link.attr('href').match(/lists\/([0-9]+)$/);
  164. // trace('MaterioFlag :: type', type);
  165. loadList(fid[1]);
  166. return false;
  167. };
  168. function loadList(fid){
  169. //trace('MaterioFlag :: loadList | fid', fid);
  170. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/ajax/list/'+fid;
  171. $.event.trigger('loading-content');
  172. $.getJSON(url, {'current_path':document.location.href},function(json){
  173. //trace('MaterioFlag :: json', json);
  174. if(json.redirect){
  175. window.location = json.redirect;
  176. }else{
  177. changeContent(json);
  178. }
  179. });
  180. };
  181. function changeContent(json){
  182. if(json.rendered){
  183. $('.inner-content','#content').html(json.rendered);
  184. $.event.trigger('loaded-content');
  185. // no need of ajaxifylinks because it's triggered with resultschanged
  186. // ajaxifyLinks('#content');
  187. var path = Drupal.settings.basePath + Drupal.settings.pathPrefix + json.path;
  188. $.event.trigger({
  189. type : 'new-history-page',
  190. path : path,
  191. title : json.title,
  192. content : json.rendered
  193. });
  194. // TODO: change language links for folders
  195. // for (language in Drupal.settings.materio_search_api_ajax.languages) {
  196. // var l = Drupal.settings.materio_search_api_ajax.languages[language];
  197. // $('#block-locale-language li.'+language+' a').attr('href', Drupal.settings.basePath + l.prefix+'/' + json.search_path + '/' + json.keys)
  198. // };
  199. triggerContentChanged();
  200. }else{
  201. //trace('MaterioFlag :: no results');
  202. }
  203. };
  204. function triggerContentChanged(){
  205. $.event.trigger({
  206. type: 'resultschanged',
  207. container : '#content .flaglist-items'
  208. });
  209. };
  210. /**
  211. * onClickCreatLink(event)
  212. */
  213. function onClickCreatLink(event){
  214. // trace('MaterioFlag :: onClickCreatLink | event', event);
  215. event.preventDefault();
  216. var $link = $(event.currentTarget);
  217. var type = $link.attr('href').match(/[^\/]*$/);
  218. // trace('MaterioFlag :: type', type);
  219. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/createlist/form/'+type[0];
  220. $.getJSON(url, function(json){
  221. //trace('MaterioFlag :: creat list : json', json);
  222. showCreateListForm(json, $link);
  223. });
  224. return false;
  225. };
  226. function showCreateListForm(json, $link){
  227. // trace('MaterioFlag :: showCreateListForm | json', json);
  228. // google analytics
  229. $.event.trigger({
  230. type:"record-stat",
  231. categorie:"flagLists",
  232. action: 'show create form'
  233. });
  234. var $modal = $('<div id="modal" class="modal"/>').appendTo('body');
  235. $modal
  236. .css({
  237. position:'absolute',
  238. top:'40%', left:'50%',
  239. marginLeft:'-150px', width:'300px',
  240. zIndex:"99999"
  241. })
  242. .append(json.rendered_form)
  243. .find('input[type="submit"]', '#materio-flag-create-list-form').bind('click', function(event) {
  244. event.preventDefault();
  245. switch($(this).attr('name')){
  246. case 'cancel':
  247. //trace('MaterioFlag :: cancel',event);
  248. $(this).parents('#modal').remove();
  249. // google analytics
  250. $.event.trigger({
  251. type:"record-stat",
  252. categorie:"flagLists",
  253. action: 'cancel create form'
  254. });
  255. break;
  256. case 'op':
  257. trace('MaterioFlag :: create',event);
  258. var name = $(this).parents('form').find('input[name*="title"]').val();
  259. // name = encodeURIComponent(name);
  260. var type = $(this).parents('form').find('input[name*="type"]').val();
  261. var token = $(this).parents('form').find('input[name*="form_token"]').val();
  262. // google analytics
  263. $.event.trigger({
  264. type : "record-stat",
  265. categorie : "flagLists",
  266. action : "submit create form",
  267. label : 'title : '+name
  268. });
  269. createList($modal, type, name, token, $link);
  270. break;
  271. }
  272. return false;
  273. })
  274. .parents('form').find('input[type="text"]').focus();
  275. // TODO: esc keypressed close the form
  276. };
  277. function createList($modal, type, name, token, $link){
  278. // trace('materioflag :: createList | title', name);
  279. $('.flag-lists-create').addClass('loading');
  280. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'flag-lists/add/'+type+'/js';
  281. $.getJSON(url, {form_token:token,name:name}, function(data) {
  282. if (data.error) {
  283. trace("MaterioFlag :: created list : data.error", data.error);
  284. }
  285. else {
  286. // select.append('<option value="'+data.flag.fid+'">'+data.flag.title+'</option>');
  287. // $('input.name', $(this)).val('');
  288. // dialog.dialog('close');
  289. // trace('MaterioFlag :: created list : data', data);
  290. if($link.attr('nid') && $link.attr('token')){
  291. flagEntityWithList(data.flag.name, $link.attr('nid'), $link.attr('token'));
  292. }else{
  293. refreshBlocks(data.flag.name);
  294. refreshNodeLinks();
  295. }
  296. $modal.remove();
  297. }
  298. });
  299. };
  300. function flagEntityWithList(name, nid, token){
  301. //trace('MaterioFlag :: flagEntityWithList | name', name);
  302. // var ret;
  303. // Send POST request
  304. $.ajax({
  305. type: 'POST',
  306. url: Drupal.settings.basePath+Drupal.settings.pathPrefix+'flag-lists/flag/'+name+'/'+nid,
  307. data: { js: true, token: token },
  308. dataType: 'json',
  309. success: function (data2) {
  310. //trace('MaterioFlag :: node taged with newly created list : data2', data2)
  311. if (data2.status) {
  312. // google analytics
  313. $.event.trigger({
  314. type : "record-stat",
  315. categorie : 'FlagLists',
  316. action : 'node flaged',
  317. label : 'nid : '+nid+' | flag : '+name
  318. });
  319. refreshBlocks(name);
  320. refreshNodeLinks();
  321. }else {
  322. // Failure.
  323. alert(data2.errorMessage);
  324. }
  325. },
  326. error: function (xmlhttp) {
  327. alert('An HTTP error '+ xmlhttp.status +' occurred.\n'+ element.href);
  328. }
  329. });
  330. };
  331. function refreshNodeLinks(){
  332. //trace('MaterioFlag :: refreshNodeLinks');
  333. var nids = new Array();
  334. $('.flag-lists-entity-links')
  335. // .addClass('loading')
  336. .parents('.node')
  337. .each(function(index) {
  338. nids.push($(this).attr('class').match(/node-([0-9]+)/)[1]);
  339. });
  340. // trace('MaterioFlag :: nids', nids);
  341. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/nodelinks';
  342. $.getJSON(url, {nids:nids.join(";")}, function(data) {
  343. // trace('MaterioFlag :: data', data);
  344. for(nid in data.links){
  345. // trace('MaterioFlag :: nid', nid);
  346. // trace('MaterioFlag :: data.links[nid]', data.links[nid]);
  347. $('.node-'+nid+' .flag-lists-entity-links').replaceWith(data.links[nid]);
  348. // trace('MaterioFlag :: typeof Drupal.flagLink', typeof Drupal.flagLink);
  349. // if (typeof Drupal.flagLink != 'undefined')
  350. // Drupal.flagLink($('.node-'+nid+' .flag-lists-entity-links'));
  351. // TODO: sortir ajaxifyLinks de la boucle, je pense que ça prend trop de ressources
  352. ajaxifyLinks('.node-'+nid+' .flag-lists-entity-links');
  353. }
  354. });
  355. $.event.trigger({
  356. type : 'materioflag-nodelinks-updated',
  357. nids : nids
  358. });
  359. };
  360. /**
  361. * onCLickEditList(event)
  362. */
  363. function onCLickEditList(event){
  364. //trace('MaterioFlag :: onCLickEditList | event', event);
  365. // TODO: empécher le double formulaire
  366. event.preventDefault();
  367. var $link = $(event.currentTarget);
  368. var lid = $link.attr('href').match(/[^\/]*$/);
  369. var type = 'materiau'; // this is cheap
  370. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/editlistform/'+type+'/'+lid[0];
  371. $.getJSON(url, function(json){
  372. //trace('MaterioFlag :: editlist : json', json);
  373. showEditListForm(json, $link);
  374. });
  375. return false;
  376. };
  377. function showEditListForm(json, $link){
  378. //trace('MaterioFlag :: showEditListForm | json', json);
  379. // google analytics
  380. $.event.trigger({
  381. type:"record-stat",
  382. categorie:"flagLists",
  383. action: 'show edit form'
  384. });
  385. var $modal = $('<div id="modal" class="modal"/>').appendTo('body');
  386. $modal
  387. .css({
  388. position:'absolute',
  389. top:'40%', left:'50%',
  390. marginLeft:'-150px', width:'300px',
  391. zIndex:"99999"
  392. })
  393. .append(json.rendered_form)
  394. .find('input[type="submit"]', '#materio-flag-edit-list-form').bind('click', function(event) {
  395. event.preventDefault();
  396. var $form = $(this).parents('form');
  397. var title = $form.find('input[name*="flag-lists-title"]').val();
  398. var fid = $form.find('input[name*="fid"]').val();
  399. var name = $form.find('input[name*="name"]').val();
  400. switch($(this).attr('name')){
  401. case 'cancel':
  402. //trace('MaterioFlag :: cancel',event);
  403. $(this).parents('#modal').remove();
  404. // google analytics
  405. var action = 'cancel edit form';
  406. break;
  407. case 'save':
  408. //trace('MaterioFlag :: create',event);
  409. // google analytics
  410. var action = "submit edit form";
  411. saveList($modal, fid, name, title);
  412. break;
  413. case 'delete':
  414. //trace('MaterioFlag :: delete',event);
  415. if(confirm('Do you realy want to delete your '+title+' folder ?')){
  416. var action = "submit delete form";
  417. deleteList($modal, fid);
  418. }else{
  419. var action = "cancel delete form";
  420. }
  421. break;
  422. }
  423. // google analytics
  424. $.event.trigger({
  425. type:"record-stat",
  426. categorie:"flagLists",
  427. action: action
  428. });
  429. return false;
  430. })
  431. .parents('form').find('input[type="text"]').focus();
  432. // TODO: esc keypressed close the form
  433. };
  434. function saveList($modal, fid, name, title){
  435. //trace('MaterioFlag :: saveList | fid : '+fid+'| name', name);
  436. $('.flag-lists-link.fid-'+fid).addClass('loading');
  437. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/editlist/'+fid+'/'+name+'/'+title;
  438. $.getJSON(url, function(data) {
  439. if (data.error) {
  440. // trace(data.error);
  441. if(data.message)
  442. alert(data.message);
  443. }
  444. else {
  445. //trace('MaterioFlag :: saved list : data', data);
  446. $.event.trigger({
  447. type : 'list-edited',
  448. name : data.listname,
  449. title : data.title,
  450. });
  451. refreshBlocks();
  452. refreshNodeLinks();
  453. $modal.remove();
  454. }
  455. });
  456. };
  457. function deleteList($modal, fid){
  458. //trace('MaterioFlag :: deletelist | fid', fid);
  459. $('.flag-lists-link.fid-'+fid).hide();
  460. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/deletelist/'+fid;
  461. $.getJSON(url, function(data) {
  462. if (data.error) {
  463. // trace(data.error);
  464. if(data.message)
  465. alert(data.message);
  466. }
  467. else {
  468. trace('MaterioFlag :: deleted list : data', data);
  469. refreshBlocks();
  470. refreshNodeLinks();
  471. $modal.remove();
  472. // TODO: if the deleted list was the current displayed list ??
  473. trace("MaterioFlag :: deleted list : document.location.href", document.location.href);
  474. if(document.location.href.indexOf("/lists/"+data.fid) !== -1){
  475. window.location = Drupal.settings.basePath + Drupal.settings.pathPrefix +"actuality";
  476. }
  477. }
  478. });
  479. };
  480. /**
  481. * onUnflagList()
  482. */
  483. function onUnflagList(event){
  484. //trace('onUnflagList', event);
  485. $(this).parents('article.node').addClass('removed');
  486. };
  487. /**
  488. *
  489. */
  490. function onInitScrollerPager(event){
  491. // trace('MaterioFlag :: MaterioFlag :: onInitScrollerPager');
  492. if (isList()){
  493. // trace('MaterioFlag :: event.pager', event);
  494. event.pager.hide();
  495. }
  496. };
  497. function onLoadScrollerPager(event){
  498. if (isList())
  499. loadNextListPage(event.href);
  500. };
  501. function loadNextListPage(href){
  502. // trace('MaterioFlag :: loadNextListPage', href);
  503. if(!_isLoadingList){
  504. var fid = href.match(/lists\/([^\/|\?]+)/);
  505. var page = href.match(/\?page=([0-9]+)/);
  506. var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/ajax/list/'+fid[1]+'/'+page[1];
  507. // trace('MaterioFlag :: url', url);
  508. loadNextPage(url, $('.materio-flags-list', '#content'), '.flaglist-items');
  509. }
  510. };
  511. function loadNextPage(url, $container, target){
  512. //trace('MaterioFlag :: loadNextPage');
  513. _isLoadingList = true;
  514. $container.addClass('loading');
  515. $.getJSON(url, function(json){
  516. //trace('json', json);
  517. _isLoadingList = false;
  518. $container.removeClass('loading');
  519. addNextpage(json, target);
  520. });
  521. };
  522. function addNextpage(json, container_class){
  523. var $newcontent = $(json.rendered),
  524. $newitems = $(container_class, $newcontent).children('article').addClass('just-added'),
  525. $newpager = $('ul.pager', $newcontent);
  526. $(container_class, '#content').append($newitems);
  527. $('ul.pager', '#content').replaceWith($newpager.hide());
  528. // TODO: animation, this should be on theme side
  529. $(container_class, '#content').children('.just-added').each(function(i){
  530. // $(this).delay(5000*i).removeClass('just-added');
  531. var $this = $(this);
  532. setTimeout(function(){
  533. $this.removeClass('just-added');
  534. }, 150*i);
  535. });
  536. $.event.trigger({
  537. type : 'resultscompleted',
  538. container : $(container_class, '#content')
  539. });
  540. };
  541. function onViewModeChanged(event){
  542. if (isList())
  543. loadList(getFid());
  544. };
  545. /**
  546. * history
  547. */
  548. function onHistoryStateChange(event){
  549. if(isList())
  550. triggerContentChanged();
  551. };
  552. /**
  553. * Helpers
  554. */
  555. function getFid(){
  556. return $('.materio-flags-list', '#content').attr('fid');;
  557. };
  558. function isList(){
  559. return $('.materio-flags-list', '#content').length;
  560. };
  561. /**
  562. * cookies
  563. */
  564. function createCookie(name,value,days) {
  565. if (days) {
  566. var date = new Date();
  567. date.setTime(date.getTime()+(days*24*60*60*1000));
  568. var expires = "; expires="+date.toGMTString();
  569. }
  570. else var expires = "";
  571. document.cookie = name+"="+value+expires+"; path=/";
  572. }
  573. function readCookie(name) {
  574. var nameEQ = name + "=";
  575. var ca = document.cookie.split(';');
  576. for(var i=0;i < ca.length;i++) {
  577. var c = ca[i];
  578. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  579. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  580. }
  581. return null;
  582. }
  583. function eraseCookie(name) {
  584. createCookie(name,"",-1);
  585. }
  586. init();
  587. };
  588. $(document).ready(function() {
  589. var materioflag = new MaterioFlag();
  590. });
  591. })(jQuery);