Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Sunday, September 6, 2015

How to customise code Autocompletion in ace editor.

It is easy to customize the code completion in the ace editor,
The following code will do the autosuggestion in the editor.

 editor = ace.edit("editor")
  editor.setOptions({
    // mode: "ace/mode/javascript",
    enableBasicAutocompletion: true
  });
  editor.completers.push({
    getCompletions: function(editor, session, pos, prefix, callback) {
      callback(null, [
        {value: "foo", score: 1000, meta: "custom"},
        {value: "bar", score: 1000, meta: "custom"}
      ]);
    }
  })
But the above code will do autosuggestion with the completion we have provided with the words available in the editor, 
This code is done in the ace/ext/language_tools.js

You can customize the TextCompleter in the file language_tools.js 
In line no 70 if you remove the textCompletor, you can complete control according to your recommendation.
example
 var completers = [snippetCompleter,  keyWordCompleter];//textCompleter


Thursday, May 14, 2015

A Collection Framework in Java Script

Hi,
I just created a Collection framework in javascript.

please find the code in https://github.com/askeralim/Collection.js


Asker Ali M

Tuesday, August 26, 2014

Drawing a self reference directed edge in graph

I come across a requirement to draw a self-reference edge in my graph on Raphael Graph.

The edge from inDirect to Direct is drawn using Bezier curve,
For the selef refernce edge as welli used the same Bazier curve,


Here P1 & P4 can be easily calculated as center point of each sides. and P2 & P3 are assumed to be the part of a square,
other wise we can get better value using angle and two point mathematical calculation in Geometry.

Hope it will help you draw better graphs and edges using Raphael and Mathematics.

Best,
Asker

Thursday, May 15, 2014

How to check whether scrollbar available Using JQuery

In my Example I have a DIV contains some data Table.


As the application looks like Excel, I have to check whether the div have horizontal or Vertical Scrollbar present to set the size of other Div.




JQuery Code is as folows:

       if($('div.dataTableDiv').width()<$('#dataTable').width())
             console.log('Horizontal Scrollbar Present');
       else
             console.log('Horizontal Scrollbar NOT Present');


For Vertical Scrollbar:


       if($('div.dataTableDiv').height()<$('#dataTable').height())
             console.log('Vertical Scrollbar Present');
       else
             console.log('Vertical Scrollbar NOT Present');

Wednesday, November 6, 2013

ReplaceAll Function in Javascript

Replace All Function in Javascript : Implemented through Recursion
 function replaceAll(word, text, newWord){
  var pos = text.search(word);
  if(pos == -1)
   return text;
  var str1 = text.substr(0, pos);
  var str2 = replaceAll(word, text.substr(pos+word.length), newWord);
  return str1+newWord+str2;
 }