PageRenderTime 121ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/fusion-core/admin/page-builder/assets/js/category.js

https://gitlab.com/webkod3r/tripolis
JavaScript | 89 lines | 60 code | 12 blank | 17 comment | 2 complexity | ce72aa4ef4a57626ca47ea04e879d944 MD5 | raw file
  1. /*
  2. * This is the Category element placeholder
  3. */
  4. ( function($) {
  5. var Category = {};
  6. window.Category = Category;
  7. // Category Element Model
  8. Category.ElementEntry = Backbone.Model.extend();
  9. // Category collection, it act as array for elements
  10. Category.Elements = Backbone.Collection.extend({
  11. model: Category.ElementEntry
  12. });
  13. // Category view object
  14. Category.DisplayElement = Backbone.View.extend({
  15. // tag name for the element is div, it means each element will be surrounding by <div></div>
  16. tagName: 'div',
  17. // classes for the element div
  18. className: 'item-wrapper pre_element_block',
  19. initialize: function() {
  20. // use template that has name "element-template"
  21. this.template = window.HandlebarsLoadTemplate('element');
  22. },
  23. events: function(){
  24. var _events = {};
  25. // add click event to the element hyperlink, which will execute addElementByClicking on click
  26. _events["click " + ".element_block"] = "addElementByClicking";
  27. return _events;
  28. },
  29. render: function() {
  30. this.$el.html(this.template(this.model.toJSON()));
  31. // Get model "data" array and loop over it and add it to the DOM element with prefix "data-"
  32. var dataArray = this.model.get('data');
  33. if(dataArray)
  34. {
  35. for(var index in dataArray)
  36. {
  37. $(this.el).attr("data-"+index, dataArray[index] );
  38. }
  39. }
  40. // activate dragging for the current element
  41. DdHelper.activateDragging($(this.el));
  42. return this;
  43. },
  44. addElementByClicking: function(){
  45. var elementObject = app.palette.createElement(this.model.get('id'));
  46. // get last element index
  47. var elements = $( '#editor .item-wrapper' );
  48. var lastItem = $( '.item-wrapper:last' );
  49. var elementIndex = elements.index(lastItem);
  50. //var elementIndex = $("#editor").children().closest('.item-wrapper').index(); //:: Not working
  51. // add 1 to the last element index which is used as element order. i.e. element index is the element order in it's parent
  52. elementObject.attributes.index = elementIndex+1;
  53. // add the element to the selectedElements
  54. app.editor.selectedElements.add(elementObject);
  55. // capture editor
  56. fusionHistoryManager.captureEditor();
  57. },
  58. });
  59. Category.DisplayTab = Backbone.View.extend({
  60. initialize: function() {
  61. this.template = window.HandlebarsLoadTemplate('tab');
  62. },
  63. render: function() {
  64. this.$el.html(this.template(this.model.toJSON()));
  65. return this;
  66. }
  67. });
  68. Category.DisplayTabContent = Backbone.View.extend({
  69. initialize: function() {
  70. this.template = window.HandlebarsLoadTemplate('tabContent');
  71. },
  72. render: function() {
  73. this.$el.html(this.template(this.model.toJSON()));
  74. return this;
  75. }
  76. });
  77. })(jQuery);