I am trying to display math-equations in a Sencha view component (extends: Ext.Container), using a Ext.Label Component and MathJax JS. (As was suggested answering my other question: Display math symbols in Ext.js / Sencha Touch)
This is the initialization of the view component:
Ext.define('TIQuiz3.view.Question', {
extend: 'Ext.Container',
...
requires: ['Ext.Label', ...],
config: {
fullscreen: true,
...
layout: {
type: 'vbox',
align: 'stretch'
}
},
initialize: function() {
this.callParent();
...
var questionLabel = {
xtype: 'label',
style: {
'border':'1px solid black',
'background':'white'
},
margin: 10,
padding: 10,
html: "<div>Es sei $L = \{011, 01, 11, 100\}$ \"uber dem Alphabet $\Sigma = \{0,1\}$.</div>",
flex: 1
};
...
this.add([...,questionLabel,...]);
}
I have included a local copy of MathJAX in the app.json file:
"js": [
{
"path": "touch/sencha-touch.js",
"x-bootstrap": true
},
{
"path": "bootstrap.js",
"x-bootstrap": true
},
{
"path": "resources/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML",
"update": "delta"
},
{
"path": "app.js",
"bundle": true, /* Indicates that all class dependencies are concatenated into this file when build */
"update": "delta"
}
],
MathJax indicates to be loaded successfully.
But the output of the label does not display math properly. Instead it simply looks like this:
Es sei $L = {011, 01, 11, 100}$ "uber dem Alphabet $Sigma = {0,1}$.
Is displaying math with MathJax and HTML possible using a Sencha Label Component?
Any advice appreciated!
Thanks,
Thomas
Ok, thanks Peter, that brought me to the solution.
The problem was indeed the rendering of the content after the onload-event of the page.
For these cases MathJax holds a method to invoke the typesetting manually at a later time. So what I did was adding the following afterPainted-Listener to the rendered view component:
listeners : {
order : 'after',
painted : function() {
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
}
Note that, as Peter pointed out, in order for the upper to work one has to configure $ to be accepted as math delimiter from MathJax - which is not default behaviour.
Thanks for the advice!
Related
I am learning to build a blog using Sanity CMS and React. I am new to Sanity.
I should be able to insert code snippets in my blog posts. So, I have installed the code-input plugin.
According to the link here, after I install the plugin I have to use the following code in my schema types.
I have no idea where do I insert the code.
Please help.
My folder structure is as follows:
sanityblog/blockContent.js
/**
* This is the schema definition for the rich text fields used for
* for this blog studio. When you import it in schemas.js it can be
* reused in other parts of the studio with:
* {
* name: 'someName',
* title: 'Some title',
* type: 'blockContent'
* }
*/
export default {
title: "Block Content",
name: "blockContent",
type: "array",
of: [
{
title: "Block",
type: "block",
// Styles let you set what your user can mark up blocks with. These
// correspond with HTML tags, but you can set any title or value
// you want and decide how you want to deal with it where you want to
// use your content.
styles: [
{ title: "Normal", value: "normal" },
{ title: "H1", value: "h1" },
{ title: "H2", value: "h2" },
{ title: "H3", value: "h3" },
{ title: "H4", value: "h4" },
{ title: "Quote", value: "blockquote" },
],
lists: [{ title: "Bullet", value: "bullet" }],
// Marks let you mark up inline text in the block editor.
marks: {
// Decorators usually describe a single property – e.g. a typographic
// preference or highlighting by editors.
decorators: [
{ title: "Strong", value: "strong" },
{ title: "Emphasis", value: "em" },
],
// Annotations can be any object structure – e.g. a link or a footnote.
annotations: [
{
title: "URL",
name: "link",
type: "object",
fields: [
{
title: "URL",
name: "href",
type: "url",
},
],
},
],
},
},
// You can add additional types here. Note that you can't use
// primitive types such as 'string' and 'number' in the same array
// as a block type.
{
type: "image",
options: { hotspot: true },
},
],
};
sanityblog/schema.js
// First, we must import the schema creator
import createSchema from "part:#sanity/base/schema-creator";
// Then import schema types from any plugins that might expose them
import schemaTypes from "all:part:#sanity/base/schema-type";
// We import object and document schemas
import blockContent from "./blockContent";
import category from "./category";
import post from "./post";
import author from "./author";
// Then we give our schema to the builder and provide the result to Sanity
export default createSchema({
// We name our schema
name: "default",
// Then proceed to concatenate our document type
// to the ones provided by any plugins that are installed
types: schemaTypes.concat([
// The following are document types which will appear
// in the studio.
post,
author,
category,
// When added to this list, object types can be used as
// { type: 'typename' } in other document schemas
blockContent,
]),
});
If you installed the plugin correctly, it's now available as a schema type to be used in any of your other schemas. So, to answer your question, you can put that code anywhere you want code blocks in your Sanity studio. I'd strongly suggest going over the content modelling documentation 😉
Specifically to your question, assuming you use the sanityBlog/blockContent.js field for the content of your posts, you can add it there. Here's how that would look like:
export default {
title: "Block Content",
name: "blockContent",
type: "array",
of: [
{
title: "Block",
type: "block",
// ...annotations, styles, lists and marks you already have
},
{
type: "image",
options: { hotspot: true },
},
// Add the code block here 👇
// it'll show up as one of the blocks available in your
// Portable Text Editor
{
type: "code",
title: "Code block",
}
],
};
For specifics on the portable text / rich content field (type: "block"), refer to the block type documentation. If you want to take it one step back, refer to the general block content documentation.
Hope this helps 🙌
Just started using Quill and find it very useful. My projects require plain text editing. Specifically I'm using quill as a form to enter YAML code. The dash, "-", is a key item in YAML. The problem is Quill automatically formats the line as a bullet.
Is there a way to disable automatic bullets?
Kevin
As mentioned in the comments, whitelist things you'll allow in the "formats" option (not the toolbar area)
var editor = new quill("#someElemId", {
modules: {
toolbar: [
'bold',
//{ 'list': 'bullet' },
{ 'indent': '-1'},
{ 'indent': '+1' },
{ 'color': ['black', 'red', 'blue', 'green'] },
'link',
'clean'
]
},
formats : [
"background",
"bold",
"color",
"font",
"code",
"italic",
"link",
"size",
"strike",
"script",
"underline",
"blockquote",
// "header",
"indent",
// "list", <-- commented-out to suppress auto bullets
"align",
"direction",
"code-block",
"formula",
"image",
"video"
],
theme: 'snow', // snow bubble
});
Quill's built in Keyboard module is responsible for auto formatting lists. You can override or disable this behavior by importing and extending the keyboard module like so.
var Keyboard = Quill.import('modules/keyboard');
class CustomKeyboard extends Keyboard {
static DEFAULTS = {
...Keyboard.DEFAULTS,
bindings: {
...Keyboard.DEFAULTS.bindings,
['list autofill']: undefined,
}
}
}
Quill.register('modules/keyboard', CustomKeyboard);
If you still list detection for other input ("* " for example), you can change the regex that the 'list autofill' binding matches like so
var Keyboard = Quill.import('modules/keyboard');
class CustomKeyboard extends Keyboard {
static DEFAULTS = {
...Keyboard.DEFAULTS,
bindings: {
...Keyboard.DEFAULTS.bindings,
['list autofill']: {
...Keyboard.DEFAULTS.bindings['list autofill'],
prefix: /^\s*?(\d+\.|\*|\[ ?\]|\[x\])$/
},
}
}
}
Quill.register('modules/keyboard', CustomKeyboard);
Here is a working example: https://codepen.io/josephdangerstewart/pen/dyNEGoj
Further documentation on Modules can be found on the Quill website: https://quilljs.com/docs/modules/#extending
Looking at https://quilljs.com/docs/formats/ there doesn't appear to be a way to disable a specific format, but you may be able to simply create a list of all formats and remove the list format.
Just write:
modules: {
keyboard: {
bindings: {
'list autofill': {
prefix: /^\s*()$/
}
}
}
}
This will ignore automatically ordered lists.
However, you still use bullets manually, by clicking the indent command or using the tab key.
Trying to display Milestone for each release, but when trying to create DataStore for Milestone getting error
Uncaught Rally.data.ModelFactory.getModel(): Could not find registered factory for type: milestone
below is my code any ideas or suggestions on this
_getMileStones: function(startDate, endDate, project_id) {
var startDateFilter = Ext.create('Rally.data.QueryFilter', {
property: 'TargetDate',
operator: '>',
value: startDate
});
startDateFilter = startDateFilter.and({
property: 'TargetDate',
operator: '<',
value: endDate
});
startDateFilter = startDateFilter.and({
property: 'TargetDate',
operator: '!=',
value: null
});
startDateFilter = startDateFilter.and({
property: 'TargetDate',
operator: '!=',
value: null
});
var filters = startDateFilter;
Ext.create('Rally.data.wsapi.Store',{
model: 'milestone',
autoLoad: true,
filters: filters,
context: {
project: project_id,
projectScopeDown: true,
projectScopeUp: false
},
fetch: ['Name','FormattedID','DisplayColor'],
listeners: {
load: function(store,records) {
console.log("records values", records);
}
}
}, this);
},
The current stable rc3 release candidate of AppSDK2 predates milestones. They are not available in rc3. When I use rc3 I get the same error you get. If I switch to "x", in the app's config file, and use rab build to rebuild the app, the error goes away:
{
"name": "myapp",
"className": "CustomApp",
"server": "https://rally1.rallydev.com",
"sdk": "x",
"javascript": [
"App.js"
],
"css": [
"app.css"
]
}
Generally it is not recommend using "x" because it is constantly changes. It is not a stable version. But as long as you know that, you may use "x". The AppSDK next release may not be too far in the future, and it will include support for Milestones.
UPDATE: AppSDK2.0 GA has not been announced yet, but it is expected to be released soon. If you use "sdk":"2.0" you get Milestone data.
"x" returns Milestones, but it is a head version that is subject to constant changes. 2.0rc3 does not have Milestones.
You may choose to use 2.0 even though it is not formally available yet.
This app example:
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
Ext.create('Rally.data.wsapi.Store',{
model: 'milestone',
autoLoad: true,
fetch: ['Name'],
listeners: {
load: function(store,records) {
console.log("records values", records);
}
}
}, this);
}
});
Along with this config:
{
"name": "milestones",
"className": "CustomApp",
"server": "https://rally1.rallydev.com",
"sdk": "2.0",
"javascript": [
"App.js"
],
"css": [
"app.css"
]
}
will return milestone data:
I try to use Ext.Direct with the ExtJS 4 MVC structure, and I'm not able to add the provider.
I get the error Uncaught TypeError: Cannot call method 'addProvider' of undefined while calling addProvider:
Ext.Direct.addProvider(Ext.app.REMOTING_API);
I tried both in launch of the application and in initof the controller.
Ext.define('Dir.Application', {
require: [
'Ext.direct.*',
'Ext.data.*',
'Ext.grid.*'
],
launch: function(){
Ext.Direct.addProvider(Ext.app.REMOTING_API);
}
...
});
and
Ext.define('Dir.controller.Main', {
init: function(){
Ext.Direct.addProvider(Ext.app.REMOTING_API);
}
...
});
both give the same error.
Where is the correct location to put addProvider into the code ?
Update: applying the recommendations of #rixo.
Ext.define('Dir.Application', {
view:['Grid'],
requires: [
'Ext.direct.*',
'Ext.data.*',
'Ext.grid.*'
],
launch: function(){
Ext.Direct.addProvider(Ext.app.REMOTING_API);
}
...
});
My view is defining a store and a proxy:
Ext.define('Dir.view.Grid', {
extend: 'Ext.grid.Panel',
store: {
proxy: {
type: 'direct',
reader:{root: 'table'},
api: {
create: QueryDatabase.createRecord,
read: QueryDatabase.getResults,
update: QueryDatabase.updateRecords,
destroy: QueryDatabase.destroyRecord
}
}
...
}
Now the first error is OK, but I receiver an error complaining that QueryDatabase is not defined. It gets defined through the provider at Ext.Direct.addProvider(Ext.app.REMOTING_API); but it is not ready when the view is loaded through the views: [] declaration in the application definition.
Is there a way to get this working without nesting Ext.application inside Ext.onReady like in my solution?
No nesting would be better for the MVC way like explained here in the docs.
The require in your application definition won't do anything. It should be plural requires.
Also, you seem to have devised this in your own answer, but the name Ext.direct.Manager seems to be the favored by Sencha over Ext.Direct now.
Edit
According to the docs, you can set your direct functions using a string. Apparently, this is intended to solve exactly the kind of problems you've run into.
This should work and fix your issue:
api: {
create: 'QueryDatabase.createRecord',
read: 'QueryDatabase.getResults',
update: 'QueryDatabase.updateRecords',
destroy: 'QueryDatabase.destroyRecord'
}
Probably you are missing the API definition before calling the provider, take a look to this definition from Sencha's examples page
Ext.ns("Ext.app"); Ext.app.REMOTING_API = {
"url": "php\/router.php",
"type": "remoting",
"actions": {
"TestAction": [{
"name": "doEcho",
"len": 1
}, {
"name": "multiply",
"len": 1
}, {
"name": "getTree",
"len": 1
}, {
"name": "getGrid",
"len": 1
}, {
"name": "showDetails",
"params": ["firstName", "lastName", "age"]
}], ...}]
} };
It should be included as a javascript file inside your webpage
<script type="text/javascript" src="api.php"></script>
Something like this example.
Hope it helps.
Adding Direct providers is better done before the Application constructor runs:
Ext.define('Foo.Application', {
extend: 'Ext.app.Application',
requires: [
'Ext.direct.Manager',
'Ext.direct.RemotingProvider'
],
name: 'Foo',
constructor: function() {
Ext.direct.Manager.addProvider(...);
this.callParent(arguments);
}
});
Ext.application('Foo.Application');
I found this solution:
Ext.require([
'Ext.direct.RemotingProvider',
'Ext.direct.Manager',
'Ext.data.proxy.Direct'
]);
Ext.onReady(function(){
Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);
Ext.application({
name: 'Dir',
extend: 'Dir.Application'
});
});
It doesn't look really nice, because it uses the ExtJS 4 application instantiation inside a Ext.onReady.
At least it works. Maybe there is a better solution ?
I am working in extjs4 MVC. I am getting stuck at a point where I have been working on association.Association is working properly when I am using in my system local side.But when I am uploading it to server side then the associated data is not displaying.I am trying a lot but not getting answer how this conflict occurs.
My application is working properly at client side.It displays associated data also.But when when I uploading data to server side then it does not display associated data.
Here is my application's some part which is working at local side:--
But when I am uploading my side to server side then the options means associated data is not displayed
Here Is my some code:--
1) Model class :--
Ext.define('B.model.kp.PollModel',{
extend: 'Ext.data.Model',
idproperty:'',//fields property first position pk.
fields: ['pollId','pollQuestion','isActive','pollTypeId','createDate','userId','publishDate','isPublished','approvalUserId','percentagevotes','optionId'],
hasMany:{
model:'B.model.kp.PolloptionModel',
foreignKey:'pollId',
name:'options',
},
proxy:
{
type:'ajax',
api:
{
read:'index.php/KnowledgePortal/Poll/GetPublicPoll',
create:'index.php/KnowledgePortal/Pollvote/setPollVote',
},//End of api
reader:
{
type:'json',
root: 'polls',
//successProperty: ,
},//End of reader
writer:
{
type:'json',
root: 'records',
//successProperty: ,
},
}//End of proxy
});
2) Store class :--
Ext.define('B.store.kp.PollStore',{
extend: 'Ext.data.Store',
model: 'B.model.kp.PollModel',
autoLoad: true,
});//End of store
3) View class:--
Ext.define('B.view.kp.poll.PollView',{
extend:'Ext.view.View',
id:'pollViewId',
alias:'widget.PollView',
store:'kp.PollStore',
config:
{
tpl:'<tpl for=".">'+
'<div id="main">'+
'</br>'+
'<b>Question :-</b> {pollQuestion}</br>'+
'<tpl for="options">'+
'<p>{#}.<input type="radio" name="{parent.pollId}" value="{optionId}"> {option}</p>'+
'</tpl></p>'+
'</div>'+
'</tpl>',
itemSelector:'div.main',
},
});// End of login class
4) here is my main view class
Ext.define('B.view.kp.poll.Poll',{
extend:'Ext.form.Panel',
requires:[
'B.view.kp.poll.PollView'
],
id:'pollId',
alias:'widget.Poll',
title:'Poll',
//height:180,
items:[
{
xtype:'PollView',
},
],//end of items square
buttons:[
{
disabled:true,
name:'vote',
formBind:true,
text:'vote',
action:'voteAction'
},
{
text:'result',
action:'resultAction',
}
]
});
5) And here is the json file --
{
'polls': [
{
"pollId": 1,
"pollQuestion": 'Who will win the match',
"options": [
{
"optionId":1,
"option":'India',
"pollId":1
},
{
"optionId": 2,
"option": 'Pakistan',
"pollId":1
},
{
"optionId": 3,
"option": 'Srilanka',
"pollId":1
},
{
"optionId": 4,
"option": 'Australia',
"pollId":1
},
],
}
]
}
6) PollOption model class :--
Ext.define('B.model.kp.PolloptionModel',{
extend: 'Ext.data.Model',
//idproperty:'',//fields property first position pk.
fields: ['optionId','option','pollId','percentagevotes'],
associations:[
{type:'HasMany', model:'Pollvotemodel', foreignKey:'optionId'},
{type:'BelongsTo', model:'PollModel', foreignKey:'pollId'},
]
});
Please someone give me some suggestion to solve this problem...
are you sure your server-side data feed is exactly the same as your local data feed.
Are the related questions entered into the live database?