I'm working with ActionScript3.0 on a basic movement engine. When I try to test my code, I get this error:
MovementClass.as, Line 44, Column 22 1084: Syntax error: expecting rightparen before colon.
I get this for lines 44, 52, 60, and 68 of the following code; these are the lines reading heroGoing<direction>(e:TimerEvent);
package {
import flash.display.*;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.TimerEvent;
public class MovementClass extends MovieClip {
var reference:Reference = new Reference();
var hero:Hero = new Hero();
var enemy:Enemy = new Enemy();
var wall:Wall = new Wall();
//Timer
var moveTimer:Timer = new Timer(25, 10)
//Booleans
var movingHeroRight:Boolean = false;
var movingHeroLeft:Boolean = false;
var movingHeroUp:Boolean = false;
var movingHeroDown:Boolean = false;
public function MovementClass() {
hero.x = stage.stageWidth * .5;
hero.y = stage.stageHeight * .5;
addChild(hero);
startEngine();
}
public function startEngine():void {
stage.addEventListener(KeyboardEvent.KEY_DOWN, movementHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, stopHandler);
}
public function movementHandler(keyDown:KeyboardEvent):void {
if (keyDown.keyCode == 39) {
if (movingHeroLeft == true, movingHeroUp == true, movingHeroDown == true) {
return;
} else {
heroGoingRight(e:TimerEvent);
movingHeroRight = true;
moveTimer.start;
}
} else if (keyDown.keyCode == 37) {
if (movingHeroRight == true, movingHeroUp == true, movingHeroDown == true) {
return;
} else {
heroGoingLeft(e:TimerEvent);
movingHeroLeft = true;
moveTimer.start;
}
} else if (keyDown.keyCode == 38) {
if (movingHeroLeft == true, movingHeroRight == true, movingHeroDown == true) {
return;
} else {
heroGoingUp(e:TimerEvent);
movingHeroUp = true;
moveTimer.start;
}
} else if (keyDown.keyCode == 40) {
if (movingHeroLeft == true, movingHeroUp == true, movingHeroRight == true) {
return;
} else {
heroGoingDown(e:TimerEvent);
movingHeroDown = true;
moveTimer.start;
}
}
//moveTimer.start();
}
function heroGoingUp(eUp:TimerEvent):void {
if (movingHeroUp == true) {
reference.y += 5;
}
}
function heroGoingDown(eDown:TimerEvent):void {
if (movingHeroDown == true) {
reference.y -= 5;
}
}
function heroGoingLeft(eLeft:TimerEvent):void {
if (movingHeroLeft == true) {
reference.x += 5;
}
}
function heroGoingRight(eRight:TimerEvent):void {
if (movingHeroRight == true) {
reference.x -= 5;
}
}
public function stopHandler(keyUp:KeyboardEvent):void {
if (movingHeroRight == true) {
movingHeroRight = false;
} else if (movingHeroLeft == true) {
movingHeroLeft = false;
} else if (movingHeroUp == true) {
movingHeroUp = false;
} else if (movingHeroDown == true) {
movingHeroDown = false;
}
}
}
}
What am I doing wrong?
The problem is with the first heroMoving call:
heroGoingRight(e:TimerEvent);
The compiler thinks you're trying to declare a variable in situ. Declare e:TimerEvent appropriately, before you use it, and you should be fine.
Related
I'm importend in my workspace, a project build in appcelerator.
So I have some error like this:
If I open any file, I have this situation:
I don't know, how to fix this.
So this is my plugin.js
"use strict";
exports.__esModule = true;
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require("babel-runtime/helpers/inherits");
var _inherits3 = _interopRequireDefault(_inherits2);
var _optionManager = require("./file/options/option-manager");
var _optionManager2 = _interopRequireDefault(_optionManager);
var _babelMessages = require("babel-messages");
var messages = _interopRequireWildcard(_babelMessages);
var _store = require("../store");
var _store2 = _interopRequireDefault(_store);
var _babelTraverse = require("babel-traverse");
var _babelTraverse2 = _interopRequireDefault(_babelTraverse);
var _assign = require("lodash/assign");
var _assign2 = _interopRequireDefault(_assign);
var _clone = require("lodash/clone");
var _clone2 = _interopRequireDefault(_clone);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint max-len: 0 */
var GLOBAL_VISITOR_PROPS = ["enter", "exit"];
var Plugin = function (_Store) {
(0, _inherits3.default)(Plugin, _Store);
function Plugin(plugin, key) {
(0, _classCallCheck3.default)(this, Plugin);
var _this = (0, _possibleConstructorReturn3.default)(this, _Store.call(this));
_this.initialized = false;
_this.raw = (0, _assign2.default)({}, plugin);
_this.key = key;
_this.manipulateOptions = _this.take("manipulateOptions");
_this.post = _this.take("post");
_this.pre = _this.take("pre");
_this.visitor = _this.normaliseVisitor((0, _clone2.default)(_this.take("visitor")) || {});
return _this;
}
Plugin.prototype.take = function take(key) {
var val = this.raw[key];
delete this.raw[key];
return val;
};
Plugin.prototype.chain = function chain(target, key) {
if (!target[key]) return this[key];
if (!this[key]) return target[key];
var fns = [target[key], this[key]];
return function () {
var val = void 0;
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
for (var _iterator = fns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var fn = _ref;
if (fn) {
var ret = fn.apply(this, args);
if (ret != null) val = ret;
}
}
return val;
};
};
Plugin.prototype.maybeInherit = function maybeInherit(loc) {
var inherits = this.take("inherits");
if (!inherits) return;
inherits = _optionManager2.default.normalisePlugin(inherits, loc, "inherits");
this.manipulateOptions = this.chain(inherits, "manipulateOptions");
this.post = this.chain(inherits, "post");
this.pre = this.chain(inherits, "pre");
this.visitor = _babelTraverse2.default.visitors.merge([inherits.visitor, this.visitor]);
};
/**
* We lazy initialise parts of a plugin that rely on contextual information such as
* position on disk and how it was specified.
*/
Plugin.prototype.init = function init(loc, i) {
if (this.initialized) return;
this.initialized = true;
this.maybeInherit(loc);
for (var key in this.raw) {
throw new Error(messages.get("pluginInvalidProperty", loc, i, key));
}
};
Plugin.prototype.normaliseVisitor = function normaliseVisitor(visitor) {
for (var _iterator2 = GLOBAL_VISITOR_PROPS, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var key = _ref2;
if (visitor[key]) {
throw new Error("Plugins aren't allowed to specify catch-all enter/exit handlers. Please target individual nodes.");
}
}
_babelTraverse2.default.explode(visitor);
return visitor;
};
return Plugin;
}(_store2.default);
exports.default = Plugin;
module.exports = exports["default"];
How can I fixed it?
import syntax is from ECMAScript 6 - which is yet to be added in the Appcelerator Studio.
https://jira.appcelerator.org/browse/TISTUD-6927
i 'm working with crm application. i developed it finally i'm getting confused how i detect new messages as per flag must have display and message not have to true.
here is my db schema for understanding problem.
here is my constructed query to get new message count :
int new_messages = 0;
foreach (var enquiry in db.Enquiries.Where(i => (i.ForwardTo.Equals(userid) || i.AttendBy.Equals(userid))).ToList())
{
if (enquiry != null)
{
bool IsIns = true;
foreach (var flag in db.Flags.Where(f => f.Enquiry_History_id.Equals(enquiry.Ref_no) && f.User_id.Equals(userid)).Select(f => new { IsDisplay = f.IsDisplay }).ToList())
{
if (flag != null)
{
if (flag.IsDisplay == false)
{
IsIns = false;
}
}
}
if (IsIns == true)
{
foreach (var message in db.Messages.Where(m => m.Enquiry_History_id.Equals(enquiry.Ref_no) && m.User_id.Equals(userid)).Select(m => new { IsRead = m.IsRead }).ToList())
{
if (message.IsRead == true)
{
//do another stuff
}
else
{
new_messages++;
}
}
}
}
}
lbl_msg.Text = new_messages.ToString();
here i have to take each enquiry that have been AttendBy or ForwardBy to user and check it first it should be display is not false and after that check as per each message should not have IsRead to true. i'm trying with my best way but this not gives me out put as i want.
i have an idea just insert two values one for true which generate message and second for false to froward. and at finding out only which have IsRead to false.
something like this way :
using (DataClassesDataContext db = new DataClassesDataContext())
{
string userid = db.Users.Where(u => u.Username.Equals((String)Session["Username"])).Select(u => u.Ref_no).SingleOrDefault().ToString();
bool IsIns = true;
foreach (var enquiry in db.Enquiries.Where(i => i.AttendBy.Equals(userid) || i.ForwardTo.Equals(userid)).ToList())
{
if (enquiry != null)
{
foreach (var flag in db.Flags.Where(f => f.Enquiry_History_id.Equals(enquiry.Ref_no) && f.User_id.Equals(userid)).Select(f => new { IsDisplay = f.IsDisplay }).ToList())
{
if (flag.IsDisplay == false)
{
IsIns = false;
}
if (IsIns == true)
{
foreach (var message in db.Messages.Where(m => m.Enquiry_History_id.Equals(enquiry.Ref_no)).ToList())
{
if (message != null)
{
bool IsIns1 = false;
foreach (var messageflag in db.MessageFlags.Where(mf => mf.MessageId.Equals(message.Id) && mf.UserId.Equals(userid)).Select(mf => new
{
IsRead = mf.IsRead,
User_id = mf.UserId,
Message = message.body,
CreatedDate = message.Created_date
}).ToList())
{
if (messageflag.IsRead == false)
{
IsIns1 = true;
}
if (IsIns1 == true)
{
DataRow dr = dt.NewRow();
dr["Ref_no"] = enquiry.Ref_no.ToString();
dr["Name"] = db.Users.Where(u => u.Ref_no.Equals(messageflag.User_id)).Select(u => u.FirstName + ' ' + u.LastName).SingleOrDefault().ToString();
dr["UserId"] = db.Users.Where(u => u.Ref_no.Equals(messageflag.User_id)).Select(u => u.Ref_no).SingleOrDefault().ToString();
dr["Message"] = messageflag.Message.ToString();
dr["CreatedDate"] = messageflag.CreatedDate.ToString();
dt.Rows.Add(dr);
}
}
}
}
}
}
}
}
myDataSet.Tables.Add(dt);
lbl_count_messages.Text = myDataSet.Tables[0].Rows.Count.ToString();
if (myDataSet.Tables[0].Rows.Count == 0)
{
message_alert.Visible = false;
}
Repeater_Messages.DataSource = myDataSet;
Repeater_Messages.DataBind();
}
I got JqGrid with modified cellEdit ( full up-down-left-right cell navigation ).
Here is bits of jqgrid.src:
if (e.keyCode === 37) {
if(!$t.grid.hDiv.loading ) {
{$($t).jqGrid("prevCell",iRow,iCol);} //left
} else {
return false;
}
}
if (e.keyCode === 39) {
if(!$t.grid.hDiv.loading ) {
{$($t).jqGrid("nextCell",iRow,iCol);} //right
} else {
return false;
}
}
if (e.keyCode === 38) {
if(!$t.grid.hDiv.loading ) {
{$($t).jqGrid("prevRow",iRow,iCol);} //up
} else {
return false;
}
}
if (e.keyCode === 40) {
if(!$t.grid.hDiv.loading ) {
{$($t).jqGrid("nextRow",iRow,iCol);} //down
} else {
return false;
}
}
and others
nextCell : function (iRow,iCol) {
return this.each(function (){
var $t = this, nCol=false, i;
if (!$t.grid || $t.p.cellEdit !== true) {return;}
// try to find next editable cell
for (i=iCol+1; i<$t.p.colModel.length; i++) {
if ($t.p.colModel[i].editable ===true && $t.p.colModel[i].hidden !== true ) {
//alert($t.p.colModel[i-1].hidden);
nCol = i; break;
}
}
if(nCol !== false) {
$($t).jqGrid("editCell",iRow,nCol,true);
} else {
if ($t.p.savedRow.length >0) {
$($t).jqGrid("saveCell",iRow,iCol);
}
}
});
},
prevCell : function (iRow,iCol) {
return this.each(function (){
var $t = this, nCol=false, i;
if (!$t.grid || $t.p.cellEdit !== true) {return;}
// try to find next editable cell
for (i=iCol-1; i>=0; i--) {
if ($t.p.colModel[i].editable ===true && $t.p.colModel[i].hidden !== true ) {
nCol = i; break;
}
}
if(nCol !== false) {
$($t).jqGrid("editCell",iRow,nCol,true);
} else {
if ($t.p.savedRow.length >0) {
$($t).jqGrid("saveCell",iRow,iCol);
}
}
});
},
prevRow : function (iRow,iCol) {
return this.each(function (){
var $t = this, nCol=false, i;
if (!$t.grid || $t.p.cellEdit !== true) {return;}
// try to find next editable cell
iRow--;
iCol++;
for (i=iCol-1; i>=0; i--) {
if ( $t.p.colModel[i].editable ===true) {
nCol = i; break;
}
}
if(nCol !== false) {
$($t).jqGrid("editCell",iRow,nCol,true);
} else {
if ($t.p.savedRow.length >0) {
$($t).jqGrid("saveCell",iRow,iCol);
}
}
});
},
nextRow : function (iRow,iCol) {
return this.each(function (){
var $t = this, nCol=false, i;
if (!$t.grid || $t.p.cellEdit !== true) {return;}
// try to find next editable cell
iRow++;
iCol++;
for (i=iCol-1; i>=0; i--) {
if ( $t.p.colModel[i].editable ===true) {
nCol = i; break;
}
}
if(nCol !== false) {
$($t).jqGrid("editCell",iRow,nCol,true);
} else {
if ($t.p.savedRow.length >0) {
$($t).jqGrid("saveCell",iRow,iCol);
}
}
});
}
Also i got autocomplete working with JqGrid event afterEditCell:
getautocompl = function(rowid,cellname,value,iRow,iCol){
setTimeout(function() { $("#"+iRow+"_"+cellname).select().focus();},10);
if(cellname!=='date_factory' || cellname!=='date_otgr_factory' || cellname!=='date_shipment' || cellname!=='date_sklad' || cellname!=='kolinkor'
|| cellname!=='kolkor' || cellname!=='kol_quantity' || cellname!=='description') {
$("#"+iRow+"_"+cellname).autocomplete({
source:"../../phpmon/autocomplete.php?fname="+cellname,
delay:250,
minLength: 2});
}
}
Problem here is that i cant manage autocomplete hotkeys to work, when i hit "down" button it just goes to next cell, rather then to any of the autocomplete options.
you could suppress jqgrid navigation when autocomplete element is visible. something like:
$(document).keydown(function( fn ){
var key = fn.keyCode;
if( $("#autocomplete") && key == 40)
/* your autocomplete action*/
});
Its not quite what i needed, but it helped me to make it.
I just modified jqgrid source code like this :
if (e.keyCode === 40) {
if(!$t.grid.hDiv.loading ) {
if ($('.ui-menu-item').length < 1) {
{$($t).jqGrid("nextRow",iRow,iCol);} //down
}
} else {
return false;
}
}
Where .ui-menu-item is class of autocomplete widget.
thk a lot
I'm new to Flash and AS3 and I'm trying to make an image gallery. For some reason it .. doesn't do anything.
I have 2 buttons: back & next and a Dynamic Text field for loading progress. zonaAfisare_mc is the container for the images.
It doesn't load any image, here's the code:
import flash.events.*;
import flash.display.*;
import flash.net.*;
var source:*;
var loader:Loader;
var loaderIndex:Number = 1;
next.addEventListener(MouseEvent.CLICK, loadNext);
back.addEventListener(MouseEvent.CLICK, loadPrev);
function loadIt()
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onLoadingProgress);
loader.contentLoaderInfo.addEventListener(Event.INIT,initHandler);
addChild(loader);
loadImage();
}
function initHandler(event:Event):void
{
source = loader.content;
source.alpha = 0;
source.x = zonaAfisare_mc.x;
source.y = zonaAfisare_mc.y;
addEventListener(Event.ENTER_FRAME,enterFrameHandler);
}
function onLoadingProgress(evt:ProgressEvent):void{
var percentage:Number=(evt.bytesLoaded/evt.bytesTotal)*100;
var total_percentage:Number=Math.floor(percentage);
loaded.text=total_percentage.toString()+" %";
}
function loadNext(event:Event):void
{
if (loaderIndex = 5) {
loaderIndex = 1
loadImage();
} else {
loaderIndex = loaderIndex + 1;
loadImage();
}
}
function loadPrev(event:Event):void
{
if (loaderIndex = 1) {
loadImage();
} else {
loaderIndex = loaderIndex - 1;
loadImage();
}
}
function enterFrameHandler(event:Event):void
{
if( source.alpha < 1 ){
source.alpha += .1;
}else{
removeEventListener(Event.ENTER_FRAME,enterFrameHandler);
}
}
function getPath():String
{
return ("images/image"+loaderIndex+".jpg");
}
function loadImage():void
{
loader.load(new URLRequest(getPath()));
}
loadIt();
I have asked a question like this before, and the answer was great but the more I looked at my code the more confused I got, and after 10hrs my brain is shot and I'm in need of help. So all my content is loaded dynamically via Jquery's $.post and loaded into #content-container. Now I included my entire Jquery file to show you why I am getting so confused as how to get this to work without re-writing all the code. As you can see, and what I'm thinking, is that the history plugins such as BBQ, and history.js seem to be out of the question because I don't use anchor tags and the multitude of .live('click', funcition() { I have use different classes and id's for various reasons. I also believe that rules out using the hash and linking it to a single class via .trigger(), executing the AJAX(hope that makes sense). The only option I have left is actually kinda my question. Would it be possible to load the dynamic content into #content-container still using the $.post with $.load() or window.location and actually have the previous content loaded when the browser back button is clicked.
I greatly appreciate the help, really.....
$(document).ready(function() {
$(window).load(function () {
});
$('#map').hide();
$('#informational-container').hide();
$('.clickable').click(function(){
$('#map').hide();
});
function getTotalDealCount() {
$.post('../service/service.getTotalDealCount.php', {}, function(data) {
if(data.success) $('#deal-counter').append(data.results);
}, 'json');
return false;
}
function loadMap(lat, lon) {
var latlng = new google.maps.LatLng(lat, lon);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map
});
}
function getLatLon(address, zipcode) {
$.post('../service/service.getLatLon.php', { address: address, zipcode: zipcode }, function(data) {
if(data.success) {
var res = data.results;
var coordinates = res.split('_');
loadMap(coordinates[0], coordinates[1]);
} else {
return false;
}
}, 'json');
return false;
}
function getAddressZipcode(id) {
$.post('../service/service.getAddressZipcode.php', { id: id }, function(data) {
if(data.success) {
var res = data.results;
var location = res.split('_');
getLatLon(location[0], location[1]);
} else {
return -1;
}
}, 'json');
return false;
}
$('#how-it-works').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m1');
});
$('#why-post-a-deal').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m2');
});
$('#who-are-we').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m3');
});
$('#contact-us').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m4');
});
$('#post-deal-img').live('click', function() {
$('#content-container').load('post.php');
});
$('.post-deal-inputs').live('click', function() {
$('.post-deal-inputs').live('click', function(e) {
$(this).val('');
$(this).removeClass('post-deal-inputs')
.addClass('post-deal-inputs-clicked');
});
});
$('#df5').live('click', function() {
$('#df7').val('');
$('#df7').hide();
});
$('#df6').live('click', function() {
$('#df7').show();
});
$('#post-how-to-link').live('click', function() {
apprise();
});
$('#terms').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m5');
});
$('#disclaimer').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m6');
});
$('#post-deal-button').live('click', function() {
var dealForm = $('#deal-form').serialize();
var company = $('#df1').val();
var description = $('#df2').val();
var zipcode = $('#df4').val();
var starts = $('#df7').val();
var ends = $('#df8').val();
if(company == '' || company == 'Company') {
apprise('A company name is required!');
return false;
}
if(description == '' || description == 'Deal') {
apprise('A deal is required!');
return false;
}
var swear = swearFilter(description);
if(swear != false) {
apprise('Please remove the naughty word `' + swear + '` from your deal.');
return false;
}
if(zipcode == '' || zipcode == 'Zipcode') {
apprise('A zipcode is required!');
return false;
}
if($('#df7').is(':visible') && typeof(ends) != 'undefined') {
var res = validateDate(starts);
if(res == false) {
apprise('Please select a valid start date!');
return false;
}
}
if(typeof(ends) != 'undefined') {
var res = validateDate(ends);
if(res == false) {
apprise('Please select a valid end date!');
return false;
}
}
if(ends == '') {
apprise('A deal end date is required!');
return false;
}
if($('#df7').is(':visible') && $('#df7').val() == '') {
apprise('If its not a one day sale a start date is required!');
return false
}
$.post('../service/service.postDeal.php', { dealForm: dealForm }, function(data) {
if(data.success == true) {
apprise('Your deal has been posted, thank you!');
window.location = '../root/index.php';
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured and your deal has not been posted. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('The zipcode you supplied was not in our database. Please enter the city ' +
'and state/province in the following prompts to add your location.' , {'confirm':true}, function() {
insertNewLocation(zipcode);
});
}
if(data.fail == 3) {
apprise('A zipcode is required!');
}
}
}, 'json');
return false;
});
function validateDate(string) {
if(string.toLowerCase().indexOf('-') >= 0) {
var dateArray = string.split('-');
var year = dateArray[0], month = dateArray[1], day = dateArray[2];
if(year.length == 4 && month.length == 2 && day.length == 2) return true;
else return false;
}
return false;
}
function swearFilter(string) {
var ret = false;
var filter = [];
var stringArray = string.split(' ');
for(var i = 0; i < stringArray.length; i++) {
if(jQuery.inArray(stringArray[i], filter) > -1) {
ret = stringArray[i];
break;
}
}
return ret;
}
function insertNewLocation(zipcode) {
var city = '';
var state = '';
if (/[^a-zA-Z 0-9]+/g.test(zipcode)) {
apprise('The zipcode should contain only numbers, letters or both!');
return false;
}
apprise('Enter the name of the city:', {'input':true}, function(_city_) {
if(/[^a-zA-Z]+/g.test(_city_)) {
apprise('The city should contain only letters!');
return false;
}
city = _city_;
apprise('Enter the state in 2 letter abbreviated format:', {'input':true}, function(_state_) {
if (/[^a-zA-Z]+/g.test(_state_)) {
apprise('The state should contain only letters');
return false;
}
if(_state_.length > 2) {
apprise('The state should only be 2 letters in length');
}
state = _state_;
$.post('../service/service.insertNewLocation.php', { city: city, state: state, zipcode: zipcode }, function(data) {
if(data.success == true) {
apprise('Thank you, you may now submit you deal!');
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured and your location has not been added to our database. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('A zipcode is required!');
return false;
}
}
}, 'json');
return false;
});
});
}
$('#search-type-button').live('click', function() {
var search = $('#search-type-text').val();
var keyword = $('#keyword-type-text').val();
if(search == '') {
apprise('A zipcode or city and state combo to search for deals in your area!');
return false;
}
if(keyword == 'Keyword') {
apprise('If you want to add a keyword to you deal, make sure its unique!');
return false;
}
$.post('../service/service.loadDealsByCityOrZipcode.php', { search: search, keyword: keyword }, function(data) {
if(data.success) {
$('#content-container').html(data.results);
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured locating the deals. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('There are no deals within the zipcode you provided, be the first to add one!');
return false;
}
if(data.fail == 3) {
apprise('There are no deals matching the tag you supplied!');
return false;
}
if(data.fail == 4) {
apprise('A zipcode or city and state combo to search for deals in your area!');
return false;
}
}
}, 'json');
return false;
});
$('.deals-queried-deal').live('click', function() {
var id = this.id;
$('#comment-link').show();
$.post('../service/service.loadDealDescription.php', { id: id }, function(data) {
if(data.success == true) {
$('#content-container').html(data.results);
var res = getAddressZipcode(id);
if(res != -1) $('#map').show();
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured loading the deal you selected. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
} else if(data.fail == 2) {
apprise('The deal you selected does not exist! ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
} else if(data.fail == 3) {
apprise('An error has occured loading the deal you selected. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
}
}
}, 'json');
return false;
});
$('.vote-down').live('click', function() {
var id = this.id;
var vote = 0;
$.post('../service/service.tallyVote.php', { id: id, vote: vote }, function(data) {
if(data.success == true) {
apprise('Thank you for your vote!');
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured when voting for this deal. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('You have already voted for this deal!');
return false;
}
}
}, 'json');
return false;
});
$('.vote-up').live('click', function() {
var id = this.id;
var vote = 1;
$.post('../service/service.tallyVote.php', { id: id, vote: vote }, function(data) {
if(data.success == true) {
apprise('Thank you for your vote!');
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured when voting for this deal. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('You have already voted for this deal!');
return false;
}
}
}, 'json');
return false;
});
$('#email-button').live('click', function() {
var emailAddress = $('.email-textbox').val();
var from = $('#from-textbox').val();
var message = $('#email-div').html();
var atpos = emailAddress.indexOf("#");
var dotpos = emailAddress.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= emailAddress.length) {
apprise('Please enter a valid email address!');
return false;
}
if(emailAddress == '') {
apprise('An email address is required!');
return false;
}
if(from == '') {
apprise('Your name is required!');
return false;
}
$.post('../service/service.emailDeal.php', { emailAddress: emailAddress, from: from, message: message}, function(data) {
if(data.success == true) {
apprise('The deal has been sent, we hope they enjoy it!');
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured sending the email. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('An email address is required!');
return false;
}
}
}, 'json');
return false;
});
$('.comment-link').live('click', function() {
var id = this.id;
$.post('../service/service.loadComments.php', { id: id }, function(data) {
if(data.success == true) {
$('#content-container').html(data.results);
return true;
}
if(data.success == false) {
apprise('An error has occured retrieving the comments for this deal. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
}, 'json');
return false;
});
$('.post-comment-button').live('click', function() {
var id = this.id;
var comment = $('#comment-textarea').val();
var author = $('#post-comment-whois').val();
var swear = swearFilter(comment);
if(swear == true) {
apprise('Please remove the word "' + swear + '" from your comment.');
return false;
}
if(comment == '') {
apprise('Please fill out a comment first!');
return false;
}
$.post('../service/service.postComment.php', { id: id, comment: comment, author: author }, function(data) {
if(data.success == true) {
$.post('../service/service.loadComments.php', { id: id }, function(data) {
if(data.success == true) {
$('#content-container').html(data.results);
return true;
}
if(data.success == false) {
apprise('An error has occured retrieving the comments for this deal. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
}, 'json');
return false;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured while attempting to post your comment. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('Please fill out a comment first!');
return false;
}
}
}, 'json');
return false;
});
});`
Use history.js to pushState and then window.history.back()