materio_flag.js 21 KB

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