Advertisement
Guest User

Untitled

a guest
Jun 29th, 2020
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function PB4October(editor, options){
  2.  
  3.  
  4. //October Partial Block
  5.  
  6.     editor.DomComponents.addType('october-partial', {
  7.         isComponent: el => {
  8.             if (el.attributes) {
  9.  
  10.                 if(el.attributes.getNamedItem('october-partial')) {
  11.                     var r = el.attributes.getNamedItem('october-partial').value;
  12.  
  13.                     if(r == '1'){
  14.  
  15.                         return true;
  16.                     }
  17.  
  18.                 }
  19.  
  20.             }
  21.  
  22.         },
  23.         model: {
  24.             defaults: {
  25.                 traits: [
  26.                 'id',
  27.                 {
  28.                     type: 'select',
  29.                     name: 'partial',
  30.  
  31.                     options: options.partials
  32.                 },
  33.  
  34.                 ]
  35.  
  36.             },
  37.             init() {
  38.                 this.on('change:attributes:partial', this.handleChange);
  39.                 this.handleChange();
  40.             },
  41.             handleChange() {
  42.                 const partial = this.getAttributes().partial;
  43.  
  44.  
  45.  
  46.                 if(this.getAttributes()['october-partial'] == '1'){          
  47.  
  48.                     if (partial) {
  49.  
  50.  
  51.                         this.attributes['content'] = '';
  52.                         this.components(` {% partial '${partial}' %}`);
  53.  
  54.  
  55.  
  56.                     } else {
  57.                         this.attributes['content'] = '';
  58.                         this.components(`Select partial`);
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.     });
  64.  
  65.     editor.BlockManager.add('october-partial-block', {
  66.         label: 'October CMS partial',
  67.         category: 'October CMS',        
  68.         content:`<div data-gjs-type="october-partial" october-partial="1" ></div>`,
  69.         attributes: {
  70.             class: 'fa fa-code'
  71.         }
  72.     });
  73.  
  74. //October Content Block
  75.  
  76.     editor.DomComponents.addType('october-content', {
  77.         isComponent: el => {
  78.             if (el.attributes) {
  79.  
  80.                 if(el.attributes.getNamedItem('october-content')) {
  81.                     var r = el.attributes.getNamedItem('october-content').value;
  82.  
  83.                     if(r == '1'){
  84.  
  85.                         return true;
  86.                     }
  87.  
  88.                 }
  89.  
  90.             }
  91.  
  92.         },
  93.         model: {
  94.             defaults: {
  95.                 traits: [
  96.                 'id',
  97.                 {
  98.                     type: 'select',
  99.                     name: 'content',
  100.  
  101.                     options: options.contents
  102.                 },
  103.  
  104.                 ]
  105.  
  106.             },
  107.             init() {
  108.                 this.on('change:attributes:content', this.handleChange);
  109.                 this.handleChange();
  110.             },
  111.             handleChange() {
  112.                 const content = this.getAttributes().content;
  113.  
  114.  
  115.  
  116.                 if(this.getAttributes()['october-content'] == '1'){          
  117.  
  118.                     if (content) {
  119.  
  120.  
  121.                         this.attributes['content'] = '';
  122.                         this.components(` {% content '${content}' %}`);
  123.  
  124.  
  125.  
  126.                     } else {
  127.                         this.attributes['content'] = '';
  128.                         this.components(`Select content`);
  129.                     }
  130.                 }
  131.             }
  132.         }
  133.     });
  134.  
  135.  
  136.     editor.BlockManager.add('october-content-block', {
  137.         label: 'October CMS Content',
  138.         category: 'October CMS',        
  139.         content:`<div data-gjs-type="october-content" october-content="1" ></div>`,
  140.         attributes: {
  141.             class: 'fa fa-code'
  142.         }
  143.     });
  144.  
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement