...

Hi! I’m Starx

experienced Software Developer. And this is my blog
Start Reading About me
Blog Page
April 10, 2012

Clear cookie via jquery?

Question by SOLDIER-OF-FORTUNE

I have a DNN installation but one of the portals is broken and the “logout” button doesnt seem to clear the cokoie. Is it possible to use jquery to clear a specific cookie? or a seperate ASP.NET page?

Answer by Starx

Sure, Using cookie plugin like this

$.cookie("name", null);

Update:

if($('a[href="webiste.co.uk/en-gb/admin.aspx"]').length) {
    $.cookie("name", null);
}

Update 2: Pure Js

function deleteCookie(name) {
    document.cookie = name+'="";-1; path=/';
}

var login = document.getElementById("loginlink");
login.onclick = function() {
  deleteCookie("name");
};
Read more

jquery issue copying data from div to input text

Question by Irfan Mulic

I am working on inplace edit for a form.
I am having two divs one of them holds display elements and the other holds input form.

When you click edit data moves from display div to input form. I see the change when I use val(text), however when I serialize the form to json elements are old.

I need some help understanding what is the problem here?

Here is some code:

function editForm2(){
    $("#editLink").click(function() {
        if (this.text == 'Edit') {
            console.log('editing');
            $("#display div.edit").each(function(i) {
                var e = $("#input :input")[i];
                $(e).val($(this).text());
            });
            $("#display").hide();
            $("#input").show();
            $(this).text('Save');
        }
        else if (this.text =='Save') {
            // problem is here... When I serialize the form I got nothing ?!
            console.log('saving');
            console.log($("#form1 :input")); // old values

            var json_form = $('#form1').serializeObject();
            console.log(json_form); // old values?
            $(this).text('Edit');

            $("#display").show();
            $("#input").hide();
        }
    });

    console.log(this);
}

$(document).ready(function() {
    editForm2();
});​

here is html

<div class="editSection" id="display" >
    <div id="person_firstName" class="edit" width="200">
        Hello
    </div>
    <div id="person_lastName" class="edit">
        World
    </div>
</div>

<div class="editSectionEdit" id="input" >
    <form id="form1">
        <input name="person_firstName_in" type="text" class="edit" value="123" >
        <input name="person_lastName_in" type="text" class="edit" value="456" >
    </form>
</div><br/>

<div id="buttons">
    <a href="#" id="editLink">Edit</a>
    <a href="#" id="cancelLink">Cancel</a>
</div><br>

<pre id="result"></pre>

Answer by Starx

The problem was .serializeObject() which was reported as undefined by firebug.

Here is your solution

var json_form = $('#form1').serialize();

Check here

Read more

What resources mean in ACL in zend framework

Question by PalAla

I want to know what is resouces in ACL, is it module, controller in a module or action in controller in module.

In the documentation, resoiurces (newsletter, news,latest) and others are not clear what they are.

Also in this example the resources are not clear!!!

[mainMenu]
login          = Everyone
applications   = Everyone
preferences    = User
administration = Implementor

[userPreferences]
details = User
params  = User
themes  = User

Answer by Jani Hartikainen

Resource is simply something you want to limit access to. It could be a page, a record in your DB or whatever your application needs.

I wrote a three-part series on Zend_Acl, in which I talk about what resources are amongst other things: http://codeutopia.net/blog/2009/02/06/zend_acl-part-1-misconceptions-and-simple-acls/

Answer by Starx

For example

new Zend_Acl_Resource('someResource')

Denotes that someResource points to an PHP module/section, which is suppose to be accessible but, it has be controlled so that only authorized roles can access it.

Read more

Difference between heading inside section or before it in HTML5

Question by knittl

In HTML5, what is the difference between a section with a heading as child element and a section which is the next sibling of a heading element? Does the same difference hold for div elements instead of section?

<section>
<h1>First section</h1>
<!-- other content -->
</section>

<!-- vs. -->

<h1>Second section</h1>
<section>
<!-- other content -->
</section>

Answer by Starx

The answers will highly depend upon logical view.

<section>
  <h1>....</h1>
</section>

On the above case <h1> denotes the heading of the section. Now lets look at another example:

<div id="info">
    <h1>Sections:</h1>
    <section>
       <h1> Section: 1</h1>
    </section>
    <section>
       <h2> Section: 2</h2>
    </section>
</div>

This the defines a major portion of a page called sections, where as the heading inside each heading, only tend to emphasis the contains within the section i.e of a particular type of section like section 1.

Hope it helps

Read more

What is the syntax for a CSS media query that applies to more than one property (AND operator)?

Question by mattwindwer

I would like to write a CSS media query that matches all devices with at least a 800px width and 800px height. The purpose of this media query is to target tablets and exclude phones. I do not need to worry about desktops in this case, since I am only targeting mobile devices.

I started with:

@media all and (min-device-width: 800px), all and (min-device-height: 800px)

…but I don’t believe that will work because it will be true if either of the two conditions are met (logical OR).

So my next guess would be:

@media all and (min-device-width: 800px, min-device-height: 800px)

What is the syntax for an AND and not an OR?

Answer by Starx

Remove the commas from your declaration

@media all and (min-device-width: 800px) and (min-device-height: 800px) {
  //...........
}

Read this doc for more info

Read more

How can I capture the blur and focus of the entire browser window?

Question by Adam

I would like to capture the blur and focus of the actual browser window – meaning that change of focus to child frames is not of interest.

Currently I have been using
$(top).focus()
$(top).blur()

and
$(window).focus()
$(window).blur()

However, these fire when the user changes focus to embedded iframes, which I don’t want.

Does anyone know of a way to capture TRUE activation and deactivation of the window?

[EDIT]

Blur and focus events fire when a user moves from a web-page, to the web-page of an embedded iframe.
This is different from ‘window activation’ events, which only fire when the actual BROWSER WINDOW (or tab) is brought to the front, or sent away (i.e, tab changed, or minimized).

I am not interested in blur, because the fact that the user has navigated to an embedded frame is of no consequence to the program. However, if the user minimizes the window, changes tabs, or switches to another program, I want to know about it…

Answer by Starx

You can use something like this to detect the browser events.

function onBlur() {
    document.body.className = 'blurred';
};
function onFocus(){
    document.body.className = 'focused';
};

if (/*@cc_on!@*/false) { // check for Internet Explorer
    document.onfocusin = onFocus;
    document.onfocusout = onBlur;
} else {
    window.onfocus = onFocus;
    window.onblur = onBlur;
}

Source Post

Read more

Password is not checking case sensitivity

Question by user725719

I have a login form in a website which I have created.I have used PHP for verifying password,and password is stored in MYSQL database.The problem i’m facing is Password is not case sensitive.It accepts the characters without considering the case.I’m using Kubuntu linux OS

Could anyone please help to solve this problem?.What value I should use for COLLATION in mysql/my.cnf to avoid this?Or is there any other solution for this?

Any help is greatly appreciated.

Thanks.

Answer by Konerak

Your MySQL collation is probably case-insensitive. Change the column where the password is stored to a case-sensitive collation.

Some rules of thumb:

  • When a collation ends in _ci, it is case-insensitive.
  • When a collation ends in _cs, it is case-sensitive.

Example:

  • utf8_general_ci is case-insensitive.
  • utf8_bin is case-sensitive

However, an important note

If you are experiencing this problem, you are probably storing the passwords wrong. You should not store the passwords in plain text, but you should store a hash of the password instead, and salt it properly.

Then, when a user logs in, you hash his entry, and compare the hash with what your DB holds. When both equal, the user probably entered a correct password.

Answer by Starx

It seems like you are storing password in general text. Otherwise collation like utf8_general_ci should not be a problem generally.

You should hash you password with md5() or sha1() while you store passwords.

Read more
April 9, 2012

Cross-browser method to prevent all methods of text copying from a textarea?

Question by think123

I am working on an online typing software. In the typing software, all is going well but I have the problem of dishonest users who might possibly type the text into the textarea, copy it, then reload the page (therefore resetting the timer) and pasting it in straightaway. So I was thinking along the lines of using something like evt.preventDefault(); when javascript detects the pressing of the ctrl / cmd button along with the C key. But then I realized that the user could always go up to the menu bar to press Edit -> Copy. So I was wondering, is there a cross-browser method to disable both methods of copying?

Answer by Selcuk

You can try to use the following jQuery code:

$('input[type=text],textarea').bind('copy paste cut drag drop', function (e) {
   e.preventDefault();
});

Answer by Starx

Bind the event handlers and prevent the clipboard function like such:

$('textarea').on('copy paste cut drag drop', function (e) {
   e.preventDefault();
});
Read more

Force variable pass as object

Question by Gabriel Santos

I need to define the type of passed variable as an generic object, how?

Tried:

public function set($service = null, (object) $instance) {
    [..]
}

Can stdClass help? How?

Thanks!

Answer by zerkms

Nope, in php all classes aren’t derive from the common ancestor.

So doubtfully you can use current php’s implementation to state “object of any class”

Answer by Starx

No, the object has to be some class. You can give the any class name as object’s type

public function set($service = null, ClassName $instance) {
    //now the instance HAS to be the object of the class
}

Or a basic trick would be to create a basic class yourself

Class GenericObject {}
$myobj = new GenericObject();
$myobj -> myCustomVar = 'my custom var';

//Now send it
public function set($service = null, GenericObject $instance) {
   [...]
}
Read more

Adding a class via jQuery

Question by Onyx

I have some code dynamically created by Sigma, which looks like this:

<div id="myGrid1_headDiv" class="gt-head-div">
<div class="gt-head-wrap">
<table id="myGrid1_headTable" class="gt-head-table">
<tbody>
<tr class="gt-hd-row">
<td class="gt-col-mygrid1-uid">
<div class="gt-inner gt-inner-left" unselectable="on" title="#">
<span>#</span>
<div class="gt-hd-tool"><span class="gt-hd-icon"></span>
<span class="gt-hd-button"></span>
<span class="gt-hd-split" style="cursor: col-resize; "></span></div></div></td>
<td class="gt-col-mygrid1-p_deldate">
<div class="gt-inner gt-inner-left" unselectable="on" title="Planned Delivery Date">
<span>Planned Delivery Date</span>
<div class="gt-hd-tool"><span class="gt-hd-icon"></span>
<span class="gt-hd-button"></span>
<span class="gt-hd-split" style="cursor: col-resize; "></span></div></div></td>

I am trying to target the un-classed spans( # and Planned Delivery Date), in order to style them, with:

  $("div.gt-inner:first-child span")
    {
          $(this).addClass("celltitle");
        };

but it has no effect. As you can see, there other spans around it that I don’t want to touch. What am I doing wrong?

=====
Final Answer for others using Sigma Grid:

Thanks to @minitech for the pointers, the answer is to add to Sigma Grid’s gridOption with:

onComplete:function(grid){ 
 $('div.gt-inner > span').addClass('celltitle'); //add cell title after grid load
}

Answer by minitech

You’ve inserted an arbitrary code block in there. You need to use jQuery’s .each function and pass your function; jQuery is a library, not a language construct.

$("div.gt-inner:first-child span").each(function() {
    $(this).addClass("celltitle");
});

Or, more concisely, since addClass (like many jQuery functions) implicitly operates on the entire collection:

$('div.gt-inner:first-child span').addClass('celltitle');

Answer by Starx

Use it like this

$("div.gt-inner:first-child span").addClass("celltitle");

Demo

Read more
...

Please fill the form - I will response as fast as I can!