Skip to content

Instantly share code, notes, and snippets.

View abachuk's full-sized avatar
✍️
dev manager by day, writing code at night

Alex Bachuk abachuk

✍️
dev manager by day, writing code at night
View GitHub Profile
<!-- Main script file -->
<!-- when JSON object is received it's passed to template (id of script tag) -->
<!-- posts in the end is JSON object we received from AJAX -->
var template = _.template( $("#posts_template").html(), posts );
<!-- in HTML document -->
<!-- emplty placeholder -->
<div id="posts-container"></div>
<!-- compiled template adds html to empty placeholder -->
var template = _.template($('#template-in-script').html());
$('#placeholder-container').html(template(data));
@abachuk
abachuk / deferred-example.js
Created June 12, 2013 16:07
jquery deferred
var dfd = $.Deferred();
var endpoint = $.ajax({
url: 'http://yourdomain.com/data.json',
sucess: dfd.resolve
});
endpoint.success(function(data){console.log(data)});
@abachuk
abachuk / wppb.login.php
Last active December 18, 2015 02:58
WP User Frontend Login with Email
<?php
/* wp_signon can only be executed before anything is outputed in the page because of that we're adding it to the init hook */
global $wppb_login;
$wppb_login = false;
function wppb_signon(){
global $error;
global $wppb_login;
@abachuk
abachuk / gist:5658751
Created May 27, 2013 19:41
getting blog posts with ajax request in JSON format
blog: function(){
$.ajax({
url: 'http://alexbachuk.com/api/get_recent_posts/',
type: 'GET',
dataType: 'json',
success: function(data){
console.log(data);
},
error: function(data){
console.log(data);
@abachuk
abachuk / ajax polling
Created May 1, 2013 19:43
Ajax Polling
(function(exports, document, $) {
var window = exports;
var RecentGiftsController = function(mediator) {
var mediator = mediator;
var pollingProcess = null;
var url = '/ajax/get-recent-gifts';
var buffer = [];
@abachuk
abachuk / Phonegap + jQuery Mobile + android.js
Last active January 2, 2017 21:29
Phonegap + jQuery Mobile + android
/// PHONEGAP + jQUERY MOBILE (page from android app)
$(document).on("pageinit", ".ui-page", function () {
$('input').focus(function(){
$('#signin-footer').hide();
});
$('input').blur(function(){
$('#signin-footer').show();
})
@abachuk
abachuk / gist:5485177
Last active December 16, 2015 19:29
WordPress + Backbone
//NAMESPCING APP
var App = {
Models : {},
Collections: {},
Views: {},
Router: {}
};
//DECLARING MODEL
App.Models.Post = Backbone.Model.extend({});
@abachuk
abachuk / gist:4703394
Last active December 12, 2015 02:58
meta box code example
$meta_boxes[] = array(
'id' => 'home_page_metabox2',
'title' => 'Preview',
'pages' => array( 'page', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'show_on' => array( 'key' => 'page-template', 'value' => 'page_home.php' ),
'fields' => array(
array(
@abachuk
abachuk / gist:4478258
Created January 7, 2013 20:49
Outlook background image hack
<!--[if gte mso 9]>
<v:image xmlns:v="urn:schemas-microsoft-com:vml" id="theImage" style='behavior: url(#default#VML); display: inline-block; position: absolute; width: 374px; height: 246px; top: 0; left: 130px; border: 0; z-index: 1;' src="/imgs/myPhoto.png" />
<v:shape xmlns:v="urn:schemas-microsoft-com:vml" id="theText" style='behavior: url(#default#VML); display: inline-block; position: absolute; width: 374px; height: 246px; top: -5; left: 125px; border: 0; z-index: 2;'>
<div>
<![endif]-->
<table style="background: /imgs/myPhoto.png”>
</table>
<!--[if gte mso 9]>
</div>
</v:shape>