git-svn-id: https://beef.googlecode.com/svn/trunk@606 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
104 lines
2.6 KiB
JavaScript
104 lines
2.6 KiB
JavaScript
/*!
|
|
* @literal object: beef.dom
|
|
*
|
|
* Provides functionalities to manipulate the DOM.
|
|
*/
|
|
beef.dom = {
|
|
|
|
/**
|
|
* Creates a new element but does not append it to the DOM.
|
|
* @param: {String} the name of the element.
|
|
* @param: {Literal Object} the attributes of that element.
|
|
* @return: the created element.
|
|
*/
|
|
createElement: function(type, attributes) {
|
|
var el = document.createElement(type);
|
|
|
|
for(index in attributes) {
|
|
if(typeof attributes[index] == 'string') {
|
|
el.setAttribute(index, attributes[index]);
|
|
}
|
|
}
|
|
|
|
return el;
|
|
},
|
|
|
|
/**
|
|
* Removes element from the DOM.
|
|
* @param: {String or DOM Object} the target element to be removed.
|
|
*/
|
|
removeElement: function(el) {
|
|
if (!beef.dom.isDOMElement(el))
|
|
{
|
|
el = document.getElementById(el);
|
|
}
|
|
try {
|
|
el.parentNode.removeChild(el);
|
|
} catch (e) { }
|
|
},
|
|
|
|
/**
|
|
* Tests if the object is a DOM element.
|
|
* @param: {Object} the DOM element.
|
|
* @return: true if the object is a DOM element.
|
|
*/
|
|
isDOMElement: function(obj) {
|
|
return (obj.nodeType) ? true : false;
|
|
},
|
|
|
|
/**
|
|
* Creates an invisible iframe on the hook browser's page.
|
|
* @return: the iframe.
|
|
*/
|
|
createInvisibleIframe: function() {
|
|
var iframe = this.createElement('iframe', {
|
|
width: '1px',
|
|
height: '1px',
|
|
style: 'visibility:hidden;'
|
|
});
|
|
|
|
document.body.appendChild(iframe);
|
|
|
|
return iframe;
|
|
},
|
|
|
|
/**
|
|
* @param: {String} type: can be one of the following: hidden, fullscreen, custom
|
|
* @param: {Hash} params: list of params that will be sent in request.
|
|
* @param: {String} src: the source of the iframe
|
|
* @param: {Function} a callback function to fire once the iframe has loaded
|
|
* @return: {Object} the inserted iframe
|
|
*/
|
|
|
|
createIframe: function(type, params, src, onload) {
|
|
var css = {};
|
|
if (type == 'hidden') { css = $j.extend(true, {'border':'none', 'width':'1px', 'height':'1px', 'display':'none', 'visibility':'hidden'}, params); }
|
|
if (type == 'fullscreen') { css = $j.extend(true, {'border':'none', 'background-color':'white', 'width':'100%', 'height':'100%', 'position':'absolute', 'top':'0px', 'left':'0px'}, params); }
|
|
return $j('body').prepend('<iframe />').find('iframe').first().css(css).attr('src', src).load(onload);
|
|
},
|
|
|
|
|
|
/**
|
|
* Get the location of the current page.
|
|
* @return: the location.
|
|
*/
|
|
getLocation: function() {
|
|
return document.location.href;
|
|
},
|
|
|
|
/**
|
|
* Get links of the current page.
|
|
* @return: array of URLs.
|
|
*/
|
|
getLinks: function() {
|
|
var linksarray = [];
|
|
var links = document.links;
|
|
for(var i = 0; i<links.length; i++) {
|
|
linksarray = linksarray.concat(links[i].href)
|
|
};
|
|
return linksarray
|
|
}
|
|
|
|
};
|
|
|
|
beef.regCmp('beef.dom'); |