views:

373

answers:

2

hey guys,

hope you can help me, again :) i want to build a little webbased gui designer. the user can switch into editor-mode and can place the components wherever (s)he wants via drag'n'drop. when (s)he switches back to user-mode i want the position-details in the external css-file to be updated via javascript. i looked into some examples that sort of do what i want, but i can't seem to figure out, how to get it working.

thnx in advance, dg

+1  A: 

In order to edit external stylesheets with JS you'll need to use the methods listed here : http://www.quirksmode.org/dom/w3c_css.html (see Accessing Stylesheets and Changing Style Sheets). As you can see from PPKs tables, there some significant CSS incompatabilities - this is edge case stuff and I do not know how you would save this generated CSS file.

I would look at posting (possibly with ajax) the values back to the server which generates the new CSS file which is then called by the user-mode page.

In the edit mode I would have all the styles inline (style="...") and then when the page is submitted, enumerate each element's style property to extract the values and use them to build a POST request. Then create the new file on the server.

edeverett
thnx, i will look into that.
doro
thnx for the link, it is really helpful!
doro
+1  A: 

you want to use jquery... it uses css to select groups of elements and allows you to manipulate the css style on the elements you have selected

lets say you have an div element with the class awesomeDiv:

<div class="awesomeDiv">some content</div>

you can select it using jquery with the following line:

$(".awesomeDiv")

and you can change the css like so:

$(".awesomeDiv").css({'background-color': '#000000', 'width': '250px'});
Jiaaro
does that change the external css file or just add those properties to the style property of your selected elements?
edeverett
i still didn't get it running with the drag'n'drop and then getting the new position, but i also dunno how to save it permanently. i am sorry, if i am bugging you. do you have any idea how i could do that? i never worked with jquery but just looked at some examples. i could get to like it. thnx for the hint :)
doro
@edeverett: as far as i could see it is not saved anywhere. it is like onClick it changes (i used it in a function after a button was clicked) ... if i remember correctly there should be some way to manipulate the css-file directly or at least add the css-rules in the html-file ... maybe someone can shed some light into this.
doro
it is not saved... you could use jquery's ajax methods to send the changes to the server, and load the changes as a seperate css import
Jiaaro