Tuesday, May 28, 2013

Refreshing Dom Element Using JQuery

    jQuery.fn.redraw = function() {      return this.hide(0, function() {          $(this).show();      });  };    $(el).redraw();

Monday, April 29, 2013

CHM help file does not show contents in right-hand pane

Symptom: an externally-originated CHM (Compiled Help) file shows the navigation outline in the left pane, but the right pane displays the error "Navigation to the webpage was canceled".

Cause: Windows security treats ad-hoc CHM files with great suspicion and disables their content under a variety of conditions, including location of the file on a network drive. A search on Google will bring up many pages about this, including Microsoft's own knowledge base. It is unlikely to be a problem with the CHM file itself, but in the way that Windows is handling it. Even Microsoft's own CHM files can be affected.

Workarounds: One or more of the following may solve the issue. The options available will depend on which version of Windows you are using.

  1. Try copying the file from a network drive location to a local drive (e.g. to C:\Temp\).
  2. If you get a Security Warning asking if you want to open the file, un-check the option "Always ask before opening this file", if this checkbox is present.
  3. Navigate to the .chm file in Windows Explorer, right-click on the file, select Properties and click Unblock. Then click OK to save the change.
  4. If there is no "Unblock" button for the previous step, try going to the file's Properties > Advanced tab and un-check the option "File is ready for archiving". (Unverified, but a low risk change anyway).
  5. The viewer component may not be correctly registered. From the command prompt, enter regsvr32 hhctrl.ocx  and hit return.
  6. Check that the file name or folder names in the path to the file do not contain the hash character (#). Rename or move the file elsewhere if they do.

To permanently solve item #1, it is possible to edit the registry to allow network drives to be a trusted zone. A web search will bring up more detailed information.

Friday, April 12, 2013

selectionStart property (Internet Explorer)

function getInputSelection(el) {
    var start = 0, end = 0, normalizedValue, range,
        textInputRange, len, endRange;

    if (typeof el.selectionStart == "number" && typeof el.selectionEnd == "number") {
        start = el.selectionStart;
        end = el.selectionEnd;
    } else {
        range = document.selection.createRange();

        if (range && range.parentElement() == el) {
            len = el.value.length;
            normalizedValue = el.value.replace(/\r\n/g, "\n");

            // Create a working TextRange that lives only in the input
            textInputRange = el.createTextRange();
            textInputRange.moveToBookmark(range.getBookmark());

            // Check if the start and end of the selection are at the very end
            // of the input, since moveStart/moveEnd doesn't return what we want
            // in those cases
            endRange = el.createTextRange();
            endRange.collapse(false);

            if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
                start = end = len;
            } else {
                start = -textInputRange.moveStart("character", -len);
                start += normalizedValue.slice(0, start).split("\n").length - 1;

                if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
                    end = len;
                } else {
                    end = -textInputRange.moveEnd("character", -len);
                    end += normalizedValue.slice(0, end).split("\n").length - 1;
                }
            }
        }
    }

    return {
        start: start,
        end: end
    };
  }

Friday, January 4, 2013

Resize image proportionally javascript

function reSizeImageProportionally (imgObj,imgContainerId) {
    var container = $(imgContainerId);
   
    var imgRatio = imgObj.height / imgObj.width;
    var containerRatio = container.height() / container.width();
    var ratio = containerRatio / imgRatio;
   
    imgObj.style.height = ratio * container.height()+ "px";
    imgObj.style.width = ratio * container.width()+ "px";

    container.append(imgObj);

    return container;
};
  
Usage:
------------
var img= new Image();
img.src="http://localhost/Custom/USSI/Layers/Ticket/Legend.jpeg";
var result=reSizeImageProportionally(img,'.tl_tab_legend_panel_div'); //  Div id  or Class Name