YUI3 autocomplete - autocomplete

I think I would like to make the switch from Scriptaculous to YUI. So, the first thing I am trying to do is an autocomplete feature on the front page of my application demo. Every single search I do for this, refers me to YUI2 examples and instructions. These use YAHOO objects instead of YUI objects, and I just don't trust that this is the right way to do it.
If I was already familiar with 2.x, it may not be too hard, but I'm coming from a different set of libraries. Does anyone have instructions how to implement an autocomplete feature using YUI 3? Any help would be appreciated.
Thanks, Dave

The official YUI 3 AutoComplete widget was released in YUI 3.3.0: http://developer.yahoo.com/yui/3/autocomplete/

Some initial work was done on AutoComplete in YUI 3. Due to resource issues, it was moved to the Gallery for the time being so implementers would have access to it until it is fully fleshed out, documented, and examples written for official release.
http://yuilibrary.com/gallery/show/autocomplete

A lot of the widgets haven't been ported from 2.x to 3.x yet. If you're really opposed to using YUI 2.x, you could probably port the widget yourself; YUI is on GitHub.

This is example of implementing YUI3 AutoComplete (with a bonus implementation of GAE autocomplete services for both XHR and JSONP style URLs).

Here's an example from Apache Roller using Y.DataSource.IO to retrieve data using JSON (I also include a testing line "ds2" using a local array, that I've since removed from the code.) As I understand, Y.DataSource.Get should be used instead if you're using JSONP.
This autocomplete is for the "tags" field that people use to type in 0 or more tags (topics) for a blog entry. It queries previously used tags for other blog entries as suggestions for the user, based on the user input (as the user types in more letters "b..a... etc., fewer items appear.) If helpful for understanding the sample, here's a sample of the JSON returned:
{ "prefix": "ba",
"weblog": "gmazza",
"tagcounts": [
{ "tag" : "bahamas", "count" : 1 },
{ "tag" : "baltimore", "count" : 3 },
{ "tag" : "baseball", "count" : 3 }]
}
My recommendation is to first get the autocomplete working with a local hardcoded array as the source (my ds2 in the example above.) Once done, then focus on getting the datasource operative and having the autocomplete correctly read from it instead of the array.

Related

What are Visual Studio Code experiments?

Today I was surprised to find an "Enable Experiments" option under VSCode's Workbench settings, turned on by default.
The setting's description is "Fetches experiments to run from a Microsoft online service" which seems rather vague to me. I tried googling this but didn't find any clear answers.
So, does anybody know what those "experiments" are and if it would probably be better to turn this off?
This is one of the case where using open-source software is a good idea. Because the source code of visual studio code is published in https://github.com/Microsoft/vscode. We could try to search in where the code would be used.
First, we could try to search the string Enable Experiments. And see, to which action the option is tied to. From there, I see that, the file src/vs/workbench/contrib/experiments/node/experimentService.ts is using it. Specifically, when trying to load an experiment in line 173
if (!product.experimentsUrl || this.configurationService.getValue('workbench.enableExperiments') === false) {
We see that, the code would check for "experiment URL". this could be seen in product.json which #Joey mentioned in the comment. In my case, the text looks like this.
"experimentsUrl": "https://az764295.vo.msecnd.net/experiments/vscode-experiments.json",
From there, we could see the content of the JSON file by making a GET request to that URL. And, it returns this (at least, at the time I make the request)
{
"experiments": [
{
"id": "cdias.searchForAzure",
"enabled": true,
"action": {
"type": "ExtensionSearchResults",
"properties": {
"searchText": "azure",
"preferredResults": [
"ms-vscode.vscode-node-azure-pack",
"ms-azuretools.vscode-azureappservice",
"ms-azuretools.vscode-azurestorage",
"ms-azuretools.vscode-cosmosdb"
]
}
}
}
]
}
Based on the response, I could see that, it try to alter my search result if I search using "azure" key word. Which I tried, and the search result shows the 4 items there on top of the result search.
As to whether to disable it or not. On safe side (if you don't want for it to alter your experience using vscode) I think you would want to disable it. But, I don't think microsoft would do something crazy.
I just noticed this one and was curious about it as well. A search through the VS Code release notes finds one reference to it in July 2018. workbench.enableExperiments is listed as one of the settings for VS Code's "Offline mode": https://code.visualstudio.com/updates/v1_26#_offline-mode
The description of offline mode suggests that this settings is for "A/B experiments":
To support this offline mode, we have added new settings to turn off features such as automatic extension update checking, querying settings for A/B experiments, and fetching of online data for auto-completions.
As mentioned by others, the source code for VS Code shows this setting being used in experimentService.ts: https://github.com/microsoft/vscode/blob/93bb67d7efb669b4d1a7e40cd299bfefe5e85574/src/vs/workbench/contrib/experiments/common/experimentService.ts
If you look at the code of experimentService.ts, the stuff it's fetching seems to be related to extension recommendations, notifications about new features, and similar things. So it looks like the experiment service is for fetching data to do A/B testing of feature and extension recommendations to users.

How to selectively clear cache (using tags or other option) with Memchached backend and Zend Framework

We use Memcached and Zend Framework in our web project. Now, we need to clean cache selectively using tags as specified in Zend_Cache API.
Unfortunately, memcached doesn't support tags.
I have found these workarounds:
Memcached-tag project. Has anybody tested it? How to implement it with Zend?
Use wildchards like in this question, but it seems a bit confusing, less transparent and harder to implement with Zend.
Use this implementation or this one, for supporting tags in Memcached, beeing aware of the drawbacks.
Any other option?
Thanks in advance
You're right. Memcache don't support tags.
You can use another key-value to implement tag for memcache.
EX :
$this->objCache->save($arrResults, $strKey,array($strMyTag),$intCacheTime) // note : array($strMyTag) don't work for Memcache
MemcacheTag::setTag($strKey, $strMyTag) // our work around
About setTag Method & MemcacheTag:
function setTag($strKey,$strTag){
$arrKey = $cacheOjb->get($strTag);
$arrKey[]= $strKey;
}
function deleteCacheWithTag($strTag){
$arrKey = $cacheOjb->get($strTag);
foreach ($arrKey as $strKey){
$objCache->delete($strKey);
}
}
This work around is quite simple and it works for my projects.
*Note: these codes need some modification, sorry for posting in a hurry

Unicode normalization in GWT [duplicate]

I tried
s=Normalizer.normalize(s, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "");
But it seems that GWT API doesn't provide such fonction.
I tried also :
s=s.replace("é",e);
But it doesn't work either
The scenario is I'am trying to générate token from the clicked Widget's text for the history management
You can take ASCII folding filter from Lucene and add to your project. You can just take foldToASCII() method from ASCIIFoldingFilter (the method does not have any dependencies). There is also a patch in Jira that has a full class for that without any dependencies - see here. It should be compiled by GWT without any problems. License should be also OK, since it is Apache License, but don't quote me on it - you should ask a real lawyer.
#okrasz, the foldToASCII() worked but I found a shorter one Transform a String to URL standard String in Java

TinyMCE: Copy-Paste from Google Docs

Folks,
My company needs to support the following workflow:
- There's rich content getting created in Google Docs (with simple formatting - bold/italic, as well as hyperlinks)
- That content is then pasted into an internal CMS that uses TinyMCE.
Problem: all formatting gets lost when pasting stuff in.
Already tried the "paste from Word" plugin - it doesn't work.
Please advise. Thank you!
UPDATE:
I narrowed the problem down to Google Chrome. Firefox works just fine. I also used the paste_pre_processing() callbacks - the data gets corrupted before getting in there.
I ended up giving up on the Paste plugin into TinyMCE. Instead, I used the undocumented valid_styles property of TinyMCE. This solved the problem fine for my scenario. Here's the config snippet we ended up using:
valid_elements: "a[href|title|target],del,b,strong,del,i,blockquote,p,br,em,ul,li,ol,span[style]",
valid_styles : { '*' : 'font-weight,font-style,text-decoration' },
I know this question was asked a long time ago however I am making an application that requires a copy and paste from google drive into tiny mce. This is actually fairly simple with the free paste plugin. Simply remove the filters so that it can copy in all of the data.
tinymce.init({
selector: 'textarea',
plugins: "paste",
paste_data_images: true,
paste_enable_default_filters: false,
paste_remove_styles_if_webkit: false
});
Your problem is a somewhat complex issue.
First you need to make sure that tinymce does not remove tags and tag-attributes that it recognises as invalid (have a closer look at the tinymce configuration options valid_elements and valid_children).
Second you will have to implement an own handling of the paste process.
There are three way to do this. The most time consuming option is to write an own custom paste plugin and replace the given one. The other options are ways to configure the paste plugins and define own functions to interact with and change the pasted content.
The seetings paste_pre_processing and paste_post_processing are the way to go here.

How do you automatically set focus on a form field using yui

I currently have an issue where I want text field to be automatically selected when the user visits my webpage, I currently do this by Javascript but would, ideally, like to use YUI. After searching the web, i found this command,
YAHOO.util.Dom.get("first_element").focus();
and
YAHOO.util.Dom.get("text1t").focus();
but have had very little luck getting it to work, one suggestion was to use a setTimeout fnction, but this seems a rather ugly way of doing it.
If anyone has any suggstions I would be very grateful.
Thanks,
Try using onAvailable
YAHOO.util.Event.onAvailable("elementId", function(me) { me.focus(); }, YAHOO.util.Dom.get("elementId"));
You may need to use a later event, like onContentReady or even onDOMReady if that doesn't work.