terehovskiy Posted January 1, 2015 Share Posted January 1, 2015 Пожалуйста, помогите добавить функцию, для моего bb кода . Есть функция в которой я посмотрел реализацию всплывающего окна, при использовании bb кода в визуальном редакторе. Мне нужно переделать эту функцию под мой код. Ниже сама функция. Не понятные которые части функции, их я отметил комментарием. В моем случае юзеры будут вставлять часть ссылки после "=" с youtube, например aF_GwG4v-sw . this.___IPB_FUNCTIONS = function() {}; this.createlink = function(e) { var _text = this.get_selection(); // _text = _text.replace(/\n|\r|<br \/>/g, ''); // if (_text.match(/(<a href|\[url)/ig)) { this.format_text(e, "unlink", false); } else { var _url = prompt(ipb_global_lang['editor_enter_youtube'], ''); if (!_url || _url == null || _url == '') { return false; } _text = _text ? _text : prompt(ipb_global_lang[ 'editor_enter_title'], ipb_global_lang[ 'visit_my_website']); if (!_text || _text == null) { return false; } this.wrap_tags('url', _url, _text); } }; Link to comment Share on other sites More sharing options...
siv1987 Posted January 1, 2015 Share Posted January 1, 2015 Через всплывающие окно можно вставлять и прямую ссылку, и парсить из нее нужный параметр. var match = _text.match(/(?:\?|&)v=(.+?)(&|$)/); if(match){ _text = match[1]; } this.wrap_tags('youtube', false, _text); Link to comment Share on other sites More sharing options...
terehovskiy Posted January 3, 2015 Author Share Posted January 3, 2015 Простите за мою тупость, но я так и не понял как в итоге должна выглядеть функция. Link to comment Share on other sites More sharing options...
siv1987 Posted January 3, 2015 Share Posted January 3, 2015 Да все также как у вас.this.wrap_tags - вставляет отформатированный ббкод в редактор. В вашем случае this.wrap_tags('youtube', false, _text); this.createlink - это функция которая отработает при нажатии кнопки. Если кнопка в редакторе имеет ид "fast-reply_cmd_ipb_youtube", то имя функции будет this.ipb_youtube.Если хотите дополнительно обработать прямые ссылки ютуба, можете юзать код который я привел выше. В итоге должно получится нечто похожее на это: this.ipb_youtube = function(e) { var _text = this.get_selection(); _text = _text ? _text : prompt('Enter youtube url or video id', ''); if (!_text || _text == null) { return false; } var match = _text.match(/(?:\?|&)v=(.+?)(&|$)/); if(match){ _text = match[1]; } this.wrap_tags('youtube', false, _text); }; Можно будет вставлять как полною ссылку на ютуб, так и только ид видео. В \jscripts\ips_text_editor.js (для полного редактора)Добавить ниже this.ipb_code=function(){this.wrap_tags_lite('[code]','',0)};[/code]В \jscripts\ips_text_editor_lite.js (для быстрого редактора)Добавить ниже this.ipb_code=function(){var _text=this.get_selection();this.wrap_tags('code',false,_text);}; 1 Link to comment Share on other sites More sharing options...
terehovskiy Posted January 3, 2015 Author Share Posted January 3, 2015 К сожалению функция в итоге не работает, в \jscripts\ips_text_editor.js и \jscripts\ips_text_editor_lite.js она у меня уже добавлена как youtube. Тут "_text = _text ? _text : prompt('Enter youtube url or video id', '');" изменил на "_text = _text ? _text : prompt(ipb_global_lang['editor_enter_youtube'], '');", т.к. в ланг кеше у меня проставлен тег как для url "editor_enter_youtube", но это также ни к чему, не привело. Кеш обновлял. Link to comment Share on other sites More sharing options...
siv1987 Posted January 3, 2015 Share Posted January 3, 2015 Функция рабочая, я ее тестировал на локалхосте. Еще раз внимательно все проверьте, особенно с редактированием файлов, там легко ошибиться. Также обратите внимание где я говорил про имени функции в зависимости от ид кнопки, возможно она просто не срабатывает. Link to comment Share on other sites More sharing options...
terehovskiy Posted January 3, 2015 Author Share Posted January 3, 2015 (edited) Не работает. Кеш обновлял. Как и раньше, просто вставляется bb код в окно редактора. this.ipb_youtube = function(e) { var _text = this.get_selection(); _text = _text ? _text : prompt('Enter youtube url or video id', ''); if (!_text || _text == null) { return false; } var match = _text.match(/(?:\?|&)v=(.+?)(&|$)/); if(match){ _text = match[1]; } this.wrap_tags('youtube', false, _text); }; this.ipb_youtube = function() { this.wrap_tags_lite('[youtube]', '[/youtube]', 0) }; this.ipb_youtube=function(){var _text=this.get_selection();this.wrap_tags('youtube',false,_text);}; Edited January 3, 2015 by terehovskiy Link to comment Share on other sites More sharing options...
siv1987 Posted January 4, 2015 Share Posted January 4, 2015 Переправеряйте, учитывая все нюансы о которых я говорил выше. Дебажте что у вас там просто "вставляется". Не советую плодить много функций, еще больше в них запутаетесь. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now