PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/js_composer/assets/js/frontend_editor/models.js

https://bitbucket.org/acipriani/madeinapulia.com
JavaScript | 75 lines | 52 code | 2 blank | 21 comment | 5 complexity | f5c50a6a8cd732566874a48de3c1ff56 MD5 | raw file
Possible License(s): GPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
  1. /* =========================================================
  2. * custom_views.js v1.1
  3. * =========================================================
  4. * Copyright 2013 Wpbakery
  5. *
  6. * Visual composer Frontend modals & collections
  7. * ========================================================= */
  8. (function ($) {
  9. if(_.isUndefined(window.vc)) window.vc = {};
  10. /**
  11. * Shortcode model
  12. * @type {*}
  13. */
  14. var Shortcode = Backbone.Model.extend({
  15. defaults:function () {
  16. var id = vc_guid();
  17. return {
  18. id:id,
  19. shortcode:'vc_text_block',
  20. order: vc.shortcodes.nextOrder(),
  21. params:{
  22. },
  23. parent_id:false
  24. };
  25. },
  26. settings: false,
  27. getParam: function(key) {
  28. return _.isObject(this.get('params')) && !_.isUndefined(this.get('params')[key]) ? this.get('params')[key] : '';
  29. },
  30. sync: function () {
  31. return false;
  32. },
  33. setting: function(name) {
  34. if(this.settings === false) this.settings = vc.getMapped(this.get('shortcode')) || {};
  35. return this.settings[name];
  36. },
  37. view: false
  38. });
  39. /**
  40. * Collection of all shortcodes.
  41. * @type {*}
  42. */
  43. var Shortcodes = Backbone.Collection.extend({
  44. model: Shortcode,
  45. sync: function () {
  46. return false;
  47. },
  48. nextOrder: function() {
  49. if (!this.length) return 1;
  50. return this.last().get('order') + 1;
  51. },
  52. initialize:function () {
  53. this.bind('remove', this.removeChildren, this);
  54. this.bind('remove', vc.builder.checkNoContent);
  55. },
  56. comparator:function (model) {
  57. return model.get('order');
  58. },
  59. /**
  60. * Remove all children of the model from storage.
  61. * Will remove children of children models too.
  62. * @param parent - model which is parent
  63. */
  64. removeChildren: function (parent) {
  65. var models = vc.shortcodes.where({parent_id:parent.id});
  66. _.each(models, function (model) {
  67. model.destroy();
  68. // this.removeChildren(model);
  69. }, this);
  70. }
  71. });
  72. vc.shortcodes = new Shortcodes;
  73. })(window.jQuery);