| 1 |
(function() { |
| 2 |
tinymce.create('tinymce.plugins.kadvideo', { |
| 3 |
init : function(ed, url) { |
| 4 |
var t = this; |
| 5 |
// Register commands |
| 6 |
ed.addCommand('mcekadvideo', function() { |
| 7 |
ed.windowManager.open({ |
| 8 |
file: ajaxurl + '?action=kadvideo_tinymce', |
| 9 |
width : 350 + ed.getLang('button.delta_width', 0), // size of our window |
| 10 |
height : 250 + ed.getLang('button.delta_height', 0), // size of our window |
| 11 |
inline : 1 |
| 12 |
}, { |
| 13 |
plugin_url : url |
| 14 |
}); |
| 15 |
}); |
| 16 |
ed.onNodeChange.add(function(ed, cm, n) { |
| 17 |
cm.setActive('kadvideo', n.nodeName == 'IMG'); |
| 18 |
}); |
| 19 |
|
| 20 |
// Register buttons |
| 21 |
ed.addButton('kadvideo', {title : 'Insert video', cmd : 'mcekadvideo', image: url + '/img/video.png' }); |
| 22 |
ed.onBeforeSetContent.add(function(ed, o) { |
| 23 |
o.content = t._do_video(o.content, url); |
| 24 |
}); |
| 25 |
ed.onBeforeSetContent.add(function(ed, o) { |
| 26 |
o.content = t._do_videoend(o.content, url); |
| 27 |
}); |
| 28 |
|
| 29 |
ed.onPostProcess.add(function(ed, o) { |
| 30 |
if (o.get) |
| 31 |
o.content = t._get_video(o.content, url); |
| 32 |
}); |
| 33 |
ed.onPostProcess.add(function(ed, o) { |
| 34 |
if (o.get) |
| 35 |
o.content = t._get_videoend(o.content, url); |
| 36 |
}); |
| 37 |
}, |
| 38 |
|
| 39 |
_do_video : function(co) { |
| 40 |
return co.replace(/\[video([^\]]*)\]/g, function(a,b){ |
| 41 |
return '<img src="'+url+'/img/t.gif" class="kadvideo mceItem" title="video'+tinymce.DOM.encode(b)+'" />'; |
| 42 |
}); |
| 43 |
}, |
| 44 |
_do_videoend : function(co) { |
| 45 |
return co.replace(/\[\/video([^\]]*)\]/g, function(a,b){ |
| 46 |
return '<img src="'+url+'/img/t.gif" class="kadvideoend mceItem" title="/video" />'; |
| 47 |
}); |
| 48 |
}, |
| 49 |
|
| 50 |
_get_video : function(co) { |
| 51 |
|
| 52 |
function getAttr(s, n) { |
| 53 |
n = new RegExp(n + '=\"([^\"]+)\"', 'g').exec(s); |
| 54 |
return n ? tinymce.DOM.decode(n[1]) : ''; |
| 55 |
}; |
| 56 |
|
| 57 |
return co.replace(/(?:<p[^>]*>)*(<img[^>]+>)(?:<\/p>)*/g, function(a,im) { |
| 58 |
var cls = getAttr(im, 'class'); |
| 59 |
|
| 60 |
if ( cls.indexOf('kadvideo') != -1 ) |
| 61 |
return '<p>['+tinymce.trim(getAttr(im, 'title'))+']</p>'; |
| 62 |
|
| 63 |
return a; |
| 64 |
}); |
| 65 |
}, |
| 66 |
_get_videoend : function(co) { |
| 67 |
|
| 68 |
function getAttr(s, n) { |
| 69 |
n = new RegExp(n + '=\"([^\"]+)\"', 'g').exec(s); |
| 70 |
return n ? tinymce.DOM.decode(n[1]) : ''; |
| 71 |
}; |
| 72 |
|
| 73 |
return co.replace(/(?:<p[^>]*>)*(<img[^>]+>)(?:<\/p>)*/g, function(a,im) { |
| 74 |
var cls = getAttr(im, 'class'); |
| 75 |
|
| 76 |
if ( cls.indexOf('kadvideoend') != -1 ) |
| 77 |
return '<p>['+tinymce.trim(getAttr(im, 'title'))+']</p>'; |
| 78 |
|
| 79 |
return a; |
| 80 |
}); |
| 81 |
}, |
| 82 |
getInfo : function() { |
| 83 |
return { |
| 84 |
longname : 'Insert video', |
| 85 |
author : 'Benjamin Ritner', |
| 86 |
authorurl : 'http://kadencethemes.com', |
| 87 |
infourl : 'http://kadencethemes.com', |
| 88 |
version : tinymce.majorVersion + "." + tinymce.minorVersion |
| 89 |
}; |
| 90 |
} |
| 91 |
}); |
| 92 |
|
| 93 |
// Register plugin |
| 94 |
// first parameter is the button ID and must match ID elsewhere |
| 95 |
// second parameter must match the first parameter of the tinymce.create() function above |
| 96 |
tinymce.PluginManager.add('kadvideo', tinymce.plugins.kadvideo); |
| 97 |
|
| 98 |
})(); |