📁 File Manager Pro
v10.0.3 | PHP: 7.4.33
Server: LiteSpeed
2026-06-26 10:33:42
📂
/ (Root)
/
home
/
supecsoq
/
public_html
/
domains
/
migalexpark.com
/
wp-content
/
plugins
/
shortcode-ui
/
js
/
src
/
models
📍 /home/supecsoq/public_html/domains/migalexpark.com/wp-content/plugins/shortcode-ui/js/src/models
🔄 Refresh
✏️
Editing: shortcode.js
Writable
var Backbone = require('backbone'); var ShortcodeAttributes = require('sui-collections/shortcode-attributes'); var InnerContent = require('sui-models/inner-content'); var $ = require('jquery'); Shortcode = Backbone.Model.extend({ defaults: { label: '', shortcode_tag: '', attrs: new ShortcodeAttributes(), attributes_backup: {}, }, /** * Custom set method. * Handles setting the attribute collection. */ set: function( attributes, options ) { if ( attributes.attrs !== undefined && ! ( attributes.attrs instanceof ShortcodeAttributes ) ) { attributes.attrs = new ShortcodeAttributes( attributes.attrs ); } if ( attributes.inner_content && ! ( attributes.inner_content instanceof InnerContent ) ) { attributes.inner_content = new InnerContent( attributes.inner_content ); } return Backbone.Model.prototype.set.call(this, attributes, options); }, /** * Custom toJSON. * Handles converting the attribute collection to JSON. */ toJSON: function( options ) { options = Backbone.Model.prototype.toJSON.call(this, options); if ( options.attrs && ( options.attrs instanceof ShortcodeAttributes ) ) { options.attrs = options.attrs.toJSON(); } if ( options.inner_content && ( options.inner_content instanceof InnerContent ) ) { options.inner_content = options.inner_content.toJSON(); } return options; }, /** * Custom clone * Make sure we don't clone a reference to attributes. */ clone: function() { var clone = Backbone.Model.prototype.clone.call( this ); clone.set( 'attrs', clone.get( 'attrs' ).clone() ); if ( clone.get( 'inner_content' ) ) { clone.set( 'inner_content', clone.get( 'inner_content' ).clone() ); } return clone; }, /** * Get the shortcode as... a shortcode! * * @return string eg [shortcode attr1=value] */ formatShortcode: function() { var template, shortcodeAttributes, attrs = [], content, self = this; this.get( 'attrs' ).each( function( attr ) { // Skip empty attributes. if ( ! attr.get( 'value' ) || attr.get( 'value' ).length < 1 ) { return; } // Encode textareas incase HTML if ( attr.get( 'encode' ) ) { attr.set( 'value', encodeURIComponent( decodeURIComponent( attr.get( 'value' ).replace( /%/g, "%" ) ) ), { silent: true } ); } attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' ); } ); $.each( this.get( 'attributes_backup' ), function( key, value){ attrs.push( key + '="' + value + '"' ); }); if ( this.get( 'inner_content' ) ) { content = this.get( 'inner_content' ).get( 'value' ); } else if ( this.get( 'inner_content_backup' ) ) { content = this.get( 'inner_content_backup' ); } if ( attrs.length > 0 ) { template = "[{{ shortcode }} {{ attributes }}"; } else { template = "[{{ shortcode }}"; } if ( content && content.length > 0 ) { template += "]{{ content }}[/{{ shortcode }}]"; } else { // add closing slash to shortcodes without content template += " /]"; } template = template.replace( /{{ shortcode }}/g, this.get('shortcode_tag') ); template = template.replace( /{{ attributes }}/g, attrs.join( ' ' ) ); template = template.replace( /{{ content }}/g, content ); return template; }, }); module.exports = Shortcode;
💾 Save Changes
❌ Cancel