<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="../../third-party/mathquill/mathquill.css"/>
<style>
html, body, .main{
margin: 0;
padding: 0;
overflow: hidden;
}
.main{
width:1024px;
height:1024px;
}
.mathquill-editable,
.mathquill-rendered-math{
border: 0px;
padding: 0px;
margin:4px;
}
</style>
</head>
<body>
<div class="main">
<div class="mathquill-editable"></div>
</div>
<div>
<input id="blurHelper" />
</div>
<script src="../../third-party/jquery.min.js"></script>
<script src="../../third-party/mathquill/mathquill.js"></script>
<script>
$(function(){
var UM = parent.UM,
$iframe = $(getSelfIframe()),
editorId = $iframe.parents('.edui-body-container').attr('id'),
editor = UM.getEditor(editorId),
timer;
/* 获得当前公式所在的iframe节点 */
function getSelfIframe(){
var iframes = parent.document.getElementsByTagName('iframe');
for (var key in iframes) {
if (iframes[key].contentWindow == window) {
return iframes[key];
}
}
return null;
}
/* 获得当前url上的hash存储的参数值 */
function getLatex() {
return $iframe.attr('data-latex') || '';
}
/* 保存场景 */
function saveScene(){
timer && clearTimeout(timer);
timer = setTimeout(function(){
editor.fireEvent('savescene');
editor.fireEvent('contentchange');
editor.fireEvent('selectionchange');
timer = null;
}, 300);
}
/* 设置编辑器可编辑 */
function enableEditor(){
if(editor.body.contentEditable == 'false') {
editor.setEnabled();
}
}
/* 设置编辑器不可编辑 */
function disableEditor(){
if(editor.body.contentEditable == 'true') {
editor.setDisabled(['undo', 'redo', 'preview', 'formula'], true);
}
}
/* 公式 */
var Formula = function(){
var _this = this,
latex = getLatex();
this.isFocus = false;
this.isDisabled = false;
/* 加载公式内容 */
this.$mathquill = $('.mathquill-editable').mathquill('latex', latex);
/* 设置活动状态的公式iframe */
this.$mathquill.on('mousedown', function(){
/* 编辑器不可用时,公式也不可用 */
if(_this.disabled) return false;
/* 第一次点击当前公式,设置公式活动 */
if(!$iframe.hasClass('edui-formula-active')) {
disableEditor();
editor.blur();
editor.$body.find('iframe').not($iframe).each(function(k, v){
v.contentWindow.formula.blur();
});
if(_this.$mathquill.find('.cursor').css('display') == 'none') {
_this.refresh();
_this.$mathquill.addClass('hasCursor');
}
}
_this.focus();
});
editor.addListener('click', function(){
_this.blur();
enableEditor();
});
/* 里面focus,编辑器也判断为focus */
editor.addListener('isFocus', function(){
return _this.isFocus;
});
/* um不可用,公式也不可编辑 */
editor.addListener('setDisabled', function(type, except){
if (!(except && except.join(' ').indexOf('formula') != -1) && _this.isDisabled != true ) {
_this.setDisabled();
}
});
editor.addListener('setEnabled', function(){
if (_this.isDisabled != false) {
_this.setEnabled();
}
});
/* 设置更新外层iframe的大小和属性 */
$(document.body).on('keydown', function(){
_this.updateIframe();
}).on('keyup', function(){
_this.updateIframe();
});
/* 清除初始化的高亮状态 */
this.$mathquill.removeClass('hasCursor');
/* 初始化后延迟刷新外层iframe大小 */
setTimeout(function(){
_this.updateIframe();
}, 300);
};
Formula.prototype = {
focus:function(){
$iframe.addClass('edui-formula-active');
this.isFocus = true;
},
blur:function(){
$iframe.removeClass('edui-formula-active');
this.removeCursor();
this.isFocus = false;
},
removeCursor: function(){
this.$mathquill.find('span.cursor').hide();
this.$mathquill.parent().find('.hasCursor').removeClass('hasCursor');
},
updateIframe: function(){
$iframe.width(this.$mathquill.width()+8).height(this.$mathquill.height()+8);
var latex = $iframe.attr('data-latex'),
newLatex = this.getLatex();
if(latex != newLatex) {
$iframe.attr('data-latex', this.getLatex());
saveScene();
}
},
insertLatex: function(latex){
this.$mathquill.mathquill('write', latex);
this.updateIframe();
this.removeCursor();
},
setLatex: function(latex){
this.$mathquill.mathquill('latex', latex);
this.updateIframe();
},
getLatex: function(){
return this.$mathquill.mathquill('latex');
},
redraw: function(){
this.$mathquill.mathquill('redraw');
},
setDisabled: function(){
this.blur();
var latex = this.getLatex();
this.$mathquill.mathquill('revert').text(latex).mathquill();
this.updateIframe();
this.isDisabled = true;
},
setEnabled: function(){
this.$mathquill.removeClass('mathquill-rendered-math');
this.refresh();
this.isDisabled = false;
},
refresh: function(){
var latex = this.getLatex();
this.$mathquill.mathquill('revert').text(latex).mathquill('editable');
this.updateIframe();
}
};
/* 绑定到window上,给上级window调用 */
window.formula = new Formula();
});
</script>
</body>
</html>
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
萤火小程序商城,是一款新型便捷的电商小程序系统 (735个子文件)
.bowerrc 34B
UploadController.cs 11KB
Startup.cs 10KB
SettingController.cs 10KB
AutoMapperConfig.cs 9KB
Extensions.cs 8KB
GoodsController.cs 8KB
DeliveryController.cs 8KB
BaseController.cs 7KB
OrderController.cs 7KB
LoginController.cs 6KB
SellerGoodsRequest.cs 6KB
UserController.cs 6KB
WxAppController.cs 5KB
Middlewares.cs 5KB
CategoryController.cs 4KB
AddressController.cs 4KB
ErrorController.cs 4KB
TagHelpers.cs 3KB
HelpController.cs 3KB
SpecController.cs 3KB
HomeController.cs 3KB
GlobalConfig.cs 3KB
OrderGoods.cs 3KB
Order.cs 2KB
WxHttpClient.cs 2KB
Goods.cs 2KB
CartController.cs 2KB
SellerBaseController.cs 2KB
Wxapp.cs 2KB
UserIndexController.cs 2KB
Models.cs 2KB
SpecManyDto.cs 2KB
Region.cs 2KB
IndexController.cs 2KB
OrderAddress.cs 2KB
SellerDeliveryRequest.cs 2KB
UserBaseController.cs 2KB
User.cs 2KB
Program.cs 2KB
UploadFile.cs 2KB
GoodsSpec.cs 2KB
Enums.cs 1KB
UserAddress.cs 1KB
SellerBaseViewModel.cs 1KB
WxappController.cs 1KB
ResultInfo.cs 1KB
NavigationViewComponent.cs 1KB
Category.cs 1KB
GoodsController.cs 1KB
DeliveryRule.cs 1KB
CartDto.cs 1KB
OrderDto.cs 1KB
ApiBaseController.cs 1KB
SpecManyDto.cs 991B
GoodsSpecRel.cs 972B
UserController.cs 963B
GoodsDto.cs 959B
FileUploadRequest.cs 925B
Requests.cs 908B
Models.cs 876B
WxappNavbar.cs 870B
GoodsSpecDto.cs 844B
DeliveryRuleDto.cs 841B
UploadGroup.cs 835B
GoodsImage.cs 804B
FilePageRequest.cs 785B
WxappHelp.cs 775B
UploadFileUsed.cs 774B
CategoryController.cs 772B
Delivery.cs 759B
StoreUser.cs 745B
BaseEntity.cs 707B
SellerLoginRequest.cs 707B
Dictionary.cs 688B
CategoryDto.cs 667B
SpecValue.cs 654B
WxappPage.cs 653B
SellerPasswordRequest.cs 653B
RegionDto.cs 632B
UserDto.cs 631B
Program.cs 599B
UploadGroupRequest.cs 584B
Setting.cs 579B
GoodsSpecRelDto.cs 570B
Spec.cs 519B
MenuDto.cs 504B
DeliveryDto.cs 500B
AppSettings.cs 482B
AddressRequest.cs 452B
SessionConfig.cs 448B
SpecValueDto.cs 435B
StoreUserDto.cs 398B
WxappConfig.cs 357B
BaseDto.cs 356B
WxappHelpDto.cs 351B
CartGoodsDto.cs 211B
Edit.cshtml 22KB
Add.cshtml 20KB
Detail.cshtml 15KB
共 735 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
白话机器学习
- 粉丝: 8795
- 资源: 7682
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功