How do I format HTML code in Code Mirror when the value is set to it? - codemirror

I am using the Code Mirror plugin to edit HTML source of a page. The HTML code is fetched from database and set as value in Code Mirror. But, after setting the value it is displayed in the same format in which it was saved in the database. How can I display it in proper format? Thanks in advance.

There is a function called autoFormatRange
editor.autoFormatRange(range.from, range.to);
This fragment from the CodeMirror Group might be what you need:
function autoFormat() {
var totalLines = editor.lineCount();
var totalChars = editor.getTextArea().value.length;
editor.autoFormatRange({line:0, ch:0}, {line:totalLines, ch:totalChars});
}
http://codemirror.net/2/demo/formatting.html

Related

Formatting date inside of component (ionic)

Im working an app with appery.io platform using ionic 1
I have a date value inside of text component.
If I use:
{{user.user_date}}
Return
{"$date":"1958-12-08T00:00:000Z"} // Correct value but wrong format
If I use:
{{user.user_date | amDateFormat:'DD/MM/YYYY'}}
Return
22/01/2021 // today date
How can I format this date value inside of component?
Thanks
Your question can be summarize as "How to use a pipe in a Typescript file". Where your can find the solution here Is it possible to use a pipe in the code?
You need to import the pipe amDateFormat in the providers of your module. Then, you need to inject the pipe in the constructor of the component. Finally call the transform function of the pipe.
constructor(
private datePipe: DatePipe
) {
return this.datePipe.transform(user.user_date, "DD/MM/YYYY");
}
You need to change DatePipe with the name of the pipe you as using. The code works in the last version of Ionic/Angular, not tested in Ionic 1.
You need to watch appery.io youtube video how to work with pipe https://www.youtube.com/watch?v=rzMiIKeaJcc

PreloadJS - Loading an image from a URL without file format

I'm trying to use PreloadJS to load an image. I took the getting started code from http://www.createjs.com/getting-started so,
function loadImage() {
var preload = new createjs.LoadQueue();
preload.addEventListener("fileload", handleFileComplete);
preload.loadFile("assets/preloadjs-bg-center.png");
}
function handleFileComplete(event) {
document.body.appendChild(event.result);
}
Which works great, but changing the URL to a custom one doesn't play so nice:
preload.loadFile("http://localhost:3000/URLthatReturnsAnImageWithoutFileType");
I'm unable to render the image. I'm guessing the loadFile function parses the file type in the provided URL string. Is there a way to tell PreloadJS the provided asset is indeed an image and render it?
According to LoadQueue's documentation, the file type of an item is determined by it's file extension. If it doesn't have an extension, then you can pass in a type property:
preload.loadFile({src:"hello", type:createjs.AbstractLoader.IMAGE});

parse.com set undefined to date field in data browser

How can I set undefined or null and make empty to a date field in the parse.com data browser.
There is nothing related with code, in the pic i attached, you can see the parse.com data browser and i want to set undefined or null whatever and make that field empty but whenever i tried and double click the cell, data browser open date widget and it is not allowed to delete the data or there is no button to make empty.
Parse.com Data Browser
In data-browser I don't think it's possible to delete a date value, I couldn't find a way to do it at least.
And now that Parse.com will not be maintained anymore(in 01/01/2017 it will shut down), I don't think this may come up as a feature.
My solution to this problem was to make a request to this register and use unset. It gets a bit more of work but solves the problem.
I don't know if you're using parse with Javascript but it can be really easy to adapt to other enviroments.
In Javascript this script should do the trick:
var DateUpdate = Parse.Object.extend("MyTableOnParse");
var dateUpdateEdit = new Parse.Query(DateUpdate);
dateUpdateEdit.equalTo("objectId",myObjectId);
dateUpdateEdit.first({
success: function(object)
{
object.unset("saleDate");
object.save({
success: function(updatedObject)
{
console.log("Data deleted");
}
})
}
});

BlackBerry 10: Load GroupDataModel data into a JSON file?

I have a ListView in QML using a cpp GroupDataModel that is created from a .json file in the assets folder. Items from this ListView are removed and added to. In cpp how do I get the GroupDataModel data into the JSON file?
I know there is this:
JsonDataAccess jda;
jda.save(huh?, "/app/native/assets/employees.json");
How do I get the GroupDataModel data into a QVariant to put in the first parameter of that function? I can't just stick my m_model GroupDataModel in there; it causes an error.
You have to iterate over your model with GroupDataModel::data() and GroupDataModel::childCount() to create your resulting QVariant, then store it. As far as I know, there's no automatic way to do this.
Edit: there is one.
for loading groupdatamodel content in to json file, you have to do:
QList<QVariantMap> myList = m_model->toListOfMaps();
QVariantList membersList;
foreach(QVariantMap s, myList){
membersList << s;
}
JsonDataAccess jda;
jda.save(membersList,path);

how to get static block content custom attributes by block id in magento

I am creating this below block content in admin HTML. I cant able to get the slidertype attributes in 3columns.phtml but in template page i can get
$this->getData('slidertype').
So kindly give the solution that how to get the following attributes.
{{block type="catalog/product_bestseller" name="bestseller" slidercount="20" slidertype="1" template="catalog/product/bestseller_right.phtml"}}
I am using the below code to get static block attribute value. Its working fine for us.
$bestSellerBlock = Mage::getModel('cms/block')
->setStoreId(Mage::app()->getStore()->getId())
->load("best_seller");
$bestSellerContentText = strip_tags($bestSellerBlock->getContent());
preg_match('/slidertype="(.*?)"/u',$bestSellerContentText,$sliderTypeArray);
$sliderType = trim($sliderTypeArray[1]);
Thanks,
Arularasan D.