mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 07:20:57 +01:00
df7f21b4e8
Summary: Reuse PHUIMarkupPreviewView in Phame for consistency, less custom code. Also, doesn't work (JS issue). Test Plan: New Post, Edit Post, Save Post Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14552
67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
/**
|
|
* @provides javelin-behavior-phame-post-preview
|
|
* @requires javelin-behavior
|
|
* javelin-dom
|
|
* javelin-util
|
|
* phabricator-shaped-request
|
|
*/
|
|
|
|
JX.behavior('phame-post-preview', function(config) {
|
|
|
|
var title = JX.$(config.title);
|
|
var phame_title = JX.$(config.phame_title);
|
|
var sync_titles = true;
|
|
|
|
var titleCallback = function() {
|
|
if (!sync_titles) {
|
|
return;
|
|
}
|
|
var title_string = title.value;
|
|
phame_title.value = normalizeSlug(title_string);
|
|
};
|
|
|
|
var phameTitleKeyupCallback = function () {
|
|
// stop sync'ing once user edits phame_title directly
|
|
sync_titles = false;
|
|
var normalized = normalizeSlug(phame_title.value, true);
|
|
if (normalized == phame_title.value) {
|
|
return;
|
|
}
|
|
var position = phame_title.value.length;
|
|
if ('selectionStart' in phame_title) {
|
|
position = phame_title.selectionStart;
|
|
}
|
|
phame_title.value = normalized;
|
|
if ('setSelectionRange' in phame_title) {
|
|
phame_title.focus();
|
|
phame_title.setSelectionRange(position, position);
|
|
}
|
|
};
|
|
|
|
var phameTitleBlurCallback = function () {
|
|
phame_title.value = normalizeSlug(phame_title.value);
|
|
};
|
|
|
|
// This is a sort of implementation of PhabricatorSlug::normalize
|
|
var normalizeSlug = function (slug, spare_trailing_underscore) {
|
|
var s = slug.toLowerCase().replace(/[^a-z0-9/]+/g, '_').substr(0, 63);
|
|
if (spare_trailing_underscore) {
|
|
// do nothing
|
|
} else {
|
|
s = s.replace(/_$/g, '');
|
|
}
|
|
return s;
|
|
};
|
|
|
|
var getdata = function() {
|
|
return {
|
|
title : title.value,
|
|
phame_title : phame_title.value
|
|
};
|
|
};
|
|
|
|
JX.DOM.listen(title, 'keyup', null, titleCallback);
|
|
JX.DOM.listen(phame_title, 'keyup', null, phameTitleKeyupCallback);
|
|
JX.DOM.listen(phame_title, 'blur', null, phameTitleBlurCallback);
|
|
|
|
});
|