jordandelozier / wysibb

WYSIWYG BBcode editor
http://www.wysibb.com
246 stars 86 forks source link

I need advanced transform #91

Closed KiberMath closed 9 years ago

KiberMath commented 9 years ago

as i can se now in this plugin we can use only simple transform

                transform: {
                    '<font size="2">{SELTEXT}</font>':'[size=85]{SELTEXT}[/size]'
                }

but i need more advanced one.

for example

if want to add tag [img id=234]

and transform it with function

function MyFunction(id)
{
///// some stuff
///.

return "< img src='path/to/img'  class='MY_img_Class'/>";
}            
SiteSplat commented 9 years ago

+1.

Jinkx commented 9 years ago

If you are using a modal you can have an OnSubmit parameter. I am totally noob in jquery but I could figure some things out by looking in the source code. There is an modal/transform for Youtube-video which can give you some clues.

                video: {
                    title: CURLANG.video,
                    buttonHTML: '<span class="fonticon ve-tlb-video1">\uE008</span>',
                    modal: {
                        title: CURLANG.video,
                        width: "600px",
                        tabs: [
                            {
                                title: CURLANG.video,
                                input: [
                                    {param: "SRC",title:CURLANG.modal_video_text}
                                ]
                            }
                        ],
                        onSubmit: function(cmd,opt,queryState) {
                            var url = this.$modal.find('input[name="SRC"]').val();

                            if (url) {
                                url = url.replace(/^\s+/,"").replace(/\s+$/,"");
                            }
                            var a;
                            if (url.indexOf("youtu.be")!=-1) {
                                a = url.match(/^http[s]*:\/\/youtu\.be\/([a-z0-9_-]+)/i);
                            }else{
                                a = url.match(/^http[s]*:\/\/www\.youtube\.com\/watch\?.*?v=([a-z0-9_-]+)/i);
                            }
                            if (a && a.length==2) {
                                var code = a[1];
                                this.insertAtCursor(this.getCodeByCommand(cmd,{src:code}));
                            }
                            this.closeModal();
                            this.updateUI();
                            return false;
                        }
                    },
                    transform: {
                        '<iframe src="http://www.youtube.com/embed/{SRC}" width="640" height="480" frameborder="0"></iframe>':'[video]{SRC}[/video]'

From this I managed to add som custom bbcodes and I dont think your transform would be a problem. Good Luck!

baychae commented 8 years ago

+1 I need to be able to process between transforms. onTransform: function(cmd,opt,queryState){}