News

 

This is very easy to check, which mouse button was pressed using jQuery.

 

This solution works propertly on IE (tested on 9), Firefox (tested on 4), Chrome. In Opera there doesn't work the middle button

and the browser context menu is showing.

 

$('#someElement').mousedown(function(e) {
    switch (e.which) {
        case 1:
            alert('Left mouse button pressed');
            break;
        case 2:
            alert('Middle mouse button pressed');
            break;
        case 3:
            alert('Right mouse button pressed');
            break;
        default:
            alert('Unsupported mouse button');
    }
});

 

In the Latex begin{displaymath} all spaces are ignored, e.g. this code

\begin{displaymath}
Y=\{ B_i \subseteq Z : i \in X \},  where X \subseteq \mathbb{N}
\end{displaymath}

will look after compile: ...,whereX...

To avoid this situation there is a list of commands to deal with this:

  • \,  (thinspace)
  • \;  (thickspace)
  • \quad    (quadspace)
  • \qquad   (double quadspace)
  • \!  (negative thinspace)

More info can be found here


 

I have lost recently some time to send a json parameter to my web service using jquery.

Suppose that we have the data in an javascript array:

var attributes=[];
$('#PreviewGroup1_DecisionAttributesList input:checkbox').each(function(index,elem){ 	
	attributes.push({attribute: elem.value, checked: elem.checked});
});

To send that array to web service we simply need to do

 $.ajax({
	url: '../Services/PreviewFormWebService.asmx/UpdateDecisionAttributes',
	dataType: "json",
	data: "attrs="+ JSON.stringify(attributes),
	contentType: "application/json; charset=utf-8"
});

and in the web method:

[WebMethod] 
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)] 
public void UpdateDecisionAttributes( )
{ 
System.Web.HttpContext context = System.Web.HttpContext.Current; 
var attributes = context.Request["attrs"];
 //...

 The  JSON.stringify() can be found here: https://github.com/douglascrockford/JSON-js

 [edit]

The string from result can be of course deserialized in easy way, e.g.:<

var attributes = context.Request["attrs"];
JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.RegisterConverters(new[] { new DecisionAttributeJavaScriptConverter() });
var deserializedData = serializer.Deserialize

and the converter:

    public class DecisionAttribute
    {
        public string Name { set; get; }
        public bool IsDecisionAttr { set; get; }
    }

public class DecisionAttributeJavaScriptConverter : JavaScriptConverter
    {
        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            return new DecisionAttribute()
            {
                Name = Convert.ToString(dictionary["attribute"]),
                IsDecisionAttr = Convert.ToBoolean(dictionary["checked"])
            };
        }

        public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            throw new NotImplementedException();
        }

        public override IEnumerable<Type> SupportedTypes
        {
            get
            {
                return new ReadOnlyCollection<Type>(new Type[] { typeof(DecisionAttribute) });
            }
        }
    }