25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

bookmarks.js 2.7 KiB

12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. // recent document list
  4. wn.ui.toolbar.Bookmarks = Class.extend({
  5. init:function() {
  6. $('.navbar .nav:first').append('<li class="dropdown">\
  7. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  8. title="'+wn._("Bookmarks")+'"\
  9. onclick="return false;">'+wn._("Bookmarks")+'</a>\
  10. <ul class="dropdown-menu" id="toolbar-bookmarks">\
  11. <li class="divider"></li>\
  12. <li><a href="#" id="add-bookmark-link"><i class="icon-plus"></i> '
  13. +wn._('Add Bookmark')+'</a></li>\
  14. <li style="display: none" id="remove-bookmark-link"><a href="#"><i class="icon-minus"></i> '
  15. +wn._('Remove Bookmark')+'</a></li>\
  16. </ul>\
  17. </li>');
  18. this.setup();
  19. },
  20. setup: function() {
  21. var me = this;
  22. this.bookmarks = wn.defaults.get_default("_bookmarks") || [];
  23. for(var i=this.bookmarks.length-1; i>=0; i--) {
  24. var bookmark = this.bookmarks[i];
  25. this.add_item(bookmark.route, bookmark.title)
  26. }
  27. $("#add-bookmark-link").click(function() {
  28. me.add(wn.get_route_str(), document.title);
  29. return false;
  30. })
  31. $("#remove-bookmark-link").click(function() {
  32. me.remove(wn.get_route_str());
  33. me.save();
  34. me.show_hide_bookmark();
  35. return false;
  36. });
  37. $(window).bind('hashchange', function() {
  38. me.show_hide_bookmark();
  39. });
  40. me.show_hide_bookmark();
  41. },
  42. show_hide_bookmark: function() {
  43. $("#remove-bookmark-link").toggle(this.bookmarked(wn.get_route_str()) ? true : false);
  44. },
  45. add_item: function(route, title) {
  46. var route_parts = decodeURIComponent(route).split("/");
  47. if(route_parts[0]==="List" || route_parts[0]==="Form") {
  48. var icon = wn.boot.doctype_icons[route_parts[1]];
  49. } else {
  50. var icon = "icon-play";
  51. }
  52. var html = repl('<li><a href="#%(route)s"><i class="icon-fixed-width %(icon)s"></i> %(title)s</a></li>',
  53. {route: route, title: title, icon: icon});
  54. $('#toolbar-bookmarks').prepend(html);
  55. },
  56. add: function(route, title) {
  57. // bring to front
  58. if(this.bookmarked(route)) {
  59. this.remove(route);
  60. }
  61. // max length
  62. if(this.bookmarks.length >= 11) {
  63. this.remove(this.bookmarks[this.bookmarks.length-1].route);
  64. }
  65. this.add_item(route, title);
  66. this.bookmarks = [{"route":route, "title":title}].concat(this.bookmarks);
  67. this.save();
  68. },
  69. bookmarked: function(route) {
  70. return wn.utils.filter_dict(this.bookmarks, {"route": route}).length;
  71. },
  72. save: function() {
  73. wn.defaults.set_default("_bookmarks", this.bookmarks);
  74. },
  75. remove: function(route) {
  76. this.bookmarks = $.map(this.bookmarks, function(d) {
  77. if(d.route!=route) return d; });
  78. $(repl('#toolbar-bookmarks li a[href="#%(route)s"]', {route:route})).parent().remove();
  79. },
  80. });