commit 3bf720d23346a4f3f9da847378924bf7202bab7a Author: ReimarPB Date: Sun Jul 10 11:20:04 2022 +0200 Initial commit diff --git a/07_27_1978.txt b/07_27_1978.txt new file mode 100644 index 0000000..c23d45c --- /dev/null +++ b/07_27_1978.txt @@ -0,0 +1 @@ +Now where could my pipe be? Gaaarrrfieeeld! When I was 18, 18 years old, I saw for the first time in my life, I saw a vision of clarity I saw a comic strip, a 3-panel comic strip, that though simple as it seemed, changed me, changed my being, changed who I am, made me who I am... Enlightened me. The strip, Garfield. The comic strip was new, no more than maybe a month and a half since inception, since... since coming into existence. And there it was before me in print, I saw it, a comic strip... What was it called? Garfield. The story here is of a man, a plain man, He is Jon, but he is more than that. I will get to this later, but first let us just say he is Jon, a plain man. And then there is a cat, Garfield. This is the nature of the world here. When I see the world, the politics, the future, the... The satellites in space, and the people who put them there... You could look at everything as a man and a cat. Two beings in harmony, and at war. So this strip I saw about this man, Jon, and the cat, Garfield, you see? Yes... It... it is about everything. This little comic is... oh... Lo' and behold, not so little anymore. So yes, when I was 18... I saw this comic. And it hit me all at once, its power. I clipped it and every day I looked at it and I said, "Okay..." "Let me look at this here." "What is this doing to me? Why is this so powerful?" Jon Arbuckle, he sits here, legs crossed... comfortable in his home and he reads his newspaper. The news of the World, perhaps. And then he extends his fingers. Lightly, delicately. He taps his fingers on an end table and he feels for something. What is it? It is something he needs... but it is not there. And then he looks up, slightly cockeyed, and he thinks... his newspaper is in his lap now, and he thinks this: "Now where could my pipe be?" This... I always come to this, because I was a young man. I'm older now. And I still don't have the secrets, the answers, so this question still rings true, Jon looks up and he thinks "Now where could my pipe be?" And then it happens, you see it, you see... It's almost like divine intervention. Suddenly... it is there. And it overpowers you! A cat is smoking a pipe! It is the man's pipe - It's Jon's pipe - but the cat... This cat Garfield is smoking the pipe. And from afar, and from someplace near, but... not clear, near but not clear. The man calls out. Jon calls out, he is shocked, "GARFIELD!!" He shouts... Garfield. The cat's name. But, let's take a step back. Let us examine this from all sides, all perspectives. And when I first came across this comic strip, I was at my father's house. The newspaper had arrived and I picked it up for him. And brought it inside. I organized his sections for him, and then, yes... The comic strip section fell out from somewhere in the middle. Landed on the kitchen floor. I picked up the paper pages and saw.. Up, somewhere near the top of this strip. And just like Jon, I too was wearing an aquamarine shirt. So I thought, "Interesting." "I'll have to see to this later." I snipped out the little comic, and held onto it. And five days later, I reexamined. And it gripped me. I needed to find out more about this. The information I had was minimal. But enough. An orange cat named Garfield. Okay. That seemed to be the linchpin of this whole operation. Yes. Another clue, a signature in the bottom right corner. A man's name. "Jim Davis" Yes. I am onto it for sure. So, one: Garfield, orange cat. And two: Jim Davis, the creator of this cat, And that curiously plain man. I did not know at the time that his name was Jon. The strip, you see, had no mention of this man's name, and I'd never seen it before. But I had these clues: Jim Davis, Garfield. And then I saw more. I spotted the tiny copyright mark in the upper left corner. ©1978 to... What is this? Copyright belongs to a... "PAWS, Incorporated." I used the local library and mail services to track down the information I was looking for. Jim Davis, a cartoonist, had created a comic strip about a cat, Garfield, and a man, Jon Arbuckle. Well, from that point on, I made sure I read the Garfield comic strips. But as I read each one, as each day passed, the strips seemed to resonate with me less and less. I sent letters to "PAWS, Incorporated". Long letter, pages upon pages. Asking if Mr. Jim Davis could, somehow, publish just the one comic, over and over again. "It would be meditative" I wrote, "The strength of that." Could you imagine? But... No response. The strips lost their power. And, eventually, I stopped reading, but... I did not want my perceptions diluted, so I vowed to read "The Pipe Strip" over and over again. That is what I called it. "The Pipe Strip". "The Pipe Strip" Everything about it is perfect. I can only describe it as a miracle creation. Something came together. The elements aligned, it was like the comets. The cosmic orchestra that is up there, over your head. The immense, enormous void is working all for one thing, to tell you one thing. Gas, and rock, and purity, and nothing. I will say this. When I see "The Pipe Strip", and I mean every single time I look at the lines. The colors, the shapes that make up the 3-panel comic. I see perfection. Do I find perfection in many things? Some things, I would say, some things are perfect. And this is one of them. I can look at the little tuft of hair on Jon Arbuckle's head. It is the perfect shade. The purple pipe in Garfield's mouth... How could a mere mortal even make this? I have a theory about Jim Davis. After copious research, and yes of course now we have the internet, and this information is all readily available, but... Jim Davis, he used his life experiences to influence his comic. And like I mentioned before: None of them seemed to have the weight of "The Pipe Strip". But you have to wonder about the man who is able to even just once, create the perfect form, a literally flawless execution of art. Brilliance just isn't a word, I think there is a spiritual element at work I've seen my share of bad times. And when you have something, well it's just emotions and neurons in your brain, but something tells you that it's the truth. Truth's radiant light. Garfield the cat? Neurons in my brain, it's...it's harmony, you see. Jon and Garfield... It's truly harmony, like a continuous, looping, everlasting harmony. The lavender chair, the brown end table, the salmon-colored wall, the forest-green carpet, and Garfield is hunched, perched, perhaps, with the pipe stuck firmly between his jowls. His tail curls around. It's more than shapes, too, because... I... Okay, stay with me... I've done this experiment several times. You take the strip. You trace only the basic elements. You can do anything. You can simplify the shapes down to just... blobs, just outlines, but it still makes sense. You can replace the blobs with magazine cutouts of other things. Replace Jon Arbuckle with a car parked in a driveway sideways. Cut that out of a magazine, stick it in. Replace him there in the second panel with a... a food processor. Okay... And then we put a picture of a planet in the third panel over Garfield. It still works. These are universal proportions, I don't know how best to explain why it works. I've studied "The Pipe Strip" and analyzed Jon and Garfield's proportions against several universal mathematical constants. e, π, the golden ratio, the Feigenbaum constants, and so on. And it's surprising... scary even... how things align. You can take just tiny pieces of "The Pipe Strip", for instance, take Jon's elbow from the second panel. And take that and project it back over Jon's entire shape in the second panel, and you'll see a near perfect Fibonacci sequence emerge. It's eerie to me. And it makes you wonder if you are in the presence of a deity. If there is some larger hand at work. There's no doubt in my mind that Jim Davis is a smart man. Jim Davis is capable of... anything, to me. He is remarkable. But this is so far beyond that. I think we might see that this work of art is revered and respected in years to come. Jim Davis is possibly a new master of the craft, a genius of the eye. They very well may say the same things about Jim Davis in 500 years that we say about the great philosophical and artistic masters from centuries ago. Jim Davis is a modern day Socrates or da Vinci. Mixing both striking visual beauty with classical, daring, unheard of intellect. Look, he combines these things to make profoundly simple expressions. This strip is his masterpiece. "The Pipe Strip" is his masterpiece. And it is a masterpiece and a marvel. I often look at... Garfield's... particular pose in this strip. He is poised and statuesque. And his cat stare is reminiscent of the fiery gazes often found in religious iconography. But still his eyes are playful, lying somewhere between the solemn father's expression in Rembrandt's "Return of the Prodigal Son" and the coy smirk of da Vinci's "St. John the Baptist". His ears stick up, signifying a peaked readiness. It's as if he could at any moment pounce, he is after all, a close relative and descendant of the mighty jungle cats of Africa that could leap after prey. You can see the power drawn into Garfield's hind quarters, powerful haunches indeed. The third panel... Now just saying this now, this is just coming to me now. The third panel of "The Pipe Strip" is essentially a microcosm for the entire strip itself. All the power dynamics, the struggle for superiority, right? Who has the pipe? Where is the pipe? All of that is drawn, built, layered into Garfield's iconic pose here. You can see it in the curl of his tail. Garfield's ear whiskers stick up on end, the smoke billows upward, drawing the eye upward, increasing scope. I'm just... amazed. Really, that after 33 years of reading and analyzing the same comic strip I'm able to find new dimensions. It's a testament to the work. For six years I delved into tobacco research. Because... can a cat smoke? This is a metaphysical question. Yes. Can any cat smoke? Do we know? Can just Garfield smoke? The research says no. Nicotine poising can kill animals, especially household pets. All it takes is the nicotine found in as little as a single cigarette. Surely Jon's pipe holds a substantial amount of tobacco. It is true that pets living in the homes of smokers are nearly 25% more likely to develop some form of cancer. Most likely due to secondhand smoke. But these are facts of smoking and its tolls on our world. But after visiting two tobacco processing plants in Virginia, and the Philip Morris Cigaret Manufacturing Facility, I came no closer to cracking the meaning. I was looking for any insight. A detective of a homicide case has to look at every angle. So I'm always taking apart "The Pipe Strip". I focused on every minutia, every detail of this strip. Jon Arbuckle's clothing. I have replicas. I am an expert in textiles. So you see this smoking thing was a hangup for me. What was the statement here? Until... This is key... This is the breakthrough. The pipe is not a pipe really. Obviously there's symbolism at work here. I saw that from the beginning, and I looked at the literal aspects of the strip to gain insight into the metaphors at play. I worked at a newspaper printing press for 18 months in the late 1980s. I was learning the literal to inform the gestural, the... subliteral, the in-between. Jon reading the newspaper means so much more than just Jon reading the newspaper. But how could you ever hope to decipher the puzzle without knowing everything there is to know about newspapers? Okay. For example: Jon holds his paper up with his left hand, thumb griping the interior. I learned that this particular grip here is the newspaper grip of 19th century aristocrats. And this aristocrat grip was a point of contention that influenced the decision to move foward prohibition in the United States in the early 20th century! So Jon's hand position is much more that that, it is a comment on class war and the resulting reactionary culture. But I didn't know about the aristocratic newspaper grip until I came across microfiche archives at the printing press. It's about information. You have to take it apart. And the breakthrough on a smoking cat came late. Just eight years ago actually. "Smoking cat" is an industry term. It's what the smoking industry calls a tattletale teenager who tells on his friends after they've all tried smoking for the first time. And it is actually a foreign translation, bastardization, of the term "smoking rat"! But the phrase was confused when secret documents went back and forth between China and America. These documents are still secret. And the only reason I know about the term is because I know a man, my friend... let's call him Timothy. Yeah. Yes. It's a fake name for his protection. Timothy worked for Philip Morris for 16 years, and he had seen the documents. When he told me, it was an "aha!" moment. And he said: "But how?" "How could this cartoonist Jim Davis know about this obscure term from the mid-70s used exclusively by a few cigaret companies? This is still a mystery to me. But I connect the dots by noting Jim Davis's childhood experiences on a farm. He must have seen something. What could it be? Timothy went on to tell me there was one particular smoking cat. A boy, from... yes... Indiana! A boy named Ernie Barguckle who became a thorn in the side of the Tobacco companies' for a couple of years. He did more than tattle to his parents. He and his family took legal action and they eventually received a huge settlement payout. But that name is too similar. Ernie Barguckle... Jon Arbuckle... Jim Davis must have used this. There's more here, Ernie Barguckle spent nearly half that settlement money on experimental medical procedures to cure his... impotence. He was impotent. So, he was a smoking cat with a... a metaphorical pipe that did not work. Are you starting to see the layers here? This is exciting stuff! You start to get a whole picture here and it informs the work. It's just remarkable... Jim Davis took these raw ideas, these pieces and he transformed them into smart social commentary that is... Oh, so ravishingly beautiful. I have cried. I've cried, I've cried. I've cried, cried over this piece. It just... gets into my soul. I tried to explain this to people, I have the newspaper articles about Ernie Barguckle. People have fought me on this. They don't see it. Or they're close-minded. How can a comic strip about a cat smoking a pipe mean any more than that? But it is more. When I feel spiritual or start to think existentially, I still see this comic. Here is something from 1981 that I wrote thinking about the implications of this strip. This is just an excerpt here, there is more before and after but this part in the essence to me: If a comic about a cat smoking a pipe can be the only thing in the universe, then maybe this is strongest evidence for that. Many of you say, "Oh but I am not blind. I have never been blind." But when you truly see, you will understand just how truly blind you once were to even think it right to say you were not blind! What does a blind man see? Blackness. Darkness. Blankness. Black darkness. Dark blankness. The absence of things. Quite literally no thing. No things. Nothing. Nothings. So you see nothing, and I bring you into the light. A cat has your pipe! You've been blind! DO YOU UNDERSTAND THIS? The cat has your pipe! You can't fully immerse yourself, you don't have the light, you don't have the radiance, the radical light, the radically radiant light of truth, and truths's belonging love and nature of light, and loving truthful radiance. So don't be bold and make bold statements, I know of you. The cat has your pipe. The... cat... has... your... pipe. Remember that. That writing, well... it's kind of rough. Kind of an early 80s feel. And I see that. But I'm still, I'm still proud of it. Sometimes I imagine that it is the editorial column on the newspaper Jon Arbuckle's reading. It's an exercise in recursion, it's like a vortex opens up. It's like you hold two mirrors up to each other: one is reality and the other is a cartoon script. Let's see... Oh yes. I must bring this up. Because I think surely Jim Davis is again speaking on multiple levels by including the details set before us in the comic. Notice the glimpse of Jon Arbuckle's foot in the first panel. The size of the shoe would indicate that maybe the man just has small feet? But a deeper investigation takes us to the foot binding rituals of certain Asian cultures. Inflicted usually on women for the desire of men, this practice was incredibly painful and crippling. Aha! Mr. Davis is here presenting us with a man or, rather "man" who engages in foot binding. A body modification for woman on top of being without his pipe or impotent. This is a man facing extreme inner turmoil. The panels tell that story subconsciously. Notice the background wall shading of the first panel points inward towards Jon in the second panel. And the sharp tapered end of the purple pipe in the third frame also points at Jon in the second panel, inward. The eye is drawn to the center panel. You can connect these points and draw a triangle across the panel, and this triangle will align with a reoriented points of Jon's collar. This, this is majestic artwork! And to uncover this hidden order is bliss like I've never known. Comforting, in an empty world. I can't help but read the thought bubble, again and again. "Now where could my pipe be?" "Now where could my pipe be?" It is a profound question. Why am I here? What is my purpose? It is reflection and self-examination here. It is facing the dust, the misery of a cold, careless universe. You can feel the weight of it. Now where could my pipe be? One imagines the author, Jim Davis, nearly teetering on the edge of insanity, his rationality, his lucidity, hovering over the void, and he seeks the truth. You can see it in the line quality of the drawings; the thoughtful, controlled outlines mixed with the... occasional, chaotic scribbles that lurk in the shadows of Garfield's dark stripes. It's almost as if Garfield is chaos himself. Yes. He is the embodiment of chaos, disorder, hatred, fear. Thievery, death, destruction, desolation! These are the things Garfield represents; HE stole the pipe, HE sits with his back to Jon, Garfield... Garfield! Garfield, this chaos cat, Garfield has turned his back on everything, everyone! One recalls the great existential forces in literature, Camus' Meursalt, Kafka's Gregor Samsa, or Sartre's Antoine Roquentin. Garfield the Cat sees the hopelessness of life, which... yes... This is why Jim Davis has chosen smoking. It represents a recklessness, a... a disregard for what some would define as the beauty of life. Garfield may die from the nicotine, he may not... He defies life; he sits defiant, saying nothing, but looking as if he could say: "Then let me die. It does not matter." It does not matter. And we are faced with this: Could Jon behave the same? Is Jon the glimmer of hope? He seems to be unsure. Again his question: "Now where could my pipe be?", indicates that he is wrestling with his own existence. The center panel centers the issue, and again, this hearkens to many of the great religious works of art. I'm talking about "The Pipe Strip" in relation to religion. It's interesting to assign the roles of God and anti-God, or, as many know him to be, the devil. Or on a much larger scale, simply the forces of good and evil. Garfield, the thief-cat, evil and malicious. He is the devil, placed to the right. And note the two forms of Jon; the Jon on the left, still innocent, still draped in the delight of the lack of knowledge. He is the humans in the Garden of Eden. He feels for his pipe, but he has yet to eat from the tree. And Garfield, the sinister serpent. And notice, notice how Jim Davis has framed this; The center Jon is locked in a struggle, between his innocence, and knowledge of the truth, knowledge of the existence of evil. It is stunning. The great struggle, the struggle that transcends time, and Jim Davis floats over all this, as creator, God, of sorts, in his own right. And he presents this cautionary message to us all; it is as if he is speaking from high, and he is saying, unto our awaiting ears: "Where will you be, when the cat reveals himself?" [-Jim 7:27:78] I can tell you where you'll be. You will have a choice. You can face endless suffering, and eternal misery. You can be forced and beaten down with barbarians, who claw at each other just for a view of salvation. They'll tear your eyeballs out, and rip your gizzards from end to end. They worship this cat, this, this false idol! This evil, horrible cat, do not be seduced by the cat and the pipe! Garfield... thy name is a mark of the demons of hell. Something like this, and to those listening, it is a stark reminder to follow the path of the first panel Jon; be humble, be grateful, honor the law, and honor thyself, be true, and be good, and no harm will come to you. Pray for salvation, and it will be granted unto you. Be like Jon Arbuckle, as he lowers his head. Be like Jon Arbuckle as he lowers his paper, as he turns his head. Bow with Jon Arbuckle, and praise unto the creator, Jim Davis, and banish demon Garfield from your life. So what is all this? What am I saying? What does all this mean? Why is this one comic strip so important to me? And why do I feel the need to share this? Obligation. I have an obligation to you all. This is a redemption, this is a belief in redemption, a sacrifice of all the obvious trappings of this false modern life. Look at the simplicity in this strip, in "The Pipe Strip". Look at the simple clothes Jon wears, look at his simple, basic furniture. No adornments on the wall, even the very pipe his cat Garfield stole; it is a plain, modest pipe. And I have adapted this way of life, it speaks to me. In our times... well, you don't need me to point out the hyperbole of our times. You have children being born eight or nine at a time. You have more money being spent on a single Hollywood movie than some nations can spend feeding their starving people. Torture, distrust. Look around you, it's overwhelming. What can you contribute? And every day, I look in the mirror, and I hold this comic up to the mirror, and I look into the mirror, and at this little comic strip. Be humble. Be thankful. It is a reminder. Be respectful. You are a statue. You are fragile. And when you break, when you shatter, where will those pieces go? Ask, ask, ask, ask this question. Will you ask? Humankind is only as great as you, YOU, the individual, it begins and ends with you! You must treat this expedition, this search, this... life with a reverence and intensity found only in the smallest sticks. The littlest leaf, the tiniest stone! The most minuscule grain of sand... on a beach of billions! This is the secret. Do you want the pipe? Do you want to know where the pipe has gone? You ask yourself, you ask... you ask... you ask... Now where could my pipe be? When I was a young man... Remember, now, I first saw this comic when I was 18 years old. Ages ago. But I was youthful, vibrant. For weeks, I denied that a comic strip was having such a profound effect on me. I was much like Jon Arbuckle. In this middle panel, he says, "Now where could my pipe be?" You could look into his eyes, his half-lowered eyes, and think to yourself, "Now, surely, Jon... Surely, you cannot be this naive. This is nothing new for you." And if you've read more of the Garfield comic strips by Jim Davis, you understand what I am saying now; Garfield the cat does things like this all the time. He will take things from Jon; food, items, anything. This is his very nature. So you see this, and you want to say, "Jon Arbuckle, come now. You are lying to yourself. You are lying to yourself and to all of us, if you pretend to have not... any idea of where your pipe has gone. Perhaps you think you've left it somewhere else, but... you're not so forgetful. You are lying to yourself, Yes... You are lying to yourself, Jon Arbuckle. You know that Garfield has the pipe, somewhere, deep down, you know this. You don't even need to think the question. And that was me when I saw that strip. One week passed, and each morning I opened my drawer and slammed it shut again. I would go to look at the comic! But I'd pause and think: "No, I don't need this comic." "I don't NEED to look at it." But there I was, lying to myself. I did need to see it. And so I did. It's... cathartic. You give in, and that is the transition from the second panel of life to the third panel of life. It is a simple story structure, the passage from the second act to the third, the twilight of things. Jon gives into his suspicions, he knows the truth, he's always known the truth, he yells out, "GARFIELD! GARFIELD! GARFIELD!" It is like... pressure from a steam valve, being released; the buildup is unbearable, and then... PSSHHWW, it's gone. So it is like this... When I speak about the truth... the truth, the light, the radiance, this... this is the kind of thing I'm talking about. This is the essence of this brilliant work of art, the practical mixing, meeting, agreeing with the spiritual, it is all here. But spirituality is not an easy thing to confront. You might find yourself able to wrap your mind around a simple math problem, or a basic newspaper article, or... but intellect... is much less subjective. What is spirituality... and how have I found spiritual peace and serenity in Garfield? A long time ago, after I encountered the Pipe Strip, I spent some time, as I mentioned before, soul-searching. When something impacts you, or alters your very perception so greatly, there is a long period of confusion, recovery time... It's as if you don't know who you are, and that can be a... a very scary prospect, especially if you thought you had a good grasp on that sort of thing. Imagine if Jim Davis did not know who he was. Would he be capable of shaping the cultural landscape as he's done? No. No, of course he wouldn't. And how about his characters? Jon... what if Jim Davis suddenly woke up, and didn't know who Jon was? What if he couldn't make the informed decisions to accurately depict Garfield's personality, because of... he could no longer specify, or demarcate the boundaries of Garfield's behavior? What kind of comic would that be? You see? So draw the parallel. I saw this comic and, yes, I was disoriented... and if I didn't reconcile this issue with myself, what kind of person would I be? Undoubtedly dire circumstances, but remember; this was not a math problem, this was not an article, this was not something I could just... figure out. And as skeptical as I was, I realized that faith and spirituality were avenues that... required exploring. At first I tried... long nights, reading Garfield by candlelight, or... aromatic meditation settings, while thinking of Garfield, but... nothing snapped. Nothing clicked, I still felt lost... But I kept it up, I hired a shaman, and a young... personal Yogi Sikh Guru; Avram Dahb Singh Sahib. I pushed and pushed, determined to find myself. And then, a miracle happened. Upon retrieving my morning paper to clip the Garfield comic I noticed a young girl, selling lemonade two houses down. She sat, occupied at her stand. She had no customers in sight. So, I approached, and saw that she was coloring. I looked at her drawing. Three rectangular boxes. A man, in a blue shirt. An orange cat. I knew what this was. Even in her crude scribbles, I knew EXACTLY what this was. She was drawing a Garfield comic. I looked at her words, and I saw that, in her strip, Jon asked Garfield to retrieve a newspaper. Funny. Since I'd done just that with myself.. Garfield is sarcastic, but agrees to it. He returns and calls Jon... (Sahib) "صاحب" Jon exclaims that the paper's all chewed up, but then Garfield says, and I quote, "Sahib asks fish, paper is wet. Sahib asks cat, paper is holey." I remember the words, and ran back to my house, I thought, "How odd that Sahib shows up in the strip, and my spiritual advisor's name is Avram Dahb Singh Sahib!" Coincidence surely, but, nonetheless, I spent the next sixteen hours poring through my clipped Garfield comics, looking for the strip this young girl had been coloring. I couldn't find it. And I eventually fell asleep, right on my kitchen table. Next morning, I retrieved my paper again, and I clipped the Garfield comic. The date was July 12th, 1983. And there it was. The Sahib Strip, in all of its glory. The girl had been drawing the next day's strip! Well, I ran right out of my house, I ran back to where she was... But she was gone, and in place of the lemonade stand was a... "For Sale" sign. They'd moved out. I rushed back to my house to call Avram, but I was informed that he'd moved away as well. I reeled, for several hours, and then it all connected for me. It was meant to be. It was meant to be this way! Jim Davis. Jon. Garfield. It was always meant to be this way for me. They move to the forefront, and everything else fades away, EVERYTHING else; the girl, the lemonade stand, Avram Dahb Singh Sahib, it all existed to show me the way, and when I'd found the way... Everything else melted away. It was a beautiful miracle. And if July 27th, 1978, the day I first saw the pipe strip was the first day of my life, then that day, July 12th, 1983, was the second day of my life. I've never looked back. Garfield has transformed me. And I am a man born anew, because of Garfield. When I was in my mid-30s, I was interviewed for a documentary. It was a documentary on the subject of cat behavior. Now, I've had cats my whole life. I have three cats now, and at the time of this documentary interview, I had four cats. I sat down for the interview and was joined by a veterinarian who specialized in felines. Doctor Caroline Wellmitz was her name, I believe. And the doctor discussed colorblindness in animals, and how it affects their behavior. She specifically brought up the fact that cats are red-green colorblind. They can see colors, but they can't tell the difference between red and green. And look at the color choice in this strip here. Garfield sits on a green floor, behind a pinkish red wall. I heard this, and I immediately pulled a copy of the comic from my wallet to show to the doctor. I moved so fast, I'm sure I nearly scared her. I pointed at the paper and said, "Like this! Like this!" "Look, at this here! This cat, Garfield, he's colorblind, he must be! That must be the answer here. Like this." As overexcited as I was, I managed to take in her response. She said, "Yes, a cat in this room would have a hard time differentiating the wall from the floor. Add to that a cat's known spatial confusion, and you have the makings of a Cat Rage room." Now, she informed me that this isn't exactly common knowledge among cat owners. But a seasoned cat owner, or someone particularly perceptive will have picked up on it. So what's incredible here is not only is Garfield's behavior symbolic of the devil, and all the evil constructs in the world, but... But also, it is rooted in science and scientific fact. Look at that. You cannot spell fact without "cat". Just a little joke there. Just some wordplay. But getting back on track. And you can't spell track without "cat." Okay. I digress. I gotcha, I gotcha. Enough kidding around. It is established here that Garfield is in a rage, an ultimate rage of fury and hatred, caused by colorblindness. We know the "what", we know the "why". But let us examine the "how", the how of his rage is particularly interesting here. We've looked at his posture and called it "powerful", "in control", "statuesque", etc. etc. Composed rage. It's peculiar, and I've talked to a number of psychologists and psychiatrists, and even a couple of anger management therapists about this concept. Could we see the same kind of behavior in a human? Is Garfield representative of something more specific than just chaos and rage? Deciphering this is going to take some perseverance, for sure. The psychologists pointed to a phenomenon in humans, and, yes, I believe one of the anger management counselors brought it up as well. The idea that people, oftentimes, will bottle their rage. Garfield the cat, here. He could be bottling his anger, inside, shoving it deep into his cat gut, to ignore and deal with at a later time. No, that's not exactly right. Garfield has already acted out. He's already stolen the pipe. He's SMOKING the pipe, he's already dealt with his anger. He's already lashed out, so, psychologically, what is going on here? What is this cat doing, and how does it impact his owner, Jon Arbuckle, psychologically? Well, Garfield is angry. He is acting on his anger. But is this passive anger, or aggressive anger? Passive. It is passive because if Garfield has a problem with Jon specifically, he's choosing a passive way of dealing with that problem. He has not confronted Jon, and said, "Jon, I have a problem with the way you've decorated this room; as a cat, I am colorblind, and this room sends me into a rage. You've created a rage room for me here, and I don't like it. I want you to change it." Instead of that confrontational approach, though, Garfield has chosen to steal Jon's pipe. And that, in turn, angers Jon. But Jon decides to be aggressively angry and yell at Garfield. So now, instead of a calm conversation between two respectful parties, you have two heated, angry individuals, each with a problem and no direct line to solving it. The layered emotions here tell a story with tight, focused brevity that would make Hemingway weep. This is an entire drama, in just three panels, people. But let's not be remiss, and miss the humor of the situation. The absurdity of it all. For certainly, there is a reason that the visual shorthand for drama includes both the crying mask AND a laughing mask. Comedy and tragedy complement each other, and meld together to create drama, tension, the height of humanity, the peak of art that reflects back to us our own condition. And here in its basest form, we can laugh at this comic, yes, COMIC, in which a cat smokes a pipe. When was the last time you've SEEN such a thing in your life? Never, I presume. I certainly never have. The Greek muse, Thalia's presence is strong in this work of art, here. Comedy, it is COMEDY. And if you look at the structure again, you'll see this perfect form of thirds works magically for the transmission of, yes, YES, a JOKE. The joke is as old as time. Even cavemen told jokes, and the joke here is that Jon has lost his pipe. Or he thinks he has. But lo and behold, it is the cat, Garfield, who has the pipe. Surprise, surprise, the cat is smoking! Again, the transition, from set-up to punchline takes place between the second and third panels. But make no mistake, the comic is more than just a comic. Yes, it IS funny, of course it is. It is operating at the height of sophisticated humor, on par with any of Shakespeare's piercing wit. On the one hand, Garfield the comic, with Jon the man, humor as art. The other hand, Garfield comic, with Jon the man, stirring... no, RIVETING drama. As with everything, it is tension, and release. TENSION... and RELEASE. A cycle. I keep returning to this idea, because it is so omnipresent. Yes, you could, and yes, I have done this, on more than one occasion. You could print this comic strip on a giant piece of paper. The dimensions would be something like... thirty-four inches by eleven inches. Now, tape the ends together, with the comic facing inward. Stick your head in the middle of this Garfield comic loop and READ, start at the first panel. Jon is reading the newspaper. He feels for something on the end table. Second panel; he sets the newspaper down. Something is not right. "Where could my pipe be?" he thinks. And then, the payoff. The third panel. Garfield has Jon's pipe, and is smoking it. The paper is in a loop, around your head. So that you can see that, once again, Jon is in his seat, reading the paper. And so on, and so on. You can literally read the comic strip for an eternity! I spent many a relaxing Sunday afternoon reading this strip, over and over. I'm reminded of the Portuguese death carvings, which always begin and end with the same scrawled image. So, this idea of repetition, of the beginning being the end, and the end being the beginning. It's not new, it is an ageless tradition among the best storytellers humanity has ever offered. And I'm not wrong to include cartoonist Jim Davis in that exalted set for this particular strip alone. I'm not foolish enough to deny that great art is subjective. Divisive, even. And that some people see this Garfield comic and shrug with no real reaction. But I will say that I believe everyone in the world should see it. At the very least, see it! You should all see it. Read it. Spend some time with it. Spend an hour reading it. What's an hour? Yes, you could watch some television program, you could play some fast-paced video games or computer games. Yes, you could do all those things. But it's just an hour. And if you give this strip a chance. If you look into Jon Arbuckle's eyes. If you look into Jon Arbuckle's SOUL. You might find that you'll really be looking into your own soul. It is self discovery, that is what I'm talking about here. YOU have the opportunity, the possibility. It could change you. Don't be afraid. You know, just last week, I was eating lunch near the Municipal Court. Like I do every Thursday. And there was a plumbing banner. A plumbing van, parked out in front. And a man, a plumber, would step out from the court, and retrieve something from this van every so often. A few times, this happened. I thought nothing of it. Just a plumber, doing some work at the Municipal Court. But then he came out, and looked through his van, and it was clear. He couldn't find something. I noticed, and thought, "Well, that's sort of similar to the Garfield comic, in a way. Someone looks for something, can't find it." But, yes, that probably happens billions of times a day around the world. But then, this plumber put his hands on his hips. Then, he scratched his head, and he said aloud... "Now, where could my pipe wrench be?" Well, at this, I leaped off the bench, sandwich still in hand, and I rushed over, I shouted, "What was that you said!?" He looked at me and said, "What? I can't find my pipe wrench." And I said, "No! No, no, say it... like how you just said it." He scratched his head, and repeated, "Now where could my pipe wrench be?" I slapped him on the back and said, "Garfield!" He looked so confused, so I said it again. Then, I said, "Your orange cat took it!" Then I laughed and laughed. And he smiled, and went back into the courtroom. I walked away, knowing that the plumber and I, two complete strangers, bonded over this Garfield comic. You see, life imitates art, becomes a common ground. I have a feeling that if I see this plumber again, we'll be sharing stories like two old friends. Because we've been united by art. We have a common love for Jim Davis and his characters, his writings. The humor, the drama, the... That rascal Garfield, the cat. And by the way, if you're wondering what I was having for lunch that day, it was a ham sandwich with an apple and potato chips. In a bag, I had a soda as well. I think it's important to view the Pipe Strip in philosophical terms. We've touched briefly on the notion of existentialism. That theme is very prevalent in this strip. Garfield is, in fact, a modern existential anti-hero. But if Garfield embodies the bewilderment in a meaningless life, what is Jon? What are the telltale signs that inform Jon's philosophical standpoint? His approach, what style of thinking he represents? Jon is depicted as being grounded in the material world. A world of things; he is surrounded by objects, and he touches these objects, he interacts with them. The newspaper, the end table, the chair. His clothes, all these physical things make up Jon's world. In some sense, even his cat Garfield is an object to him, a thing. The first ideology that comes to mind when thinking of objects in the tangible world is pragmatism. Is Jon Arbuckle a pragmatist? His beliefs stem from a useful, coherent view of his environment. A sort of cause-and-effect understanding of his world... helps him. A: Deduce that his pipe is missing. And B: Catch his cat, Garfield, using the pipe. This kind of empirical and logical thinking lends credence to the idea that Jon is, indeed, a pragmatist. Although, it is hard to entirely ignore the rest of the Garfield comic canon. While Garfield is consistently anarchic, and embraces the chaos and absurdity of life. Jon Arbuckle exhibits an erratic, unpredictable mix of philosophical behaviors. At times, he is borderline; delusional, an idealist, an almost slap-happy version of Don Quixote. Other moments, he is rigid, nearly to the point of being obsessive. Somewhat like a structuralist. And certainly has streaks of sarcasm and negativity that might classify him as a skeptic. But isn't there some universal truth in this approach? How can any one man, how can Jon Arbuckle be just one thing? How can any of us be just one thing? We're an amalgamation of ideas, of emotions, conducts and functions, thoughts and feelings. Jon Arbuckle may very well inhabit tenets of nearly every major philosophical tract known to man. We all might. Characters are reduced to make them recognizable, definable. A story needs a good guy, a story needs a bad guy. But rarely is one person defined in such black and white terms. Even Garfield, with all his bad behavior, Machiavellian motivation and general ne'er-do-well attitude, can be kind and thoughtful. You just have to find that rare strip. Speaking philosophically about the entire Garfield franchise, it's an incredibly accurate depiction of life. Its bold lines and bright colors are merely a facade, a red herring, a lie. This cartoon is not a cartoon at all. It is not a caricature. It is not caricature despite adopting caricature as its visual style and tone. But I don't really like to speak in broad sweeping generalizations about Garfield. The comic has been running for over thirty years, and to try and boil that all down is just, well... It's impossible. I think the only way that any historian worth his salt will agree with me is to look at individual moments. Isolated instances, single comic strips. Can I discuss this one strip in the context of the entire run of Garfield? Yes, I do that just as a film historian might analyze one movie in relation to the history of all movies, or a war enthusiast might look at a single battle's impact on an entire war. The Pipe Strip is just an instance in the lives of Jon and Garfield. Perhaps Jon is not a pragmatist at all. Let's look at this again. Maybe Jon is exhibiting the traits of a rationalist thinker. His question, "Now where could my pipe be?" is a clue that his thought process stems from the early rationalist questions posed by René Descartes. The well-known quote, "I think, therefore I am," attributed to Descartes, is applicable. Another close look at the strip, and we see that Jim Davis chose to draw Jon thinking his question. "Now where could my pipe be?" Jon does not speak this question aloud, so Jim Davis is also exploring the mind/body duality. Jon's question operates on the level of a literal question. But it also examines the nature of reality. Jim Davis' epistemological approach tells us something about the human condition; Jon's thoughts remain the focal point of this strip. The comic is, quite literally, centered around his thought. "Now where could my pipe be?" This is his reality, this is where cognition, and the power and function of the mind take over. As Plato believed, the body is just a shell for Jon Arbuckle. Yes, he can use his physical body to read his paper or cross his legs, but these inputs of touch, sight, hearing, et cetera, these senses are the triggers of the mind, as we see here, the mind.. Is something greater. It is the originator of ideas, and ideas are forever. Immortal. Immortality through thought, a major theme in literature and philosophy. And isn't that what Mister Jim Davis himself has achieved? Will he live forever? The universe will continue to spread, and spread outward, and... entropy will turn a chaotic infinity into a homogenous, controlled system. This will take billions of years, and in that time, humans will push technology to heights we can't imagine. We'll explore and inhabit space, and occupy more and more of the universe, just as time allowed our ancestors to... multiply in numbers, and populate more and more of the Earth. And as the specific people come and go, their physical bodies will be born, and grow, and die. But their thoughts will remain. And Jim Davis' comics, his glorious Garfield comics are recorded ideas of his, that will still be here. Even when the Earth is no longer inhabitable, and humanity has long since moved away to bigger planets, they'll carry with them a record, a record we all keep. Mark my words. And look at what we've started. What is... What is the internet? What is the online world, if not a record? Never-ending feed of ideas, immortal ideas, forever placed in the ether of dualism. What is an idea? Where does it live? How does it manifest itself? Can it live forever? Will it live forever, outside of these physical husks of ours, our bodies? And Jon Arbuckle, and Garfield, started merely as thoughts. But they've become so much more. That old cliché rings true, they've taken on a life of their own. And life may not be what we think. Life brings to mind a beating heart, breathing lungs, blinking eyes. But the real life is in our imaginations. And who better embodies the definition of imagination if not a simple man. A cartoonist, who puts his ideas to paper so that they may live on. So that our children, and our children's children, and their children's children's children can access the wealth of ideas that have accumulated thus far. They will plug themselves into an information grid, and they will have... access. They will read every Garfield comic, 80,000 years from now, a child will see a simple Jon Arbuckle, reading a newspaper. He will feel around for something, but that something is not there. He will lift his head and think... "Now where could my pipe be?" And Garfield will be smoking the pipe, and Jon will yell "GARFIELD!" And what then? 80,000 years from now? The child reading this comic will smile. And that smile will transcend space and time and the physical limitations of this existence, whatever it may be, however many dimensions exist. There will always be Garfield. And there will always be its creator... Jim Davis. \ No newline at end of file diff --git a/about/index.php b/about/index.php new file mode 100644 index 0000000..2d4f955 --- /dev/null +++ b/about/index.php @@ -0,0 +1,64 @@ + + + + + + + + + +
+ +
+
+
+
+
Contact
+ Discord: ReimarPB#5736 +
+ XMPP: + reimar@reimarpb.com +

+
Donate
+ + +
+
+ + + Bitcoin + +
+ +
+
+ + +
+
+ + + Monero + +
+ +
+
+
+ +
+
+
+ +
+ + + + + diff --git a/api/set_theme/auto.php b/api/set_theme/auto.php new file mode 100644 index 0000000..ab7585d --- /dev/null +++ b/api/set_theme/auto.php @@ -0,0 +1,6 @@ + + + + + + + \ No newline at end of file diff --git a/assets/icons/cs.svg b/assets/icons/cs.svg new file mode 100644 index 0000000..5f58f92 --- /dev/null +++ b/assets/icons/cs.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/icons/dark-mode/check.png b/assets/icons/dark-mode/check.png new file mode 100644 index 0000000..751d11a Binary files /dev/null and b/assets/icons/dark-mode/check.png differ diff --git a/assets/icons/dark-mode/check.svg b/assets/icons/dark-mode/check.svg new file mode 100644 index 0000000..fcd62ea --- /dev/null +++ b/assets/icons/dark-mode/check.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/icons/dark-mode/copy.png b/assets/icons/dark-mode/copy.png new file mode 100644 index 0000000..44b93e7 Binary files /dev/null and b/assets/icons/dark-mode/copy.png differ diff --git a/assets/icons/dark-mode/copy.svg b/assets/icons/dark-mode/copy.svg new file mode 100644 index 0000000..4517c2b --- /dev/null +++ b/assets/icons/dark-mode/copy.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/icons/dark-mode/github.png b/assets/icons/dark-mode/github.png new file mode 100644 index 0000000..628da97 Binary files /dev/null and b/assets/icons/dark-mode/github.png differ diff --git a/assets/icons/dark-mode/github.svg b/assets/icons/dark-mode/github.svg new file mode 100644 index 0000000..8d8dbe4 --- /dev/null +++ b/assets/icons/dark-mode/github.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/assets/icons/gameoflife.ico b/assets/icons/gameoflife.ico new file mode 100644 index 0000000..0c7b020 Binary files /dev/null and b/assets/icons/gameoflife.ico differ diff --git a/assets/icons/javascript.png b/assets/icons/javascript.png new file mode 100644 index 0000000..4675be4 Binary files /dev/null and b/assets/icons/javascript.png differ diff --git a/assets/icons/light-mode/check.png b/assets/icons/light-mode/check.png new file mode 100644 index 0000000..87a7356 Binary files /dev/null and b/assets/icons/light-mode/check.png differ diff --git a/assets/icons/light-mode/check.svg b/assets/icons/light-mode/check.svg new file mode 100644 index 0000000..e6a00ab --- /dev/null +++ b/assets/icons/light-mode/check.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/icons/light-mode/copy.png b/assets/icons/light-mode/copy.png new file mode 100644 index 0000000..4c2ec56 Binary files /dev/null and b/assets/icons/light-mode/copy.png differ diff --git a/assets/icons/light-mode/copy.svg b/assets/icons/light-mode/copy.svg new file mode 100644 index 0000000..5d2b365 --- /dev/null +++ b/assets/icons/light-mode/copy.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/icons/light-mode/github.png b/assets/icons/light-mode/github.png new file mode 100644 index 0000000..8b25551 Binary files /dev/null and b/assets/icons/light-mode/github.png differ diff --git a/assets/icons/light-mode/github.svg b/assets/icons/light-mode/github.svg new file mode 100644 index 0000000..60d23d7 --- /dev/null +++ b/assets/icons/light-mode/github.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/assets/icons/linkedin.ico b/assets/icons/linkedin.ico new file mode 100644 index 0000000..f3e5d18 Binary files /dev/null and b/assets/icons/linkedin.ico differ diff --git a/assets/icons/linkedin.png b/assets/icons/linkedin.png new file mode 100644 index 0000000..ee90def Binary files /dev/null and b/assets/icons/linkedin.png differ diff --git a/assets/icons/monero.png b/assets/icons/monero.png new file mode 100644 index 0000000..7268f82 Binary files /dev/null and b/assets/icons/monero.png differ diff --git a/assets/icons/monero.svg b/assets/icons/monero.svg new file mode 100644 index 0000000..fbd4b20 --- /dev/null +++ b/assets/icons/monero.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/icons/popup-timer.ico b/assets/icons/popup-timer.ico new file mode 100644 index 0000000..ce1cdfa Binary files /dev/null and b/assets/icons/popup-timer.ico differ diff --git a/assets/icons/reimtris.ico b/assets/icons/reimtris.ico new file mode 100644 index 0000000..cd8acb7 Binary files /dev/null and b/assets/icons/reimtris.ico differ diff --git a/assets/img/grass_dark.png b/assets/img/grass_dark.png new file mode 100644 index 0000000..2c4efae Binary files /dev/null and b/assets/img/grass_dark.png differ diff --git a/assets/img/grass_light.png b/assets/img/grass_light.png new file mode 100644 index 0000000..80228a3 Binary files /dev/null and b/assets/img/grass_light.png differ diff --git a/assets/img/tree_dark.png b/assets/img/tree_dark.png new file mode 100644 index 0000000..86380e8 Binary files /dev/null and b/assets/img/tree_dark.png differ diff --git a/assets/img/tree_dark.svg b/assets/img/tree_dark.svg new file mode 100644 index 0000000..cb004f1 --- /dev/null +++ b/assets/img/tree_dark.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/assets/img/tree_light.png b/assets/img/tree_light.png new file mode 100644 index 0000000..ed1f2fb Binary files /dev/null and b/assets/img/tree_light.png differ diff --git a/assets/img/tree_light.svg b/assets/img/tree_light.svg new file mode 100644 index 0000000..f701979 --- /dev/null +++ b/assets/img/tree_light.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/assets/lib/box-sizing-polyfill/boxsizing.htc b/assets/lib/box-sizing-polyfill/boxsizing.htc new file mode 100644 index 0000000..ef5dfe2 --- /dev/null +++ b/assets/lib/box-sizing-polyfill/boxsizing.htc @@ -0,0 +1,504 @@ +/** +* box-sizing Polyfill +* +* A polyfill for box-sizing: border-box for IE6 & IE7. +* +* JScript +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published +* by the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* See +* +* @category JScript +* @package box-sizing-polyfill +* @author Christian Schepp Schaefer +* @copyright 2012 Christian Schepp Schaefer +* @license http://www.gnu.org/copyleft/lesser.html The GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 +* @link http://github.com/Schepp/box-sizing-polyfill +* +* PREFACE: +* +* This box-sizing polyfill is based on previous work done by Erik Arvidsson, +* which he published in 2002 on http://webfx.eae.net/dhtml/boxsizing/boxsizing.html. +* +* USAGE: +* +* Add the behavior/HTC after every `box-sizing: border-box;` that you assign: +* +* box-sizing: border-box; +* *behavior: url(/scripts/boxsizing.htc);` +* +* Prefix the `behavior` property with a star, like seen above, so it will only be seen by +* IE6 & IE7, not by IE8+ who already implement box-sizing. +* +* The URL to the HTC file must be relative to your HTML(!) document, not relative to your CSS. +* That's why I'd advise you to use absolute paths like in the example. +* +*/ + + + + + + \ No newline at end of file diff --git a/assets/lib/css3pie/PIE.htc b/assets/lib/css3pie/PIE.htc new file mode 100644 index 0000000..ca3b547 --- /dev/null +++ b/assets/lib/css3pie/PIE.htc @@ -0,0 +1,96 @@ + + + + + + + + + diff --git a/assets/lib/css3pie/PIE.js b/assets/lib/css3pie/PIE.js new file mode 100644 index 0000000..d36448a --- /dev/null +++ b/assets/lib/css3pie/PIE.js @@ -0,0 +1,88 @@ +/* +PIE: CSS3 rendering for IE +Version 1.0.0 +http://css3pie.com +Dual-licensed for use under the Apache License Version 2.0 or the General Public License (GPL) Version 2. +*/ +(function(){ +var doc = document;var f=window.PIE; +if(!f){f=window.PIE={F:"-pie-",nb:"Pie",La:"pie_",Ac:{TD:1,TH:1},cc:{TABLE:1,THEAD:1,TBODY:1,TFOOT:1,TR:1,INPUT:1,TEXTAREA:1,SELECT:1,OPTION:1,IMG:1,HR:1},fc:{A:1,INPUT:1,TEXTAREA:1,SELECT:1,BUTTON:1},Gd:{submit:1,button:1,reset:1},aa:function(){}};try{doc.execCommand("BackgroundImageCache",false,true)}catch(aa){}for(var ba=4,Z=doc.createElement("div"),ca=Z.getElementsByTagName("i"),ga;Z.innerHTML=" + + + + + + + + diff --git a/assets/lib/css3pie/PIE_uncompressed.js b/assets/lib/css3pie/PIE_uncompressed.js new file mode 100644 index 0000000..85f6785 --- /dev/null +++ b/assets/lib/css3pie/PIE_uncompressed.js @@ -0,0 +1,4474 @@ +/* +PIE: CSS3 rendering for IE +Version 1.0.0 +http://css3pie.com +Dual-licensed for use under the Apache License Version 2.0 or the General Public License (GPL) Version 2. +*/ +(function(){ +var doc = document;var PIE = window['PIE']; + +if( !PIE ) { + PIE = window['PIE'] = { + CSS_PREFIX: '-pie-', + STYLE_PREFIX: 'Pie', + CLASS_PREFIX: 'pie_', + tableCellTags: { + 'TD': 1, + 'TH': 1 + }, + + /** + * Lookup table of elements which cannot take custom children. + */ + childlessElements: { + 'TABLE':1, + 'THEAD':1, + 'TBODY':1, + 'TFOOT':1, + 'TR':1, + 'INPUT':1, + 'TEXTAREA':1, + 'SELECT':1, + 'OPTION':1, + 'IMG':1, + 'HR':1 + }, + + /** + * Elements that can receive user focus + */ + focusableElements: { + 'A':1, + 'INPUT':1, + 'TEXTAREA':1, + 'SELECT':1, + 'BUTTON':1 + }, + + /** + * Values of the type attribute for input elements displayed as buttons + */ + inputButtonTypes: { + 'submit':1, + 'button':1, + 'reset':1 + }, + + emptyFn: function() {} + }; + + // Force the background cache to be used. No reason it shouldn't be. + try { + doc.execCommand( 'BackgroundImageCache', false, true ); + } catch(e) {} + + (function() { + /* + * IE version detection approach by James Padolsey, with modifications -- from + * http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/ + */ + var ieVersion = 4, + div = doc.createElement('div'), + all = div.getElementsByTagName('i'), + shape; + while ( + div.innerHTML = '', + all[0] + ) {} + PIE.ieVersion = ieVersion; + + // Detect IE6 + if( ieVersion === 6 ) { + // IE6 can't access properties with leading dash, but can without it. + PIE.CSS_PREFIX = PIE.CSS_PREFIX.replace( /^-/, '' ); + } + + PIE.ieDocMode = doc.documentMode || PIE.ieVersion; + + // Detect VML support (a small number of IE installs don't have a working VML engine) + div.innerHTML = ''; + shape = div.firstChild; + shape.style['behavior'] = 'url(#default#VML)'; + PIE.supportsVML = (typeof shape['adj'] === "object"); + }()); +/** + * Utility functions + */ +(function() { + var vmlCreatorDoc, + idNum = 0, + imageSizes = {}; + + + PIE.Util = { + + /** + * To create a VML element, it must be created by a Document which has the VML + * namespace set. Unfortunately, if you try to add the namespace programatically + * into the main document, you will get an "Unspecified error" when trying to + * access document.namespaces before the document is finished loading. To get + * around this, we create a DocumentFragment, which in IE land is apparently a + * full-fledged Document. It allows adding namespaces immediately, so we add the + * namespace there and then have it create the VML element. + * @param {string} tag The tag name for the VML element + * @return {Element} The new VML element + */ + createVmlElement: function( tag ) { + var vmlPrefix = 'css3vml'; + if( !vmlCreatorDoc ) { + vmlCreatorDoc = doc.createDocumentFragment(); + vmlCreatorDoc.namespaces.add( vmlPrefix, 'urn:schemas-microsoft-com:vml' ); + } + return vmlCreatorDoc.createElement( vmlPrefix + ':' + tag ); + }, + + + /** + * Generate and return a unique ID for a given object. The generated ID is stored + * as a property of the object for future reuse. + * @param {Object} obj + */ + getUID: function( obj ) { + return obj && obj[ '_pieId' ] || ( obj[ '_pieId' ] = '_' + ++idNum ); + }, + + + /** + * Simple utility for merging objects + * @param {Object} obj1 The main object into which all others will be merged + * @param {...Object} var_args Other objects which will be merged into the first, in order + */ + merge: function( obj1 ) { + var i, len, p, objN, args = arguments; + for( i = 1, len = args.length; i < len; i++ ) { + objN = args[i]; + for( p in objN ) { + if( objN.hasOwnProperty( p ) ) { + obj1[ p ] = objN[ p ]; + } + } + } + return obj1; + }, + + + /** + * Execute a callback function, passing it the dimensions of a given image once + * they are known. + * @param {string} src The source URL of the image + * @param {function({w:number, h:number})} func The callback function to be called once the image dimensions are known + * @param {Object} ctx A context object which will be used as the 'this' value within the executed callback function + */ + withImageSize: function( src, func, ctx ) { + var size = imageSizes[ src ], img, queue; + if( size ) { + // If we have a queue, add to it + if( Object.prototype.toString.call( size ) === '[object Array]' ) { + size.push( [ func, ctx ] ); + } + // Already have the size cached, call func right away + else { + func.call( ctx, size ); + } + } else { + queue = imageSizes[ src ] = [ [ func, ctx ] ]; //create queue + img = new Image(); + img.onload = function() { + size = imageSizes[ src ] = { w: img.width, h: img.height }; + for( var i = 0, len = queue.length; i < len; i++ ) { + queue[ i ][ 0 ].call( queue[ i ][ 1 ], size ); + } + img.onload = null; + }; + img.src = src; + } + } + }; +})();/** + * Utility functions for handling gradients + */ +PIE.GradientUtil = { + + getGradientMetrics: function( el, width, height, gradientInfo ) { + var angle = gradientInfo.angle, + startPos = gradientInfo.gradientStart, + startX, startY, + endX, endY, + startCornerX, startCornerY, + endCornerX, endCornerY, + deltaX, deltaY, + p, UNDEF; + + // Find the "start" and "end" corners; these are the corners furthest along the gradient line. + // This is used below to find the start/end positions of the CSS3 gradient-line, and also in finding + // the total length of the VML rendered gradient-line corner to corner. + function findCorners() { + startCornerX = ( angle >= 90 && angle < 270 ) ? width : 0; + startCornerY = angle < 180 ? height : 0; + endCornerX = width - startCornerX; + endCornerY = height - startCornerY; + } + + // Normalize the angle to a value between [0, 360) + function normalizeAngle() { + while( angle < 0 ) { + angle += 360; + } + angle = angle % 360; + } + + // Find the start and end points of the gradient + if( startPos ) { + startPos = startPos.coords( el, width, height ); + startX = startPos.x; + startY = startPos.y; + } + if( angle ) { + angle = angle.degrees(); + + normalizeAngle(); + findCorners(); + + // If no start position was specified, then choose a corner as the starting point. + if( !startPos ) { + startX = startCornerX; + startY = startCornerY; + } + + // Find the end position by extending a perpendicular line from the gradient-line which + // intersects the corner opposite from the starting corner. + p = PIE.GradientUtil.perpendicularIntersect( startX, startY, angle, endCornerX, endCornerY ); + endX = p[0]; + endY = p[1]; + } + else if( startPos ) { + // Start position but no angle specified: find the end point by rotating 180deg around the center + endX = width - startX; + endY = height - startY; + } + else { + // Neither position nor angle specified; create vertical gradient from top to bottom + startX = startY = endX = 0; + endY = height; + } + deltaX = endX - startX; + deltaY = endY - startY; + + if( angle === UNDEF ) { + // Get the angle based on the change in x/y from start to end point. Checks first for horizontal + // or vertical angles so they get exact whole numbers rather than what atan2 gives. + angle = ( !deltaX ? ( deltaY < 0 ? 90 : 270 ) : + ( !deltaY ? ( deltaX < 0 ? 180 : 0 ) : + -Math.atan2( deltaY, deltaX ) / Math.PI * 180 + ) + ); + normalizeAngle(); + findCorners(); + } + + return { + angle: angle, + startX: startX, + startY: startY, + endX: endX, + endY: endY, + startCornerX: startCornerX, + startCornerY: startCornerY, + endCornerX: endCornerX, + endCornerY: endCornerY, + deltaX: deltaX, + deltaY: deltaY, + lineLength: PIE.GradientUtil.distance( startX, startY, endX, endY ) + } + }, + + /** + * Find the point along a given line (defined by a starting point and an angle), at which + * that line is intersected by a perpendicular line extending through another point. + * @param x1 - x coord of the starting point + * @param y1 - y coord of the starting point + * @param angle - angle of the line extending from the starting point (in degrees) + * @param x2 - x coord of point along the perpendicular line + * @param y2 - y coord of point along the perpendicular line + * @return [ x, y ] + */ + perpendicularIntersect: function( x1, y1, angle, x2, y2 ) { + // Handle straight vertical and horizontal angles, for performance and to avoid + // divide-by-zero errors. + if( angle === 0 || angle === 180 ) { + return [ x2, y1 ]; + } + else if( angle === 90 || angle === 270 ) { + return [ x1, y2 ]; + } + else { + // General approach: determine the Ax+By=C formula for each line (the slope of the second + // line is the negative inverse of the first) and then solve for where both formulas have + // the same x/y values. + var a1 = Math.tan( -angle * Math.PI / 180 ), + c1 = a1 * x1 - y1, + a2 = -1 / a1, + c2 = a2 * x2 - y2, + d = a2 - a1, + endX = ( c2 - c1 ) / d, + endY = ( a1 * c2 - a2 * c1 ) / d; + return [ endX, endY ]; + } + }, + + /** + * Find the distance between two points + * @param {Number} p1x + * @param {Number} p1y + * @param {Number} p2x + * @param {Number} p2y + * @return {Number} the distance + */ + distance: function( p1x, p1y, p2x, p2y ) { + var dx = p2x - p1x, + dy = p2y - p1y; + return Math.abs( + dx === 0 ? dy : + dy === 0 ? dx : + Math.sqrt( dx * dx + dy * dy ) + ); + } + +};/** + * + */ +PIE.Observable = function() { + /** + * List of registered observer functions + */ + this.observers = []; + + /** + * Hash of function ids to their position in the observers list, for fast lookup + */ + this.indexes = {}; +}; +PIE.Observable.prototype = { + + observe: function( fn ) { + var id = PIE.Util.getUID( fn ), + indexes = this.indexes, + observers = this.observers; + if( !( id in indexes ) ) { + indexes[ id ] = observers.length; + observers.push( fn ); + } + }, + + unobserve: function( fn ) { + var id = PIE.Util.getUID( fn ), + indexes = this.indexes; + if( id && id in indexes ) { + delete this.observers[ indexes[ id ] ]; + delete indexes[ id ]; + } + }, + + fire: function() { + var o = this.observers, + i = o.length; + while( i-- ) { + o[ i ] && o[ i ](); + } + } + +};/* + * Simple heartbeat timer - this is a brute-force workaround for syncing issues caused by IE not + * always firing the onmove and onresize events when elements are moved or resized. We check a few + * times every second to make sure the elements have the correct position and size. See Element.js + * which adds heartbeat listeners based on the custom -pie-poll flag, which defaults to true in IE8-9 + * and false elsewhere. + */ + +PIE.Heartbeat = new PIE.Observable(); +PIE.Heartbeat.run = function() { + var me = this, + interval; + if( !me.running ) { + interval = doc.documentElement.currentStyle.getAttribute( PIE.CSS_PREFIX + 'poll-interval' ) || 250; + (function beat() { + me.fire(); + setTimeout(beat, interval); + })(); + me.running = 1; + } +}; +/** + * Create an observable listener for the onunload event + */ +(function() { + PIE.OnUnload = new PIE.Observable(); + + function handleUnload() { + PIE.OnUnload.fire(); + window.detachEvent( 'onunload', handleUnload ); + window[ 'PIE' ] = null; + } + + window.attachEvent( 'onunload', handleUnload ); + + /** + * Attach an event which automatically gets detached onunload + */ + PIE.OnUnload.attachManagedEvent = function( target, name, handler ) { + target.attachEvent( name, handler ); + this.observe( function() { + target.detachEvent( name, handler ); + } ); + }; +})()/** + * Create a single observable listener for window resize events. + */ +PIE.OnResize = new PIE.Observable(); + +PIE.OnUnload.attachManagedEvent( window, 'onresize', function() { PIE.OnResize.fire(); } ); +/** + * Create a single observable listener for scroll events. Used for lazy loading based + * on the viewport, and for fixed position backgrounds. + */ +(function() { + PIE.OnScroll = new PIE.Observable(); + + function scrolled() { + PIE.OnScroll.fire(); + } + + PIE.OnUnload.attachManagedEvent( window, 'onscroll', scrolled ); + + PIE.OnResize.observe( scrolled ); +})(); +/** + * Listen for printing events, destroy all active PIE instances when printing, and + * restore them afterward. + */ +(function() { + + var elements; + + function beforePrint() { + elements = PIE.Element.destroyAll(); + } + + function afterPrint() { + if( elements ) { + for( var i = 0, len = elements.length; i < len; i++ ) { + PIE[ 'attach' ]( elements[i] ); + } + elements = 0; + } + } + + if( PIE.ieDocMode < 9 ) { + PIE.OnUnload.attachManagedEvent( window, 'onbeforeprint', beforePrint ); + PIE.OnUnload.attachManagedEvent( window, 'onafterprint', afterPrint ); + } + +})();/** + * Create a single observable listener for document mouseup events. + */ +PIE.OnMouseup = new PIE.Observable(); + +PIE.OnUnload.attachManagedEvent( doc, 'onmouseup', function() { PIE.OnMouseup.fire(); } ); +/** + * Wrapper for length and percentage style values. The value is immutable. A singleton instance per unique + * value is returned from PIE.getLength() - always use that instead of instantiating directly. + * @constructor + * @param {string} val The CSS string representing the length. It is assumed that this will already have + * been validated as a valid length or percentage syntax. + */ +PIE.Length = (function() { + var lengthCalcEl = doc.createElement( 'length-calc' ), + parent = doc.body || doc.documentElement, + s = lengthCalcEl.style, + conversions = {}, + units = [ 'mm', 'cm', 'in', 'pt', 'pc' ], + i = units.length, + instances = {}; + + s.position = 'absolute'; + s.top = s.left = '-9999px'; + + parent.appendChild( lengthCalcEl ); + while( i-- ) { + s.width = '100' + units[i]; + conversions[ units[i] ] = lengthCalcEl.offsetWidth / 100; + } + parent.removeChild( lengthCalcEl ); + + // All calcs from here on will use 1em + s.width = '1em'; + + + function Length( val ) { + this.val = val; + } + Length.prototype = { + /** + * Regular expression for matching the length unit + * @private + */ + unitRE: /(px|em|ex|mm|cm|in|pt|pc|%)$/, + + /** + * Get the numeric value of the length + * @return {number} The value + */ + getNumber: function() { + var num = this.num, + UNDEF; + if( num === UNDEF ) { + num = this.num = parseFloat( this.val ); + } + return num; + }, + + /** + * Get the unit of the length + * @return {string} The unit + */ + getUnit: function() { + var unit = this.unit, + m; + if( !unit ) { + m = this.val.match( this.unitRE ); + unit = this.unit = ( m && m[0] ) || 'px'; + } + return unit; + }, + + /** + * Determine whether this is a percentage length value + * @return {boolean} + */ + isPercentage: function() { + return this.getUnit() === '%'; + }, + + /** + * Resolve this length into a number of pixels. + * @param {Element} el - the context element, used to resolve font-relative values + * @param {(function():number|number)=} pct100 - the number of pixels that equal a 100% percentage. This can be either a number or a + * function which will be called to return the number. + */ + pixels: function( el, pct100 ) { + var num = this.getNumber(), + unit = this.getUnit(); + switch( unit ) { + case "px": + return num; + case "%": + return num * ( typeof pct100 === 'function' ? pct100() : pct100 ) / 100; + case "em": + return num * this.getEmPixels( el ); + case "ex": + return num * this.getEmPixels( el ) / 2; + default: + return num * conversions[ unit ]; + } + }, + + /** + * The em and ex units are relative to the font-size of the current element, + * however if the font-size is set using non-pixel units then we get that value + * rather than a pixel conversion. To get around this, we keep a floating element + * with width:1em which we insert into the target element and then read its offsetWidth. + * For elements that won't accept a child we insert into the parent node and perform + * additional calculation. If the font-size *is* specified in pixels, then we use that + * directly to avoid the expensive DOM manipulation. + * @param {Element} el + * @return {number} + */ + getEmPixels: function( el ) { + var fs = el.currentStyle.fontSize, + px, parent, me; + + if( fs.indexOf( 'px' ) > 0 ) { + return parseFloat( fs ); + } + else if( el.tagName in PIE.childlessElements ) { + me = this; + parent = el.parentNode; + return PIE.getLength( fs ).pixels( parent, function() { + return me.getEmPixels( parent ); + } ); + } + else { + el.appendChild( lengthCalcEl ); + px = lengthCalcEl.offsetWidth; + if( lengthCalcEl.parentNode === el ) { //not sure how this could be false but it sometimes is + el.removeChild( lengthCalcEl ); + } + return px; + } + } + }; + + + /** + * Retrieve a PIE.Length instance for the given value. A shared singleton instance is returned for each unique value. + * @param {string} val The CSS string representing the length. It is assumed that this will already have + * been validated as a valid length or percentage syntax. + */ + PIE.getLength = function( val ) { + return instances[ val ] || ( instances[ val ] = new Length( val ) ); + }; + + return Length; +})(); +/** + * Wrapper for a CSS3 bg-position value. Takes up to 2 position keywords and 2 lengths/percentages. + * @constructor + * @param {Array.} tokens The tokens making up the background position value. + */ +PIE.BgPosition = (function() { + + var length_fifty = PIE.getLength( '50%' ), + vert_idents = { 'top': 1, 'center': 1, 'bottom': 1 }, + horiz_idents = { 'left': 1, 'center': 1, 'right': 1 }; + + + function BgPosition( tokens ) { + this.tokens = tokens; + } + BgPosition.prototype = { + /** + * Normalize the values into the form: + * [ xOffsetSide, xOffsetLength, yOffsetSide, yOffsetLength ] + * where: xOffsetSide is either 'left' or 'right', + * yOffsetSide is either 'top' or 'bottom', + * and x/yOffsetLength are both PIE.Length objects. + * @return {Array} + */ + getValues: function() { + if( !this._values ) { + var tokens = this.tokens, + len = tokens.length, + Tokenizer = PIE.Tokenizer, + identType = Tokenizer.Type, + length_zero = PIE.getLength( '0' ), + type_ident = identType.IDENT, + type_length = identType.LENGTH, + type_percent = identType.PERCENT, + type, value, + vals = [ 'left', length_zero, 'top', length_zero ]; + + // If only one value, the second is assumed to be 'center' + if( len === 1 ) { + tokens.push( new Tokenizer.Token( type_ident, 'center' ) ); + len++; + } + + // Two values - CSS2 + if( len === 2 ) { + // If both idents, they can appear in either order, so switch them if needed + if( type_ident & ( tokens[0].tokenType | tokens[1].tokenType ) && + tokens[0].tokenValue in vert_idents && tokens[1].tokenValue in horiz_idents ) { + tokens.push( tokens.shift() ); + } + if( tokens[0].tokenType & type_ident ) { + if( tokens[0].tokenValue === 'center' ) { + vals[1] = length_fifty; + } else { + vals[0] = tokens[0].tokenValue; + } + } + else if( tokens[0].isLengthOrPercent() ) { + vals[1] = PIE.getLength( tokens[0].tokenValue ); + } + if( tokens[1].tokenType & type_ident ) { + if( tokens[1].tokenValue === 'center' ) { + vals[3] = length_fifty; + } else { + vals[2] = tokens[1].tokenValue; + } + } + else if( tokens[1].isLengthOrPercent() ) { + vals[3] = PIE.getLength( tokens[1].tokenValue ); + } + } + + // Three or four values - CSS3 + else { + // TODO + } + + this._values = vals; + } + return this._values; + }, + + /** + * Find the coordinates of the background image from the upper-left corner of the background area. + * Note that these coordinate values are not rounded. + * @param {Element} el + * @param {number} width - the width for percentages (background area width minus image width) + * @param {number} height - the height for percentages (background area height minus image height) + * @return {Object} { x: Number, y: Number } + */ + coords: function( el, width, height ) { + var vals = this.getValues(), + pxX = vals[1].pixels( el, width ), + pxY = vals[3].pixels( el, height ); + + return { + x: vals[0] === 'right' ? width - pxX : pxX, + y: vals[2] === 'bottom' ? height - pxY : pxY + }; + } + }; + + return BgPosition; +})(); +/** + * Wrapper for a CSS3 background-size value. + * @constructor + * @param {String|PIE.Length} w The width parameter + * @param {String|PIE.Length} h The height parameter, if any + */ +PIE.BgSize = (function() { + + var CONTAIN = 'contain', + COVER = 'cover', + AUTO = 'auto'; + + + function BgSize( w, h ) { + this.w = w; + this.h = h; + } + BgSize.prototype = { + + pixels: function( el, areaW, areaH, imgW, imgH ) { + var me = this, + w = me.w, + h = me.h, + areaRatio = areaW / areaH, + imgRatio = imgW / imgH; + + if ( w === CONTAIN ) { + w = imgRatio > areaRatio ? areaW : areaH * imgRatio; + h = imgRatio > areaRatio ? areaW / imgRatio : areaH; + } + else if ( w === COVER ) { + w = imgRatio < areaRatio ? areaW : areaH * imgRatio; + h = imgRatio < areaRatio ? areaW / imgRatio : areaH; + } + else if ( w === AUTO ) { + h = ( h === AUTO ? imgH : h.pixels( el, areaH ) ); + w = h * imgRatio; + } + else { + w = w.pixels( el, areaW ); + h = ( h === AUTO ? w / imgRatio : h.pixels( el, areaH ) ); + } + + return { w: w, h: h }; + } + + }; + + BgSize.DEFAULT = new BgSize( AUTO, AUTO ); + + return BgSize; +})(); +/** + * Wrapper for angle values; handles conversion to degrees from all allowed angle units + * @constructor + * @param {string} val The raw CSS value for the angle. It is assumed it has been pre-validated. + */ +PIE.Angle = (function() { + function Angle( val ) { + this.val = val; + } + Angle.prototype = { + unitRE: /[a-z]+$/i, + + /** + * @return {string} The unit of the angle value + */ + getUnit: function() { + return this._unit || ( this._unit = this.val.match( this.unitRE )[0].toLowerCase() ); + }, + + /** + * Get the numeric value of the angle in degrees. + * @return {number} The degrees value + */ + degrees: function() { + var deg = this._deg, u, n; + if( deg === undefined ) { + u = this.getUnit(); + n = parseFloat( this.val, 10 ); + deg = this._deg = ( u === 'deg' ? n : u === 'rad' ? n / Math.PI * 180 : u === 'grad' ? n / 400 * 360 : u === 'turn' ? n * 360 : 0 ); + } + return deg; + } + }; + + return Angle; +})();/** + * Abstraction for colors values. Allows detection of rgba values. A singleton instance per unique + * value is returned from PIE.getColor() - always use that instead of instantiating directly. + * @constructor + * @param {string} val The raw CSS string value for the color + */ +PIE.Color = (function() { + var instances = {}; + + function Color( val ) { + this.val = val; + } + + /** + * Regular expression for matching rgba colors and extracting their components + * @type {RegExp} + */ + Color.rgbaRE = /\s*rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d+|\d*\.\d+)\s*\)\s*/; + + Color.names = { + "aliceblue":"F0F8FF", "antiquewhite":"FAEBD7", "aqua":"0FF", + "aquamarine":"7FFFD4", "azure":"F0FFFF", "beige":"F5F5DC", + "bisque":"FFE4C4", "black":"000", "blanchedalmond":"FFEBCD", + "blue":"00F", "blueviolet":"8A2BE2", "brown":"A52A2A", + "burlywood":"DEB887", "cadetblue":"5F9EA0", "chartreuse":"7FFF00", + "chocolate":"D2691E", "coral":"FF7F50", "cornflowerblue":"6495ED", + "cornsilk":"FFF8DC", "crimson":"DC143C", "cyan":"0FF", + "darkblue":"00008B", "darkcyan":"008B8B", "darkgoldenrod":"B8860B", + "darkgray":"A9A9A9", "darkgreen":"006400", "darkkhaki":"BDB76B", + "darkmagenta":"8B008B", "darkolivegreen":"556B2F", "darkorange":"FF8C00", + "darkorchid":"9932CC", "darkred":"8B0000", "darksalmon":"E9967A", + "darkseagreen":"8FBC8F", "darkslateblue":"483D8B", "darkslategray":"2F4F4F", + "darkturquoise":"00CED1", "darkviolet":"9400D3", "deeppink":"FF1493", + "deepskyblue":"00BFFF", "dimgray":"696969", "dodgerblue":"1E90FF", + "firebrick":"B22222", "floralwhite":"FFFAF0", "forestgreen":"228B22", + "fuchsia":"F0F", "gainsboro":"DCDCDC", "ghostwhite":"F8F8FF", + "gold":"FFD700", "goldenrod":"DAA520", "gray":"808080", + "green":"008000", "greenyellow":"ADFF2F", "honeydew":"F0FFF0", + "hotpink":"FF69B4", "indianred":"CD5C5C", "indigo":"4B0082", + "ivory":"FFFFF0", "khaki":"F0E68C", "lavender":"E6E6FA", + "lavenderblush":"FFF0F5", "lawngreen":"7CFC00", "lemonchiffon":"FFFACD", + "lightblue":"ADD8E6", "lightcoral":"F08080", "lightcyan":"E0FFFF", + "lightgoldenrodyellow":"FAFAD2", "lightgreen":"90EE90", "lightgrey":"D3D3D3", + "lightpink":"FFB6C1", "lightsalmon":"FFA07A", "lightseagreen":"20B2AA", + "lightskyblue":"87CEFA", "lightslategray":"789", "lightsteelblue":"B0C4DE", + "lightyellow":"FFFFE0", "lime":"0F0", "limegreen":"32CD32", + "linen":"FAF0E6", "magenta":"F0F", "maroon":"800000", + "mediumauqamarine":"66CDAA", "mediumblue":"0000CD", "mediumorchid":"BA55D3", + "mediumpurple":"9370D8", "mediumseagreen":"3CB371", "mediumslateblue":"7B68EE", + "mediumspringgreen":"00FA9A", "mediumturquoise":"48D1CC", "mediumvioletred":"C71585", + "midnightblue":"191970", "mintcream":"F5FFFA", "mistyrose":"FFE4E1", + "moccasin":"FFE4B5", "navajowhite":"FFDEAD", "navy":"000080", + "oldlace":"FDF5E6", "olive":"808000", "olivedrab":"688E23", + "orange":"FFA500", "orangered":"FF4500", "orchid":"DA70D6", + "palegoldenrod":"EEE8AA", "palegreen":"98FB98", "paleturquoise":"AFEEEE", + "palevioletred":"D87093", "papayawhip":"FFEFD5", "peachpuff":"FFDAB9", + "peru":"CD853F", "pink":"FFC0CB", "plum":"DDA0DD", + "powderblue":"B0E0E6", "purple":"800080", "red":"F00", + "rosybrown":"BC8F8F", "royalblue":"4169E1", "saddlebrown":"8B4513", + "salmon":"FA8072", "sandybrown":"F4A460", "seagreen":"2E8B57", + "seashell":"FFF5EE", "sienna":"A0522D", "silver":"C0C0C0", + "skyblue":"87CEEB", "slateblue":"6A5ACD", "slategray":"708090", + "snow":"FFFAFA", "springgreen":"00FF7F", "steelblue":"4682B4", + "tan":"D2B48C", "teal":"008080", "thistle":"D8BFD8", + "tomato":"FF6347", "turquoise":"40E0D0", "violet":"EE82EE", + "wheat":"F5DEB3", "white":"FFF", "whitesmoke":"F5F5F5", + "yellow":"FF0", "yellowgreen":"9ACD32" + }; + + Color.prototype = { + /** + * @private + */ + parse: function() { + if( !this._color ) { + var me = this, + v = me.val, + vLower, + m = v.match( Color.rgbaRE ); + if( m ) { + me._color = 'rgb(' + m[1] + ',' + m[2] + ',' + m[3] + ')'; + me._alpha = parseFloat( m[4] ); + } + else { + if( ( vLower = v.toLowerCase() ) in Color.names ) { + v = '#' + Color.names[vLower]; + } + me._color = v; + me._alpha = ( v === 'transparent' ? 0 : 1 ); + } + } + }, + + /** + * Retrieve the value of the color in a format usable by IE natively. This will be the same as + * the raw input value, except for rgba values which will be converted to an rgb value. + * @param {Element} el The context element, used to get 'currentColor' keyword value. + * @return {string} Color value + */ + colorValue: function( el ) { + this.parse(); + return this._color === 'currentColor' ? el.currentStyle.color : this._color; + }, + + /** + * Retrieve the alpha value of the color. Will be 1 for all values except for rgba values + * with an alpha component. + * @return {number} The alpha value, from 0 to 1. + */ + alpha: function() { + this.parse(); + return this._alpha; + } + }; + + + /** + * Retrieve a PIE.Color instance for the given value. A shared singleton instance is returned for each unique value. + * @param {string} val The CSS string representing the color. It is assumed that this will already have + * been validated as a valid color syntax. + */ + PIE.getColor = function(val) { + return instances[ val ] || ( instances[ val ] = new Color( val ) ); + }; + + return Color; +})();/** + * A tokenizer for CSS value strings. + * @constructor + * @param {string} css The CSS value string + */ +PIE.Tokenizer = (function() { + function Tokenizer( css ) { + this.css = css; + this.ch = 0; + this.tokens = []; + this.tokenIndex = 0; + } + + /** + * Enumeration of token type constants. + * @enum {number} + */ + var Type = Tokenizer.Type = { + ANGLE: 1, + CHARACTER: 2, + COLOR: 4, + DIMEN: 8, + FUNCTION: 16, + IDENT: 32, + LENGTH: 64, + NUMBER: 128, + OPERATOR: 256, + PERCENT: 512, + STRING: 1024, + URL: 2048 + }; + + /** + * A single token + * @constructor + * @param {number} type The type of the token - see PIE.Tokenizer.Type + * @param {string} value The value of the token + */ + Tokenizer.Token = function( type, value ) { + this.tokenType = type; + this.tokenValue = value; + }; + Tokenizer.Token.prototype = { + isLength: function() { + return this.tokenType & Type.LENGTH || ( this.tokenType & Type.NUMBER && this.tokenValue === '0' ); + }, + isLengthOrPercent: function() { + return this.isLength() || this.tokenType & Type.PERCENT; + } + }; + + Tokenizer.prototype = { + whitespace: /\s/, + number: /^[\+\-]?(\d*\.)?\d+/, + url: /^url\(\s*("([^"]*)"|'([^']*)'|([!#$%&*-~]*))\s*\)/i, + ident: /^\-?[_a-z][\w-]*/i, + string: /^("([^"]*)"|'([^']*)')/, + operator: /^[\/,]/, + hash: /^#[\w]+/, + hashColor: /^#([\da-f]{6}|[\da-f]{3})/i, + + unitTypes: { + 'px': Type.LENGTH, 'em': Type.LENGTH, 'ex': Type.LENGTH, + 'mm': Type.LENGTH, 'cm': Type.LENGTH, 'in': Type.LENGTH, + 'pt': Type.LENGTH, 'pc': Type.LENGTH, + 'deg': Type.ANGLE, 'rad': Type.ANGLE, 'grad': Type.ANGLE + }, + + colorFunctions: { + 'rgb': 1, 'rgba': 1, 'hsl': 1, 'hsla': 1 + }, + + + /** + * Advance to and return the next token in the CSS string. If the end of the CSS string has + * been reached, null will be returned. + * @param {boolean} forget - if true, the token will not be stored for the purposes of backtracking with prev(). + * @return {PIE.Tokenizer.Token} + */ + next: function( forget ) { + var css, ch, firstChar, match, val, + me = this; + + function newToken( type, value ) { + var tok = new Tokenizer.Token( type, value ); + if( !forget ) { + me.tokens.push( tok ); + me.tokenIndex++; + } + return tok; + } + function failure() { + me.tokenIndex++; + return null; + } + + // In case we previously backed up, return the stored token in the next slot + if( this.tokenIndex < this.tokens.length ) { + return this.tokens[ this.tokenIndex++ ]; + } + + // Move past leading whitespace characters + while( this.whitespace.test( this.css.charAt( this.ch ) ) ) { + this.ch++; + } + if( this.ch >= this.css.length ) { + return failure(); + } + + ch = this.ch; + css = this.css.substring( this.ch ); + firstChar = css.charAt( 0 ); + switch( firstChar ) { + case '#': + if( match = css.match( this.hashColor ) ) { + this.ch += match[0].length; + return newToken( Type.COLOR, match[0] ); + } + break; + + case '"': + case "'": + if( match = css.match( this.string ) ) { + this.ch += match[0].length; + return newToken( Type.STRING, match[2] || match[3] || '' ); + } + break; + + case "/": + case ",": + this.ch++; + return newToken( Type.OPERATOR, firstChar ); + + case 'u': + if( match = css.match( this.url ) ) { + this.ch += match[0].length; + return newToken( Type.URL, match[2] || match[3] || match[4] || '' ); + } + } + + // Numbers and values starting with numbers + if( match = css.match( this.number ) ) { + val = match[0]; + this.ch += val.length; + + // Check if it is followed by a unit + if( css.charAt( val.length ) === '%' ) { + this.ch++; + return newToken( Type.PERCENT, val + '%' ); + } + if( match = css.substring( val.length ).match( this.ident ) ) { + val += match[0]; + this.ch += match[0].length; + return newToken( this.unitTypes[ match[0].toLowerCase() ] || Type.DIMEN, val ); + } + + // Plain ol' number + return newToken( Type.NUMBER, val ); + } + + // Identifiers + if( match = css.match( this.ident ) ) { + val = match[0]; + this.ch += val.length; + + // Named colors + if( val.toLowerCase() in PIE.Color.names || val === 'currentColor' || val === 'transparent' ) { + return newToken( Type.COLOR, val ); + } + + // Functions + if( css.charAt( val.length ) === '(' ) { + this.ch++; + + // Color values in function format: rgb, rgba, hsl, hsla + if( val.toLowerCase() in this.colorFunctions ) { + function isNum( tok ) { + return tok && tok.tokenType & Type.NUMBER; + } + function isNumOrPct( tok ) { + return tok && ( tok.tokenType & ( Type.NUMBER | Type.PERCENT ) ); + } + function isValue( tok, val ) { + return tok && tok.tokenValue === val; + } + function next() { + return me.next( 1 ); + } + + if( ( val.charAt(0) === 'r' ? isNumOrPct( next() ) : isNum( next() ) ) && + isValue( next(), ',' ) && + isNumOrPct( next() ) && + isValue( next(), ',' ) && + isNumOrPct( next() ) && + ( val === 'rgb' || val === 'hsa' || ( + isValue( next(), ',' ) && + isNum( next() ) + ) ) && + isValue( next(), ')' ) ) { + return newToken( Type.COLOR, this.css.substring( ch, this.ch ) ); + } + return failure(); + } + + return newToken( Type.FUNCTION, val ); + } + + // Other identifier + return newToken( Type.IDENT, val ); + } + + // Standalone character + this.ch++; + return newToken( Type.CHARACTER, firstChar ); + }, + + /** + * Determine whether there is another token + * @return {boolean} + */ + hasNext: function() { + var next = this.next(); + this.prev(); + return !!next; + }, + + /** + * Back up and return the previous token + * @return {PIE.Tokenizer.Token} + */ + prev: function() { + return this.tokens[ this.tokenIndex-- - 2 ]; + }, + + /** + * Retrieve all the tokens in the CSS string + * @return {Array.} + */ + all: function() { + while( this.next() ) {} + return this.tokens; + }, + + /** + * Return a list of tokens from the current position until the given function returns + * true. The final token will not be included in the list. + * @param {function():boolean} func - test function + * @param {boolean} require - if true, then if the end of the CSS string is reached + * before the test function returns true, null will be returned instead of the + * tokens that have been found so far. + * @return {Array.} + */ + until: function( func, require ) { + var list = [], t, hit; + while( t = this.next() ) { + if( func( t ) ) { + hit = true; + this.prev(); + break; + } + list.push( t ); + } + return require && !hit ? null : list; + } + }; + + return Tokenizer; +})();/** + * Handles calculating, caching, and detecting changes to size and position of the element. + * @constructor + * @param {Element} el the target element + */ +PIE.BoundsInfo = function( el ) { + this.targetElement = el; +}; +PIE.BoundsInfo.prototype = { + + _locked: 0, + + positionChanged: function() { + var last = this._lastBounds, + bounds; + return !last || ( ( bounds = this.getBounds() ) && ( last.x !== bounds.x || last.y !== bounds.y ) ); + }, + + sizeChanged: function() { + var last = this._lastBounds, + bounds; + return !last || ( ( bounds = this.getBounds() ) && ( last.w !== bounds.w || last.h !== bounds.h ) ); + }, + + getLiveBounds: function() { + var el = this.targetElement, + rect = el.getBoundingClientRect(), + isIE9 = PIE.ieDocMode === 9, + isIE7 = PIE.ieVersion === 7, + width = rect.right - rect.left; + return { + x: rect.left, + y: rect.top, + // In some cases scrolling the page will cause IE9 to report incorrect dimensions + // in the rect returned by getBoundingClientRect, so we must query offsetWidth/Height + // instead. Also IE7 is inconsistent in using logical vs. device pixels in measurements + // so we must calculate the ratio and use it in certain places as a position adjustment. + w: isIE9 || isIE7 ? el.offsetWidth : width, + h: isIE9 || isIE7 ? el.offsetHeight : rect.bottom - rect.top, + logicalZoomRatio: ( isIE7 && width ) ? el.offsetWidth / width : 1 + }; + }, + + getBounds: function() { + return this._locked ? + ( this._lockedBounds || ( this._lockedBounds = this.getLiveBounds() ) ) : + this.getLiveBounds(); + }, + + hasBeenQueried: function() { + return !!this._lastBounds; + }, + + lock: function() { + ++this._locked; + }, + + unlock: function() { + if( !--this._locked ) { + if( this._lockedBounds ) this._lastBounds = this._lockedBounds; + this._lockedBounds = null; + } + } + +}; +(function() { + +function cacheWhenLocked( fn ) { + var uid = PIE.Util.getUID( fn ); + return function() { + if( this._locked ) { + var cache = this._lockedValues || ( this._lockedValues = {} ); + return ( uid in cache ) ? cache[ uid ] : ( cache[ uid ] = fn.call( this ) ); + } else { + return fn.call( this ); + } + } +} + + +PIE.StyleInfoBase = { + + _locked: 0, + + /** + * Create a new StyleInfo class, with the standard constructor, and augmented by + * the StyleInfoBase's members. + * @param proto + */ + newStyleInfo: function( proto ) { + function StyleInfo( el ) { + this.targetElement = el; + this._lastCss = this.getCss(); + } + PIE.Util.merge( StyleInfo.prototype, PIE.StyleInfoBase, proto ); + StyleInfo._propsCache = {}; + return StyleInfo; + }, + + /** + * Get an object representation of the target CSS style, caching it for each unique + * CSS value string. + * @return {Object} + */ + getProps: function() { + var css = this.getCss(), + cache = this.constructor._propsCache; + return css ? ( css in cache ? cache[ css ] : ( cache[ css ] = this.parseCss( css ) ) ) : null; + }, + + /** + * Get the raw CSS value for the target style + * @return {string} + */ + getCss: cacheWhenLocked( function() { + var el = this.targetElement, + ctor = this.constructor, + s = el.style, + cs = el.currentStyle, + cssProp = this.cssProperty, + styleProp = this.styleProperty, + prefixedCssProp = ctor._prefixedCssProp || ( ctor._prefixedCssProp = PIE.CSS_PREFIX + cssProp ), + prefixedStyleProp = ctor._prefixedStyleProp || ( ctor._prefixedStyleProp = PIE.STYLE_PREFIX + styleProp.charAt(0).toUpperCase() + styleProp.substring(1) ); + return s[ prefixedStyleProp ] || cs.getAttribute( prefixedCssProp ) || s[ styleProp ] || cs.getAttribute( cssProp ); + } ), + + /** + * Determine whether the target CSS style is active. + * @return {boolean} + */ + isActive: cacheWhenLocked( function() { + return !!this.getProps(); + } ), + + /** + * Determine whether the target CSS style has changed since the last time it was used. + * @return {boolean} + */ + changed: cacheWhenLocked( function() { + var currentCss = this.getCss(), + changed = currentCss !== this._lastCss; + this._lastCss = currentCss; + return changed; + } ), + + cacheWhenLocked: cacheWhenLocked, + + lock: function() { + ++this._locked; + }, + + unlock: function() { + if( !--this._locked ) { + delete this._lockedValues; + } + } +}; + +})();/** + * Handles parsing, caching, and detecting changes to background (and -pie-background) CSS + * @constructor + * @param {Element} el the target element + */ +PIE.BackgroundStyleInfo = PIE.StyleInfoBase.newStyleInfo( { + + cssProperty: PIE.CSS_PREFIX + 'background', + styleProperty: PIE.STYLE_PREFIX + 'Background', + + attachIdents: { 'scroll':1, 'fixed':1, 'local':1 }, + repeatIdents: { 'repeat-x':1, 'repeat-y':1, 'repeat':1, 'no-repeat':1 }, + originAndClipIdents: { 'padding-box':1, 'border-box':1, 'content-box':1 }, + positionIdents: { 'top':1, 'right':1, 'bottom':1, 'left':1, 'center':1 }, + sizeIdents: { 'contain':1, 'cover':1 }, + propertyNames: { + CLIP: 'backgroundClip', + COLOR: 'backgroundColor', + IMAGE: 'backgroundImage', + ORIGIN: 'backgroundOrigin', + POSITION: 'backgroundPosition', + REPEAT: 'backgroundRepeat', + SIZE: 'backgroundSize' + }, + + /** + * For background styles, we support the -pie-background property but fall back to the standard + * backround* properties. The reason we have to use the prefixed version is that IE natively + * parses the standard properties and if it sees something it doesn't know how to parse, for example + * multiple values or gradient definitions, it will throw that away and not make it available through + * currentStyle. + * + * Format of return object: + * { + * color: , + * bgImages: [ + * { + * imgType: 'image', + * imgUrl: 'image.png', + * imgRepeat: <'no-repeat' | 'repeat-x' | 'repeat-y' | 'repeat'>, + * bgPosition: , + * bgAttachment: <'scroll' | 'fixed' | 'local'>, + * bgOrigin: <'border-box' | 'padding-box' | 'content-box'>, + * bgClip: <'border-box' | 'padding-box'>, + * bgSize: , + * origString: 'url(img.png) no-repeat top left' + * }, + * { + * imgType: 'linear-gradient', + * gradientStart: , + * angle: , + * stops: [ + * { color: , offset: }, + * { color: , offset: }, ... + * ] + * } + * ] + * } + * @param {String} css + * @override + */ + parseCss: function( css ) { + var el = this.targetElement, + cs = el.currentStyle, + tokenizer, token, image, + tok_type = PIE.Tokenizer.Type, + type_operator = tok_type.OPERATOR, + type_ident = tok_type.IDENT, + type_color = tok_type.COLOR, + tokType, tokVal, + beginCharIndex = 0, + positionIdents = this.positionIdents, + gradient, stop, width, height, + props = { bgImages: [] }; + + function isBgPosToken( token ) { + return token && token.isLengthOrPercent() || ( token.tokenType & type_ident && token.tokenValue in positionIdents ); + } + + function sizeToken( token ) { + return token && ( ( token.isLengthOrPercent() && PIE.getLength( token.tokenValue ) ) || ( token.tokenValue === 'auto' && 'auto' ) ); + } + + // If the CSS3-specific -pie-background property is present, parse it + if( this.getCss3() ) { + tokenizer = new PIE.Tokenizer( css ); + image = {}; + + while( token = tokenizer.next() ) { + tokType = token.tokenType; + tokVal = token.tokenValue; + + if( !image.imgType && tokType & tok_type.FUNCTION && tokVal === 'linear-gradient' ) { + gradient = { stops: [], imgType: tokVal }; + stop = {}; + while( token = tokenizer.next() ) { + tokType = token.tokenType; + tokVal = token.tokenValue; + + // If we reached the end of the function and had at least 2 stops, flush the info + if( tokType & tok_type.CHARACTER && tokVal === ')' ) { + if( stop.color ) { + gradient.stops.push( stop ); + } + if( gradient.stops.length > 1 ) { + PIE.Util.merge( image, gradient ); + } + break; + } + + // Color stop - must start with color + if( tokType & type_color ) { + // if we already have an angle/position, make sure that the previous token was a comma + if( gradient.angle || gradient.gradientStart ) { + token = tokenizer.prev(); + if( token.tokenType !== type_operator ) { + break; //fail + } + tokenizer.next(); + } + + stop = { + color: PIE.getColor( tokVal ) + }; + // check for offset following color + token = tokenizer.next(); + if( token.isLengthOrPercent() ) { + stop.offset = PIE.getLength( token.tokenValue ); + } else { + tokenizer.prev(); + } + } + // Angle - can only appear in first spot + else if( tokType & tok_type.ANGLE && !gradient.angle && !stop.color && !gradient.stops.length ) { + gradient.angle = new PIE.Angle( token.tokenValue ); + } + else if( isBgPosToken( token ) && !gradient.gradientStart && !stop.color && !gradient.stops.length ) { + tokenizer.prev(); + gradient.gradientStart = new PIE.BgPosition( + tokenizer.until( function( t ) { + return !isBgPosToken( t ); + }, false ) + ); + } + else if( tokType & type_operator && tokVal === ',' ) { + if( stop.color ) { + gradient.stops.push( stop ); + stop = {}; + } + } + else { + // Found something we didn't recognize; fail without adding image + break; + } + } + } + else if( !image.imgType && tokType & tok_type.URL ) { + image.imgUrl = tokVal; + image.imgType = 'image'; + } + else if( isBgPosToken( token ) && !image.bgPosition ) { + tokenizer.prev(); + image.bgPosition = new PIE.BgPosition( + tokenizer.until( function( t ) { + return !isBgPosToken( t ); + }, false ) + ); + } + else if( tokType & type_ident ) { + if( tokVal in this.repeatIdents && !image.imgRepeat ) { + image.imgRepeat = tokVal; + } + else if( tokVal in this.originAndClipIdents && !image.bgOrigin ) { + image.bgOrigin = tokVal; + if( ( token = tokenizer.next() ) && ( token.tokenType & type_ident ) && + token.tokenValue in this.originAndClipIdents ) { + image.bgClip = token.tokenValue; + } else { + image.bgClip = tokVal; + tokenizer.prev(); + } + } + else if( tokVal in this.attachIdents && !image.bgAttachment ) { + image.bgAttachment = tokVal; + } + else { + return null; + } + } + else if( tokType & type_color && !props.color ) { + props.color = PIE.getColor( tokVal ); + } + else if( tokType & type_operator && tokVal === '/' && !image.bgSize && image.bgPosition ) { + // background size + token = tokenizer.next(); + if( token.tokenType & type_ident && token.tokenValue in this.sizeIdents ) { + image.bgSize = new PIE.BgSize( token.tokenValue ); + } + else if( width = sizeToken( token ) ) { + height = sizeToken( tokenizer.next() ); + if ( !height ) { + height = width; + tokenizer.prev(); + } + image.bgSize = new PIE.BgSize( width, height ); + } + else { + return null; + } + } + // new layer + else if( tokType & type_operator && tokVal === ',' && image.imgType ) { + image.origString = css.substring( beginCharIndex, tokenizer.ch - 1 ); + beginCharIndex = tokenizer.ch; + props.bgImages.push( image ); + image = {}; + } + else { + // Found something unrecognized; chuck everything + return null; + } + } + + // leftovers + if( image.imgType ) { + image.origString = css.substring( beginCharIndex ); + props.bgImages.push( image ); + } + } + + // Otherwise, use the standard background properties; let IE give us the values rather than parsing them + else { + this.withActualBg( PIE.ieDocMode < 9 ? + function() { + var propNames = this.propertyNames, + posX = cs[propNames.POSITION + 'X'], + posY = cs[propNames.POSITION + 'Y'], + img = cs[propNames.IMAGE], + color = cs[propNames.COLOR]; + + if( color !== 'transparent' ) { + props.color = PIE.getColor( color ) + } + if( img !== 'none' ) { + props.bgImages = [ { + imgType: 'image', + imgUrl: new PIE.Tokenizer( img ).next().tokenValue, + imgRepeat: cs[propNames.REPEAT], + bgPosition: new PIE.BgPosition( new PIE.Tokenizer( posX + ' ' + posY ).all() ) + } ]; + } + } : + function() { + var propNames = this.propertyNames, + splitter = /\s*,\s*/, + images = cs[propNames.IMAGE].split( splitter ), + color = cs[propNames.COLOR], + repeats, positions, origins, clips, sizes, i, len, image, sizeParts; + + if( color !== 'transparent' ) { + props.color = PIE.getColor( color ) + } + + len = images.length; + if( len && images[0] !== 'none' ) { + repeats = cs[propNames.REPEAT].split( splitter ); + positions = cs[propNames.POSITION].split( splitter ); + origins = cs[propNames.ORIGIN].split( splitter ); + clips = cs[propNames.CLIP].split( splitter ); + sizes = cs[propNames.SIZE].split( splitter ); + + props.bgImages = []; + for( i = 0; i < len; i++ ) { + image = images[ i ]; + if( image && image !== 'none' ) { + sizeParts = sizes[i].split( ' ' ); + props.bgImages.push( { + origString: image + ' ' + repeats[ i ] + ' ' + positions[ i ] + ' / ' + sizes[ i ] + ' ' + + origins[ i ] + ' ' + clips[ i ], + imgType: 'image', + imgUrl: new PIE.Tokenizer( image ).next().tokenValue, + imgRepeat: repeats[ i ], + bgPosition: new PIE.BgPosition( new PIE.Tokenizer( positions[ i ] ).all() ), + bgOrigin: origins[ i ], + bgClip: clips[ i ], + bgSize: new PIE.BgSize( sizeParts[ 0 ], sizeParts[ 1 ] ) + } ); + } + } + } + } + ); + } + + return ( props.color || props.bgImages[0] ) ? props : null; + }, + + /** + * Execute a function with the actual background styles (not overridden with runtimeStyle + * properties set by the renderers) available via currentStyle. + * @param fn + */ + withActualBg: function( fn ) { + var isIE9 = PIE.ieDocMode > 8, + propNames = this.propertyNames, + rs = this.targetElement.runtimeStyle, + rsImage = rs[propNames.IMAGE], + rsColor = rs[propNames.COLOR], + rsRepeat = rs[propNames.REPEAT], + rsClip, rsOrigin, rsSize, rsPosition, ret; + + if( rsImage ) rs[propNames.IMAGE] = ''; + if( rsColor ) rs[propNames.COLOR] = ''; + if( rsRepeat ) rs[propNames.REPEAT] = ''; + if( isIE9 ) { + rsClip = rs[propNames.CLIP]; + rsOrigin = rs[propNames.ORIGIN]; + rsPosition = rs[propNames.POSITION]; + rsSize = rs[propNames.SIZE]; + if( rsClip ) rs[propNames.CLIP] = ''; + if( rsOrigin ) rs[propNames.ORIGIN] = ''; + if( rsPosition ) rs[propNames.POSITION] = ''; + if( rsSize ) rs[propNames.SIZE] = ''; + } + + ret = fn.call( this ); + + if( rsImage ) rs[propNames.IMAGE] = rsImage; + if( rsColor ) rs[propNames.COLOR] = rsColor; + if( rsRepeat ) rs[propNames.REPEAT] = rsRepeat; + if( isIE9 ) { + if( rsClip ) rs[propNames.CLIP] = rsClip; + if( rsOrigin ) rs[propNames.ORIGIN] = rsOrigin; + if( rsPosition ) rs[propNames.POSITION] = rsPosition; + if( rsSize ) rs[propNames.SIZE] = rsSize; + } + + return ret; + }, + + getCss: PIE.StyleInfoBase.cacheWhenLocked( function() { + return this.getCss3() || + this.withActualBg( function() { + var cs = this.targetElement.currentStyle, + propNames = this.propertyNames; + return cs[propNames.COLOR] + ' ' + cs[propNames.IMAGE] + ' ' + cs[propNames.REPEAT] + ' ' + + cs[propNames.POSITION + 'X'] + ' ' + cs[propNames.POSITION + 'Y']; + } ); + } ), + + getCss3: PIE.StyleInfoBase.cacheWhenLocked( function() { + var el = this.targetElement; + return el.style[ this.styleProperty ] || el.currentStyle.getAttribute( this.cssProperty ); + } ), + + /** + * Tests if style.PiePngFix or the -pie-png-fix property is set to true in IE6. + */ + isPngFix: function() { + var val = 0, el; + if( PIE.ieVersion < 7 ) { + el = this.targetElement; + val = ( '' + ( el.style[ PIE.STYLE_PREFIX + 'PngFix' ] || el.currentStyle.getAttribute( PIE.CSS_PREFIX + 'png-fix' ) ) === 'true' ); + } + return val; + }, + + /** + * The isActive logic is slightly different, because getProps() always returns an object + * even if it is just falling back to the native background properties. But we only want + * to report is as being "active" if either the -pie-background override property is present + * and parses successfully or '-pie-png-fix' is set to true in IE6. + */ + isActive: PIE.StyleInfoBase.cacheWhenLocked( function() { + return (this.getCss3() || this.isPngFix()) && !!this.getProps(); + } ) + +} );/** + * Handles parsing, caching, and detecting changes to border CSS + * @constructor + * @param {Element} el the target element + */ +PIE.BorderStyleInfo = PIE.StyleInfoBase.newStyleInfo( { + + sides: [ 'Top', 'Right', 'Bottom', 'Left' ], + namedWidths: { + 'thin': '1px', + 'medium': '3px', + 'thick': '5px' + }, + + parseCss: function( css ) { + var w = {}, + s = {}, + c = {}, + active = false, + colorsSame = true, + stylesSame = true, + widthsSame = true; + + this.withActualBorder( function() { + var el = this.targetElement, + cs = el.currentStyle, + i = 0, + style, color, width, lastStyle, lastColor, lastWidth, side, ltr; + for( ; i < 4; i++ ) { + side = this.sides[ i ]; + + ltr = side.charAt(0).toLowerCase(); + style = s[ ltr ] = cs[ 'border' + side + 'Style' ]; + color = cs[ 'border' + side + 'Color' ]; + width = cs[ 'border' + side + 'Width' ]; + + if( i > 0 ) { + if( style !== lastStyle ) { stylesSame = false; } + if( color !== lastColor ) { colorsSame = false; } + if( width !== lastWidth ) { widthsSame = false; } + } + lastStyle = style; + lastColor = color; + lastWidth = width; + + c[ ltr ] = PIE.getColor( color ); + + width = w[ ltr ] = PIE.getLength( s[ ltr ] === 'none' ? '0' : ( this.namedWidths[ width ] || width ) ); + if( width.pixels( this.targetElement ) > 0 ) { + active = true; + } + } + } ); + + return active ? { + widths: w, + styles: s, + colors: c, + widthsSame: widthsSame, + colorsSame: colorsSame, + stylesSame: stylesSame + } : null; + }, + + getCss: PIE.StyleInfoBase.cacheWhenLocked( function() { + var el = this.targetElement, + cs = el.currentStyle, + css; + + // Don't redraw or hide borders for cells in border-collapse:collapse tables + if( !( el.tagName in PIE.tableCellTags && el.offsetParent.currentStyle.borderCollapse === 'collapse' ) ) { + this.withActualBorder( function() { + css = cs.borderWidth + '|' + cs.borderStyle + '|' + cs.borderColor; + } ); + } + return css; + } ), + + /** + * Execute a function with the actual border styles (not overridden with runtimeStyle + * properties set by the renderers) available via currentStyle. + * @param fn + */ + withActualBorder: function( fn ) { + var rs = this.targetElement.runtimeStyle, + rsWidth = rs.borderWidth, + rsColor = rs.borderColor, + ret; + + if( rsWidth ) rs.borderWidth = ''; + if( rsColor ) rs.borderColor = ''; + + ret = fn.call( this ); + + if( rsWidth ) rs.borderWidth = rsWidth; + if( rsColor ) rs.borderColor = rsColor; + + return ret; + } + +} ); +/** + * Handles parsing, caching, and detecting changes to border-radius CSS + * @constructor + * @param {Element} el the target element + */ +(function() { + +PIE.BorderRadiusStyleInfo = PIE.StyleInfoBase.newStyleInfo( { + + cssProperty: 'border-radius', + styleProperty: 'borderRadius', + + parseCss: function( css ) { + var p = null, x, y, + tokenizer, token, length, + hasNonZero = false; + + if( css ) { + tokenizer = new PIE.Tokenizer( css ); + + function collectLengths() { + var arr = [], num; + while( ( token = tokenizer.next() ) && token.isLengthOrPercent() ) { + length = PIE.getLength( token.tokenValue ); + num = length.getNumber(); + if( num < 0 ) { + return null; + } + if( num > 0 ) { + hasNonZero = true; + } + arr.push( length ); + } + return arr.length > 0 && arr.length < 5 ? { + 'tl': arr[0], + 'tr': arr[1] || arr[0], + 'br': arr[2] || arr[0], + 'bl': arr[3] || arr[1] || arr[0] + } : null; + } + + // Grab the initial sequence of lengths + if( x = collectLengths() ) { + // See if there is a slash followed by more lengths, for the y-axis radii + if( token ) { + if( token.tokenType & PIE.Tokenizer.Type.OPERATOR && token.tokenValue === '/' ) { + y = collectLengths(); + } + } else { + y = x; + } + + // Treat all-zero values the same as no value + if( hasNonZero && x && y ) { + p = { x: x, y : y }; + } + } + } + + return p; + } +} ); + +var zero = PIE.getLength( '0' ), + zeros = { 'tl': zero, 'tr': zero, 'br': zero, 'bl': zero }; +PIE.BorderRadiusStyleInfo.ALL_ZERO = { x: zeros, y: zeros }; + +})();/** + * Handles parsing, caching, and detecting changes to border-image CSS + * @constructor + * @param {Element} el the target element + */ +PIE.BorderImageStyleInfo = PIE.StyleInfoBase.newStyleInfo( { + + cssProperty: 'border-image', + styleProperty: 'borderImage', + + repeatIdents: { 'stretch':1, 'round':1, 'repeat':1, 'space':1 }, + + parseCss: function( css ) { + var p = null, tokenizer, token, type, value, + slices, widths, outsets, + slashCount = 0, + Type = PIE.Tokenizer.Type, + IDENT = Type.IDENT, + NUMBER = Type.NUMBER, + PERCENT = Type.PERCENT; + + if( css ) { + tokenizer = new PIE.Tokenizer( css ); + p = {}; + + function isSlash( token ) { + return token && ( token.tokenType & Type.OPERATOR ) && ( token.tokenValue === '/' ); + } + + function isFillIdent( token ) { + return token && ( token.tokenType & IDENT ) && ( token.tokenValue === 'fill' ); + } + + function collectSlicesEtc() { + slices = tokenizer.until( function( tok ) { + return !( tok.tokenType & ( NUMBER | PERCENT ) ); + } ); + + if( isFillIdent( tokenizer.next() ) && !p.fill ) { + p.fill = true; + } else { + tokenizer.prev(); + } + + if( isSlash( tokenizer.next() ) ) { + slashCount++; + widths = tokenizer.until( function( token ) { + return !token.isLengthOrPercent() && !( ( token.tokenType & IDENT ) && token.tokenValue === 'auto' ); + } ); + + if( isSlash( tokenizer.next() ) ) { + slashCount++; + outsets = tokenizer.until( function( token ) { + return !token.isLength(); + } ); + } + } else { + tokenizer.prev(); + } + } + + while( token = tokenizer.next() ) { + type = token.tokenType; + value = token.tokenValue; + + // Numbers and/or 'fill' keyword: slice values. May be followed optionally by width values, followed optionally by outset values + if( type & ( NUMBER | PERCENT ) && !slices ) { + tokenizer.prev(); + collectSlicesEtc(); + } + else if( isFillIdent( token ) && !p.fill ) { + p.fill = true; + collectSlicesEtc(); + } + + // Idents: one or values for 'repeat' + else if( ( type & IDENT ) && this.repeatIdents[value] && !p.repeat ) { + p.repeat = { h: value }; + if( token = tokenizer.next() ) { + if( ( token.tokenType & IDENT ) && this.repeatIdents[token.tokenValue] ) { + p.repeat.v = token.tokenValue; + } else { + tokenizer.prev(); + } + } + } + + // URL of the image + else if( ( type & Type.URL ) && !p.src ) { + p.src = value; + } + + // Found something unrecognized; exit. + else { + return null; + } + } + + // Validate what we collected + if( !p.src || !slices || slices.length < 1 || slices.length > 4 || + ( widths && widths.length > 4 ) || ( slashCount === 1 && widths.length < 1 ) || + ( outsets && outsets.length > 4 ) || ( slashCount === 2 && outsets.length < 1 ) ) { + return null; + } + + // Fill in missing values + if( !p.repeat ) { + p.repeat = { h: 'stretch' }; + } + if( !p.repeat.v ) { + p.repeat.v = p.repeat.h; + } + + function distributeSides( tokens, convertFn ) { + return { + 't': convertFn( tokens[0] ), + 'r': convertFn( tokens[1] || tokens[0] ), + 'b': convertFn( tokens[2] || tokens[0] ), + 'l': convertFn( tokens[3] || tokens[1] || tokens[0] ) + }; + } + + p.slice = distributeSides( slices, function( tok ) { + return PIE.getLength( ( tok.tokenType & NUMBER ) ? tok.tokenValue + 'px' : tok.tokenValue ); + } ); + + if( widths && widths[0] ) { + p.widths = distributeSides( widths, function( tok ) { + return tok.isLengthOrPercent() ? PIE.getLength( tok.tokenValue ) : tok.tokenValue; + } ); + } + + if( outsets && outsets[0] ) { + p.outset = distributeSides( outsets, function( tok ) { + return tok.isLength() ? PIE.getLength( tok.tokenValue ) : tok.tokenValue; + } ); + } + } + + return p; + } + +} );/** + * Handles parsing, caching, and detecting changes to box-shadow CSS + * @constructor + * @param {Element} el the target element + */ +PIE.BoxShadowStyleInfo = PIE.StyleInfoBase.newStyleInfo( { + + cssProperty: 'box-shadow', + styleProperty: 'boxShadow', + + parseCss: function( css ) { + var props, + getLength = PIE.getLength, + Type = PIE.Tokenizer.Type, + tokenizer; + + if( css ) { + tokenizer = new PIE.Tokenizer( css ); + props = { outset: [], inset: [] }; + + function parseItem() { + var token, type, value, color, lengths, inset, len; + + while( token = tokenizer.next() ) { + value = token.tokenValue; + type = token.tokenType; + + if( type & Type.OPERATOR && value === ',' ) { + break; + } + else if( token.isLength() && !lengths ) { + tokenizer.prev(); + lengths = tokenizer.until( function( token ) { + return !token.isLength(); + } ); + } + else if( type & Type.COLOR && !color ) { + color = value; + } + else if( type & Type.IDENT && value === 'inset' && !inset ) { + inset = true; + } + else { //encountered an unrecognized token; fail. + return false; + } + } + + len = lengths && lengths.length; + if( len > 1 && len < 5 ) { + ( inset ? props.inset : props.outset ).push( { + xOffset: getLength( lengths[0].tokenValue ), + yOffset: getLength( lengths[1].tokenValue ), + blur: getLength( lengths[2] ? lengths[2].tokenValue : '0' ), + spread: getLength( lengths[3] ? lengths[3].tokenValue : '0' ), + color: PIE.getColor( color || 'currentColor' ) + } ); + return true; + } + return false; + } + + while( parseItem() ) {} + } + + return props && ( props.inset.length || props.outset.length ) ? props : null; + } +} ); +/** + * Retrieves the state of the element's visibility and display + * @constructor + * @param {Element} el the target element + */ +PIE.VisibilityStyleInfo = PIE.StyleInfoBase.newStyleInfo( { + + getCss: PIE.StyleInfoBase.cacheWhenLocked( function() { + var cs = this.targetElement.currentStyle; + return cs.visibility + '|' + cs.display; + } ), + + parseCss: function() { + var el = this.targetElement, + rs = el.runtimeStyle, + cs = el.currentStyle, + rsVis = rs.visibility, + csVis; + + rs.visibility = ''; + csVis = cs.visibility; + rs.visibility = rsVis; + + return { + visible: csVis !== 'hidden', + displayed: cs.display !== 'none' + } + }, + + /** + * Always return false for isActive, since this property alone will not trigger + * a renderer to do anything. + */ + isActive: function() { + return false; + } + +} ); +PIE.RendererBase = { + + /** + * Create a new Renderer class, with the standard constructor, and augmented by + * the RendererBase's members. + * @param proto + */ + newRenderer: function( proto ) { + function Renderer( el, boundsInfo, styleInfos, parent ) { + this.targetElement = el; + this.boundsInfo = boundsInfo; + this.styleInfos = styleInfos; + this.parent = parent; + } + PIE.Util.merge( Renderer.prototype, PIE.RendererBase, proto ); + return Renderer; + }, + + /** + * Flag indicating the element has already been positioned at least once. + * @type {boolean} + */ + isPositioned: false, + + /** + * Determine if the renderer needs to be updated + * @return {boolean} + */ + needsUpdate: function() { + return false; + }, + + /** + * Run any preparation logic that would affect the main update logic of this + * renderer or any of the other renderers, e.g. things that might affect the + * element's size or style properties. + */ + prepareUpdate: PIE.emptyFn, + + /** + * Tell the renderer to update based on modified properties + */ + updateProps: function() { + this.destroy(); + if( this.isActive() ) { + this.draw(); + } + }, + + /** + * Tell the renderer to update based on modified element position + */ + updatePos: function() { + this.isPositioned = true; + }, + + /** + * Tell the renderer to update based on modified element dimensions + */ + updateSize: function() { + if( this.isActive() ) { + this.draw(); + } else { + this.destroy(); + } + }, + + + /** + * Add a layer element, with the given z-order index, to the renderer's main box element. We can't use + * z-index because that breaks when the root rendering box's z-index is 'auto' in IE8+ standards mode. + * So instead we make sure they are inserted into the DOM in the correct order. + * @param {number} index + * @param {Element} el + */ + addLayer: function( index, el ) { + this.removeLayer( index ); + for( var layers = this._layers || ( this._layers = [] ), i = index + 1, len = layers.length, layer; i < len; i++ ) { + layer = layers[i]; + if( layer ) { + break; + } + } + layers[index] = el; + this.getBox().insertBefore( el, layer || null ); + }, + + /** + * Retrieve a layer element by its index, or null if not present + * @param {number} index + * @return {Element} + */ + getLayer: function( index ) { + var layers = this._layers; + return layers && layers[index] || null; + }, + + /** + * Remove a layer element by its index + * @param {number} index + */ + removeLayer: function( index ) { + var layer = this.getLayer( index ), + box = this._box; + if( layer && box ) { + box.removeChild( layer ); + this._layers[index] = null; + } + }, + + + /** + * Get a VML shape by name, creating it if necessary. + * @param {string} name A name identifying the element + * @param {string=} subElName If specified a subelement of the shape will be created with this tag name + * @param {Element} parent The parent element for the shape; will be ignored if 'group' is specified + * @param {number=} group If specified, an ordinal group for the shape. 1 or greater. Groups are rendered + * using container elements in the correct order, to get correct z stacking without z-index. + */ + getShape: function( name, subElName, parent, group ) { + var shapes = this._shapes || ( this._shapes = {} ), + shape = shapes[ name ], + s; + + if( !shape ) { + shape = shapes[ name ] = PIE.Util.createVmlElement( 'shape' ); + if( subElName ) { + shape.appendChild( shape[ subElName ] = PIE.Util.createVmlElement( subElName ) ); + } + + if( group ) { + parent = this.getLayer( group ); + if( !parent ) { + this.addLayer( group, doc.createElement( 'group' + group ) ); + parent = this.getLayer( group ); + } + } + + parent.appendChild( shape ); + + s = shape.style; + s.position = 'absolute'; + s.left = s.top = 0; + s['behavior'] = 'url(#default#VML)'; + } + return shape; + }, + + /** + * Delete a named shape which was created by getShape(). Returns true if a shape with the + * given name was found and deleted, or false if there was no shape of that name. + * @param {string} name + * @return {boolean} + */ + deleteShape: function( name ) { + var shapes = this._shapes, + shape = shapes && shapes[ name ]; + if( shape ) { + shape.parentNode.removeChild( shape ); + delete shapes[ name ]; + } + return !!shape; + }, + + + /** + * For a given set of border radius length/percentage values, convert them to concrete pixel + * values based on the current size of the target element. + * @param {Object} radii + * @return {Object} + */ + getRadiiPixels: function( radii ) { + var el = this.targetElement, + bounds = this.boundsInfo.getBounds(), + w = bounds.w, + h = bounds.h, + tlX, tlY, trX, trY, brX, brY, blX, blY, f; + + tlX = radii.x['tl'].pixels( el, w ); + tlY = radii.y['tl'].pixels( el, h ); + trX = radii.x['tr'].pixels( el, w ); + trY = radii.y['tr'].pixels( el, h ); + brX = radii.x['br'].pixels( el, w ); + brY = radii.y['br'].pixels( el, h ); + blX = radii.x['bl'].pixels( el, w ); + blY = radii.y['bl'].pixels( el, h ); + + // If any corner ellipses overlap, reduce them all by the appropriate factor. This formula + // is taken straight from the CSS3 Backgrounds and Borders spec. + f = Math.min( + w / ( tlX + trX ), + h / ( trY + brY ), + w / ( blX + brX ), + h / ( tlY + blY ) + ); + if( f < 1 ) { + tlX *= f; + tlY *= f; + trX *= f; + trY *= f; + brX *= f; + brY *= f; + blX *= f; + blY *= f; + } + + return { + x: { + 'tl': tlX, + 'tr': trX, + 'br': brX, + 'bl': blX + }, + y: { + 'tl': tlY, + 'tr': trY, + 'br': brY, + 'bl': blY + } + } + }, + + /** + * Return the VML path string for the element's background box, with corners rounded. + * @param {Object.<{t:number, r:number, b:number, l:number}>} shrink - if present, specifies number of + * pixels to shrink the box path inward from the element's four sides. + * @param {number=} mult If specified, all coordinates will be multiplied by this number + * @param {Object=} radii If specified, this will be used for the corner radii instead of the properties + * from this renderer's borderRadiusInfo object. + * @return {string} the VML path + */ + getBoxPath: function( shrink, mult, radii ) { + mult = mult || 1; + + var r, str, + bounds = this.boundsInfo.getBounds(), + w = bounds.w * mult, + h = bounds.h * mult, + radInfo = this.styleInfos.borderRadiusInfo, + floor = Math.floor, ceil = Math.ceil, + shrinkT = shrink ? shrink.t * mult : 0, + shrinkR = shrink ? shrink.r * mult : 0, + shrinkB = shrink ? shrink.b * mult : 0, + shrinkL = shrink ? shrink.l * mult : 0, + tlX, tlY, trX, trY, brX, brY, blX, blY; + + if( radii || radInfo.isActive() ) { + r = this.getRadiiPixels( radii || radInfo.getProps() ); + + tlX = r.x['tl'] * mult; + tlY = r.y['tl'] * mult; + trX = r.x['tr'] * mult; + trY = r.y['tr'] * mult; + brX = r.x['br'] * mult; + brY = r.y['br'] * mult; + blX = r.x['bl'] * mult; + blY = r.y['bl'] * mult; + + str = 'm' + floor( shrinkL ) + ',' + floor( tlY ) + + 'qy' + floor( tlX ) + ',' + floor( shrinkT ) + + 'l' + ceil( w - trX ) + ',' + floor( shrinkT ) + + 'qx' + ceil( w - shrinkR ) + ',' + floor( trY ) + + 'l' + ceil( w - shrinkR ) + ',' + ceil( h - brY ) + + 'qy' + ceil( w - brX ) + ',' + ceil( h - shrinkB ) + + 'l' + floor( blX ) + ',' + ceil( h - shrinkB ) + + 'qx' + floor( shrinkL ) + ',' + ceil( h - blY ) + ' x e'; + } else { + // simplified path for non-rounded box + str = 'm' + floor( shrinkL ) + ',' + floor( shrinkT ) + + 'l' + ceil( w - shrinkR ) + ',' + floor( shrinkT ) + + 'l' + ceil( w - shrinkR ) + ',' + ceil( h - shrinkB ) + + 'l' + floor( shrinkL ) + ',' + ceil( h - shrinkB ) + + 'xe'; + } + return str; + }, + + + /** + * Get the container element for the shapes, creating it if necessary. + */ + getBox: function() { + var box = this.parent.getLayer( this.boxZIndex ), s; + + if( !box ) { + box = doc.createElement( this.boxName ); + s = box.style; + s.position = 'absolute'; + s.top = s.left = 0; + this.parent.addLayer( this.boxZIndex, box ); + } + + return box; + }, + + + /** + * Hide the actual border of the element. In IE7 and up we can just set its color to transparent; + * however IE6 does not support transparent borders so we have to get tricky with it. Also, some elements + * like form buttons require removing the border width altogether, so for those we increase the padding + * by the border size. + */ + hideBorder: function() { + var el = this.targetElement, + cs = el.currentStyle, + rs = el.runtimeStyle, + tag = el.tagName, + isIE6 = PIE.ieVersion === 6, + sides, side, i; + + if( ( isIE6 && ( tag in PIE.childlessElements || tag === 'FIELDSET' ) ) || + tag === 'BUTTON' || ( tag === 'INPUT' && el.type in PIE.inputButtonTypes ) ) { + rs.borderWidth = ''; + sides = this.styleInfos.borderInfo.sides; + for( i = sides.length; i--; ) { + side = sides[ i ]; + rs[ 'padding' + side ] = ''; + rs[ 'padding' + side ] = ( PIE.getLength( cs[ 'padding' + side ] ) ).pixels( el ) + + ( PIE.getLength( cs[ 'border' + side + 'Width' ] ) ).pixels( el ) + + ( PIE.ieVersion !== 8 && i % 2 ? 1 : 0 ); //needs an extra horizontal pixel to counteract the extra "inner border" going away + } + rs.borderWidth = 0; + } + else if( isIE6 ) { + // Wrap all the element's children in a custom element, set the element to visiblity:hidden, + // and set the wrapper element to visiblity:visible. This hides the outer element's decorations + // (background and border) but displays all the contents. + // TODO find a better way to do this that doesn't mess up the DOM parent-child relationship, + // as this can interfere with other author scripts which add/modify/delete children. Also, this + // won't work for elements which cannot take children, e.g. input/button/textarea/img/etc. Look into + // using a compositor filter or some other filter which masks the border. + if( el.childNodes.length !== 1 || el.firstChild.tagName !== 'ie6-mask' ) { + var cont = doc.createElement( 'ie6-mask' ), + s = cont.style, child; + s.visibility = 'visible'; + s.zoom = 1; + while( child = el.firstChild ) { + cont.appendChild( child ); + } + el.appendChild( cont ); + rs.visibility = 'hidden'; + } + } + else { + rs.borderColor = 'transparent'; + } + }, + + unhideBorder: function() { + + }, + + + /** + * Destroy the rendered objects. This is a base implementation which handles common renderer + * structures, but individual renderers may override as necessary. + */ + destroy: function() { + this.parent.removeLayer( this.boxZIndex ); + delete this._shapes; + delete this._layers; + } +}; +/** + * Root renderer; creates the outermost container element and handles keeping it aligned + * with the target element's size and position. + * @param {Element} el The target element + * @param {Object} styleInfos The StyleInfo objects + */ +PIE.RootRenderer = PIE.RendererBase.newRenderer( { + + isActive: function() { + var children = this.childRenderers; + for( var i in children ) { + if( children.hasOwnProperty( i ) && children[ i ].isActive() ) { + return true; + } + } + return false; + }, + + needsUpdate: function() { + return this.styleInfos.visibilityInfo.changed(); + }, + + updatePos: function() { + if( this.isActive() ) { + var el = this.getPositioningElement(), + par = el, + docEl, + parRect, + tgtCS = el.currentStyle, + tgtPos = tgtCS.position, + boxPos, + s = this.getBox().style, cs, + x = 0, y = 0, + elBounds = this.boundsInfo.getBounds(), + logicalZoomRatio = elBounds.logicalZoomRatio; + + if( tgtPos === 'fixed' && PIE.ieVersion > 6 ) { + x = elBounds.x * logicalZoomRatio; + y = elBounds.y * logicalZoomRatio; + boxPos = tgtPos; + } else { + // Get the element's offsets from its nearest positioned ancestor. Uses + // getBoundingClientRect for accuracy and speed. + do { + par = par.offsetParent; + } while( par && ( par.currentStyle.position === 'static' ) ); + if( par ) { + parRect = par.getBoundingClientRect(); + cs = par.currentStyle; + x = ( elBounds.x - parRect.left ) * logicalZoomRatio - ( parseFloat(cs.borderLeftWidth) || 0 ); + y = ( elBounds.y - parRect.top ) * logicalZoomRatio - ( parseFloat(cs.borderTopWidth) || 0 ); + } else { + docEl = doc.documentElement; + x = ( elBounds.x + docEl.scrollLeft - docEl.clientLeft ) * logicalZoomRatio; + y = ( elBounds.y + docEl.scrollTop - docEl.clientTop ) * logicalZoomRatio; + } + boxPos = 'absolute'; + } + + s.position = boxPos; + s.left = x; + s.top = y; + s.zIndex = tgtPos === 'static' ? -1 : tgtCS.zIndex; + this.isPositioned = true; + } + }, + + updateSize: PIE.emptyFn, + + updateVisibility: function() { + var vis = this.styleInfos.visibilityInfo.getProps(); + this.getBox().style.display = ( vis.visible && vis.displayed ) ? '' : 'none'; + }, + + updateProps: function() { + if( this.isActive() ) { + this.updateVisibility(); + } else { + this.destroy(); + } + }, + + getPositioningElement: function() { + var el = this.targetElement; + return el.tagName in PIE.tableCellTags ? el.offsetParent : el; + }, + + getBox: function() { + var box = this._box, el; + if( !box ) { + el = this.getPositioningElement(); + box = this._box = doc.createElement( 'css3-container' ); + box.style['direction'] = 'ltr'; //fix positioning bug in rtl environments + + this.updateVisibility(); + + el.parentNode.insertBefore( box, el ); + } + return box; + }, + + finishUpdate: PIE.emptyFn, + + destroy: function() { + var box = this._box, par; + if( box && ( par = box.parentNode ) ) { + par.removeChild( box ); + } + delete this._box; + delete this._layers; + } + +} ); +/** + * Renderer for element backgrounds. + * @constructor + * @param {Element} el The target element + * @param {Object} styleInfos The StyleInfo objects + * @param {PIE.RootRenderer} parent + */ +PIE.BackgroundRenderer = PIE.RendererBase.newRenderer( { + + boxZIndex: 2, + boxName: 'background', + + needsUpdate: function() { + var si = this.styleInfos; + return si.backgroundInfo.changed() || si.borderRadiusInfo.changed(); + }, + + isActive: function() { + var si = this.styleInfos; + return si.borderImageInfo.isActive() || + si.borderRadiusInfo.isActive() || + si.backgroundInfo.isActive() || + ( si.boxShadowInfo.isActive() && si.boxShadowInfo.getProps().inset ); + }, + + /** + * Draw the shapes + */ + draw: function() { + var bounds = this.boundsInfo.getBounds(); + if( bounds.w && bounds.h ) { + this.drawBgColor(); + this.drawBgImages(); + } + }, + + /** + * Draw the background color shape + */ + drawBgColor: function() { + var props = this.styleInfos.backgroundInfo.getProps(), + bounds = this.boundsInfo.getBounds(), + el = this.targetElement, + color = props && props.color, + shape, w, h, s, alpha; + + if( color && color.alpha() > 0 ) { + this.hideBackground(); + + shape = this.getShape( 'bgColor', 'fill', this.getBox(), 1 ); + w = bounds.w; + h = bounds.h; + shape.stroked = false; + shape.coordsize = w * 2 + ',' + h * 2; + shape.coordorigin = '1,1'; + shape.path = this.getBoxPath( null, 2 ); + s = shape.style; + s.width = w; + s.height = h; + shape.fill.color = color.colorValue( el ); + + alpha = color.alpha(); + if( alpha < 1 ) { + shape.fill.opacity = alpha; + } + } else { + this.deleteShape( 'bgColor' ); + } + }, + + /** + * Draw all the background image layers + */ + drawBgImages: function() { + var props = this.styleInfos.backgroundInfo.getProps(), + bounds = this.boundsInfo.getBounds(), + images = props && props.bgImages, + img, shape, w, h, s, i; + + if( images ) { + this.hideBackground(); + + w = bounds.w; + h = bounds.h; + + i = images.length; + while( i-- ) { + img = images[i]; + shape = this.getShape( 'bgImage' + i, 'fill', this.getBox(), 2 ); + + shape.stroked = false; + shape.fill.type = 'tile'; + shape.fillcolor = 'none'; + shape.coordsize = w * 2 + ',' + h * 2; + shape.coordorigin = '1,1'; + shape.path = this.getBoxPath( 0, 2 ); + s = shape.style; + s.width = w; + s.height = h; + + if( img.imgType === 'linear-gradient' ) { + this.addLinearGradient( shape, img ); + } + else { + shape.fill.src = img.imgUrl; + this.positionBgImage( shape, i ); + } + } + } + + // Delete any bgImage shapes previously created which weren't used above + i = images ? images.length : 0; + while( this.deleteShape( 'bgImage' + i++ ) ) {} + }, + + + /** + * Set the position and clipping of the background image for a layer + * @param {Element} shape + * @param {number} index + */ + positionBgImage: function( shape, index ) { + var me = this; + PIE.Util.withImageSize( shape.fill.src, function( size ) { + var el = me.targetElement, + bounds = me.boundsInfo.getBounds(), + elW = bounds.w, + elH = bounds.h; + + // It's possible that the element dimensions are zero now but weren't when the original + // update executed, make sure that's not the case to avoid divide-by-zero error + if( elW && elH ) { + var fill = shape.fill, + si = me.styleInfos, + border = si.borderInfo.getProps(), + bw = border && border.widths, + bwT = bw ? bw['t'].pixels( el ) : 0, + bwR = bw ? bw['r'].pixels( el ) : 0, + bwB = bw ? bw['b'].pixels( el ) : 0, + bwL = bw ? bw['l'].pixels( el ) : 0, + bg = si.backgroundInfo.getProps().bgImages[ index ], + bgPos = bg.bgPosition ? bg.bgPosition.coords( el, elW - size.w - bwL - bwR, elH - size.h - bwT - bwB ) : { x:0, y:0 }, + repeat = bg.imgRepeat, + pxX, pxY, + clipT = 0, clipL = 0, + clipR = elW + 1, clipB = elH + 1, //make sure the default clip region is not inside the box (by a subpixel) + clipAdjust = PIE.ieVersion === 8 ? 0 : 1; //prior to IE8 requires 1 extra pixel in the image clip region + + // Positioning - find the pixel offset from the top/left and convert to a ratio + // The position is shifted by half a pixel, to adjust for the half-pixel coordorigin shift which is + // needed to fix antialiasing but makes the bg image fuzzy. + pxX = Math.round( bgPos.x ) + bwL + 0.5; + pxY = Math.round( bgPos.y ) + bwT + 0.5; + fill.position = ( pxX / elW ) + ',' + ( pxY / elH ); + + // Set the size of the image. We have to actually set it to px values otherwise it will not honor + // the user's browser zoom level and always display at its natural screen size. + fill['size']['x'] = 1; //Can be any value, just has to be set to "prime" it so the next line works. Weird! + fill['size'] = size.w + 'px,' + size.h + 'px'; + + // Repeating - clip the image shape + if( repeat && repeat !== 'repeat' ) { + if( repeat === 'repeat-x' || repeat === 'no-repeat' ) { + clipT = pxY + 1; + clipB = pxY + size.h + clipAdjust; + } + if( repeat === 'repeat-y' || repeat === 'no-repeat' ) { + clipL = pxX + 1; + clipR = pxX + size.w + clipAdjust; + } + shape.style.clip = 'rect(' + clipT + 'px,' + clipR + 'px,' + clipB + 'px,' + clipL + 'px)'; + } + } + } ); + }, + + + /** + * Draw the linear gradient for a gradient layer + * @param {Element} shape + * @param {Object} info The object holding the information about the gradient + */ + addLinearGradient: function( shape, info ) { + var el = this.targetElement, + bounds = this.boundsInfo.getBounds(), + w = bounds.w, + h = bounds.h, + fill = shape.fill, + stops = info.stops, + stopCount = stops.length, + PI = Math.PI, + GradientUtil = PIE.GradientUtil, + perpendicularIntersect = GradientUtil.perpendicularIntersect, + distance = GradientUtil.distance, + metrics = GradientUtil.getGradientMetrics( el, w, h, info ), + angle = metrics.angle, + startX = metrics.startX, + startY = metrics.startY, + startCornerX = metrics.startCornerX, + startCornerY = metrics.startCornerY, + endCornerX = metrics.endCornerX, + endCornerY = metrics.endCornerY, + deltaX = metrics.deltaX, + deltaY = metrics.deltaY, + lineLength = metrics.lineLength, + vmlAngle, vmlGradientLength, vmlColors, + stopPx, vmlOffsetPct, + p, i, j, before, after; + + // In VML land, the angle of the rendered gradient depends on the aspect ratio of the shape's + // bounding box; for example specifying a 45 deg angle actually results in a gradient + // drawn diagonally from one corner to its opposite corner, which will only appear to the + // viewer as 45 degrees if the shape is equilateral. We adjust for this by taking the x/y deltas + // between the start and end points, multiply one of them by the shape's aspect ratio, + // and get their arctangent, resulting in an appropriate VML angle. If the angle is perfectly + // horizontal or vertical then we don't need to do this conversion. + vmlAngle = ( angle % 90 ) ? Math.atan2( deltaX * w / h, deltaY ) / PI * 180 : ( angle + 90 ); + + // VML angles are 180 degrees offset from CSS angles + vmlAngle += 180; + vmlAngle = vmlAngle % 360; + + // Add all the stops to the VML 'colors' list, including the first and last stops. + // For each, we find its pixel offset along the gradient-line; if the offset of a stop is less + // than that of its predecessor we increase it to be equal. We then map that pixel offset to a + // percentage along the VML gradient-line, which runs from shape corner to corner. + p = perpendicularIntersect( startCornerX, startCornerY, angle, endCornerX, endCornerY ); + vmlGradientLength = distance( startCornerX, startCornerY, p[0], p[1] ); + vmlColors = []; + p = perpendicularIntersect( startX, startY, angle, startCornerX, startCornerY ); + vmlOffsetPct = distance( startX, startY, p[0], p[1] ) / vmlGradientLength * 100; + + // Find the pixel offsets along the CSS3 gradient-line for each stop. + stopPx = []; + for( i = 0; i < stopCount; i++ ) { + stopPx.push( stops[i].offset ? stops[i].offset.pixels( el, lineLength ) : + i === 0 ? 0 : i === stopCount - 1 ? lineLength : null ); + } + // Fill in gaps with evenly-spaced offsets + for( i = 1; i < stopCount; i++ ) { + if( stopPx[ i ] === null ) { + before = stopPx[ i - 1 ]; + j = i; + do { + after = stopPx[ ++j ]; + } while( after === null ); + stopPx[ i ] = before + ( after - before ) / ( j - i + 1 ); + } + // Make sure each stop's offset is no less than the one before it + stopPx[ i ] = Math.max( stopPx[ i ], stopPx[ i - 1 ] ); + } + + // Convert to percentage along the VML gradient line and add to the VML 'colors' value + for( i = 0; i < stopCount; i++ ) { + vmlColors.push( + ( vmlOffsetPct + ( stopPx[ i ] / vmlGradientLength * 100 ) ) + '% ' + stops[i].color.colorValue( el ) + ); + } + + // Now, finally, we're ready to render the gradient fill. Set the start and end colors to + // the first and last stop colors; this just sets outer bounds for the gradient. + fill['angle'] = vmlAngle; + fill['type'] = 'gradient'; + fill['method'] = 'sigma'; + fill['color'] = stops[0].color.colorValue( el ); + fill['color2'] = stops[stopCount - 1].color.colorValue( el ); + if( fill['colors'] ) { //sometimes the colors object isn't initialized so we have to assign it directly (?) + fill['colors'].value = vmlColors.join( ',' ); + } else { + fill['colors'] = vmlColors.join( ',' ); + } + }, + + + /** + * Hide the actual background image and color of the element. + */ + hideBackground: function() { + var rs = this.targetElement.runtimeStyle; + rs.backgroundImage = 'url(about:blank)'; //ensures the background area reacts to mouse events + rs.backgroundColor = 'transparent'; + }, + + destroy: function() { + PIE.RendererBase.destroy.call( this ); + var rs = this.targetElement.runtimeStyle; + rs.backgroundImage = rs.backgroundColor = ''; + } + +} ); +/** + * Renderer for element borders. + * @constructor + * @param {Element} el The target element + * @param {Object} styleInfos The StyleInfo objects + * @param {PIE.RootRenderer} parent + */ +PIE.BorderRenderer = PIE.RendererBase.newRenderer( { + + boxZIndex: 4, + boxName: 'border', + + needsUpdate: function() { + var si = this.styleInfos; + return si.borderInfo.changed() || si.borderRadiusInfo.changed(); + }, + + isActive: function() { + var si = this.styleInfos; + return si.borderRadiusInfo.isActive() && + !si.borderImageInfo.isActive() && + si.borderInfo.isActive(); //check BorderStyleInfo last because it's the most expensive + }, + + /** + * Draw the border shape(s) + */ + draw: function() { + var el = this.targetElement, + props = this.styleInfos.borderInfo.getProps(), + bounds = this.boundsInfo.getBounds(), + w = bounds.w, + h = bounds.h, + shape, stroke, s, + segments, seg, i, len; + + if( props ) { + this.hideBorder(); + + segments = this.getBorderSegments( 2 ); + for( i = 0, len = segments.length; i < len; i++) { + seg = segments[i]; + shape = this.getShape( 'borderPiece' + i, seg.stroke ? 'stroke' : 'fill', this.getBox() ); + shape.coordsize = w * 2 + ',' + h * 2; + shape.coordorigin = '1,1'; + shape.path = seg.path; + s = shape.style; + s.width = w; + s.height = h; + + shape.filled = !!seg.fill; + shape.stroked = !!seg.stroke; + if( seg.stroke ) { + stroke = shape.stroke; + stroke['weight'] = seg.weight + 'px'; + stroke.color = seg.color.colorValue( el ); + stroke['dashstyle'] = seg.stroke === 'dashed' ? '2 2' : seg.stroke === 'dotted' ? '1 1' : 'solid'; + stroke['linestyle'] = seg.stroke === 'double' && seg.weight > 2 ? 'ThinThin' : 'Single'; + } else { + shape.fill.color = seg.fill.colorValue( el ); + } + } + + // remove any previously-created border shapes which didn't get used above + while( this.deleteShape( 'borderPiece' + i++ ) ) {} + } + }, + + + /** + * Get the VML path definitions for the border segment(s). + * @param {number=} mult If specified, all coordinates will be multiplied by this number + * @return {Array.} + */ + getBorderSegments: function( mult ) { + var el = this.targetElement, + bounds, elW, elH, + borderInfo = this.styleInfos.borderInfo, + segments = [], + floor, ceil, wT, wR, wB, wL, + round = Math.round, + borderProps, radiusInfo, radii, widths, styles, colors; + + if( borderInfo.isActive() ) { + borderProps = borderInfo.getProps(); + + widths = borderProps.widths; + styles = borderProps.styles; + colors = borderProps.colors; + + if( borderProps.widthsSame && borderProps.stylesSame && borderProps.colorsSame ) { + if( colors['t'].alpha() > 0 ) { + // shortcut for identical border on all sides - only need 1 stroked shape + wT = widths['t'].pixels( el ); //thickness + wR = wT / 2; //shrink + segments.push( { + path: this.getBoxPath( { t: wR, r: wR, b: wR, l: wR }, mult ), + stroke: styles['t'], + color: colors['t'], + weight: wT + } ); + } + } + else { + mult = mult || 1; + bounds = this.boundsInfo.getBounds(); + elW = bounds.w; + elH = bounds.h; + + wT = round( widths['t'].pixels( el ) ); + wR = round( widths['r'].pixels( el ) ); + wB = round( widths['b'].pixels( el ) ); + wL = round( widths['l'].pixels( el ) ); + var pxWidths = { + 't': wT, + 'r': wR, + 'b': wB, + 'l': wL + }; + + radiusInfo = this.styleInfos.borderRadiusInfo; + if( radiusInfo.isActive() ) { + radii = this.getRadiiPixels( radiusInfo.getProps() ); + } + + floor = Math.floor; + ceil = Math.ceil; + + function radius( xy, corner ) { + return radii ? radii[ xy ][ corner ] : 0; + } + + function curve( corner, shrinkX, shrinkY, startAngle, ccw, doMove ) { + var rx = radius( 'x', corner), + ry = radius( 'y', corner), + deg = 65535, + isRight = corner.charAt( 1 ) === 'r', + isBottom = corner.charAt( 0 ) === 'b'; + return ( rx > 0 && ry > 0 ) ? + ( doMove ? 'al' : 'ae' ) + + ( isRight ? ceil( elW - rx ) : floor( rx ) ) * mult + ',' + // center x + ( isBottom ? ceil( elH - ry ) : floor( ry ) ) * mult + ',' + // center y + ( floor( rx ) - shrinkX ) * mult + ',' + // width + ( floor( ry ) - shrinkY ) * mult + ',' + // height + ( startAngle * deg ) + ',' + // start angle + ( 45 * deg * ( ccw ? 1 : -1 ) // angle change + ) : ( + ( doMove ? 'm' : 'l' ) + + ( isRight ? elW - shrinkX : shrinkX ) * mult + ',' + + ( isBottom ? elH - shrinkY : shrinkY ) * mult + ); + } + + function line( side, shrink, ccw, doMove ) { + var + start = ( + side === 't' ? + floor( radius( 'x', 'tl') ) * mult + ',' + ceil( shrink ) * mult : + side === 'r' ? + ceil( elW - shrink ) * mult + ',' + floor( radius( 'y', 'tr') ) * mult : + side === 'b' ? + ceil( elW - radius( 'x', 'br') ) * mult + ',' + floor( elH - shrink ) * mult : + // side === 'l' ? + floor( shrink ) * mult + ',' + ceil( elH - radius( 'y', 'bl') ) * mult + ), + end = ( + side === 't' ? + ceil( elW - radius( 'x', 'tr') ) * mult + ',' + ceil( shrink ) * mult : + side === 'r' ? + ceil( elW - shrink ) * mult + ',' + ceil( elH - radius( 'y', 'br') ) * mult : + side === 'b' ? + floor( radius( 'x', 'bl') ) * mult + ',' + floor( elH - shrink ) * mult : + // side === 'l' ? + floor( shrink ) * mult + ',' + floor( radius( 'y', 'tl') ) * mult + ); + return ccw ? ( doMove ? 'm' + end : '' ) + 'l' + start : + ( doMove ? 'm' + start : '' ) + 'l' + end; + } + + + function addSide( side, sideBefore, sideAfter, cornerBefore, cornerAfter, baseAngle ) { + var vert = side === 'l' || side === 'r', + sideW = pxWidths[ side ], + beforeX, beforeY, afterX, afterY; + + if( sideW > 0 && styles[ side ] !== 'none' && colors[ side ].alpha() > 0 ) { + beforeX = pxWidths[ vert ? side : sideBefore ]; + beforeY = pxWidths[ vert ? sideBefore : side ]; + afterX = pxWidths[ vert ? side : sideAfter ]; + afterY = pxWidths[ vert ? sideAfter : side ]; + + if( styles[ side ] === 'dashed' || styles[ side ] === 'dotted' ) { + segments.push( { + path: curve( cornerBefore, beforeX, beforeY, baseAngle + 45, 0, 1 ) + + curve( cornerBefore, 0, 0, baseAngle, 1, 0 ), + fill: colors[ side ] + } ); + segments.push( { + path: line( side, sideW / 2, 0, 1 ), + stroke: styles[ side ], + weight: sideW, + color: colors[ side ] + } ); + segments.push( { + path: curve( cornerAfter, afterX, afterY, baseAngle, 0, 1 ) + + curve( cornerAfter, 0, 0, baseAngle - 45, 1, 0 ), + fill: colors[ side ] + } ); + } + else { + segments.push( { + path: curve( cornerBefore, beforeX, beforeY, baseAngle + 45, 0, 1 ) + + line( side, sideW, 0, 0 ) + + curve( cornerAfter, afterX, afterY, baseAngle, 0, 0 ) + + + ( styles[ side ] === 'double' && sideW > 2 ? + curve( cornerAfter, afterX - floor( afterX / 3 ), afterY - floor( afterY / 3 ), baseAngle - 45, 1, 0 ) + + line( side, ceil( sideW / 3 * 2 ), 1, 0 ) + + curve( cornerBefore, beforeX - floor( beforeX / 3 ), beforeY - floor( beforeY / 3 ), baseAngle, 1, 0 ) + + 'x ' + + curve( cornerBefore, floor( beforeX / 3 ), floor( beforeY / 3 ), baseAngle + 45, 0, 1 ) + + line( side, floor( sideW / 3 ), 1, 0 ) + + curve( cornerAfter, floor( afterX / 3 ), floor( afterY / 3 ), baseAngle, 0, 0 ) + : '' ) + + + curve( cornerAfter, 0, 0, baseAngle - 45, 1, 0 ) + + line( side, 0, 1, 0 ) + + curve( cornerBefore, 0, 0, baseAngle, 1, 0 ), + fill: colors[ side ] + } ); + } + } + } + + addSide( 't', 'l', 'r', 'tl', 'tr', 90 ); + addSide( 'r', 't', 'b', 'tr', 'br', 0 ); + addSide( 'b', 'r', 'l', 'br', 'bl', -90 ); + addSide( 'l', 'b', 't', 'bl', 'tl', -180 ); + } + } + + return segments; + }, + + destroy: function() { + var me = this; + if (me.finalized || !me.styleInfos.borderImageInfo.isActive()) { + me.targetElement.runtimeStyle.borderColor = ''; + } + PIE.RendererBase.destroy.call( me ); + } + + +} ); +/** + * Renderer for border-image + * @constructor + * @param {Element} el The target element + * @param {Object} styleInfos The StyleInfo objects + * @param {PIE.RootRenderer} parent + */ +PIE.BorderImageRenderer = PIE.RendererBase.newRenderer( { + + boxZIndex: 5, + pieceNames: [ 't', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl', 'c' ], + + needsUpdate: function() { + return this.styleInfos.borderImageInfo.changed(); + }, + + isActive: function() { + return this.styleInfos.borderImageInfo.isActive(); + }, + + draw: function() { + this.getBox(); //make sure pieces are created + + var props = this.styleInfos.borderImageInfo.getProps(), + borderProps = this.styleInfos.borderInfo.getProps(), + bounds = this.boundsInfo.getBounds(), + el = this.targetElement, + pieces = this.pieces; + + PIE.Util.withImageSize( props.src, function( imgSize ) { + var elW = bounds.w, + elH = bounds.h, + zero = PIE.getLength( '0' ), + widths = props.widths || ( borderProps ? borderProps.widths : { 't': zero, 'r': zero, 'b': zero, 'l': zero } ), + widthT = widths['t'].pixels( el ), + widthR = widths['r'].pixels( el ), + widthB = widths['b'].pixels( el ), + widthL = widths['l'].pixels( el ), + slices = props.slice, + sliceT = slices['t'].pixels( el ), + sliceR = slices['r'].pixels( el ), + sliceB = slices['b'].pixels( el ), + sliceL = slices['l'].pixels( el ); + + // Piece positions and sizes + function setSizeAndPos( piece, w, h, x, y ) { + var s = pieces[piece].style, + max = Math.max; + s.width = max(w, 0); + s.height = max(h, 0); + s.left = x; + s.top = y; + } + setSizeAndPos( 'tl', widthL, widthT, 0, 0 ); + setSizeAndPos( 't', elW - widthL - widthR, widthT, widthL, 0 ); + setSizeAndPos( 'tr', widthR, widthT, elW - widthR, 0 ); + setSizeAndPos( 'r', widthR, elH - widthT - widthB, elW - widthR, widthT ); + setSizeAndPos( 'br', widthR, widthB, elW - widthR, elH - widthB ); + setSizeAndPos( 'b', elW - widthL - widthR, widthB, widthL, elH - widthB ); + setSizeAndPos( 'bl', widthL, widthB, 0, elH - widthB ); + setSizeAndPos( 'l', widthL, elH - widthT - widthB, 0, widthT ); + setSizeAndPos( 'c', elW - widthL - widthR, elH - widthT - widthB, widthL, widthT ); + + + // image croppings + function setCrops( sides, crop, val ) { + for( var i=0, len=sides.length; i < len; i++ ) { + pieces[ sides[i] ]['imagedata'][ crop ] = val; + } + } + + // corners + setCrops( [ 'tl', 't', 'tr' ], 'cropBottom', ( imgSize.h - sliceT ) / imgSize.h ); + setCrops( [ 'tl', 'l', 'bl' ], 'cropRight', ( imgSize.w - sliceL ) / imgSize.w ); + setCrops( [ 'bl', 'b', 'br' ], 'cropTop', ( imgSize.h - sliceB ) / imgSize.h ); + setCrops( [ 'tr', 'r', 'br' ], 'cropLeft', ( imgSize.w - sliceR ) / imgSize.w ); + + // edges and center + // TODO right now this treats everything like 'stretch', need to support other schemes + //if( props.repeat.v === 'stretch' ) { + setCrops( [ 'l', 'r', 'c' ], 'cropTop', sliceT / imgSize.h ); + setCrops( [ 'l', 'r', 'c' ], 'cropBottom', sliceB / imgSize.h ); + //} + //if( props.repeat.h === 'stretch' ) { + setCrops( [ 't', 'b', 'c' ], 'cropLeft', sliceL / imgSize.w ); + setCrops( [ 't', 'b', 'c' ], 'cropRight', sliceR / imgSize.w ); + //} + + // center fill + pieces['c'].style.display = props.fill ? '' : 'none'; + }, this ); + }, + + getBox: function() { + var box = this.parent.getLayer( this.boxZIndex ), + s, piece, i, + pieceNames = this.pieceNames, + len = pieceNames.length; + + if( !box ) { + box = doc.createElement( 'border-image' ); + s = box.style; + s.position = 'absolute'; + + this.pieces = {}; + + for( i = 0; i < len; i++ ) { + piece = this.pieces[ pieceNames[i] ] = PIE.Util.createVmlElement( 'rect' ); + piece.appendChild( PIE.Util.createVmlElement( 'imagedata' ) ); + s = piece.style; + s['behavior'] = 'url(#default#VML)'; + s.position = "absolute"; + s.top = s.left = 0; + piece['imagedata'].src = this.styleInfos.borderImageInfo.getProps().src; + piece.stroked = false; + piece.filled = false; + box.appendChild( piece ); + } + + this.parent.addLayer( this.boxZIndex, box ); + } + + return box; + }, + + prepareUpdate: function() { + if (this.isActive()) { + var me = this, + el = me.targetElement, + rs = el.runtimeStyle, + widths = me.styleInfos.borderImageInfo.getProps().widths; + + // Force border-style to solid so it doesn't collapse + rs.borderStyle = 'solid'; + + // If widths specified in border-image shorthand, override border-width + // NOTE px units needed here as this gets used by the IE9 renderer too + if ( widths ) { + rs.borderTopWidth = widths['t'].pixels( el ) + 'px'; + rs.borderRightWidth = widths['r'].pixels( el ) + 'px'; + rs.borderBottomWidth = widths['b'].pixels( el ) + 'px'; + rs.borderLeftWidth = widths['l'].pixels( el ) + 'px'; + } + + // Make the border transparent + me.hideBorder(); + } + }, + + destroy: function() { + var me = this, + rs = me.targetElement.runtimeStyle; + rs.borderStyle = ''; + if (me.finalized || !me.styleInfos.borderInfo.isActive()) { + rs.borderColor = rs.borderWidth = ''; + } + PIE.RendererBase.destroy.call( this ); + } + +} ); +/** + * Renderer for outset box-shadows + * @constructor + * @param {Element} el The target element + * @param {Object} styleInfos The StyleInfo objects + * @param {PIE.RootRenderer} parent + */ +PIE.BoxShadowOutsetRenderer = PIE.RendererBase.newRenderer( { + + boxZIndex: 1, + boxName: 'outset-box-shadow', + + needsUpdate: function() { + var si = this.styleInfos; + return si.boxShadowInfo.changed() || si.borderRadiusInfo.changed(); + }, + + isActive: function() { + var boxShadowInfo = this.styleInfos.boxShadowInfo; + return boxShadowInfo.isActive() && boxShadowInfo.getProps().outset[0]; + }, + + draw: function() { + var me = this, + el = this.targetElement, + box = this.getBox(), + styleInfos = this.styleInfos, + shadowInfos = styleInfos.boxShadowInfo.getProps().outset, + radii = styleInfos.borderRadiusInfo.getProps(), + len = shadowInfos.length, + i = len, j, + bounds = this.boundsInfo.getBounds(), + w = bounds.w, + h = bounds.h, + clipAdjust = PIE.ieVersion === 8 ? 1 : 0, //workaround for IE8 bug where VML leaks out top/left of clip region by 1px + corners = [ 'tl', 'tr', 'br', 'bl' ], corner, + shadowInfo, shape, fill, ss, xOff, yOff, spread, blur, shrink, color, alpha, path, + totalW, totalH, focusX, focusY, isBottom, isRight; + + + function getShadowShape( index, corner, xOff, yOff, color, blur, path ) { + var shape = me.getShape( 'shadow' + index + corner, 'fill', box, len - index ), + fill = shape.fill; + + // Position and size + shape['coordsize'] = w * 2 + ',' + h * 2; + shape['coordorigin'] = '1,1'; + + // Color and opacity + shape['stroked'] = false; + shape['filled'] = true; + fill.color = color.colorValue( el ); + if( blur ) { + fill['type'] = 'gradienttitle'; //makes the VML gradient follow the shape's outline - hooray for undocumented features?!?! + fill['color2'] = fill.color; + fill['opacity'] = 0; + } + + // Path + shape.path = path; + + // This needs to go last for some reason, to prevent rendering at incorrect size + ss = shape.style; + ss.left = xOff; + ss.top = yOff; + ss.width = w; + ss.height = h; + + return shape; + } + + + while( i-- ) { + shadowInfo = shadowInfos[ i ]; + xOff = shadowInfo.xOffset.pixels( el ); + yOff = shadowInfo.yOffset.pixels( el ); + spread = shadowInfo.spread.pixels( el ); + blur = shadowInfo.blur.pixels( el ); + color = shadowInfo.color; + // Shape path + shrink = -spread - blur; + if( !radii && blur ) { + // If blurring, use a non-null border radius info object so that getBoxPath will + // round the corners of the expanded shadow shape rather than squaring them off. + radii = PIE.BorderRadiusStyleInfo.ALL_ZERO; + } + path = this.getBoxPath( { t: shrink, r: shrink, b: shrink, l: shrink }, 2, radii ); + + if( blur ) { + totalW = ( spread + blur ) * 2 + w; + totalH = ( spread + blur ) * 2 + h; + focusX = totalW ? blur * 2 / totalW : 0; + focusY = totalH ? blur * 2 / totalH : 0; + if( blur - spread > w / 2 || blur - spread > h / 2 ) { + // If the blur is larger than half the element's narrowest dimension, we cannot do + // this with a single shape gradient, because its focussize would have to be less than + // zero which results in ugly artifacts. Instead we create four shapes, each with its + // gradient focus past center, and then clip them so each only shows the quadrant + // opposite the focus. + for( j = 4; j--; ) { + corner = corners[j]; + isBottom = corner.charAt( 0 ) === 'b'; + isRight = corner.charAt( 1 ) === 'r'; + shape = getShadowShape( i, corner, xOff, yOff, color, blur, path ); + fill = shape.fill; + fill['focusposition'] = ( isRight ? 1 - focusX : focusX ) + ',' + + ( isBottom ? 1 - focusY : focusY ); + fill['focussize'] = '0,0'; + + // Clip to show only the appropriate quadrant. Add 1px to the top/left clip values + // in IE8 to prevent a bug where IE8 displays one pixel outside the clip region. + shape.style.clip = 'rect(' + ( ( isBottom ? totalH / 2 : 0 ) + clipAdjust ) + 'px,' + + ( isRight ? totalW : totalW / 2 ) + 'px,' + + ( isBottom ? totalH : totalH / 2 ) + 'px,' + + ( ( isRight ? totalW / 2 : 0 ) + clipAdjust ) + 'px)'; + } + } else { + // TODO delete old quadrant shapes if resizing expands past the barrier + shape = getShadowShape( i, '', xOff, yOff, color, blur, path ); + fill = shape.fill; + fill['focusposition'] = focusX + ',' + focusY; + fill['focussize'] = ( 1 - focusX * 2 ) + ',' + ( 1 - focusY * 2 ); + } + } else { + shape = getShadowShape( i, '', xOff, yOff, color, blur, path ); + alpha = color.alpha(); + if( alpha < 1 ) { + // shape.style.filter = 'alpha(opacity=' + ( alpha * 100 ) + ')'; + // ss.filter = 'progid:DXImageTransform.Microsoft.BasicImage(opacity=' + ( alpha ) + ')'; + shape.fill.opacity = alpha; + } + } + } + } + +} ); +/** + * Renderer for re-rendering img elements using VML. Kicks in if the img has + * a border-radius applied, or if the -pie-png-fix flag is set. + * @constructor + * @param {Element} el The target element + * @param {Object} styleInfos The StyleInfo objects + * @param {PIE.RootRenderer} parent + */ +PIE.ImgRenderer = PIE.RendererBase.newRenderer( { + + boxZIndex: 6, + boxName: 'imgEl', + + needsUpdate: function() { + var si = this.styleInfos; + return this.targetElement.src !== this._lastSrc || si.borderRadiusInfo.changed(); + }, + + isActive: function() { + var si = this.styleInfos; + return si.borderRadiusInfo.isActive() || si.backgroundInfo.isPngFix(); + }, + + draw: function() { + this._lastSrc = src; + this.hideActualImg(); + + var shape = this.getShape( 'img', 'fill', this.getBox() ), + fill = shape.fill, + bounds = this.boundsInfo.getBounds(), + w = bounds.w, + h = bounds.h, + borderProps = this.styleInfos.borderInfo.getProps(), + borderWidths = borderProps && borderProps.widths, + el = this.targetElement, + src = el.src, + round = Math.round, + cs = el.currentStyle, + getLength = PIE.getLength, + s, zero; + + // In IE6, the BorderRenderer will have hidden the border by moving the border-width to + // the padding; therefore we want to pretend the borders have no width so they aren't doubled + // when adding in the current padding value below. + if( !borderWidths || PIE.ieVersion < 7 ) { + zero = PIE.getLength( '0' ); + borderWidths = { 't': zero, 'r': zero, 'b': zero, 'l': zero }; + } + + shape.stroked = false; + fill.type = 'frame'; + fill.src = src; + fill.position = (w ? 0.5 / w : 0) + ',' + (h ? 0.5 / h : 0); + shape.coordsize = w * 2 + ',' + h * 2; + shape.coordorigin = '1,1'; + shape.path = this.getBoxPath( { + t: round( borderWidths['t'].pixels( el ) + getLength( cs.paddingTop ).pixels( el ) ), + r: round( borderWidths['r'].pixels( el ) + getLength( cs.paddingRight ).pixels( el ) ), + b: round( borderWidths['b'].pixels( el ) + getLength( cs.paddingBottom ).pixels( el ) ), + l: round( borderWidths['l'].pixels( el ) + getLength( cs.paddingLeft ).pixels( el ) ) + }, 2 ); + s = shape.style; + s.width = w; + s.height = h; + }, + + hideActualImg: function() { + this.targetElement.runtimeStyle.filter = 'alpha(opacity=0)'; + }, + + destroy: function() { + PIE.RendererBase.destroy.call( this ); + this.targetElement.runtimeStyle.filter = ''; + } + +} ); +/** + * Root renderer for IE9; manages the rendering layers in the element's background + * @param {Element} el The target element + * @param {Object} styleInfos The StyleInfo objects + */ +PIE.IE9RootRenderer = PIE.RendererBase.newRenderer( { + + updatePos: PIE.emptyFn, + updateSize: PIE.emptyFn, + updateVisibility: PIE.emptyFn, + updateProps: PIE.emptyFn, + + outerCommasRE: /^,+|,+$/g, + innerCommasRE: /,+/g, + + setBackgroundLayer: function(zIndex, bg) { + var me = this, + bgLayers = me._bgLayers || ( me._bgLayers = [] ), + undef; + bgLayers[zIndex] = bg || undef; + }, + + finishUpdate: function() { + var me = this, + bgLayers = me._bgLayers, + bg; + if( bgLayers && ( bg = bgLayers.join( ',' ).replace( me.outerCommasRE, '' ).replace( me.innerCommasRE, ',' ) ) !== me._lastBg ) { + me._lastBg = me.targetElement.runtimeStyle.background = bg; + } + }, + + destroy: function() { + this.targetElement.runtimeStyle.background = ''; + delete this._bgLayers; + } + +} ); +/** + * Renderer for element backgrounds, specific for IE9. Only handles translating CSS3 gradients + * to an equivalent SVG data URI. + * @constructor + * @param {Element} el The target element + * @param {Object} styleInfos The StyleInfo objects + */ +PIE.IE9BackgroundRenderer = PIE.RendererBase.newRenderer( { + + bgLayerZIndex: 1, + + needsUpdate: function() { + var si = this.styleInfos; + return si.backgroundInfo.changed(); + }, + + isActive: function() { + var si = this.styleInfos; + return si.backgroundInfo.isActive() || si.borderImageInfo.isActive(); + }, + + draw: function() { + var me = this, + props = me.styleInfos.backgroundInfo.getProps(), + bg, images, i = 0, img, bgAreaSize, bgSize; + + if ( props ) { + bg = []; + + images = props.bgImages; + if ( images ) { + while( img = images[ i++ ] ) { + if (img.imgType === 'linear-gradient' ) { + bgAreaSize = me.getBgAreaSize( img.bgOrigin ); + bgSize = ( img.bgSize || PIE.BgSize.DEFAULT ).pixels( + me.targetElement, bgAreaSize.w, bgAreaSize.h, bgAreaSize.w, bgAreaSize.h + ), + bg.push( + 'url(data:image/svg+xml,' + escape( me.getGradientSvg( img, bgSize.w, bgSize.h ) ) + ') ' + + me.bgPositionToString( img.bgPosition ) + ' / ' + bgSize.w + 'px ' + bgSize.h + 'px ' + + ( img.bgAttachment || '' ) + ' ' + ( img.bgOrigin || '' ) + ' ' + ( img.bgClip || '' ) + ); + } else { + bg.push( img.origString ); + } + } + } + + if ( props.color ) { + bg.push( props.color.val ); + } + + me.parent.setBackgroundLayer(me.bgLayerZIndex, bg.join(',')); + } + }, + + bgPositionToString: function( bgPosition ) { + return bgPosition ? bgPosition.tokens.map(function(token) { + return token.tokenValue; + }).join(' ') : '0 0'; + }, + + getBgAreaSize: function( bgOrigin ) { + var me = this, + el = me.targetElement, + bounds = me.boundsInfo.getBounds(), + elW = bounds.w, + elH = bounds.h, + w = elW, + h = elH, + borders, getLength, cs; + + if( bgOrigin !== 'border-box' ) { + borders = me.styleInfos.borderInfo.getProps(); + if( borders && ( borders = borders.widths ) ) { + w -= borders[ 'l' ].pixels( el ) + borders[ 'l' ].pixels( el ); + h -= borders[ 't' ].pixels( el ) + borders[ 'b' ].pixels( el ); + } + } + + if ( bgOrigin === 'content-box' ) { + getLength = PIE.getLength; + cs = el.currentStyle; + w -= getLength( cs.paddingLeft ).pixels( el ) + getLength( cs.paddingRight ).pixels( el ); + h -= getLength( cs.paddingTop ).pixels( el ) + getLength( cs.paddingBottom ).pixels( el ); + } + + return { w: w, h: h }; + }, + + getGradientSvg: function( info, bgWidth, bgHeight ) { + var el = this.targetElement, + stopsInfo = info.stops, + stopCount = stopsInfo.length, + metrics = PIE.GradientUtil.getGradientMetrics( el, bgWidth, bgHeight, info ), + startX = metrics.startX, + startY = metrics.startY, + endX = metrics.endX, + endY = metrics.endY, + lineLength = metrics.lineLength, + stopPx, + i, j, before, after, + svg; + + // Find the pixel offsets along the CSS3 gradient-line for each stop. + stopPx = []; + for( i = 0; i < stopCount; i++ ) { + stopPx.push( stopsInfo[i].offset ? stopsInfo[i].offset.pixels( el, lineLength ) : + i === 0 ? 0 : i === stopCount - 1 ? lineLength : null ); + } + // Fill in gaps with evenly-spaced offsets + for( i = 1; i < stopCount; i++ ) { + if( stopPx[ i ] === null ) { + before = stopPx[ i - 1 ]; + j = i; + do { + after = stopPx[ ++j ]; + } while( after === null ); + stopPx[ i ] = before + ( after - before ) / ( j - i + 1 ); + } + } + + svg = [ + '' + + '' + + '' + ]; + + // Convert to percentage along the SVG gradient line and add to the stops list + for( i = 0; i < stopCount; i++ ) { + svg.push( + '' + ); + } + + svg.push( + '' + + '' + + '' + + '' + ); + + return svg.join( '' ); + }, + + destroy: function() { + this.parent.setBackgroundLayer( this.bgLayerZIndex ); + } + +} ); +/** + * Renderer for border-image + * @constructor + * @param {Element} el The target element + * @param {Object} styleInfos The StyleInfo objects + * @param {PIE.RootRenderer} parent + */ +PIE.IE9BorderImageRenderer = PIE.RendererBase.newRenderer( { + + REPEAT: 'repeat', + STRETCH: 'stretch', + ROUND: 'round', + + bgLayerZIndex: 0, + + needsUpdate: function() { + return this.styleInfos.borderImageInfo.changed(); + }, + + isActive: function() { + return this.styleInfos.borderImageInfo.isActive(); + }, + + draw: function() { + var me = this, + props = me.styleInfos.borderImageInfo.getProps(), + borderProps = me.styleInfos.borderInfo.getProps(), + bounds = me.boundsInfo.getBounds(), + repeat = props.repeat, + repeatH = repeat.h, + repeatV = repeat.v, + el = me.targetElement, + isAsync = 0; + + PIE.Util.withImageSize( props.src, function( imgSize ) { + var elW = bounds.w, + elH = bounds.h, + imgW = imgSize.w, + imgH = imgSize.h, + + // The image cannot be referenced as a URL directly in the SVG because IE9 throws a strange + // security exception (perhaps due to cross-origin policy within data URIs?) Therefore we + // work around this by converting the image data into a data URI itself using a transient + // canvas. This unfortunately requires the border-image src to be within the same domain, + // which isn't a limitation in true border-image, so we need to try and find a better fix. + imgSrc = me.imageToDataURI( props.src, imgW, imgH ), + + REPEAT = me.REPEAT, + STRETCH = me.STRETCH, + ROUND = me.ROUND, + ceil = Math.ceil, + + zero = PIE.getLength( '0' ), + widths = props.widths || ( borderProps ? borderProps.widths : { 't': zero, 'r': zero, 'b': zero, 'l': zero } ), + widthT = widths['t'].pixels( el ), + widthR = widths['r'].pixels( el ), + widthB = widths['b'].pixels( el ), + widthL = widths['l'].pixels( el ), + slices = props.slice, + sliceT = slices['t'].pixels( el ), + sliceR = slices['r'].pixels( el ), + sliceB = slices['b'].pixels( el ), + sliceL = slices['l'].pixels( el ), + centerW = elW - widthL - widthR, + middleH = elH - widthT - widthB, + imgCenterW = imgW - sliceL - sliceR, + imgMiddleH = imgH - sliceT - sliceB, + + // Determine the size of each tile - 'round' is handled below + tileSizeT = repeatH === STRETCH ? centerW : imgCenterW * widthT / sliceT, + tileSizeR = repeatV === STRETCH ? middleH : imgMiddleH * widthR / sliceR, + tileSizeB = repeatH === STRETCH ? centerW : imgCenterW * widthB / sliceB, + tileSizeL = repeatV === STRETCH ? middleH : imgMiddleH * widthL / sliceL, + + svg, + patterns = [], + rects = [], + i = 0; + + // For 'round', subtract from each tile's size enough so that they fill the space a whole number of times + if (repeatH === ROUND) { + tileSizeT -= (tileSizeT - (centerW % tileSizeT || tileSizeT)) / ceil(centerW / tileSizeT); + tileSizeB -= (tileSizeB - (centerW % tileSizeB || tileSizeB)) / ceil(centerW / tileSizeB); + } + if (repeatV === ROUND) { + tileSizeR -= (tileSizeR - (middleH % tileSizeR || tileSizeR)) / ceil(middleH / tileSizeR); + tileSizeL -= (tileSizeL - (middleH % tileSizeL || tileSizeL)) / ceil(middleH / tileSizeL); + } + + + // Build the SVG for the border-image rendering. Add each piece as a pattern, which is then stretched + // or repeated as the fill of a rect of appropriate size. + svg = [ + '' + ]; + + function addImage( x, y, w, h, cropX, cropY, cropW, cropH, tileW, tileH ) { + patterns.push( + '' + + '' + + '' + + '' + + '' + ); + rects.push( + '' + ); + i++; + } + addImage( 0, 0, widthL, widthT, 0, 0, sliceL, sliceT, widthL, widthT ); // top left + addImage( widthL, 0, centerW, widthT, sliceL, 0, imgCenterW, sliceT, tileSizeT, widthT ); // top center + addImage( elW - widthR, 0, widthR, widthT, imgW - sliceR, 0, sliceR, sliceT, widthR, widthT ); // top right + addImage( 0, widthT, widthL, middleH, 0, sliceT, sliceL, imgMiddleH, widthL, tileSizeL ); // middle left + if ( props.fill ) { // center fill + addImage( widthL, widthT, centerW, middleH, sliceL, sliceT, imgCenterW, imgMiddleH, + tileSizeT || tileSizeB || imgCenterW, tileSizeL || tileSizeR || imgMiddleH ); + } + addImage( elW - widthR, widthT, widthR, middleH, imgW - sliceR, sliceT, sliceR, imgMiddleH, widthR, tileSizeR ); // middle right + addImage( 0, elH - widthB, widthL, widthB, 0, imgH - sliceB, sliceL, sliceB, widthL, widthB ); // bottom left + addImage( widthL, elH - widthB, centerW, widthB, sliceL, imgH - sliceB, imgCenterW, sliceB, tileSizeB, widthB ); // bottom center + addImage( elW - widthR, elH - widthB, widthR, widthB, imgW - sliceR, imgH - sliceB, sliceR, sliceB, widthR, widthB ); // bottom right + + svg.push( + '' + + patterns.join('\n') + + '' + + rects.join('\n') + + '' + ); + + me.parent.setBackgroundLayer( me.bgLayerZIndex, 'url(data:image/svg+xml,' + escape( svg.join( '' ) ) + ') no-repeat border-box border-box' ); + + // If the border-image's src wasn't immediately available, the SVG for its background layer + // will have been created asynchronously after the main element's update has finished; we'll + // therefore need to force the root renderer to sync to the final background once finished. + if( isAsync ) { + me.parent.finishUpdate(); + } + }, me ); + + isAsync = 1; + }, + + /** + * Convert a given image to a data URI + */ + imageToDataURI: (function() { + var uris = {}; + return function( src, width, height ) { + var uri = uris[ src ], + image, canvas; + if ( !uri ) { + image = new Image(); + canvas = doc.createElement( 'canvas' ); + image.src = src; + canvas.width = width; + canvas.height = height; + canvas.getContext( '2d' ).drawImage( image, 0, 0 ); + uri = uris[ src ] = canvas.toDataURL(); + } + return uri; + } + })(), + + prepareUpdate: PIE.BorderImageRenderer.prototype.prepareUpdate, + + destroy: function() { + var me = this, + rs = me.targetElement.runtimeStyle; + me.parent.setBackgroundLayer( me.bgLayerZIndex ); + rs.borderColor = rs.borderStyle = rs.borderWidth = ''; + } + +} ); + +PIE.Element = (function() { + + var wrappers = {}, + lazyInitCssProp = PIE.CSS_PREFIX + 'lazy-init', + pollCssProp = PIE.CSS_PREFIX + 'poll', + trackActiveCssProp = PIE.CSS_PREFIX + 'track-active', + trackHoverCssProp = PIE.CSS_PREFIX + 'track-hover', + hoverClass = PIE.CLASS_PREFIX + 'hover', + activeClass = PIE.CLASS_PREFIX + 'active', + focusClass = PIE.CLASS_PREFIX + 'focus', + firstChildClass = PIE.CLASS_PREFIX + 'first-child', + ignorePropertyNames = { 'background':1, 'bgColor':1, 'display': 1 }, + classNameRegExes = {}, + dummyArray = []; + + + function addClass( el, className ) { + el.className += ' ' + className; + } + + function removeClass( el, className ) { + var re = classNameRegExes[ className ] || + ( classNameRegExes[ className ] = new RegExp( '\\b' + className + '\\b', 'g' ) ); + el.className = el.className.replace( re, '' ); + } + + function delayAddClass( el, className /*, className2*/ ) { + var classes = dummyArray.slice.call( arguments, 1 ), + i = classes.length; + setTimeout( function() { + if( el ) { + while( i-- ) { + addClass( el, classes[ i ] ); + } + } + }, 0 ); + } + + function delayRemoveClass( el, className /*, className2*/ ) { + var classes = dummyArray.slice.call( arguments, 1 ), + i = classes.length; + setTimeout( function() { + if( el ) { + while( i-- ) { + removeClass( el, classes[ i ] ); + } + } + }, 0 ); + } + + + + function Element( el ) { + var renderers, + rootRenderer, + boundsInfo = new PIE.BoundsInfo( el ), + styleInfos, + styleInfosArr, + initializing, + initialized, + eventsAttached, + eventListeners = [], + delayed, + destroyed, + poll; + + /** + * Initialize PIE for this element. + */ + function init() { + if( !initialized ) { + var docEl, + bounds, + ieDocMode = PIE.ieDocMode, + cs = el.currentStyle, + lazy = cs.getAttribute( lazyInitCssProp ) === 'true', + trackActive = cs.getAttribute( trackActiveCssProp ) !== 'false', + trackHover = cs.getAttribute( trackHoverCssProp ) !== 'false', + childRenderers; + + // Polling for size/position changes: default to on in IE8, off otherwise, overridable by -pie-poll + poll = cs.getAttribute( pollCssProp ); + poll = ieDocMode > 7 ? poll !== 'false' : poll === 'true'; + + // Force layout so move/resize events will fire. Set this as soon as possible to avoid layout changes + // after load, but make sure it only gets called the first time through to avoid recursive calls to init(). + if( !initializing ) { + initializing = 1; + el.runtimeStyle.zoom = 1; + initFirstChildPseudoClass(); + } + + boundsInfo.lock(); + + // If the -pie-lazy-init:true flag is set, check if the element is outside the viewport and if so, delay initialization + if( lazy && ( bounds = boundsInfo.getBounds() ) && ( docEl = doc.documentElement || doc.body ) && + ( bounds.y > docEl.clientHeight || bounds.x > docEl.clientWidth || bounds.y + bounds.h < 0 || bounds.x + bounds.w < 0 ) ) { + if( !delayed ) { + delayed = 1; + PIE.OnScroll.observe( init ); + } + } else { + initialized = 1; + delayed = initializing = 0; + PIE.OnScroll.unobserve( init ); + + // Create the style infos and renderers + if ( ieDocMode === 9 ) { + styleInfos = { + backgroundInfo: new PIE.BackgroundStyleInfo( el ), + borderImageInfo: new PIE.BorderImageStyleInfo( el ), + borderInfo: new PIE.BorderStyleInfo( el ) + }; + styleInfosArr = [ + styleInfos.backgroundInfo, + styleInfos.borderImageInfo + ]; + rootRenderer = new PIE.IE9RootRenderer( el, boundsInfo, styleInfos ); + childRenderers = [ + new PIE.IE9BackgroundRenderer( el, boundsInfo, styleInfos, rootRenderer ), + new PIE.IE9BorderImageRenderer( el, boundsInfo, styleInfos, rootRenderer ) + ]; + } else { + + styleInfos = { + backgroundInfo: new PIE.BackgroundStyleInfo( el ), + borderInfo: new PIE.BorderStyleInfo( el ), + borderImageInfo: new PIE.BorderImageStyleInfo( el ), + borderRadiusInfo: new PIE.BorderRadiusStyleInfo( el ), + boxShadowInfo: new PIE.BoxShadowStyleInfo( el ), + visibilityInfo: new PIE.VisibilityStyleInfo( el ) + }; + styleInfosArr = [ + styleInfos.backgroundInfo, + styleInfos.borderInfo, + styleInfos.borderImageInfo, + styleInfos.borderRadiusInfo, + styleInfos.boxShadowInfo, + styleInfos.visibilityInfo + ]; + rootRenderer = new PIE.RootRenderer( el, boundsInfo, styleInfos ); + childRenderers = [ + new PIE.BoxShadowOutsetRenderer( el, boundsInfo, styleInfos, rootRenderer ), + new PIE.BackgroundRenderer( el, boundsInfo, styleInfos, rootRenderer ), + //new PIE.BoxShadowInsetRenderer( el, boundsInfo, styleInfos, rootRenderer ), + new PIE.BorderRenderer( el, boundsInfo, styleInfos, rootRenderer ), + new PIE.BorderImageRenderer( el, boundsInfo, styleInfos, rootRenderer ) + ]; + if( el.tagName === 'IMG' ) { + childRenderers.push( new PIE.ImgRenderer( el, boundsInfo, styleInfos, rootRenderer ) ); + } + rootRenderer.childRenderers = childRenderers; // circular reference, can't pass in constructor; TODO is there a cleaner way? + } + renderers = [ rootRenderer ].concat( childRenderers ); + + // Add property change listeners to ancestors if requested + initAncestorEventListeners(); + + // Add to list of polled elements in IE8 + if( poll ) { + PIE.Heartbeat.observe( update ); + PIE.Heartbeat.run(); + } + + // Trigger rendering + update( 1 ); + } + + if( !eventsAttached ) { + eventsAttached = 1; + if( ieDocMode < 9 ) { + addListener( el, 'onmove', handleMoveOrResize ); + } + addListener( el, 'onresize', handleMoveOrResize ); + addListener( el, 'onpropertychange', propChanged ); + if( trackHover ) { + addListener( el, 'onmouseenter', mouseEntered ); + } + if( trackHover || trackActive ) { + addListener( el, 'onmouseleave', mouseLeft ); + } + if( trackActive ) { + addListener( el, 'onmousedown', mousePressed ); + } + if( el.tagName in PIE.focusableElements ) { + addListener( el, 'onfocus', focused ); + addListener( el, 'onblur', blurred ); + } + PIE.OnResize.observe( handleMoveOrResize ); + + PIE.OnUnload.observe( removeEventListeners ); + } + + boundsInfo.unlock(); + } + } + + + + + /** + * Event handler for onmove and onresize events. Invokes update() only if the element's + * bounds have previously been calculated, to prevent multiple runs during page load when + * the element has no initial CSS3 properties. + */ + function handleMoveOrResize() { + if( boundsInfo && boundsInfo.hasBeenQueried() ) { + update(); + } + } + + + /** + * Update position and/or size as necessary. Both move and resize events call + * this rather than the updatePos/Size functions because sometimes, particularly + * during page load, one will fire but the other won't. + */ + function update( force ) { + if( !destroyed ) { + if( initialized ) { + var i, len = renderers.length; + + lockAll(); + for( i = 0; i < len; i++ ) { + renderers[i].prepareUpdate(); + } + if( force || boundsInfo.positionChanged() ) { + /* TODO just using getBoundingClientRect (used internally by BoundsInfo) for detecting + position changes may not always be accurate; it's possible that + an element will actually move relative to its positioning parent, but its position + relative to the viewport will stay the same. Need to come up with a better way to + track movement. The most accurate would be the same logic used in RootRenderer.updatePos() + but that is a more expensive operation since it does some DOM walking, and we want this + check to be as fast as possible. */ + for( i = 0; i < len; i++ ) { + renderers[i].updatePos(); + } + } + if( force || boundsInfo.sizeChanged() ) { + for( i = 0; i < len; i++ ) { + renderers[i].updateSize(); + } + } + rootRenderer.finishUpdate(); + unlockAll(); + } + else if( !initializing ) { + init(); + } + } + } + + /** + * Handle property changes to trigger update when appropriate. + */ + function propChanged() { + var i, len = renderers.length, + renderer, + e = event; + + // Some elements like fire onpropertychange events for old-school background properties + // ('background', 'bgColor') when runtimeStyle background properties are changed, which + // results in an infinite loop; therefore we filter out those property names. Also, 'display' + // is ignored because size calculations don't work correctly immediately when its onpropertychange + // event fires, and because it will trigger an onresize event anyway. + if( !destroyed && !( e && e.propertyName in ignorePropertyNames ) ) { + if( initialized ) { + lockAll(); + for( i = 0; i < len; i++ ) { + renderers[i].prepareUpdate(); + } + for( i = 0; i < len; i++ ) { + renderer = renderers[i]; + // Make sure position is synced if the element hasn't already been rendered. + // TODO this feels sloppy - look into merging propChanged and update functions + if( !renderer.isPositioned ) { + renderer.updatePos(); + } + if( renderer.needsUpdate() ) { + renderer.updateProps(); + } + } + rootRenderer.finishUpdate(); + unlockAll(); + } + else if( !initializing ) { + init(); + } + } + } + + + /** + * Handle mouseenter events. Adds a custom class to the element to allow IE6 to add + * hover styles to non-link elements, and to trigger a propertychange update. + */ + function mouseEntered() { + //must delay this because the mouseenter event fires before the :hover styles are added. + delayAddClass( el, hoverClass ); + } + + /** + * Handle mouseleave events + */ + function mouseLeft() { + //must delay this because the mouseleave event fires before the :hover styles are removed. + delayRemoveClass( el, hoverClass, activeClass ); + } + + /** + * Handle mousedown events. Adds a custom class to the element to allow IE6 to add + * active styles to non-link elements, and to trigger a propertychange update. + */ + function mousePressed() { + //must delay this because the mousedown event fires before the :active styles are added. + delayAddClass( el, activeClass ); + + // listen for mouseups on the document; can't just be on the element because the user might + // have dragged out of the element while the mouse button was held down + PIE.OnMouseup.observe( mouseReleased ); + } + + /** + * Handle mouseup events + */ + function mouseReleased() { + //must delay this because the mouseup event fires before the :active styles are removed. + delayRemoveClass( el, activeClass ); + + PIE.OnMouseup.unobserve( mouseReleased ); + } + + /** + * Handle focus events. Adds a custom class to the element to trigger a propertychange update. + */ + function focused() { + //must delay this because the focus event fires before the :focus styles are added. + delayAddClass( el, focusClass ); + } + + /** + * Handle blur events + */ + function blurred() { + //must delay this because the blur event fires before the :focus styles are removed. + delayRemoveClass( el, focusClass ); + } + + + /** + * Handle property changes on ancestors of the element; see initAncestorEventListeners() + * which adds these listeners as requested with the -pie-watch-ancestors CSS property. + */ + function ancestorPropChanged() { + var name = event.propertyName; + if( name === 'className' || name === 'id' ) { + propChanged(); + } + } + + function lockAll() { + boundsInfo.lock(); + for( var i = styleInfosArr.length; i--; ) { + styleInfosArr[i].lock(); + } + } + + function unlockAll() { + for( var i = styleInfosArr.length; i--; ) { + styleInfosArr[i].unlock(); + } + boundsInfo.unlock(); + } + + + function addListener( targetEl, type, handler ) { + targetEl.attachEvent( type, handler ); + eventListeners.push( [ targetEl, type, handler ] ); + } + + /** + * Remove all event listeners from the element and any monitored ancestors. + */ + function removeEventListeners() { + if (eventsAttached) { + var i = eventListeners.length, + listener; + + while( i-- ) { + listener = eventListeners[ i ]; + listener[ 0 ].detachEvent( listener[ 1 ], listener[ 2 ] ); + } + + PIE.OnUnload.unobserve( removeEventListeners ); + eventsAttached = 0; + eventListeners = []; + } + } + + + /** + * Clean everything up when the behavior is removed from the element, or the element + * is manually destroyed. + */ + function destroy() { + if( !destroyed ) { + var i, len; + + removeEventListeners(); + + destroyed = 1; + + // destroy any active renderers + if( renderers ) { + for( i = 0, len = renderers.length; i < len; i++ ) { + renderers[i].finalized = 1; + renderers[i].destroy(); + } + } + + // Remove from list of polled elements in IE8 + if( poll ) { + PIE.Heartbeat.unobserve( update ); + } + // Stop onresize listening + PIE.OnResize.unobserve( update ); + + // Kill references + renderers = boundsInfo = styleInfos = styleInfosArr = el = null; + } + } + + + /** + * If requested via the custom -pie-watch-ancestors CSS property, add onpropertychange and + * other event listeners to ancestor(s) of the element so we can pick up style changes + * based on CSS rules using descendant selectors. + */ + function initAncestorEventListeners() { + var watch = el.currentStyle.getAttribute( PIE.CSS_PREFIX + 'watch-ancestors' ), + i, a; + if( watch ) { + watch = parseInt( watch, 10 ); + i = 0; + a = el.parentNode; + while( a && ( watch === 'NaN' || i++ < watch ) ) { + addListener( a, 'onpropertychange', ancestorPropChanged ); + addListener( a, 'onmouseenter', mouseEntered ); + addListener( a, 'onmouseleave', mouseLeft ); + addListener( a, 'onmousedown', mousePressed ); + if( a.tagName in PIE.focusableElements ) { + addListener( a, 'onfocus', focused ); + addListener( a, 'onblur', blurred ); + } + a = a.parentNode; + } + } + } + + + /** + * If the target element is a first child, add a pie_first-child class to it. This allows using + * the added class as a workaround for the fact that PIE's rendering element breaks the :first-child + * pseudo-class selector. + */ + function initFirstChildPseudoClass() { + var tmpEl = el, + isFirst = 1; + while( tmpEl = tmpEl.previousSibling ) { + if( tmpEl.nodeType === 1 ) { + isFirst = 0; + break; + } + } + if( isFirst ) { + addClass( el, firstChildClass ); + } + } + + + // These methods are all already bound to this instance so there's no need to wrap them + // in a closure to maintain the 'this' scope object when calling them. + this.init = init; + this.update = update; + this.destroy = destroy; + this.el = el; + } + + Element.getInstance = function( el ) { + var id = PIE.Util.getUID( el ); + return wrappers[ id ] || ( wrappers[ id ] = new Element( el ) ); + }; + + Element.destroy = function( el ) { + var id = PIE.Util.getUID( el ), + wrapper = wrappers[ id ]; + if( wrapper ) { + wrapper.destroy(); + delete wrappers[ id ]; + } + }; + + Element.destroyAll = function() { + var els = [], wrapper; + if( wrappers ) { + for( var w in wrappers ) { + if( wrappers.hasOwnProperty( w ) ) { + wrapper = wrappers[ w ]; + els.push( wrapper.el ); + wrapper.destroy(); + } + } + wrappers = {}; + } + return els; + }; + + return Element; +})(); + +/* + * This file exposes the public API for invoking PIE. + */ + + +/** + * @property supportsVML + * True if the current IE browser environment has a functioning VML engine. Should be true + * in most IEs, but in rare cases may be false. If false, PIE will exit immediately when + * attached to an element; this property may be used for debugging or by external scripts + * to perform some special action when VML support is absent. + * @type {boolean} + */ +PIE[ 'supportsVML' ] = PIE.supportsVML; + + +/** + * Programatically attach PIE to a single element. + * @param {Element} el + */ +PIE[ 'attach' ] = function( el ) { + if (PIE.ieDocMode < 10 && PIE.supportsVML) { + PIE.Element.getInstance( el ).init(); + } +}; + + +/** + * Programatically detach PIE from a single element. + * @param {Element} el + */ +PIE[ 'detach' ] = function( el ) { + PIE.Element.destroy( el ); +}; + + +} // if( !PIE ) +})(); \ No newline at end of file diff --git a/assets/lib/pngfix/pngfix.js b/assets/lib/pngfix/pngfix.js new file mode 100644 index 0000000..5fe14a0 --- /dev/null +++ b/assets/lib/pngfix/pngfix.js @@ -0,0 +1,39 @@ +/* + +Correctly handle PNG transparency in Win IE 5.5 & 6. +http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006. + +Use in with DEFER keyword wrapped in conditional comments: + + +*/ + +var arVersion = navigator.appVersion.split("MSIE") +var version = parseFloat(arVersion[1]) + +if ((version >= 5.5) && (document.body.filters)) +{ + for(var i=0; i" + img.outerHTML = strNewHTML + i = i-1 + } + } +} diff --git a/assets/script/compatibility.js b/assets/script/compatibility.js new file mode 100644 index 0000000..e312b36 --- /dev/null +++ b/assets/script/compatibility.js @@ -0,0 +1,51 @@ +if (!document.getElementsByClassName) { + document.getElementsByClassName = function(className) { + return document.querySelectorAll("." + className); + } +} + +if (!window.addEventListener) { + window.addEventListener = window.attachEvent; +} + +function toArray(iter) { + var arr = []; + for (var i = 0; i < iter.length; i++) arr.push(iter[i]); + return arr; +} + +// Fix images not updating on Opera 12.1 - 12.16 (earlier versions still broken) +// https://stackoverflow.com/a/71828058/8618686 +if(window.opera && Object.defineProperty) { + /* if browser is opera presto, updating image elements' sources will not upload the DOM visual. + So we need to do some hacking. Only thing that works is to remove and reAppend the relevant node... */ + Object.defineProperty(HTMLImageElement.prototype, "src", { + enumerable: true, + configurable: true, + get: function() { + return this.getAttribute("src"); + }, + set: function(newSrc) + { + /*max-size confinement is required for presto if parent is display flex. Image will go out of its available size otherwise*/ + this.style.maxHeight = this.style.height; + this.style.maxWidth = this.style.width; + + this.setAttribute("src", newSrc); + + /*we have to put this node back to exactly where we rip it from*/ + var parent = this.parentNode; + if(this.nextElementSibling != null) + { + var reference = this.nextElementSibling; + parent.removeChild(this); + reference.insertAdjacentElement("beforebegin", this); + } + else if (parent) + { + parent.removeChild(this); + parent.appendChild(this); + } + } + }); +} \ No newline at end of file diff --git a/assets/script/inline-code.js b/assets/script/inline-code.js new file mode 100644 index 0000000..61849ad --- /dev/null +++ b/assets/script/inline-code.js @@ -0,0 +1,82 @@ +window.addEventListener("load", function() { + + // Get list of inline code elements + var codes = document.getElementsByClassName("inline-code"); + for (var i = 0; i < codes.length; i++) { + + var code = codes[i]; + var input = code.children[1].children[0]; + + // Select all in input when clicked + input.onclick = function(event) { + console.log(event); + inputSelectAll(event.target); + } + + // Add clipboard icon + // TODO doesn't work on IE8 and below + + var themes = ["dark", "light"]; + for (var j = 0; j < themes.length; j++) { + + var base = "/assets/icons/" + themes[j] + "-mode/"; + + var svg = document.createElement("source"); + svg.type = "image/svg+xml"; + svg.srcset = base + "copy.svg"; + + //var img = document.createElement("img"); + var img = new Image(); + img.style.zIndex = "3"; + img.className = "inline-code-icon inline-code-icon-end " + themes[j]; + img.setAttribute("data-theme", themes[j]); + img.src = base + "copy.png"; + img.alt = "Clipboard Icon"; + img.title = "Copy to clipboard"; + img.onclick = function(event) { + copyInputText( + event.target.parentElement.parentElement.children[1].children[0], + event.target, + event.target.getAttribute("data-theme") + ); + }; + + var picture = document.createElement("picture"); + picture.appendChild(svg); + picture.appendChild(img); + + code.appendChild(picture); + + } + } + +}, false); + +function copyInputText(input, clipboardIcon, theme) { + + inputSelectAll(input); + + var path; + if (document.execCommand("copy")) { + path = "/assets/icons/" + theme + "-mode/"; + } else { + console.log("no"); // TODO X icon + } + + clipboardIcon.src = path + "check.svg"; + clipboardIcon.previousElementSibling.srcset = path + "check.png"; + + input.setSelectionRange(0, 0); + + setTimeout(function() { + clipboardIcon.src = path + "copy.svg"; + clipboardIcon.previousElementSibling.srcset = path + "copy.png"; + }, 1000); + +} + +function inputSelectAll(input) { + input.focus(); + if (input.select) input.select(); + else input.setSelectionRange(0, this.value.length); +} diff --git a/assets/script/navigation.js b/assets/script/navigation.js new file mode 100644 index 0000000..8ee4d23 --- /dev/null +++ b/assets/script/navigation.js @@ -0,0 +1,64 @@ +window.addEventListener("load", makeLinksDynamic, false); + +function makeLinksDynamic() { + var navLinks = document.getElementsByClassName("nav-button"); + for (var i = 0; i < navLinks.length; i++) { + navLinks[i].onclick = function(e) { + + var event = e || window.event; + var target = event.target || event.srcElement; + + if (target.nodeName !== "A" || event.ctrlKey || document.body.className.indexOf("loading") !== -1) return; + + loadUrl(target.href, function() { + if (window.history && history.pushState) { + history.pushState(null, "", target.href); + } + }); + + event.preventDefault(); + event.returnValue = false; + + } + } + +} + +window.addEventListener("popstate", function() { + loadUrl(location.href); +}, false); + +function loadUrl(href, callback) { + + document.body.className += " loading"; + + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (this.readyState === 4) { + + if (this.status !== 200) location.href = href; + + try { + var tags = ["main", "nav"]; + for (var i = 0; i < tags.length; i++) { + document.querySelector(tags[i]).innerHTML = this.responseText.match(new RegExp("<" + tags[i] + ">([\\s\\S]+)<\\/" + tags[i] + ">"))[1]; + } + } catch(e) { + location.href = href; + } + + // Dispatch load event + var loadEvent = document.createEvent('Event'); + loadEvent.initEvent('load', false, false); + window.dispatchEvent(loadEvent); + + if (callback) callback(); + + document.body.className = document.body.className.replace(/\s*loading/g, ""); + + } + } + xhr.open("GET", href); + xhr.send(); + +} \ No newline at end of file diff --git a/assets/script/theme.js b/assets/script/theme.js new file mode 100644 index 0000000..f66097a --- /dev/null +++ b/assets/script/theme.js @@ -0,0 +1,123 @@ +// Enable transitions between themes without reloading page + +var Themes = { + AUTO: "auto", + LIGHT: "light", + DARK: "dark" +}; + +var jsTheme; + +window.addEventListener("load", function() { + + var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; + + // Add trees + if (!document.querySelector(".tree")) { + for (var x = 0; x < width; x += 240) { + var left = x + Math.floor(Math.random() * 240 / 2); + var bottom = Math.floor(Math.random() * 150); + var img = document.createElement("img"); + img.className = "tree"; + img.height = 300; + img.style.position = "fixed"; + img.style.left = left + "px"; + img.style.bottom = bottom + "px"; + document.body.appendChild(img); + } + } + + // Apply current theme + var themeCookie = document.cookie.match(/theme=([a-z]+)/i); + if (themeCookie) applyTheme(themeCookie[1], true); + else applyPreferredTheme(true); + + // Add click listener to theme buttons + var themeBtns = document.getElementsByClassName("theme-btn"); + for (var i = 0; i < themeBtns.length; i++) { + themeBtns[i].onclick = function(e) { + + var event = e || window.event; + var target = event.target || event.srcElement; + + event.returnValue = false; + if (event.preventDefault) event.preventDefault(); + + // Ignore if already selected + if (target.className.indexOf("selected") > -1) return; + + // Get new theme + var theme = target.getAttribute("data-theme"); + + // Apply theme changes + if (theme === Themes.AUTO) { + document.cookie = "theme=; expires=Tue, 19 Jan 2038 03:14:08 GMT"; + applyPreferredTheme(false); + } else { + document.cookie = "theme=" + theme + "; expires=Tue, 19 Jan 2038 03:14:08 GMT" + applyTheme(theme, false); + } + + // Set new selected button + deselectThemeButton(document.querySelector(".theme-btn.selected")); + selectThemeButton(target); + + // Force redrawing of containers because of a bug in IE8 + var containers = document.getElementsByClassName("container"); + for (var i = 0; i < containers.length; i++) containers[i].className += ""; + + } + } + + // Automatically computes the preferred theme and calls applyTheme() with it + function applyPreferredTheme(firstTime) { + var preferredTheme = ("matchMedia" in window && matchMedia("(prefers-color-scheme: dark)").matches) ? Themes.DARK : Themes.LIGHT; + applyTheme(preferredTheme, firstTime); + } + + function applyTheme(theme, firstTime) { + + if (jsTheme && jsTheme.href.match(theme)) return; + + // Set trees + var trees = document.getElementsByClassName("tree"); + for (var i = 0; i < trees.length; i++) { + trees[i].src = "/assets/img/tree_" + theme + ".svg"; + } + + if (!firstTime) { + + if (jsTheme) document.head.removeChild(jsTheme); + jsTheme = document.createElement("link"); + jsTheme.rel = "stylesheet"; + jsTheme.href = "/assets/style/" + theme + "-mode.css"; + document.head.appendChild(jsTheme); + + if (linkOnloadSupported) { + document.body.className += " loading"; + jsTheme.onload = function () { + document.body.className = document.body.className.replace(/\s*loading/g, ""); + var themeStyles = document.getElementsByClassName("theme-style"); + for (var i = 0; i < themeStyles.length; i++) { + document.querySelector("head").removeChild(themeStyles[i]); + } + } + } + + } + + } + + // Functions to select/deselect a theme button + + function selectThemeButton(themeBtn) { + themeBtn.textContent += " ✓"; + themeBtn.className += "selected"; + } + + function deselectThemeButton(themeBtn) { + themeBtn.textContent = themeBtn.textContent.replace(" ✓", ""); + themeBtn.className = themeBtn.className.replace("selected", ""); + } + +}, false); \ No newline at end of file diff --git a/assets/style/dark-mode.css b/assets/style/dark-mode.css new file mode 100644 index 0000000..99b57f6 --- /dev/null +++ b/assets/style/dark-mode.css @@ -0,0 +1,68 @@ +/* Default colors */ +* { + color: #EEE; + scrollbar-color: #424242 #212121; +} +body { + *background-image: url("/assets/img/grass_dark.png"); + background-color: #011C29; + color: #EEE; +} +::selection { + background-color: #EEE; + color: #212121; +} +::-moz-selection { + background-color: #EEE; + color: #212121; +} + +/* Background */ +#grass { + background-color: #265728; +} + +/* Navigation bar */ +.nav-button-not-selected { + border-bottom-color: #757575; +} +.nav-button-not-selected:hover { + border-bottom-color: #EEE; +} + +/* Sections */ +.section hr { + border-color: #757575; + color: #757575; +} + +/* Container */ +.container { + background-color: #424242; + box-shadow: 2px 2px 0 black; + -o-box-shadow: 2px 2px 0 black; + -moz-box-shadow: 2px 2px 0 black; + -webkit-box-shadow: 2px 2px 0 black; +} +.container::selection, .container *::selection { + background-color: #EEE; + color: #424242; +} +.container::-moz-selection, .container *::-moz-selection { + background-color: #EEE; + color: #424242; +} + +.inline-code, .inline-code-text, .inline-code-icon { + background-color: #212121; +} +object[type='image/svg+xml'] { + color: #212121; +} + +.dark { + display: initial !important; +} +.light { + display: none !important; +} \ No newline at end of file diff --git a/assets/style/detect-dark-mode.css b/assets/style/detect-dark-mode.css new file mode 100644 index 0000000..847dc7f --- /dev/null +++ b/assets/style/detect-dark-mode.css @@ -0,0 +1,6 @@ +/* + Imports the dark mode stylesheet only if the browser prefers dark mode + Dark mode can be forced by importing the CSS file below in the HTML + Light mode can be forced by not loading this file at all + */ +@import "/assets/style/dark-mode.css" (prefers-color-scheme: dark); diff --git a/assets/style/light-mode.css b/assets/style/light-mode.css new file mode 100644 index 0000000..3b4ee1f --- /dev/null +++ b/assets/style/light-mode.css @@ -0,0 +1,68 @@ +/* Default colors */ +* { + color: #212121; + scrollbar-color: #BDBDBD #EEE; +} +body { + *background-image: url("/assets/img/grass_light.png"); + background-color: #B3E5FC; + color: #212121; +} +::selection { + background-color: #212121; + color: #EEE; +} +::-moz-selection { + background-color: #212121; + color: #EEE; +} + +/* Background */ +#grass { + background-color: #4CAF50; +} + +/* Navigation bar */ +.nav-button-not-selected { + border-bottom-color: #858585; +} +.nav-button-not-selected:hover { + border-bottom-color: #212121; +} + +/* Section */ +.section hr { + border-color: #E0E0E0; + color: #E0E0E0; +} + +/* Container */ +.container { + background-color: white; + box-shadow: 2px 2px 0 #BDBDBD; + -o-box-shadow: 2px 2px 0 #BDBDBD; + -moz-box-shadow: 2px 2px 0 #BDBDBD; + -webkit-box-shadow: 2px 2px 0 #BDBDBD; +} +.container::selection, .container *::selection { + background-color: #212121; + color: white; +} +.container::-moz-selection, .container *::-moz-selection { + background-color: #212121; + color: white; +} + +.inline-code, .inline-code-text { + background-color: #EEE; +} +object[type='image/svg+xml'] { + color: #EEE; +} + +.light { + display: initial !important; +} +.dark { + display: none !important; +} \ No newline at end of file diff --git a/assets/style/main.css b/assets/style/main.css new file mode 100644 index 0000000..daa9d1d --- /dev/null +++ b/assets/style/main.css @@ -0,0 +1,240 @@ +body { + margin: 0; + overflow-x: hidden; + text-align: center; + position: fixed; + width: 100%; + width: 100vw; + height: 100vh; + font-family: Arial, sans-serif; + /* Prevent user from selecting whitespace between containers */ + user-select: none; + -ms-user-select: none; + -moz-user-select: none; + -khtml-user-select: none; + -webkit-user-select: none; + -webkit-touch-callout: none; + /* Use background image for grass on old IE versions */ + *background-repeat: repeat-x; + *background-position: left bottom; +} +* { + transition: all 0.2s linear, width 0s; + -o-transition: all 0.2s linear, width 0s; + -webkit-transition: all 0.2s linear, width 0s; + -moz-transition: all 0.2s linear, width 0s; +} +a { + outline: none; +} +a:hover { + text-decoration: none; +} +.loading, .loading * { + cursor: wait !important; +} + +/* Background */ +#grass { + height: 150px; + position: fixed; + /**position: absolute;*/ + *display: none; + bottom: 0; + left: 0; + right: 0; + z-index: -2; +} +.tree { + z-index: -1; +} + +/* Navigation bar */ +#nav { + margin: 30px 0; +} +.nav-button { + font-size: 14px; + padding: 5px 10px; + cursor: pointer; + margin: 1px; + border-bottom-width: 3px; + border-bottom-style: solid; + font-weight: bold; + text-decoration: none; + transition: border-bottom-color 0.2s; + -o-transition: border-bottom-color 0.2s; + -moz-transition: border-bottom-color 0.2s; + -webkit-transition: border-bottom-color 0.2s; +} +.nav-button-selected { + border-bottom-color: #2962FF; + cursor: default; +} +.nav-button-selected:hover { + border-bottom-color: #2962FF; +} + +/* Sidebar */ +#sidebar-wrapper { + padding: 0 10px 0 10px; +} +#sidebar { + width: 100px; +} +#sidebar .container { + padding: 10px; + text-align: left; + line-height: 1.5; +} +.theme-btn.selected { + text-decoration: none; + cursor: default; +} + +/* Main section */ +#main-and-sidebar { + direction: rtl; + width: 965px; + max-width: 100%; +} +#main-wrapper { + vertical-align: top; + width: 820px; + max-width: 100%; + padding: 0 10px 20px 10px; + box-sizing: border-box; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + /* Doesn't seem to work */ + /* *behavior: url("/lib/box-sizing-polyfill/boxsizing.htc"); */ +} +#main { + width: 800px; + max-width: 100%; + box-sizing: border-box; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + vertical-align: top; + text-align: left; + line-height: 1.5; +} + +/* Like H1 but without the extra line breaks */ +.title { + font-size: 2em; + font-weight: bold; +} + +/* Sections */ +.section { + padding: 10px; + margin-bottom: 20px; +} +.section hr { + border: none; + border-bottom: 1px solid; + margin: 10px -10px; + *margin: 10px auto; +} + +/* Container */ +.container { + direction: ltr; + /* IE polyfills */ + behavior: url("/assets/lib/css3pie/PIE.htc"); + /* Re-enable user select for text */ + user-select: text; + -ms-user-select: text; + -moz-user-select: text; + -khtml-user-select: text; + -webkit-user-select: text; + -webkit-touch-callout: default; +} + +/* Inline code */ +.inline-code-text { + position: relative; + bottom: 1px; + font-family: Consolas, monospace; + /* Remove default style */ + background-color: inherit; + color: inherit; + border: none; + outline: none; +} +.inline-code { + position: relative; +} +.inline-code-text-wrapper { + position: relative; /* Fix overflow for IE6/7 - https://github.com/logeshpaul/CSS-Hacks#8-overflow-hidden-not-working-on-ie7- */ + margin: 0 21px; + overflow-x: auto; + scrollbar-width: thin; +} +.inline-code-text-wrapper::-webkit-scrollbar { + width: 3px; +} +.inline-code-icon { + position: absolute; + height: 15px; + width: 15px; +} +.inline-code-icon-start { + top: 3px; + left: 4px; +} +.inline-code-icon-end { + top: 4px; + right: 4px; +} +.clipboard-icon { + height: 15px; + cursor: pointer; + background-color: inherit; + padding: 3px 0 3px 0; + float: right; +} + +.icon { + -ms-interpolation-mode: nearest-neighbor; + display: inline-block; + width: 16px; + height: 16px; + background-size: 16px; + position: relative; + top: 3px; + margin-right: 2px; +} +.pixelated { + image-rendering: optimizeSpeed; + image-rendering: -webkit-optimize-contrast; + image-rendering: -moz-crisp-edges; + image-rendering: -o-crisp-edges; + image-rendering: crisp-edges; + image-rendering: pixelated; +} + +/* Fixes */ + +/* IE 9-11 has a bug which makes the ch css unit unusable, this will make it use the inputs size attribute instead */ +/* ch is otherwise used as it is a lot more precise on modern browsers than size */ +@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { + .inline-code-text { + width: auto !important; + } +} +/* Make inline-block work for IE 7 and below */ +/* https://stackoverflow.com/a/5838575/8618686 */ +.inline-block { + display: inline-block; + *display: inline; + zoom: 1; +} +object { + color-scheme: none; /* Remove white background from s in chrome */ + pointer-events: none; /* Fix pointer cursor on svg links */ +} +img { + border: none; /* Fix ico images on internet explorer */ +} \ No newline at end of file diff --git a/background/index.php b/background/index.php new file mode 100644 index 0000000..467ba31 --- /dev/null +++ b/background/index.php @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/dump_request.php b/dump_request.php new file mode 100644 index 0000000..0a552a0 --- /dev/null +++ b/dump_request.php @@ -0,0 +1,11 @@ + $value) + if (substr($name, 0, 5) == 'HTTP_') + echo str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))) . ": $value\r\n"; + + echo "\r\n" . file_get_contents('php://input'); \ No newline at end of file diff --git a/inc/background.inc b/inc/background.inc new file mode 100644 index 0000000..de7b343 --- /dev/null +++ b/inc/background.inc @@ -0,0 +1 @@ +
diff --git a/inc/head.inc b/inc/head.inc new file mode 100644 index 0000000..bcf4ca7 --- /dev/null +++ b/inc/head.inc @@ -0,0 +1,22 @@ + + + + + + + +ReimarPB + + + + + + + + + + + + + + diff --git a/inc/nav.inc b/inc/nav.inc new file mode 100644 index 0000000..846a63c --- /dev/null +++ b/inc/nav.inc @@ -0,0 +1,22 @@ + diff --git a/inc/sidebar.inc b/inc/sidebar.inc new file mode 100644 index 0000000..3b8b2bd --- /dev/null +++ b/inc/sidebar.inc @@ -0,0 +1,22 @@ + \ No newline at end of file diff --git a/inc/theme.inc b/inc/theme.inc new file mode 100644 index 0000000..16ea078 --- /dev/null +++ b/inc/theme.inc @@ -0,0 +1,5 @@ + diff --git a/index.php b/index.php new file mode 100644 index 0000000..6aca3b6 --- /dev/null +++ b/index.php @@ -0,0 +1,88 @@ +diff(DateTime::createFromFormat("Y-m-d", "2004-01-15"))->y; +?> + + + + + + + + + +
+ +
+
+
+ +
+
Welcome
+ I'm year old programmer from Denmark +
+ + + LinkedIn + + + + GitHub + + + + GitHub + + +
+ +
+
Projects
+
+ + Popup TimerPopup Timer +
+ Have a timer or stopwatch in the corner of your screen, directly from within your browser +
+ Open in browser + +
+ + Game of lifeGame of life +
+ Conway's Game of Life created with the win32 API +
+ + Download for Windows + • + View on GitHub + + +
+ + ReimtrisReimtris +
+ A Tetris clone written in Rust with epic background music +
+ + Download for Windows + • + Download for Linux + + + + +
+ +
+
+
+ +
+ + + + + diff --git a/opener/index.php b/opener/index.php new file mode 100644 index 0000000..059c9ea --- /dev/null +++ b/opener/index.php @@ -0,0 +1,46 @@ + + + + Opener + + + + +

HTTP

+  Referer: ' . $_SERVER["HTTP_REFERER"] . '' : 'None' ?> +

JavaScript

+  window.opener: Enable JavaScript +

+  window.name: Enable JavaScript + + \ No newline at end of file diff --git a/userscripts/index.php b/userscripts/index.php new file mode 100644 index 0000000..035dc0b --- /dev/null +++ b/userscripts/index.php @@ -0,0 +1,3 @@ +