Coder Social home page Coder Social logo

webdavjs's Introduction

WebDAV.js

This is a simple JavaScript library that attempts to implement a subset of the
WebDAV standard. It (currently) doesn’t aim to be complete – just support basic
operations.

WebDAV.js has a low-level API (the WebDAV object) and a higher level, more OO API
(WebDAV.Fs).

Both APIs can operate in synchronous and asynchronous mode: All functions that
declare a callback argument accept an optional function. If a callback function is
passed, the HTTP request will happen asynchronously, passing the result to that
function. If no callback function is passed, the result is returned directly after
the synchronous HTTP request.

For each function – “result” refers to either the function’s return value or the
argument passed to the callback function (if any).

WebDAV

This is a very thin wrapper around XMLHttpRequest.

WebDAV.Fs

This is the entry point to the OO interface. Create a new instance like this:

var fs = new WebDAV.Fs(url);

A WebDAV.Fs object has 2 methods:

  • dir(url) – returns a Dir object
  • file(url) – returns a File object

The url argument can be an absulute or relative URL. Example:

var fs = new WebDAV.Fs('http://localhost:1234/my_files');
var hello = fs.file('/my/hello.txt');
// This is the same as:
var hello = fs.file('http://localhost:1234/my_files/my/hello.txt');

File.read(callback)

Reads the file and passes the contents to the result.

File.write(data, callback)

Writes data to the file.

File.rm(callback)

Deletes the file.

Dir.children(callback)

Lists all files and directories under Dir. The result is an Array of other File
and/or Dir objects.

Dir.mkdir(callback)

Creates the directory.

Dir.rm(callback)

Removes the directory.

Usage/Example

Check out example/index.html

To see it in action in a browser, stand in the root folder and run:

ruby spec/webdav_server.rb

Then point your browser to http://localhost:10080/example/index.html

You should be able to browse and edit everything from within your browser.

Running tests

You need to download some tools. Run ./install_tools.sh to pull them down.

In shell A

ruby spec/webdav_server.rb spec/fixtures

In shell B

ant jsspec

webdavjs's People

Contributors

aslakhellesoy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

webdavjs's Issues

Node type check

Hi Aslak, i tried your sample client with a webdav server that i've written. It's working well but since my server adds extra empty spaces (space, tabulation or new lines, for debug) between xml response elemets, in firefox the statement:

 for (var i = 1; i < doc.childNodes.length; i++) {
                var response = doc.childNodes[i];

sets the response var to a text node, generating a "response.getElementsByTagName is not a function" error on the following line.

To fix this, i added a check to the tagName of response, and now it's fine.

for (var i = 1; i < doc.childNodes.length; i++) {
var response = doc.childNodes[i];
if (response.tagName == 'D:response') {// ANDREA --text node
     var href = respon.....
     .....
}

Not sure if this is due to my implementation since it works perfectly with other clients.
Hope this help..

Authentication

How do you handle authentication?
PS: Tnx 4 your effort :)

Collection : null

Hello,

I am using your script to connect an Apache Webdav Server but I have an error on this line : (null has the null value in IE)
var collection = resourcetype.getElementsByTagName('D:collection')[0];

I need to modify the lines :

/*
var collection = resourcetype.getElementsByTagName('D:collection')[0];
if(collection) {
result[i-1] = new fs.dir(href);
} else {
result[i-1] = new fs.file(href);
}
*/
result[i-1] = new fs.dir(href);

What do I need to resolve the collection's problem ?

Thanks !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.