Commit 219afeb1 authored by campaign's avatar campaign

by zhanyi

parent 1c977eb9
(function(){
var utils = KM.utils;
function hrefStartWith(href, arr) {
href = href.replace(/^\s+|\s+$/g, '');
for (var i = 0, ai; ai = arr[i++];) {
if (href.indexOf(ai) == 0) {
return true;
}
}
return false;
}
KM.registerWidget('markers', {
tpl: "<style type=\"text/css\">" +
".kmui-dialog-link .kmui-link-table{font-size: 12px;margin: 10px;line-height: 30px}" +
".kmui-dialog-link .kmui-link-txt{width:300px;height:21px;line-height:21px;border:1px solid #d7d7d7;}" +
"</style>" +
"<table class=\"kmui-link-table\">" +
"<tr>" +
"<td><label for=\"href\"><%=lang_input_url%></label></td>" +
"<td><input class=\"kmui-link-txt\" id=\"kmui-link-Jhref\" type=\"text\" /></td>" +
"</tr>" +
"<tr>" +
"<td><label for=\"title\"><%=lang_input_title%></label></td>" +
"<td><input class=\"kmui-link-txt\" id=\"kmui-link-Jtitle\" type=\"text\"/></td>" +
"</tr>" +
"<tr>" +
"<td colspan=\"2\">" +
"<label for=\"target\"><%=lang_input_target%></label>" +
"<input id=\"kmui-link-Jtarget\" type=\"checkbox\"/>" +
"</td>" +
"</tr>" +
"</table>",
initContent: function (km) {
var lang = km.getLang('dialogs.markers');
if (lang) {
var html = $.parseTmpl(this.tpl, lang.static);
}
this.root().html(html);
},
initEvent: function (km, $w) {
var link = km.queryCommandValue('link');
if(link){
$('#kmui-link-Jhref',$w).val(utils.html($(link).attr('href')));
$('#kmui-link-Jtitle',$w).val($(link).attr('title'));
$(link).attr('target') == '_blank' && $('#kmui-link-Jtarget').attr('checked',true)
}
},
buttons: {
'ok': {
exec: function (km, $w) {
var href = $('#kmui-link-Jhref').val().replace(/^\s+|\s+$/g, '');
if (href) {
km.execCommand('link', {
'href': href,
'target': $("#kmui-link-Jtarget:checked").length ? "_blank" : '_self',
'title': $("#kmui-link-Jtitle").val().replace(/^\s+|\s+$/g, ''),
'_href': href
});
}
}
},
'cancel':{}
},
width: 400
})
})();
KM.registerUI('markers',function(name){
var me = this, currentRange, $dialog,
opt = {
title: this.getLang('tooltips')[name] || '',
url: me.getOptions('KITYMINDER_HOME_URL') + 'dialogs/' + name + '/' + name + '.js'
};
var $btn = $.kmuibutton({
icon: name,
title: this.getLang('tooltips')[name] || ''
});
//加载模版数据
utils.loadFile(document,{
src: opt.url,
tag: "script",
type: "text/javascript",
defer: "defer"
},function(){
//调整数据
var data = KM.getWidgetData(name);
if(data.buttons){
var ok = data.buttons.ok;
if(ok){
opt.oklabel = ok.label || me.getLang('ok');
if(ok.exec){
opt.okFn = function(){
return $.proxy(ok.exec,null,me,$dialog)()
}
}
}
var cancel = data.buttons.cancel;
if(cancel){
opt.cancellabel = cancel.label || me.getLang('cancel');
if(cancel.exec){
opt.cancelFn = function(){
return $.proxy(cancel.exec,null,me,$dialog)()
}
}
}
}
data.width && (opt.width = data.width);
data.height && (opt.height = data.height);
$dialog = $.kmuimodal(opt);
$dialog.attr('id', 'kmui-dialog-' + name).addClass('kmui-dialog-' + name)
.find('.kmui-modal-body').addClass('kmui-dialog-' + name + '-body');
$dialog.kmui().on('beforeshow', function () {
var $root = this.root(),
win = null,
offset = null;
if (!$root.parent()[0]) {
me.$container.find('.kmui-dialog-container').append($root);
}
KM.setWidgetBody(name,$dialog,me);
}).on('afterbackdrop',function(){
this.$backdrop.css('zIndex',me.getOptions('zIndex')+1).appendTo(me.$container.find('.kmui-dialog-container'))
$dialog.css('zIndex',me.getOptions('zIndex')+2)
}).attachTo($btn)
});
me.on('interactchange', function () {
var state = this.queryCommandState(name);
$btn.kmui().disabled(state == -1).active(state == 1)
});
return $btn;
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment