| 1 |
(function( $ ) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
// Insert shortcode into TinyMCE |
| 5 |
$( document ).on( 'click', '.gridable-insert-row-button', function(event) { |
| 6 |
event.preventDefault(); |
| 7 |
/** |
| 8 |
* Create one row shortcode with one column inside |
| 9 |
*/ |
| 10 |
var column_content = wp.html.string( { |
| 11 |
tag: 'p', |
| 12 |
content: gridable_editor_params.new_column_content |
| 13 |
}); |
| 14 |
|
| 15 |
var column = wp.html.string({ |
| 16 |
tag: 'section', |
| 17 |
attrs: { |
| 18 |
class: "col gridable-mceItem grid__item", |
| 19 |
"data-sh-column-attr-size": "6", |
| 20 |
"data-mce-placeholder": "1", |
| 21 |
"contenteditable": "true" |
| 22 |
}, |
| 23 |
content: column_content |
| 24 |
}); |
| 25 |
|
| 26 |
column += wp.html.string({ |
| 27 |
tag: 'section', |
| 28 |
attrs: { |
| 29 |
class: "col gridable-mceItem grid__item", |
| 30 |
"data-sh-column-attr-size": "6", |
| 31 |
"data-mce-placeholder": "1", |
| 32 |
"contenteditable": "true" |
| 33 |
}, |
| 34 |
content: column_content |
| 35 |
}); |
| 36 |
|
| 37 |
var row = wp.html.string({ |
| 38 |
tag: 'section', |
| 39 |
attrs: { |
| 40 |
class: "row gridable-mceItem gridable gridable--grid grid", |
| 41 |
"data-sh-row-attr-cols_nr": "2", |
| 42 |
"data-gridable-row": "1", |
| 43 |
"data-mce-placeholder": "1", |
| 44 |
"contenteditable": "false" |
| 45 |
}, |
| 46 |
content: column |
| 47 |
}); |
| 48 |
|
| 49 |
function addRowShortcodeToText() { |
| 50 |
/** |
| 51 |
* Insert the new shortcode in the Text editor |
| 52 |
*/ |
| 53 |
var column_shortcode = '[col size="6"]\n\n' + gridable_editor_params.new_column_content + '\n\n[/col]'; |
| 54 |
var row_shortcode = '[row cols_nr="2"]' + column_shortcode + column_shortcode + '[/row]'; |
| 55 |
window.QTags.insertContent( row_shortcode ); |
| 56 |
} |
| 57 |
|
| 58 |
if ( typeof tinyMCE.activeEditor !== "undefined" && tinyMCE.activeEditor ) { |
| 59 |
/** |
| 60 |
* Insert the new shortcode in the editor |
| 61 |
*/ |
| 62 |
|
| 63 |
if ( ! tinyMCE.activeEditor.hidden ) { |
| 64 |
tinyMCE.activeEditor.insertContent( row ); |
| 65 |
tinyMCE.activeEditor.execCommand('gridableAddResizeHandlers'); |
| 66 |
} else { |
| 67 |
addRowShortcodeToText(); |
| 68 |
} |
| 69 |
} else { |
| 70 |
addRowShortcodeToText(); |
| 71 |
} |
| 72 |
|
| 73 |
function wpAutoP( content ) { |
| 74 |
if ( switchEditors && switchEditors.wpautop ) { |
| 75 |
content = switchEditors.wpautop(content); |
| 76 |
} |
| 77 |
return content; |
| 78 |
} |
| 79 |
|
| 80 |
}); |
| 81 |
})( jQuery ); |