Permalink
Browse files

Refactored profile page

  • Loading branch information...
1 parent be236b7 commit 94568b88b18f5bde43aa43f4d9877761dff7b99f @toantran committed Mar 7, 2012
@@ -5,3 +5,87 @@ jQuery ($) ->
$.publish = (title, body) ->
console.log title, body
+
+
+ ###
+ Template engine
+ ###
+ el = () ->
+
+ doc = document;
+
+ directProperties =
+ 'class': 'className'
+ className: 'className'
+ defaultValue: 'defaultValue'
+ 'for': 'htmlFor'
+ html: 'innerHTML'
+ text: 'textContent'
+ value: 'value'
+
+ booleanProperties =
+ checked: 1
+ defaultChecked: 1
+ disabled: 1
+ multiple: 1
+ selected: 1
+
+ setProperty = ( el, key, value ) ->
+ console.log key, value
+ prop = directProperties[ key ]
+ if prop
+ el[ prop ] = '' + (value ? '')
+ else if booleanProperties[ key ]
+ el[ key ] = !!value
+ else if not value?
+ el.removeAttribute key
+ else
+ el.setAttribute key, '' + value
+
+
+ appendChildren = ( el, children ) ->
+ for node in children when node?
+ do (node) ->
+ if node instanceof Array
+ appendChildren el, node
+ else
+ if typeof node is 'string'
+ node = doc.createTextNode node
+ el.appendChild node
+
+
+
+ splitter = /(#|\.)/
+
+ create = ( tag, props, children ) ->
+ console.log tag, props, children
+ if props instanceof Array
+ children = props;
+ props = null;
+
+ if splitter.test( tag )
+ parts = tag.split splitter
+ tag = parts[0]
+ parts = parts[1..]
+
+ if not props?
+ props = {}
+
+ for part, index in parts by 2
+ name = parts[index + 1]
+ if part is '#'
+ props.id = name
+ else
+ props.className = if props.className then props.className + ' ' + name else name
+
+ thisEl = doc.createElement tag
+
+ if props?
+ for prop, propVal of props
+ setProperty thisEl, prop, propVal
+ if children?
+ appendChildren thisEl, children
+
+ thisEl
+
+ $.el = el()
@@ -0,0 +1,47 @@
+jQuery ($) ->
+ makethis = -> @
+
+ global = makethis.call()
+ global.setActiveMenu 5
+
+ $('.new-post button').on 'click', ->
+ profileid = $(@).attr('data-profileid')
+ userid = $(@).attr('data-userid')
+ msg = $('#newpost-msg').val()
+
+ if msg # has a post
+ $.post( "/profile/#{profileid}/addpost", { posterid: userid, msg: msg } )
+ .success (data) ->
+ if data?.success
+ post = data.post
+
+ el = $.el( 'div.row.post-panel', {postid: post.id, profileid: profileid}, [
+ $.el('a.post-close-btn'),
+ $.el('div.span1', [$.el('img', {src: post.pictureurl} if post.pictureurl)]),
+ $.el('div.span5', [
+ $.el('div.post-item', , post.desc),
+ $.el('div.postmark', ,"on #{post.createdat}"),
+ $.el('div.post-comment-list', [
+
+ $.el('div.row.new-comment', [
+ $.el('div.span5', [
+ $.el('textarea.post-text', {rows:1, placeholder:'Type your comment...'}),
+ $.el('button.btn.btn-mini.btn-primary.pull-right', {postid: post.id, profileid:profileid, posterid:userid}, [
+ $.el('i.icon-comment.icon-white'),
+ ' Post'
+ ])
+ ])
+ ])
+ ])
+ ])
+ ])
+
+ el = $(el).prependTo('.post-list').show('slow')
+
+# el.find('.post-new-comment textarea')
+# .watermark('Write something...')
+# .elastic();
+# el.find('.post-new-comment button').button();
+# el.find('.post-new-comment button').click(profile.newcommentclick);
+ $('#newpost-msg').val('')
+
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,56 @@
+(function() {
+
+ jQuery(function($) {
+ var global, makethis;
+ makethis = function() {
+ return this;
+ };
+ global = makethis.call();
+ global.setActiveMenu(5);
+ return $('.new-post button').on('click', function() {
+ var msg, profileid, userid;
+ profileid = $(this).attr('data-profileid');
+ userid = $(this).attr('data-userid');
+ msg = $('#newpost-msg').val();
+ if (msg) {
+ return $.post("/profile/" + profileid + "/addpost", {
+ posterid: userid,
+ msg: msg
+ }).success(function(data) {
+ var el, post;
+ if (data != null ? data.success : void 0) {
+ post = data.post;
+ el = $.el('div.row.post-panel', {
+ postid: post.id,
+ profileid: profileid
+ }, [
+ $.el('a.post-close-btn'), $.el('div.span1', [
+ $.el('img', post.pictureurl ? {
+ src: post.pictureurl
+ } : void 0)
+ ]), $.el('div.span5', [
+ $.el('div.post-item', post.desc), $.el('div.postmark', "on " + post.createdat), $.el('div.post-comment-list', [
+ $.el('div.row.new-comment', [
+ $.el('div.span5', [
+ $.el('textarea.post-text', {
+ rows: 1,
+ placeholder: 'Type your comment...'
+ }), $.el('button.btn.btn-mini.btn-primary.pull-right', {
+ postid: post.id,
+ profileid: profileid,
+ posterid: userid
+ }, [$.el('i.icon-comment.icon-white'), $.el(' Post')])
+ ])
+ ])
+ ])
+ ])
+ ]);
+ el = $(el).prependTo('.post-list').show('slow');
+ return $('#newpost-msg').val('');
+ }
+ });
+ }
+ });
+ });
+
+}).call(this);
@@ -55,6 +55,10 @@
border: 0;
-ms-interpolation-mode: bicubic;
}
+
+.carousel-caption h3 {
+ color: white;
+}
.news-section {
.hightlight-section;
Oops, something went wrong.

0 comments on commit 94568b8

Please sign in to comment.